mirror of
https://github.com/moonlight-stream/moonlight-qt.git
synced 2026-08-07 09:30:45 +00:00
Fix capturing mouse motion outside the window on sdl2-compat
This commit is contained in:
@@ -718,10 +718,6 @@ int main(int argc, char *argv[])
|
||||
SDL_SetHint(SDL_HINT_AUDIO_DEVICE_APP_NAME, "Moonlight");
|
||||
SDL_SetHint(SDL_HINT_APP_NAME, "Moonlight");
|
||||
|
||||
// We handle capturing the mouse ourselves when it leaves the window, so we don't need
|
||||
// SDL doing it for us behind our backs.
|
||||
SDL_SetHint(SDL_HINT_MOUSE_AUTO_CAPTURE, "0");
|
||||
|
||||
// SDL will try to lock the mouse cursor on Wayland if it's not visible in order to
|
||||
// support applications that assume they can warp the cursor (which isn't possible
|
||||
// on Wayland). We don't want this behavior because it interferes with seamless mouse
|
||||
|
||||
@@ -40,6 +40,19 @@ SdlInputHandler::SdlInputHandler(StreamingPreferences& prefs, int streamWidth, i
|
||||
m_CaptureSystemKeysMode = StreamingPreferences::CSK_ALWAYS;
|
||||
}
|
||||
|
||||
// SDL3 breaks our auto-capture-on-leave logic because the mouse focus has already
|
||||
// been lost by the time we attempt to call SDL_CaptureMouse(). Fortunately, SDL3's
|
||||
// own auto-capture logic seems to be stable now (unlike SDL2), so we can rely on
|
||||
// that instead of our own hack when running on sdl2-compat.
|
||||
// https://github.com/libsdl-org/SDL/commit/e54001b02809dcebbb822bd0297919c8c76976a1
|
||||
SDL_version ver;
|
||||
SDL_GetVersion(&ver);
|
||||
m_NeedsManualCaptureOnLeave = !(ver.major == 2 && ver.minor >= 30 && ver.patch >= 50) && !SDL_GetHint("SDL3_VERSION");
|
||||
if (m_NeedsManualCaptureOnLeave) {
|
||||
// Disable the buggy auto-capture on earlier SDL2 builds
|
||||
SDL_SetHint(SDL_HINT_MOUSE_AUTO_CAPTURE, "0");
|
||||
}
|
||||
|
||||
// Allow gamepad input when the app doesn't have focus if requested
|
||||
SDL_SetHint(SDL_HINT_JOYSTICK_ALLOW_BACKGROUND_EVENTS, prefs.backgroundGamepad ? "1" : "0");
|
||||
|
||||
@@ -276,6 +289,7 @@ void SdlInputHandler::raiseAllKeys()
|
||||
|
||||
void SdlInputHandler::notifyMouseLeave()
|
||||
{
|
||||
if (m_NeedsManualCaptureOnLeave) {
|
||||
// SDL on Windows doesn't send the mouse button up until the mouse re-enters the window
|
||||
// after leaving it. This breaks some of the Aero snap gestures, so we'll capture it to
|
||||
// allow us to receive the mouse button up events later.
|
||||
@@ -292,6 +306,7 @@ void SdlInputHandler::notifyMouseLeave()
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void SdlInputHandler::notifyFocusLost()
|
||||
|
||||
@@ -210,6 +210,7 @@ private:
|
||||
bool m_ReverseScrollDirection;
|
||||
bool m_SwapFaceButtons;
|
||||
|
||||
bool m_NeedsManualCaptureOnLeave;
|
||||
bool m_MouseWasInVideoRegion;
|
||||
bool m_PendingMouseButtonsAllUpOnVideoRegionLeave;
|
||||
bool m_PointerRegionLockActive;
|
||||
|
||||
@@ -128,8 +128,10 @@ void SdlInputHandler::handleMouseMotionEvent(SDL_MouseMotionEvent* event)
|
||||
Uint32 buttonState = SDL_GetMouseState(nullptr, nullptr);
|
||||
if (buttonState == 0) {
|
||||
if (m_PendingMouseButtonsAllUpOnVideoRegionLeave) {
|
||||
if (m_NeedsManualCaptureOnLeave) {
|
||||
// Stop capturing the mouse now
|
||||
SDL_CaptureMouse(SDL_FALSE);
|
||||
}
|
||||
m_PendingMouseButtonsAllUpOnVideoRegionLeave = false;
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user