Implement a more reliable mouse capture workaround for GNOME+Wayland

This commit is contained in:
Cameron Gutman 2020-03-14 00:33:53 -07:00
parent 2d9f62761c
commit faa16b207c

View file

@ -1076,19 +1076,21 @@ void Session::exec(int displayOriginX, int displayOriginY)
SDL_SetWindowFullscreen(m_Window, m_FullScreenFlag); SDL_SetWindowFullscreen(m_Window, m_FullScreenFlag);
} }
bool needsFirstEnterCapture = false;
#ifndef QT_DEBUG #ifndef QT_DEBUG
// Capture the mouse by default on release builds only. // Capture the mouse by default on release builds only.
// This prevents the mouse from becoming trapped inside // This prevents the mouse from becoming trapped inside
// Moonlight when it's halted at a debug break. // Moonlight when it's halted at a debug break.
if (m_Preferences->windowMode != StreamingPreferences::WM_WINDOWED) { if (m_Preferences->windowMode != StreamingPreferences::WM_WINDOWED) {
#if !SDL_VERSION_ATLEAST(2, 0, 11) // HACK: For Wayland, we wait until we get the first SDL_WINDOWEVENT_ENTER
// HACK: This doesn't work on Wayland until we render a frame, so // event where it seems to work consistently on GNOME.
// just don't do it for now. This bug is fixed in SDL 2.0.11. if (strcmp(SDL_GetCurrentVideoDriver(), "wayland") != 0) {
if (strcmp(SDL_GetCurrentVideoDriver(), "wayland") != 0)
#endif
{
m_InputHandler->setCaptureActive(true); m_InputHandler->setCaptureActive(true);
} }
else {
needsFirstEnterCapture = true;
}
} }
#endif #endif
@ -1190,6 +1192,12 @@ void Session::exec(int displayOriginX, int displayOriginY)
m_InputHandler->raiseAllKeys(); m_InputHandler->raiseAllKeys();
} }
// Capture the mouse on SDL_WINDOWEVENT_ENTER if needed
if (needsFirstEnterCapture && event.window.event == SDL_WINDOWEVENT_ENTER) {
m_InputHandler->setCaptureActive(true);
needsFirstEnterCapture = false;
}
// We want to recreate the decoder for resizes (full-screen toggles) and the initial shown event. // We want to recreate the decoder for resizes (full-screen toggles) and the initial shown event.
// We use SDL_WINDOWEVENT_SIZE_CHANGED rather than SDL_WINDOWEVENT_RESIZED because the latter doesn't // We use SDL_WINDOWEVENT_SIZE_CHANGED rather than SDL_WINDOWEVENT_RESIZED because the latter doesn't
// seem to fire when switching from windowed to full-screen on X11. // seem to fire when switching from windowed to full-screen on X11.