From 45f6a0379a8d607768a191b4894d85a0795a62f9 Mon Sep 17 00:00:00 2001 From: Daniil Teterin Date: Thu, 5 Nov 2026 21:54:59 +0100 Subject: [PATCH 1/2] fix(qt): keep input and the window working in a gamescope session Under gamescope (SteamOS game mode, handhelds) OpenNOW is the only, always fullscreen client and input comes from a controller or a touchscreen. - Capture required Qt focus on the video item, and nothing gave it back after an overlay closed: no mouse click lands on the video, and controller input is dropped meanwhile. Take the focus whenever the window is active. - A saved desktop window size was letterboxed and upscaled. Skip the saved geometry and open fullscreen. - The mouse stays absolute by default, so taps and the server-drawn cursor line up. Co-Authored-By: Claude Opus 5.5 --- opennow-qt/src/app/AppController.cpp | 4 ++++ opennow-qt/src/app/ApplicationStartup.cpp | 10 ++++++++-- opennow-qt/src/streaming/StreamVideoItem.cpp | 5 +++-- opennow-qt/src/streaming/StreamVideoItem.h | 5 +++++ .../src/streaming/StreamVideoItemInput.cpp | 11 +++++++--- opennow-qt/tests/tst_streamvideoitem.cpp | 20 +++++++++++++++++++ 6 files changed, 48 insertions(+), 7 deletions(-) diff --git a/opennow-qt/src/app/AppController.cpp b/opennow-qt/src/app/AppController.cpp index 6adfcc2bc..afc9e06aa 100644 --- a/opennow-qt/src/app/AppController.cpp +++ b/opennow-qt/src/app/AppController.cpp @@ -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 screens; for (const auto *screen : QGuiApplication::screens()) screens.append(screen->availableGeometry()); diff --git a/opennow-qt/src/app/ApplicationStartup.cpp b/opennow-qt/src/app/ApplicationStartup.cpp index 97c6878e8..8b168df56 100644 --- a/opennow-qt/src/app/ApplicationStartup.cpp +++ b/opennow-qt/src/app/ApplicationStartup.cpp @@ -411,8 +411,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, diff --git a/opennow-qt/src/streaming/StreamVideoItem.cpp b/opennow-qt/src/streaming/StreamVideoItem.cpp index c6c0fede6..cfbd49c65 100644 --- a/opennow-qt/src/streaming/StreamVideoItem.cpp +++ b/opennow-qt/src/streaming/StreamVideoItem.cpp @@ -85,8 +85,9 @@ StreamVideoItem::StreamVideoItem(std::unique_ptr pointerCaptu connect(this, &QQuickItem::visibleChanged, this, &StreamVideoItem::updateSwapGate, Qt::UniqueConnection); if (s_nativeRuntime) { - m_relativeMouse = m_usesMacPointerCapture ? m_macPointerLockEnabled - : s_nativeRuntime->defaultRelativeMouse(); + m_relativeMouse = m_usesMacPointerCapture + ? m_macPointerLockEnabled + : s_nativeRuntime->defaultRelativeMouse() && !m_gamescopeSession; m_decodedVideoSize = s_nativeRuntime->decodedDisplaySize(); refreshVideoSize(); connect(s_nativeRuntime, &NativeStreamRuntime::decodedDisplaySizeChanged, this, diff --git a/opennow-qt/src/streaming/StreamVideoItem.h b/opennow-qt/src/streaming/StreamVideoItem.h index 92647646b..6da26d051 100644 --- a/opennow-qt/src/streaming/StreamVideoItem.h +++ b/opennow-qt/src/streaming/StreamVideoItem.h @@ -262,6 +262,11 @@ class StreamVideoItem : public QQuickItem bool m_cursorConfined = false; bool m_nativeWindowMoveLoop = false; std::unique_ptr 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; diff --git a/opennow-qt/src/streaming/StreamVideoItemInput.cpp b/opennow-qt/src/streaming/StreamVideoItemInput.cpp index 8c0c4c7aa..27a440cad 100644 --- a/opennow-qt/src/streaming/StreamVideoItemInput.cpp +++ b/opennow-qt/src/streaming/StreamVideoItemInput.cpp @@ -934,9 +934,14 @@ 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. + const bool focused = window() && window()->isActive() && (hasActiveFocus() || m_gamescopeSession); + 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()))) diff --git a/opennow-qt/tests/tst_streamvideoitem.cpp b/opennow-qt/tests/tst_streamvideoitem.cpp index c83dc7dbb..f8f1a3ac6 100644 --- a/opennow-qt/tests/tst_streamvideoitem.cpp +++ b/opennow-qt/tests/tst_streamvideoitem.cpp @@ -346,6 +346,26 @@ 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(), 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 clipboardPasteRouting_data() { QTest::addColumn("fullscreen"); From 8f61d9ee9de0eee596ed205481ab4580b3603620 Mon Sep 17 00:00:00 2001 From: TheWeaklessOne Date: Thu, 5 Nov 2026 23:52:24 +0100 Subject: [PATCH 2/2] fix(qt): honour the launch cover and the gamescope mouse default Under gamescope the capture path no longer waits for item focus, so a disabled item behind the launch cover took input while the user still saw "Connecting to your game". Require the item to be enabled, and resync when that changes. Accepting a WebRTC session resets the cursor to the runtime default, which switched the item back to relative mode. Apply the gamescope default in that path too; an explicit pointer-lock choice still wins. Co-Authored-By: Claude Opus 5.5 --- opennow-qt/src/streaming/StreamVideoItem.cpp | 6 +-- opennow-qt/src/streaming/StreamVideoItem.h | 1 + .../src/streaming/StreamVideoItemInput.cpp | 14 ++++-- opennow-qt/tests/tst_streamvideoitem.cpp | 43 +++++++++++++++++++ 4 files changed, 58 insertions(+), 6 deletions(-) diff --git a/opennow-qt/src/streaming/StreamVideoItem.cpp b/opennow-qt/src/streaming/StreamVideoItem.cpp index cfbd49c65..e1e7c91d9 100644 --- a/opennow-qt/src/streaming/StreamVideoItem.cpp +++ b/opennow-qt/src/streaming/StreamVideoItem.cpp @@ -84,10 +84,10 @@ StreamVideoItem::StreamVideoItem(std::unique_ptr 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() && !m_gamescopeSession; + m_relativeMouse = m_usesMacPointerCapture ? m_macPointerLockEnabled + : defaultRelativeMouse(); m_decodedVideoSize = s_nativeRuntime->decodedDisplaySize(); refreshVideoSize(); connect(s_nativeRuntime, &NativeStreamRuntime::decodedDisplaySizeChanged, this, diff --git a/opennow-qt/src/streaming/StreamVideoItem.h b/opennow-qt/src/streaming/StreamVideoItem.h index 6da26d051..1036d7166 100644 --- a/opennow-qt/src/streaming/StreamVideoItem.h +++ b/opennow-qt/src/streaming/StreamVideoItem.h @@ -196,6 +196,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(); diff --git a/opennow-qt/src/streaming/StreamVideoItemInput.cpp b/opennow-qt/src/streaming/StreamVideoItemInput.cpp index 27a440cad..b3dffea4c 100644 --- a/opennow-qt/src/streaming/StreamVideoItemInput.cpp +++ b/opennow-qt/src/streaming/StreamVideoItemInput.cpp @@ -937,8 +937,10 @@ void StreamVideoItem::syncCaptureState() // 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. - const bool focused = window() && window()->isActive() && (hasActiveFocus() || m_gamescopeSession); + // 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); @@ -1138,6 +1140,12 @@ 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; @@ -1145,7 +1153,7 @@ void StreamVideoItem::resetRemoteCursor() 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(); } diff --git a/opennow-qt/tests/tst_streamvideoitem.cpp b/opennow-qt/tests/tst_streamvideoitem.cpp index f8f1a3ac6..a965e890e 100644 --- a/opennow-qt/tests/tst_streamvideoitem.cpp +++ b/opennow-qt/tests/tst_streamvideoitem.cpp @@ -366,6 +366,49 @@ private slots: 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(), 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(), 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(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("fullscreen");