mirror of
https://github.com/moonlight-stream/moonlight-qt.git
synced 2026-06-17 14:11:33 +00:00
@@ -22,6 +22,7 @@ SdlInputHandler::SdlInputHandler(StreamingPreferences& prefs, NvComputer*, int s
|
|||||||
m_MouseWasInVideoRegion(false),
|
m_MouseWasInVideoRegion(false),
|
||||||
m_PendingMouseButtonsAllUpOnVideoRegionLeave(false),
|
m_PendingMouseButtonsAllUpOnVideoRegionLeave(false),
|
||||||
m_PointerRegionLockActive(false),
|
m_PointerRegionLockActive(false),
|
||||||
|
m_PointerRegionLockToggledByUser(false),
|
||||||
m_FakeCaptureActive(false),
|
m_FakeCaptureActive(false),
|
||||||
m_CaptureSystemKeysMode(prefs.captureSysKeysMode),
|
m_CaptureSystemKeysMode(prefs.captureSysKeysMode),
|
||||||
m_MouseCursorCapturedVisibilityState(SDL_DISABLE),
|
m_MouseCursorCapturedVisibilityState(SDL_DISABLE),
|
||||||
@@ -339,27 +340,11 @@ void SdlInputHandler::updateKeyboardGrabState()
|
|||||||
// Don't close the window on Alt+F4 when keyboard grab is enabled
|
// Don't close the window on Alt+F4 when keyboard grab is enabled
|
||||||
SDL_SetHint(SDL_HINT_WINDOWS_NO_CLOSE_ON_ALT_F4, shouldGrab ? "1" : "0");
|
SDL_SetHint(SDL_HINT_WINDOWS_NO_CLOSE_ON_ALT_F4, shouldGrab ? "1" : "0");
|
||||||
|
|
||||||
if (shouldGrab) {
|
|
||||||
#if SDL_VERSION_ATLEAST(2, 0, 15)
|
#if SDL_VERSION_ATLEAST(2, 0, 15)
|
||||||
// On SDL 2.0.15, we can get keyboard-only grab on Win32, X11, and Wayland.
|
// On SDL 2.0.15+, we can get keyboard-only grab on Win32, X11, and Wayland.
|
||||||
// This does nothing on macOS but it sets the SDL_WINDOW_KEYBOARD_GRABBED flag
|
// SDL 2.0.18 adds keyboard grab on macOS (if built with non-AppStore APIs).
|
||||||
// that we look for to see if keyboard capture is enabled. We'll handle macOS
|
SDL_SetWindowKeyboardGrab(m_Window, shouldGrab ? SDL_TRUE : SDL_FALSE);
|
||||||
// ourselves below using the private CGSSetGlobalHotKeyOperatingMode() API.
|
|
||||||
SDL_SetWindowKeyboardGrab(m_Window, SDL_TRUE);
|
|
||||||
#else
|
|
||||||
// If we're in full-screen desktop mode and SDL doesn't have keyboard grab yet,
|
|
||||||
// grab the cursor (will grab the keyboard too on X11).
|
|
||||||
if (SDL_GetWindowFlags(m_Window) & SDL_WINDOW_FULLSCREEN) {
|
|
||||||
SDL_SetWindowGrab(m_Window, SDL_TRUE);
|
|
||||||
}
|
|
||||||
#endif
|
#endif
|
||||||
}
|
|
||||||
else {
|
|
||||||
#if SDL_VERSION_ATLEAST(2, 0, 15)
|
|
||||||
// Allow the keyboard to leave the window
|
|
||||||
SDL_SetWindowKeyboardGrab(m_Window, SDL_FALSE);
|
|
||||||
#endif
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
bool SdlInputHandler::isSystemKeyCaptureActive()
|
bool SdlInputHandler::isSystemKeyCaptureActive()
|
||||||
|
|||||||
@@ -160,6 +160,7 @@ private:
|
|||||||
bool m_MouseWasInVideoRegion;
|
bool m_MouseWasInVideoRegion;
|
||||||
bool m_PendingMouseButtonsAllUpOnVideoRegionLeave;
|
bool m_PendingMouseButtonsAllUpOnVideoRegionLeave;
|
||||||
bool m_PointerRegionLockActive;
|
bool m_PointerRegionLockActive;
|
||||||
|
bool m_PointerRegionLockToggledByUser;
|
||||||
|
|
||||||
int m_GamepadMask;
|
int m_GamepadMask;
|
||||||
GamepadState m_GamepadState[MAX_GAMEPADS];
|
GamepadState m_GamepadState[MAX_GAMEPADS];
|
||||||
|
|||||||
@@ -130,6 +130,12 @@ void SdlInputHandler::performSpecialKeyCombo(KeyCombo combo)
|
|||||||
SDL_LogInfo(SDL_LOG_CATEGORY_APPLICATION,
|
SDL_LogInfo(SDL_LOG_CATEGORY_APPLICATION,
|
||||||
"Detected pointer region lock toggle combo");
|
"Detected pointer region lock toggle combo");
|
||||||
m_PointerRegionLockActive = !m_PointerRegionLockActive;
|
m_PointerRegionLockActive = !m_PointerRegionLockActive;
|
||||||
|
|
||||||
|
// Remember that the user changed this manually, so we don't mess with it anymore
|
||||||
|
// during windowed <-> full-screen transitions.
|
||||||
|
m_PointerRegionLockToggledByUser = true;
|
||||||
|
|
||||||
|
// Apply the new region lock
|
||||||
updatePointerRegionLock();
|
updatePointerRegionLock();
|
||||||
break;
|
break;
|
||||||
|
|
||||||
|
|||||||
@@ -291,10 +291,16 @@ void SdlInputHandler::updatePointerRegionLock()
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
// If we're in full-screen exclusive mode or region lock is enabled, grab the cursor so it can't accidentally leave our window.
|
// Our pointer lock behavior tracks with the fullscreen mode unless the user has
|
||||||
if (isCaptureActive() &&
|
// toggled it themselves using the keyboard shortcut. If that's the case, they
|
||||||
(m_PointerRegionLockActive ||
|
// have full control over it and we don't touch it anymore.
|
||||||
(SDL_GetWindowFlags(m_Window) & SDL_WINDOW_FULLSCREEN_DESKTOP) == SDL_WINDOW_FULLSCREEN)) {
|
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;
|
||||||
|
}
|
||||||
|
|
||||||
|
// If region lock is enabled, grab the cursor so it can't accidentally leave our window.
|
||||||
|
if (isCaptureActive() && m_PointerRegionLockActive) {
|
||||||
#if SDL_VERSION_ATLEAST(2, 0, 18)
|
#if SDL_VERSION_ATLEAST(2, 0, 18)
|
||||||
SDL_Rect src, dst;
|
SDL_Rect src, dst;
|
||||||
|
|
||||||
|
|||||||
@@ -1068,18 +1068,10 @@ void Session::toggleFullscreen()
|
|||||||
bool fullScreen = !(SDL_GetWindowFlags(m_Window) & m_FullScreenFlag);
|
bool fullScreen = !(SDL_GetWindowFlags(m_Window) & m_FullScreenFlag);
|
||||||
|
|
||||||
if (fullScreen) {
|
if (fullScreen) {
|
||||||
if (m_FullScreenFlag == SDL_WINDOW_FULLSCREEN && m_InputHandler->isCaptureActive()) {
|
|
||||||
// Confine the cursor to the window if we're capturing input while transitioning to full screen.
|
|
||||||
SDL_SetWindowGrab(m_Window, SDL_TRUE);
|
|
||||||
}
|
|
||||||
|
|
||||||
SDL_SetWindowResizable(m_Window, SDL_FALSE);
|
SDL_SetWindowResizable(m_Window, SDL_FALSE);
|
||||||
SDL_SetWindowFullscreen(m_Window, m_FullScreenFlag);
|
SDL_SetWindowFullscreen(m_Window, m_FullScreenFlag);
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
// Unconfine the cursor
|
|
||||||
SDL_SetWindowGrab(m_Window, SDL_FALSE);
|
|
||||||
|
|
||||||
SDL_SetWindowFullscreen(m_Window, 0);
|
SDL_SetWindowFullscreen(m_Window, 0);
|
||||||
SDL_SetWindowResizable(m_Window, SDL_TRUE);
|
SDL_SetWindowResizable(m_Window, SDL_TRUE);
|
||||||
|
|
||||||
@@ -1089,6 +1081,9 @@ void Session::toggleFullscreen()
|
|||||||
|
|
||||||
// Input handler might need to start/stop keyboard grab after changing modes
|
// Input handler might need to start/stop keyboard grab after changing modes
|
||||||
m_InputHandler->updateKeyboardGrabState();
|
m_InputHandler->updateKeyboardGrabState();
|
||||||
|
|
||||||
|
// Input handler might need stop/stop mouse grab after changing modes
|
||||||
|
m_InputHandler->updatePointerRegionLock();
|
||||||
}
|
}
|
||||||
|
|
||||||
void Session::notifyMouseEmulationMode(bool enabled)
|
void Session::notifyMouseEmulationMode(bool enabled)
|
||||||
|
|||||||
Reference in New Issue
Block a user