From 9bcc6291bebfa614576adcea8f5a8a26ef3eca8f Mon Sep 17 00:00:00 2001 From: Cameron Gutman Date: Wed, 22 Oct 2025 23:13:03 -0500 Subject: [PATCH] Auto-lock the cursor in single display borderless windowed scenarios --- app/streaming/input/mouse.cpp | 6 ++++-- app/streaming/session.cpp | 7 +++++++ 2 files changed, 11 insertions(+), 2 deletions(-) diff --git a/app/streaming/input/mouse.cpp b/app/streaming/input/mouse.cpp index 6b1cae79..66bb4413 100644 --- a/app/streaming/input/mouse.cpp +++ b/app/streaming/input/mouse.cpp @@ -269,8 +269,10 @@ void SdlInputHandler::updatePointerRegionLock() // toggled it themselves using the keyboard shortcut. If that's the case, they // have full control over it and we don't touch it anymore. if (!m_PointerRegionLockToggledByUser) { - // Lock the pointer in true full-screen mode and leave it unlocked in other modes - m_PointerRegionLockActive = (SDL_GetWindowFlags(m_Window) & SDL_WINDOW_FULLSCREEN_DESKTOP) == SDL_WINDOW_FULLSCREEN; + // Lock the pointer in true full-screen mode or in any fullscreen mode when only a single monitor is present + Uint32 fullscreenFlags = SDL_GetWindowFlags(m_Window) & SDL_WINDOW_FULLSCREEN_DESKTOP; + m_PointerRegionLockActive = (fullscreenFlags == SDL_WINDOW_FULLSCREEN) || + (fullscreenFlags != 0 && SDL_GetNumVideoDisplays() == 1); } // If region lock is enabled, grab the cursor so it can't accidentally leave our window. diff --git a/app/streaming/session.cpp b/app/streaming/session.cpp index fc1413d9..ddaa0637 100644 --- a/app/streaming/session.cpp +++ b/app/streaming/session.cpp @@ -2351,6 +2351,13 @@ void Session::execInternal() case SDL_FINGERUP: m_InputHandler->handleTouchFingerEvent(&event.tfinger); break; + case SDL_DISPLAYEVENT: + switch (event.display.event) { + case SDL_DISPLAYEVENT_CONNECTED: + case SDL_DISPLAYEVENT_DISCONNECTED: + m_InputHandler->updatePointerRegionLock(); + break; + } } }