Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

video: Prefer the window manager supplied coordinates for selecting a… #11621

Merged
merged 1 commit into from
Dec 9, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions src/events/SDL_windowevents.c
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,7 @@ bool SDL_SendWindowEvent(SDL_Window *window, SDL_EventType windowevent, int data
case SDL_EVENT_WINDOW_MOVED:
window->undefined_x = false;
window->undefined_y = false;
window->use_pending_position_for_fullscreen = false;
if (!(window->flags & SDL_WINDOW_FULLSCREEN)) {
window->windowed.x = data1;
window->windowed.y = data2;
Expand Down
2 changes: 1 addition & 1 deletion src/video/SDL_sysvideo.h
Original file line number Diff line number Diff line change
Expand Up @@ -96,9 +96,9 @@ struct SDL_Window
SDL_Surface *surface;
bool surface_valid;

bool is_repositioning; // Set during an SDL_SetWindowPosition() call.
bool is_hiding;
bool restore_on_show; // Child was hidden recursively by the parent, restore when shown.
bool use_pending_position_for_fullscreen;
bool is_destroying;
bool is_dropping; // drag/drop in progress, expecting SDL_SendDropComplete().

Expand Down
24 changes: 12 additions & 12 deletions src/video/SDL_video.c
Original file line number Diff line number Diff line change
Expand Up @@ -1660,20 +1660,21 @@ SDL_VideoDisplay *SDL_GetVideoDisplayForFullscreenWindow(SDL_Window *window)
displayID = window->current_fullscreen_mode.displayID;
}

/* The floating position is used here as a very common pattern is
* SDL_SetWindowPosition() followed by SDL_SetWindowFullscreen() to make the
* window fullscreen desktop on a specific display. If the backend doesn't
* support changing the window position, or the compositor hasn't yet actually
* moved the window, the current position won't be updated at the time of the
* fullscreen call.
/* This is used to handle the very common pattern of SDL_SetWindowPosition()
* followed immediately by SDL_SetWindowFullscreen() to make the window fullscreen
* desktop on a specific display. If the backend doesn't support changing the
* window position, or an async window manager hasn't yet actually moved the window,
* the current position won't be updated at the time of the fullscreen call.
*/
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, 1, 1);
} else {
if (window->use_pending_position_for_fullscreen) {
// The last coordinates were client requested; use the pending floating coordinates.
displayID = GetDisplayForRect(window->floating.x, window->floating.y, window->floating.w, window->floating.h);
}
else {
// The last coordinates were from the window manager; use the current position.
displayID = GetDisplayForRect(window->x, window->y, 1, 1);
}
}
if (!displayID) {
// Use the primary display for a window if we can't find it anywhere else
Expand Down Expand Up @@ -2806,11 +2807,10 @@ bool SDL_SetWindowPosition(SDL_Window *window, int x, int y)
window->floating.y = y;
window->undefined_x = false;
window->undefined_y = false;
window->use_pending_position_for_fullscreen = true;

if (_this->SetWindowPosition) {
window->is_repositioning = true;
const bool result = _this->SetWindowPosition(_this, window);
window->is_repositioning = false;
if (result) {
SDL_SyncIfRequired(window);
}
Expand Down
2 changes: 2 additions & 0 deletions src/video/wayland/SDL_waylandwindow.c
Original file line number Diff line number Diff line change
Expand Up @@ -2651,6 +2651,7 @@ bool Wayland_SetWindowPosition(SDL_VideoDevice *_this, SDL_Window *window)
RepositionPopup(window, false);
return true;
} else if (wind->shell_surface_type == WAYLAND_SHELL_SURFACE_TYPE_LIBDECOR || wind->shell_surface_type == WAYLAND_SHELL_SURFACE_TYPE_XDG_TOPLEVEL) {
const bool use_pending_position_for_fullscreen = window->use_pending_position_for_fullscreen;
const int x = window->floating.x;
const int y = window->floating.y;

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

Expand Down
10 changes: 10 additions & 0 deletions src/video/x11/SDL_x11window.c
Original file line number Diff line number Diff line change
Expand Up @@ -1060,7 +1060,17 @@ bool X11_SetWindowPosition(SDL_VideoDevice *_this, SDL_Window *window)
{
// Sync any pending fullscreen or maximize events.
if (window->internal->pending_operation & (X11_PENDING_OP_FULLSCREEN | X11_PENDING_OP_MAXIMIZE)) {
// Save state in case it is overwritten while synchronizing.
const bool use_client_fs_coords = window->use_pending_position_for_fullscreen;
const int x = window->floating.x;
const int y = window->floating.y;

X11_SyncWindow(_this, window);

// Restore state that may have been overwritten while synchronizing.
window->use_pending_position_for_fullscreen = use_client_fs_coords;
window->floating.x = x;
window->floating.y = y;
}

// Position will be set when window is de-maximized
Expand Down
Loading