Add workaround for duplicate size changed events on Wayland

This commit is contained in:
Cameron Gutman 2022-01-14 23:36:21 -06:00
parent 31eddd8da0
commit e1b3f90f8b

View file

@ -1381,6 +1381,7 @@ void Session::execInternal()
bool needsFirstEnterCapture = false; bool needsFirstEnterCapture = false;
bool needsPostDecoderCreationCapture = false; bool needsPostDecoderCreationCapture = false;
bool ignoreDuplicateResizes = 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. For other platforms, // event where it seems to work consistently on GNOME. For other platforms,
@ -1389,6 +1390,11 @@ void Session::execInternal()
if (strcmp(SDL_GetCurrentVideoDriver(), "wayland") == 0) { if (strcmp(SDL_GetCurrentVideoDriver(), "wayland") == 0) {
// Native Wayland: Capture on SDL_WINDOWEVENT_ENTER // Native Wayland: Capture on SDL_WINDOWEVENT_ENTER
needsFirstEnterCapture = true; needsFirstEnterCapture = true;
// As of SDL 2.0.20, we get duplicate SDL_WINDOWEVENT_SIZE_CHANGED events
// when focus is lost and gained under GNOME Wayland. This causes us to
// recreate our renderer needlessly.
ignoreDuplicateResizes = true;
} }
else { else {
// X11/XWayland: Capture after decoder creation // X11/XWayland: Capture after decoder creation
@ -1426,6 +1432,7 @@ void Session::execInternal()
// Hijack this thread to be the SDL main thread. We have to do this // Hijack this thread to be the SDL main thread. We have to do this
// because we want to suspend all Qt processing until the stream is over. // because we want to suspend all Qt processing until the stream is over.
SDL_Event event; SDL_Event event;
Sint32 lastResizeW = -1, lastResizeH = -1;
for (;;) { for (;;) {
#if SDL_VERSION_ATLEAST(2, 0, 16) && !defined(STEAM_LINK) #if SDL_VERSION_ATLEAST(2, 0, 16) && !defined(STEAM_LINK)
// SDL 2.0.16 has a proper wait event implementation that uses platform // SDL 2.0.16 has a proper wait event implementation that uses platform
@ -1544,6 +1551,19 @@ void Session::execInternal()
break; break;
} }
if (event.window.event == SDL_WINDOWEVENT_SIZE_CHANGED) {
if (ignoreDuplicateResizes && lastResizeW == event.window.data1 && lastResizeH == event.window.data2) {
SDL_LogInfo(SDL_LOG_CATEGORY_APPLICATION,
"Dropping duplicate size changed event: %d %d",
event.window.data1,
event.window.data2);
break;
}
lastResizeW = event.window.data1;
lastResizeH = event.window.data2;
}
SDL_LogInfo(SDL_LOG_CATEGORY_APPLICATION, SDL_LogInfo(SDL_LOG_CATEGORY_APPLICATION,
"Recreating renderer for window event: %d (%d %d)", "Recreating renderer for window event: %d (%d %d)",
event.window.event, event.window.event,