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 e8baac9e8..f729d4a42 100644 --- a/opennow-qt/src/app/ApplicationStartup.cpp +++ b/opennow-qt/src/app/ApplicationStartup.cpp @@ -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, diff --git a/opennow-qt/src/streaming/StreamVideoItem.cpp b/opennow-qt/src/streaming/StreamVideoItem.cpp index 9703c1381..a005f8788 100644 --- a/opennow-qt/src/streaming/StreamVideoItem.cpp +++ b/opennow-qt/src/streaming/StreamVideoItem.cpp @@ -85,9 +85,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(); + : 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 69f8dda93..7d14d8ddb 100644 --- a/opennow-qt/src/streaming/StreamVideoItem.h +++ b/opennow-qt/src/streaming/StreamVideoItem.h @@ -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(); @@ -278,6 +279,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 3a893f723..1bb70255d 100644 --- a/opennow-qt/src/streaming/StreamVideoItemInput.cpp +++ b/opennow-qt/src/streaming/StreamVideoItemInput.cpp @@ -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()))) @@ -1176,6 +1183,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; @@ -1183,7 +1196,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 f37610f12..c856d8740 100644 --- a/opennow-qt/tests/tst_streamvideoitem.cpp +++ b/opennow-qt/tests/tst_streamvideoitem.cpp @@ -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(), 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(), 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");