Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions opennow-qt/src/app/AppController.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -493,6 +493,10 @@ void AppController::restoreWindowGeometry(QWindow *window, const QRect &saved,
bool hasPosition) const
{
if (!window || saved.isEmpty()) return;
// gamescope shows one application at a time and scales its window to
// the output; a saved desktop-sized window would be letterboxed and
// upscaled. ApplicationStartup opens fullscreen there instead.
if (!qEnvironmentVariableIsEmpty("GAMESCOPE_WAYLAND_DISPLAY")) return;
QList<QRect> screens;
for (const auto *screen : QGuiApplication::screens())
screens.append(screen->availableGeometry());
Expand Down
10 changes: 8 additions & 2 deletions opennow-qt/src/app/ApplicationStartup.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -436,8 +436,14 @@ static int runApplicationSession(int argc, char *argv[], QString &restartExecuta
}
#endif
if (acceptance->prepareWindow() != EXIT_SUCCESS) return EXIT_FAILURE;
if (rootWindow && arguments.contains(u"--fullscreen"_s)) rootWindow->showFullScreen();
else if (rootWindow && !rootWindow->isVisible()) rootWindow->show();
// Under gamescope the window is the whole screen (see
// AppController::restoreWindowGeometry); fullscreen states that, so the
// window matches the output instead of being scaled from a saved size.
if (rootWindow && (arguments.contains(u"--fullscreen"_s)
|| !qEnvironmentVariableIsEmpty("GAMESCOPE_WAYLAND_DISPLAY")))
rootWindow->showFullScreen();
else if (rootWindow && !rootWindow->isVisible())
rootWindow->show();
const auto qmlReadyMs = startupTimer.elapsed();
controller.handleArguments(arguments);
QObject::connect(&controller, &AppController::activationRequested,
Expand Down
3 changes: 2 additions & 1 deletion opennow-qt/src/streaming/StreamVideoItem.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -85,9 +85,10 @@ StreamVideoItem::StreamVideoItem(std::unique_ptr<MacPointerCapture> pointerCaptu
});
connect(this, &QQuickItem::visibleChanged, this, &StreamVideoItem::updateSwapGate,
Qt::UniqueConnection);
connect(this, &QQuickItem::enabledChanged, this, &StreamVideoItem::syncCaptureState);
if (s_nativeRuntime) {
m_relativeMouse = m_usesMacPointerCapture ? m_macPointerLockEnabled
: s_nativeRuntime->defaultRelativeMouse();
: defaultRelativeMouse();
m_decodedVideoSize = s_nativeRuntime->decodedDisplaySize();
refreshVideoSize();
connect(s_nativeRuntime, &NativeStreamRuntime::decodedDisplaySizeChanged, this,
Expand Down
6 changes: 6 additions & 0 deletions opennow-qt/src/streaming/StreamVideoItem.h
Original file line number Diff line number Diff line change
Expand Up @@ -207,6 +207,7 @@ class StreamVideoItem : public QQuickItem

void applyRemoteCursor(const QByteArray &bytes);
void resetRemoteCursor();
[[nodiscard]] bool defaultRelativeMouse() const;
void setRemoteCursorShape(const QCursor &cursor);
void updateLocalCursor();
void refreshVideoSize();
Expand Down Expand Up @@ -278,6 +279,11 @@ class StreamVideoItem : public QQuickItem
bool m_cursorConfined = false;
bool m_nativeWindowMoveLoop = false;
std::unique_ptr<class WindowsWindowMoveLoop> m_windowsWindowMoveLoop;
// Under gamescope (SteamOS game mode, handhelds) this is the only, always
// fullscreen client and input comes from a controller or a touchscreen,
// so nothing gives Qt focus back to the video after an overlay closes
// (see syncCaptureState()).
const bool m_gamescopeSession = !qEnvironmentVariableIsEmpty("GAMESCOPE_WAYLAND_DISPLAY");
bool m_remoteCursorKnown = false;
bool m_serverCursorComposited = true;
bool m_remoteCursorVisible = false;
Expand Down
21 changes: 17 additions & 4 deletions opennow-qt/src/streaming/StreamVideoItemInput.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -974,9 +974,16 @@ void StreamVideoItem::setNativeWindowMoveLoop(bool active)

void StreamVideoItem::syncCaptureState()
{
auto desired = m_inputEnabled && !m_nativeWindowMoveLoop && isVisible() && hasActiveFocus()
&& window() && window()->isActive() && s_nativeRuntime && s_nativeRuntime->running()
&& s_nativeRuntime->inputAllowed();
// Under gamescope nothing hands the focus back to the video after an
// overlay closes, because no mouse click lands on it and controller input
// is dropped meanwhile. Take it whenever the window is active; another
// window on top (a sign-in browser) still stops capture, and so does a
// disabled item (the launch cover).
const bool focused = window() && window()->isActive()
&& (hasActiveFocus() || (m_gamescopeSession && isEnabled()));
auto desired = m_inputEnabled && !m_nativeWindowMoveLoop && isVisible() && focused
&& s_nativeRuntime && s_nativeRuntime->running() && s_nativeRuntime->inputAllowed();
if (desired && m_gamescopeSession && !hasActiveFocus()) forceActiveFocus(Qt::OtherFocusReason);
if (m_captureActive && (!desired || (WaylandPointerCapture::isWayland()
&& m_relativeMouse && !m_waylandPointer->locked())
|| (m_usesMacPointerCapture && m_relativeMouse && !m_macPointer->locked())))
Expand Down Expand Up @@ -1176,14 +1183,20 @@ void StreamVideoItem::updateLocalCursor()
setCursor(m_remoteCursor);
}

bool StreamVideoItem::defaultRelativeMouse() const
{
// gamescope starts absolute so taps and the server-drawn cursor line up.
return s_nativeRuntime && s_nativeRuntime->defaultRelativeMouse() && !m_gamescopeSession;
}

void StreamVideoItem::resetRemoteCursor()
{
m_remoteCursorKnown = false;
m_remoteCursorVisible = false;
m_serverCursorComposited = s_nativeRuntime ? s_nativeRuntime->serverCursorComposited() : true;
m_remoteCursor = QCursor();
setRelativeMouse(m_usesMacPointerCapture ? m_macPointerLockEnabled
: m_manualRelativeMouse.value_or(s_nativeRuntime && s_nativeRuntime->defaultRelativeMouse()));
: m_manualRelativeMouse.value_or(defaultRelativeMouse()));
updateLocalCursor();
}

Expand Down
63 changes: 63 additions & 0 deletions opennow-qt/tests/tst_streamvideoitem.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -346,6 +346,69 @@ private slots:
}
}

