video: Drop size and position requests for windows in a fixed size/position state

It is not uncommon for clients to redundantly set the window size and position, either as a holdover from an SDL 1 port, when this was required, due to any window state change triggering a universal update function that sets all window state, even if unnecessary (e.g. always calling SDL_SetWindowSize(), even if the window is fullscreen), or due to the use of compatability layers. Historically, these clients expect that their behavior won't override the base window state, which is an assumption that the windowing changes in SDL 3 broke by caching size and position changes that can't be applied immediately.

This change drops size and position requests when the window is in the maximized and fullscreen states (fullscreen-desktop windows will be repositioned, but the non-fullscreen floating position will not be overwritten), which is behavior more in line with existing client assumptions, and should ease the porting process, as well as prevent annoying bugs when older software is run via sdl2-compat.

In the process of making these changes, pending window state has been moved to separate variables in the SDL_Window struct, as this fixes bugs regarding fullscreen display selection and centering windows immediately after resize on asynchronous platforms, which had issues due to pending state possibly being overwritten.
This commit is contained in:
Frank Praznik
2024-12-13 13:58:15 -05:00
parent 6fa6297441
commit eda0261c4e
21 changed files with 359 additions and 283 deletions

View File

@@ -1432,32 +1432,6 @@ LRESULT CALLBACK WIN_WindowProc(HWND hwnd, UINT msg, WPARAM wParam, LPARAM lPara
break;
#endif // WM_GETMINMAXINFO
case WM_WINDOWPOSCHANGING:
{
if (data->expected_resize) {
returnCode = 0;
}
if (data->floating_rect_pending &&
!IsIconic(hwnd) &&
!IsZoomed(hwnd) &&
(data->window->flags & (SDL_WINDOW_MAXIMIZED | SDL_WINDOW_MINIMIZED)) &&
!(data->window->flags & SDL_WINDOW_FULLSCREEN)) {
// If a new floating size is pending, apply it if moving from a fixed-size to floating state.
WINDOWPOS *windowpos = (WINDOWPOS*)lParam;
int fx, fy, fw, fh;
WIN_AdjustWindowRect(data->window, &fx, &fy, &fw, &fh, SDL_WINDOWRECT_FLOATING);
windowpos->x = fx;
windowpos->y = fy;
windowpos->cx = fw;
windowpos->cy = fh;
windowpos->flags &= ~(SWP_NOSIZE | SWP_NOMOVE);
data->floating_rect_pending = false;
}
} break;
case WM_WINDOWPOSCHANGED:
{
SDL_Window *win;

View File

@@ -204,6 +204,11 @@ static bool WIN_AdjustWindowRectWithStyle(SDL_Window *window, DWORD style, DWORD
*width = window->floating.w;
*height = window->floating.h;
break;
case SDL_WINDOWRECT_PENDING:
SDL_RelativeToGlobalForWindow(window, window->pending.x, window->pending.y, x, y);
*width = window->pending.w;
*height = window->pending.h;
break;
default:
// Should never be here
SDL_assert_release(false);
@@ -901,10 +906,8 @@ bool WIN_SetWindowPosition(SDL_VideoDevice *_this, SDL_Window *window)
if (!(window->flags & (SDL_WINDOW_MAXIMIZED | SDL_WINDOW_MINIMIZED))) {
WIN_ConstrainPopup(window);
return WIN_SetWindowPositionInternal(window,
window->internal->copybits_flag | SWP_NOZORDER | SWP_NOOWNERZORDER |
SWP_NOACTIVATE, SDL_WINDOWRECT_FLOATING);
} else {
window->internal->floating_rect_pending = true;
window->internal->copybits_flag | SWP_NOZORDER | SWP_NOOWNERZORDER | SWP_NOSIZE |
SWP_NOACTIVATE, SDL_WINDOWRECT_PENDING);
}
} else {
return SDL_UpdateFullscreenMode(window, SDL_FULLSCREEN_OP_ENTER, true);
@@ -916,9 +919,10 @@ bool WIN_SetWindowPosition(SDL_VideoDevice *_this, SDL_Window *window)
void WIN_SetWindowSize(SDL_VideoDevice *_this, SDL_Window *window)
{
if (!(window->flags & (SDL_WINDOW_FULLSCREEN | SDL_WINDOW_MAXIMIZED))) {
WIN_SetWindowPositionInternal(window, window->internal->copybits_flag | SWP_NOMOVE | SWP_NOZORDER | SWP_NOOWNERZORDER | SWP_NOACTIVATE, SDL_WINDOWRECT_FLOATING);
WIN_SetWindowPositionInternal(window, window->internal->copybits_flag | SWP_NOMOVE | SWP_NOZORDER | SWP_NOOWNERZORDER | SWP_NOACTIVATE, SDL_WINDOWRECT_PENDING);
} else {
window->internal->floating_rect_pending = true;
// Can't resize the window
window->last_size_pending = false;
}
}

View File

@@ -38,7 +38,8 @@ typedef enum SDL_WindowRect
{
SDL_WINDOWRECT_CURRENT,
SDL_WINDOWRECT_WINDOWED,
SDL_WINDOWRECT_FLOATING
SDL_WINDOWRECT_FLOATING,
SDL_WINDOWRECT_PENDING
} SDL_WindowRect;
typedef enum SDL_WindowEraseBackgroundMode
@@ -76,7 +77,6 @@ struct SDL_WindowData
bool expected_resize;
bool in_border_change;
bool in_title_click;
bool floating_rect_pending;
Uint8 focus_click_pending;
bool skip_update_clipcursor;
Uint64 last_updated_clipcursor;