Skip to content

Commit 5447cb6

Browse files
committed
video: Prefer the window manager supplied coordinates for selecting a fullscreen display
Unless there are pending client requested window coordinates, such as in the case where the position is set followed by immediately by entering fullscreen, prefer the true window coordinates as sent by the window manager to select a fullscreen display. Fixes the case where, if the window manager moves an already maximized window to another display, the window would be made fullscreen on the wrong display since the last floating coordinates would be used.
1 parent e4215a0 commit 5447cb6

File tree

5 files changed

+26
-13
lines changed

5 files changed

+26
-13
lines changed

src/events/SDL_windowevents.c

+1
Original file line numberDiff line numberDiff line change
@@ -69,6 +69,7 @@ bool SDL_SendWindowEvent(SDL_Window *window, SDL_EventType windowevent, int data
6969
case SDL_EVENT_WINDOW_MOVED:
7070
window->undefined_x = false;
7171
window->undefined_y = false;
72+
window->use_pending_position_for_fullscreen = false;
7273
if (!(window->flags & SDL_WINDOW_FULLSCREEN)) {
7374
window->windowed.x = data1;
7475
window->windowed.y = data2;

src/video/SDL_sysvideo.h

+1-1
Original file line numberDiff line numberDiff line change
@@ -96,9 +96,9 @@ struct SDL_Window
9696
SDL_Surface *surface;
9797
bool surface_valid;
9898

99-
bool is_repositioning; // Set during an SDL_SetWindowPosition() call.
10099
bool is_hiding;
101100
bool restore_on_show; // Child was hidden recursively by the parent, restore when shown.
101+
bool use_pending_position_for_fullscreen;
102102
bool is_destroying;
103103
bool is_dropping; // drag/drop in progress, expecting SDL_SendDropComplete().
104104

src/video/SDL_video.c

+12-12
Original file line numberDiff line numberDiff line change
@@ -1660,20 +1660,21 @@ SDL_VideoDisplay *SDL_GetVideoDisplayForFullscreenWindow(SDL_Window *window)
16601660
displayID = window->current_fullscreen_mode.displayID;
16611661
}
16621662

1663-
/* The floating position is used here as a very common pattern is
1664-
* SDL_SetWindowPosition() followed by SDL_SetWindowFullscreen() to make the
1665-
* window fullscreen desktop on a specific display. If the backend doesn't
1666-
* support changing the window position, or the compositor hasn't yet actually
1667-
* moved the window, the current position won't be updated at the time of the
1668-
* fullscreen call.
1663+
/* This is used to handle the very common pattern of SDL_SetWindowPosition()
1664+
* followed immediately by SDL_SetWindowFullscreen() to make the window fullscreen
1665+
* desktop on a specific display. If the backend doesn't support changing the
1666+
* window position, or an async window manager hasn't yet actually moved the window,
1667+
* the current position won't be updated at the time of the fullscreen call.
16691668
*/
16701669
if (!displayID) {
1671-
if (window->flags & SDL_WINDOW_FULLSCREEN && !window->is_repositioning) {
1672-
// This was a window manager initiated move, use the current position.
1673-
displayID = GetDisplayForRect(window->x, window->y, 1, 1);
1674-
} else {
1670+
if (window->use_pending_position_for_fullscreen) {
1671+
// The last coordinates were client requested; use the pending floating coordinates.
16751672
displayID = GetDisplayForRect(window->floating.x, window->floating.y, window->floating.w, window->floating.h);
16761673
}
1674+
else {
1675+
// The last coordinates were from the window manager; use the current position.
1676+
displayID = GetDisplayForRect(window->x, window->y, 1, 1);
1677+
}
16771678
}
16781679
if (!displayID) {
16791680
// Use the primary display for a window if we can't find it anywhere else
@@ -2806,11 +2807,10 @@ bool SDL_SetWindowPosition(SDL_Window *window, int x, int y)
28062807
window->floating.y = y;
28072808
window->undefined_x = false;
28082809
window->undefined_y = false;
2810+
window->use_pending_position_for_fullscreen = true;
28092811

28102812
if (_this->SetWindowPosition) {
2811-
window->is_repositioning = true;
28122813
const bool result = _this->SetWindowPosition(_this, window);
2813-
window->is_repositioning = false;
28142814
if (result) {
28152815
SDL_SyncIfRequired(window);
28162816
}

src/video/wayland/SDL_waylandwindow.c

+2
Original file line numberDiff line numberDiff line change
@@ -2651,6 +2651,7 @@ bool Wayland_SetWindowPosition(SDL_VideoDevice *_this, SDL_Window *window)
26512651
RepositionPopup(window, false);
26522652
return true;
26532653
} else if (wind->shell_surface_type == WAYLAND_SHELL_SURFACE_TYPE_LIBDECOR || wind->shell_surface_type == WAYLAND_SHELL_SURFACE_TYPE_XDG_TOPLEVEL) {
2654+
const bool use_pending_position_for_fullscreen = window->use_pending_position_for_fullscreen;
26542655
const int x = window->floating.x;
26552656
const int y = window->floating.y;
26562657

@@ -2671,6 +2672,7 @@ bool Wayland_SetWindowPosition(SDL_VideoDevice *_this, SDL_Window *window)
26712672
*
26722673
* for positioning a desktop fullscreen window won't work without this.
26732674
*/
2675+
window->use_pending_position_for_fullscreen = use_pending_position_for_fullscreen;
26742676
window->floating.x = x;
26752677
window->floating.y = y;
26762678

src/video/x11/SDL_x11window.c

+10
Original file line numberDiff line numberDiff line change
@@ -1060,7 +1060,17 @@ bool X11_SetWindowPosition(SDL_VideoDevice *_this, SDL_Window *window)
10601060
{
10611061
// Sync any pending fullscreen or maximize events.
10621062
if (window->internal->pending_operation & (X11_PENDING_OP_FULLSCREEN | X11_PENDING_OP_MAXIMIZE)) {
1063+
// Save state in case it is overwritten while synchronizing.
1064+
const bool use_client_fs_coords = window->use_pending_position_for_fullscreen;
1065+
const int x = window->floating.x;
1066+
const int y = window->floating.y;
1067+
10631068
X11_SyncWindow(_this, window);
1069+
1070+
// Restore state that may have been overwritten while synchronizing.
1071+
window->use_pending_position_for_fullscreen = use_client_fs_coords;
1072+
window->floating.x = x;
1073+
window->floating.y = y;
10641074
}
10651075

10661076
// Position will be set when window is de-maximized

0 commit comments

Comments
 (0)