video: Use the origin for determining the display for fullscreen windows

Fullscreen windows may be larger than the display if they were moved between differently sized displays and the new position was received before the new size or vice versa. Using the center of the window rect in this case can report the wrong display, so use the origin.

Fixes flickering and the window bouncing between different displays when moving fullscreen X11 and Wayland windows in certain multi-monitor layouts.
This commit is contained in:
Frank Praznik
2024-04-10 13:42:02 -04:00
parent 1804ad175c
commit 26d3cbee79

View File

@@ -1406,7 +1406,15 @@ static SDL_DisplayID SDL_GetDisplayForWindowPosition(SDL_Window *window)
SDL_RelativeToGlobalForWindow(window, window->x, window->y, &x, &y);
if (!displayID) {
displayID = GetDisplayForRect(x, y, window->w, window->h);
/* Fullscreen windows may be larger than the display if they were moved between differently sized
* displays and the new position was received before the new size or vice versa. Using the center
* of the window rect in this case can report the wrong display, so use the origin.
*/
if (window->flags & SDL_WINDOW_FULLSCREEN) {
displayID = GetDisplayForRect(x, y, 1, 1);
} else {
displayID = GetDisplayForRect(x, y, window->w, window->h);
}
}
if (!displayID) {
/* Use the primary display for a window if we can't find it anywhere else */
@@ -1436,9 +1444,9 @@ SDL_VideoDisplay *SDL_GetVideoDisplayForFullscreenWindow(SDL_Window *window)
if (!displayID) {
if (window->flags & SDL_WINDOW_FULLSCREEN && !window->is_repositioning) {
/* This was a window manager initiated move, use the current position. */
displayID = GetDisplayForRect(window->x, window->y, window->w, window->h);
displayID = GetDisplayForRect(window->x, window->y, 1, 1);
} else {
displayID = GetDisplayForRect(window->floating.x, window->floating.y, window->w, window->h);
displayID = GetDisplayForRect(window->floating.x, window->floating.y, window->floating.w, window->floating.h);
}
}
if (!displayID) {