void gamescopeSessionCapturesWithoutItemFocus()
{
CursorSession session;
QVERIFY(session.start(QStringLiteral("nvst")));
qputenv("GAMESCOPE_WAYLAND_DISPLAY", "gamescope-0");
auto clearSession = qScopeGuard([] { qunsetenv("GAMESCOPE_WAYLAND_DISPLAY"); });
StreamVideoItem item(std::make_unique<MacPointerCapture>(), false, session.window.contentItem());
item.setRenderCallback({});
QTRY_VERIFY(session.window.isActive());
item.setSize(session.window.size());
item.setVideoSize(QSize(1920, 1080));
// No forceActiveFocus(): an overlay that closed left the focus elsewhere.
item.setInputEnabled(false);
item.setInputEnabled(true);
QTRY_VERIFY(item.captureActive());
QVERIFY(item.hasActiveFocus());
item.setInputEnabled(false);
QVERIFY(!item.captureActive());
}

void gamescopeSessionKeepsDisabledItemOutOfCapture()
{
CursorSession session;
QVERIFY(session.start(QStringLiteral("nvst")));
qputenv("GAMESCOPE_WAYLAND_DISPLAY", "gamescope-0");
auto clearSession = qScopeGuard([] { qunsetenv("GAMESCOPE_WAYLAND_DISPLAY"); });
StreamVideoItem item(std::make_unique<MacPointerCapture>(), false, session.window.contentItem());
item.setRenderCallback({});
item.setEnabled(false); // the launch cover
QTRY_VERIFY(session.window.isActive());
item.setSize(session.window.size());
item.setInputEnabled(false);
item.setInputEnabled(true);
QVERIFY(!item.captureActive());
QVERIFY(!item.hasActiveFocus());
item.setEnabled(true);
QTRY_VERIFY(item.captureActive());
QVERIFY(item.hasActiveFocus());
}

void gamescopeSessionKeepsAbsoluteMouseWhenTheDefaultChanges()
{
CursorSession session;
QVERIFY(session.start(QStringLiteral("nvst")));
qputenv("GAMESCOPE_WAYLAND_DISPLAY", "gamescope-0");
auto clearSession = qScopeGuard([] { qunsetenv("GAMESCOPE_WAYLAND_DISPLAY"); });
StreamVideoItem item(std::make_unique<MacPointerCapture>(), false, session.window.contentItem());
item.setRenderCallback({});
QVERIFY(!item.relativeMouse());
QVERIFY(session.runtime.send({{QStringLiteral("type"), QStringLiteral("start")},
{QStringLiteral("id"), QStringLiteral("webrtc-restart")}}));
const QByteArray ready = R"({"id":"webrtc-restart","type":"ok","transport":"webrtc"})";
CursorSession::callbacks.response_callback(
reinterpret_cast<const std::uint8_t *>(ready.constData()), ready.size(),
CursorSession::callbacks.user_data);
QTRY_VERIFY(session.runtime.defaultRelativeMouse());
QVERIFY(!item.relativeMouse());
item.togglePointerLock();
QVERIFY(item.relativeMouse());
item.resetRemoteCursor();
QVERIFY(item.relativeMouse());
}

void clipboardPasteRouting_data()
{
QTest::addColumn<bool>("fullscreen");
Expand Down