Delay mouse capture until after SDL_RecreateWindow() has been called

This commit is contained in:
Cameron Gutman
2020-05-09 19:48:13 -07:00
parent 3cb3c1c6d8
commit fc9871b075
+17 -15
View File
@@ -1138,26 +1138,20 @@ void Session::exec(int displayOriginX, int displayOriginY)
} }
bool needsFirstEnterCapture = false; bool needsFirstEnterCapture = false;
bool needsPostDecoderCreationCapture = false;
// HACK: For Wayland, we wait until we get the first SDL_WINDOWEVENT_ENTER // HACK: For Wayland, we wait until we get the first SDL_WINDOWEVENT_ENTER
// event where it seems to work consistently on GNOME. This doesn't work for // event where it seems to work consistently on GNOME. For other platforms,
// XWayland though. // especially where SDL may call SDL_RecreateWindow(), we must only capture
if (strcmp(SDL_GetCurrentVideoDriver(), "wayland") != 0) { // after the decoder is created.
// We know we aren't running on native Wayland now, but if (strcmp(SDL_GetCurrentVideoDriver(), "wayland") == 0) {
// we still may be running on XWayland.
if (!WMUtils::isRunningWayland()) {
// Neither Wayland or XWayland: capture now
m_InputHandler->setCaptureActive(true);
}
else {
// XWayland: mouse capture doesn't work reliably, so let the user
// engage the mouse capture via clicking or using the hotkey.
}
}
else {
// Native Wayland: Capture on SDL_WINDOWEVENT_ENTER // Native Wayland: Capture on SDL_WINDOWEVENT_ENTER
needsFirstEnterCapture = true; needsFirstEnterCapture = true;
} }
else {
// X11/XWayland: Capture after decoder creation
needsPostDecoderCreationCapture = true;
}
// Stop text input. SDL enables it by default // Stop text input. SDL enables it by default
// when we initialize the video subsystem, but this // when we initialize the video subsystem, but this
@@ -1309,6 +1303,14 @@ void Session::exec(int displayOriginX, int displayOriginY)
emit displayLaunchError("Unable to initialize video decoder. Please check your streaming settings and try again."); emit displayLaunchError("Unable to initialize video decoder. Please check your streaming settings and try again.");
goto DispatchDeferredCleanup; goto DispatchDeferredCleanup;
} }
// As of SDL 2.0.12, SDL_RecreateWindow() doesn't carry over mouse capture
// or mouse hiding state to the new window. By capturing after the decoder
// is set up, this ensures the window re-creation is already done.
if (needsPostDecoderCreationCapture) {
m_InputHandler->setCaptureActive(true);
needsFirstEnterCapture = false;
}
} }
// Request an IDR frame to complete the reset // Request an IDR frame to complete the reset