Skip to content

Commit 7252633

Browse files
committed
video: Check the display origin when a fullscreen window is moved
In certain cases when moving fullscreen windows in scaled desktop configurations, the window origin might overlap two displays at once. Check if the window is at the origin of a specific display before falling back to the generic window rectangle check. Fixes rare fullscreen window misplacement when moving fullscreen windows via a desktop shortcut while using the Wayland scale-to-display mode.
1 parent 248bcf6 commit 7252633

File tree

1 file changed

+21
-11
lines changed

1 file changed

+21
-11
lines changed

src/video/SDL_video.c

Lines changed: 21 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1674,6 +1674,21 @@ SDL_DisplayID SDL_GetDisplayForRect(const SDL_Rect *rect)
16741674
return GetDisplayForRect(rect->x, rect->y, rect->w, rect->h);
16751675
}
16761676

1677+
static SDL_DisplayID GetDisplayAtOrigin(int x, int y)
1678+
{
1679+
for (int i = 0; i < _this->num_displays; ++i) {
1680+
SDL_Rect rect;
1681+
const SDL_DisplayID cur_id = _this->displays[i]->id;
1682+
if (SDL_GetDisplayBounds(cur_id, &rect)) {
1683+
if (x == rect.x && y == rect.y) {
1684+
return cur_id;
1685+
}
1686+
}
1687+
}
1688+
1689+
return 0;
1690+
}
1691+
16771692
SDL_DisplayID SDL_GetDisplayForWindowPosition(SDL_Window *window)
16781693
{
16791694
int x, y;
@@ -1736,7 +1751,11 @@ SDL_VideoDisplay *SDL_GetVideoDisplayForFullscreenWindow(SDL_Window *window)
17361751
const int w = window->last_size_pending ? window->pending.w : window->w;
17371752
const int h = window->last_size_pending ? window->pending.h : window->h;
17381753

1739-
displayID = GetDisplayForRect(x, y, w, h);
1754+
// Check if the window is exactly at the origin of a display. Otherwise, fall back to the generic check.
1755+
displayID = GetDisplayAtOrigin(x, y);
1756+
if (!displayID) {
1757+
displayID = GetDisplayForRect(x, y, w, h);
1758+
}
17401759
}
17411760
if (!displayID) {
17421761
// Use the primary display for a window if we can't find it anywhere else
@@ -2929,16 +2948,7 @@ bool SDL_SetWindowPosition(SDL_Window *window, int x, int y)
29292948
* the pending fullscreen display ID if it does. This needs to be set early in case
29302949
* the window is prevented from moving to the exact origin due to struts.
29312950
*/
2932-
for (int i = 0; i < _this->num_displays; ++i) {
2933-
SDL_Rect rect;
2934-
const SDL_DisplayID cur_id = _this->displays[i]->id;
2935-
if (SDL_GetDisplayBounds(cur_id, &rect)) {
2936-
if (x == rect.x && y == rect.y) {
2937-
window->pending_displayID = cur_id;
2938-
break;
2939-
}
2940-
}
2941-
}
2951+
window->pending_displayID = GetDisplayAtOrigin(x, y);
29422952
}
29432953

29442954
window->pending.x = x;

0 commit comments

Comments
 (0)