From 1cd66419d49b1058eaecc0d81c89954e91e8a3aa Mon Sep 17 00:00:00 2001 From: Cameron Gutman Date: Sat, 30 Jan 2021 11:08:01 -0600 Subject: [PATCH] Remember desired cursor hide state Fixes #511 --- app/streaming/input/input.cpp | 3 ++- app/streaming/input/input.h | 1 + app/streaming/input/keyboard.cpp | 3 ++- app/streaming/input/mouse.cpp | 3 ++- 4 files changed, 7 insertions(+), 3 deletions(-) diff --git a/app/streaming/input/input.cpp b/app/streaming/input/input.cpp index 1a9055f4..f7dbf6fd 100644 --- a/app/streaming/input/input.cpp +++ b/app/streaming/input/input.cpp @@ -27,6 +27,7 @@ SdlInputHandler::SdlInputHandler(StreamingPreferences& prefs, NvComputer*, int s m_PendingMouseButtonsAllUpOnVideoRegionLeave(false), m_FakeCaptureActive(false), m_CaptureSystemKeysEnabled(prefs.captureSysKeys || !WMUtils::isRunningWindowManager()), + m_MouseCursorCapturedVisibilityState(SDL_DISABLE), m_PendingKeyCombo(KeyComboMax), m_LongPressTimer(0), m_StreamWidth(streamWidth), @@ -520,7 +521,7 @@ void SdlInputHandler::setCaptureActive(bool active) // If we're in relative mode, try to activate SDL's relative mouse mode if (m_AbsoluteMouseMode || SDL_SetRelativeMouseMode(SDL_TRUE) < 0) { // Relative mouse mode didn't work or was disabled, so we'll just hide the cursor - SDL_ShowCursor(SDL_DISABLE); + SDL_ShowCursor(m_MouseCursorCapturedVisibilityState); m_FakeCaptureActive = true; } diff --git a/app/streaming/input/input.h b/app/streaming/input/input.h index 98e0532d..ceb00a7b 100644 --- a/app/streaming/input/input.h +++ b/app/streaming/input/input.h @@ -168,6 +168,7 @@ private: QString m_OldIgnoreDevices; QString m_OldIgnoreDevicesExcept; bool m_CaptureSystemKeysEnabled; + int m_MouseCursorCapturedVisibilityState; struct { KeyCombo keyCombo; diff --git a/app/streaming/input/keyboard.cpp b/app/streaming/input/keyboard.cpp index 926a9de8..d95756f3 100644 --- a/app/streaming/input/keyboard.cpp +++ b/app/streaming/input/keyboard.cpp @@ -72,7 +72,8 @@ void SdlInputHandler::performPendingSpecialKeyCombo() "Detected show mouse combo"); if (!SDL_GetRelativeMouseMode()) { - SDL_ShowCursor(!SDL_ShowCursor(SDL_QUERY)); + m_MouseCursorCapturedVisibilityState = !m_MouseCursorCapturedVisibilityState; + SDL_ShowCursor(m_MouseCursorCapturedVisibilityState); } else { SDL_LogWarn(SDL_LOG_CATEGORY_APPLICATION, diff --git a/app/streaming/input/mouse.cpp b/app/streaming/input/mouse.cpp index 80650de6..8b67987c 100644 --- a/app/streaming/input/mouse.cpp +++ b/app/streaming/input/mouse.cpp @@ -146,7 +146,8 @@ void SdlInputHandler::flushMousePositionUpdate() // executes. SDL_Event event; event.type = SDL_USEREVENT; - event.user.code = mouseInVideoRegion ? SDL_CODE_HIDE_CURSOR : SDL_CODE_SHOW_CURSOR; + event.user.code = (mouseInVideoRegion && m_MouseCursorCapturedVisibilityState == SDL_DISABLE) ? + SDL_CODE_HIDE_CURSOR : SDL_CODE_SHOW_CURSOR; SDL_PushEvent(&event); if (!mouseInVideoRegion && buttonState != 0) {