Remember desired cursor hide state

Fixes #511
This commit is contained in:
Cameron Gutman 2021-01-30 11:08:01 -06:00
parent 5309a02f6d
commit 1cd66419d4
4 changed files with 7 additions and 3 deletions

View file

@ -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;
}

View file

@ -168,6 +168,7 @@ private:
QString m_OldIgnoreDevices;
QString m_OldIgnoreDevicesExcept;
bool m_CaptureSystemKeysEnabled;
int m_MouseCursorCapturedVisibilityState;
struct {
KeyCombo keyCombo;

View file

@ -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,

View file

@ -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) {