mirror of
https://github.com/libsdl-org/SDL.git
synced 2026-10-13 08:52:50 +08:00
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:
+14
-10
@@ -1529,13 +1529,12 @@ extern SDL_DECLSPEC bool SDLCALL SDL_SetWindowIcon(SDL_Window *window, SDL_Surfa
|
||||
/**
|
||||
* Request that the window's position be set.
|
||||
*
|
||||
* If, at the time of this request, the window is in a fixed-size state such
|
||||
* as maximized, this request may be deferred until the window returns to a
|
||||
* resizable state.
|
||||
* If the window is in an exclusive fullscreen or maximized state, this request
|
||||
* has no effect.
|
||||
*
|
||||
* This can be used to reposition fullscreen-desktop windows onto a different
|
||||
* display, however, exclusive fullscreen windows are locked to a specific
|
||||
* display and can only be repositioned programmatically via
|
||||
* display, however, as exclusive fullscreen windows are locked to a specific
|
||||
* display, they can only be repositioned programmatically via
|
||||
* SDL_SetWindowFullscreenMode().
|
||||
*
|
||||
* On some windowing systems this request is asynchronous and the new
|
||||
@@ -1596,12 +1595,11 @@ extern SDL_DECLSPEC bool SDLCALL SDL_GetWindowPosition(SDL_Window *window, int *
|
||||
/**
|
||||
* Request that the size of a window's client area be set.
|
||||
*
|
||||
* If, at the time of this request, the window in a fixed-size state, such as
|
||||
* maximized or fullscreen, the request will be deferred until the window
|
||||
* exits this state and becomes resizable again.
|
||||
* If the window is in a fullscreen or maximized state, this request has no
|
||||
* effect.
|
||||
*
|
||||
* To change the fullscreen mode of a window, use
|
||||
* SDL_SetWindowFullscreenMode()
|
||||
* To change the exclusive fullscreen mode of a window, use
|
||||
* SDL_SetWindowFullscreenMode().
|
||||
*
|
||||
* On some windowing systems, this request is asynchronous and the new window
|
||||
* size may not have have been applied immediately upon the return of this
|
||||
@@ -2021,6 +2019,9 @@ extern SDL_DECLSPEC bool SDLCALL SDL_MaximizeWindow(SDL_Window *window);
|
||||
/**
|
||||
* Request that the window be minimized to an iconic representation.
|
||||
*
|
||||
* If the window is in a fullscreen state, this request has no direct effect.
|
||||
* It may alter the state the window is returned to when leaving fullscreen.
|
||||
*
|
||||
* On some windowing systems this request is asynchronous and the new window
|
||||
* state may not have been applied immediately upon the return of this
|
||||
* function. If an immediate change is required, call SDL_SyncWindow() to
|
||||
@@ -2048,6 +2049,9 @@ extern SDL_DECLSPEC bool SDLCALL SDL_MinimizeWindow(SDL_Window *window);
|
||||
* Request that the size and position of a minimized or maximized window be
|
||||
* restored.
|
||||
*
|
||||
* If the window is in a fullscreen state, this request has no direct effect.
|
||||
* It may alter the state the window is returned to when leaving fullscreen.
|
||||
*
|
||||
* On some windowing systems this request is asynchronous and the new window
|
||||
* state may not have have been applied immediately upon the return of this
|
||||
* function. If an immediate change is required, call SDL_SyncWindow() to
|
||||
|
||||
@@ -69,7 +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;
|
||||
window->last_position_pending = false;
|
||||
if (!(window->flags & SDL_WINDOW_FULLSCREEN)) {
|
||||
window->windowed.x = data1;
|
||||
window->windowed.y = data2;
|
||||
@@ -86,6 +86,7 @@ bool SDL_SendWindowEvent(SDL_Window *window, SDL_EventType windowevent, int data
|
||||
window->y = data2;
|
||||
break;
|
||||
case SDL_EVENT_WINDOW_RESIZED:
|
||||
window->last_size_pending = false;
|
||||
if (!(window->flags & SDL_WINDOW_FULLSCREEN)) {
|
||||
window->windowed.w = data1;
|
||||
window->windowed.h = data2;
|
||||
|
||||
@@ -78,6 +78,9 @@ struct SDL_Window
|
||||
*/
|
||||
SDL_Rect floating;
|
||||
|
||||
// The last client requested size and position for the window.
|
||||
SDL_Rect pending;
|
||||
|
||||
/* Toggle for drivers to indicate that the current window state is tiled,
|
||||
* and sizes set non-programmatically shouldn't be cached.
|
||||
*/
|
||||
@@ -98,7 +101,8 @@ struct SDL_Window
|
||||
|
||||
bool is_hiding;
|
||||
bool restore_on_show; // Child was hidden recursively by the parent, restore when shown.
|
||||
bool use_pending_position_for_fullscreen;
|
||||
bool last_position_pending; // This should NOT be cleared by the backend, as it is used for fullscreen positioning.
|
||||
bool last_size_pending; // This should be cleared by the backend if the new size cannot be applied.
|
||||
bool is_destroying;
|
||||
bool is_dropping; // drag/drop in progress, expecting SDL_SendDropComplete().
|
||||
|
||||
|
||||
+19
-18
@@ -1664,14 +1664,13 @@ SDL_VideoDisplay *SDL_GetVideoDisplayForFullscreenWindow(SDL_Window *window)
|
||||
* the current position won't be updated at the time of the fullscreen call.
|
||||
*/
|
||||
if (!displayID) {
|
||||
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);
|
||||
}
|
||||
// Use the pending position and dimensions, if available, otherwise, use the current.
|
||||
const int x = window->last_position_pending ? window->pending.x : window->x;
|
||||
const int y = window->last_position_pending ? window->pending.y : window->y;
|
||||
const int w = window->last_size_pending ? window->pending.w : window->w;
|
||||
const int h = window->last_size_pending ? window->pending.h : window->h;
|
||||
|
||||
displayID = GetDisplayForRect(x, y, w, h);
|
||||
}
|
||||
if (!displayID) {
|
||||
// Use the primary display for a window if we can't find it anywhere else
|
||||
@@ -2763,6 +2762,9 @@ bool SDL_SetWindowPosition(SDL_Window *window, int x, int y)
|
||||
|
||||
CHECK_WINDOW_MAGIC(window, false);
|
||||
|
||||
const int w = window->last_size_pending ? window->pending.w : window->windowed.w;
|
||||
const int h = window->last_size_pending ? window->pending.h : window->windowed.h;
|
||||
|
||||
original_displayID = SDL_GetDisplayForWindow(window);
|
||||
|
||||
if (SDL_WINDOWPOS_ISUNDEFINED(x)) {
|
||||
@@ -2785,26 +2787,24 @@ bool SDL_SetWindowPosition(SDL_Window *window, int x, int y)
|
||||
}
|
||||
|
||||
SDL_zero(bounds);
|
||||
if (!SDL_GetDisplayUsableBounds(displayID, &bounds) ||
|
||||
window->windowed.w > bounds.w ||
|
||||
window->windowed.h > bounds.h) {
|
||||
if (!SDL_GetDisplayUsableBounds(displayID, &bounds) || w > bounds.w || h > bounds.h) {
|
||||
if (!SDL_GetDisplayBounds(displayID, &bounds)) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
if (SDL_WINDOWPOS_ISCENTERED(x)) {
|
||||
x = bounds.x + (bounds.w - window->windowed.w) / 2;
|
||||
x = bounds.x + (bounds.w - w) / 2;
|
||||
}
|
||||
if (SDL_WINDOWPOS_ISCENTERED(y)) {
|
||||
y = bounds.y + (bounds.h - window->windowed.h) / 2;
|
||||
y = bounds.y + (bounds.h - h) / 2;
|
||||
}
|
||||
}
|
||||
|
||||
window->floating.x = x;
|
||||
window->floating.y = y;
|
||||
window->pending.x = x;
|
||||
window->pending.y = y;
|
||||
window->undefined_x = false;
|
||||
window->undefined_y = false;
|
||||
window->use_pending_position_for_fullscreen = true;
|
||||
window->last_position_pending = true;
|
||||
|
||||
if (_this->SetWindowPosition) {
|
||||
const bool result = _this->SetWindowPosition(_this, window);
|
||||
@@ -2952,8 +2952,9 @@ bool SDL_SetWindowSize(SDL_Window *window, int w, int h)
|
||||
h = window->max_h;
|
||||
}
|
||||
|
||||
window->floating.w = w;
|
||||
window->floating.h = h;
|
||||
window->last_size_pending = true;
|
||||
window->pending.w = w;
|
||||
window->pending.h = h;
|
||||
|
||||
if (_this->SetWindowSize) {
|
||||
_this->SetWindowSize(_this, window);
|
||||
|
||||
@@ -38,7 +38,8 @@ typedef enum
|
||||
PENDING_OPERATION_NONE = 0x00,
|
||||
PENDING_OPERATION_ENTER_FULLSCREEN = 0x01,
|
||||
PENDING_OPERATION_LEAVE_FULLSCREEN = 0x02,
|
||||
PENDING_OPERATION_MINIMIZE = 0x04
|
||||
PENDING_OPERATION_MINIMIZE = 0x04,
|
||||
PENDING_OPERATION_ZOOM = 0x08
|
||||
} PendingWindowOperation;
|
||||
|
||||
@interface SDL3Cocoa_WindowListener : NSResponder <NSWindowDelegate>
|
||||
@@ -144,10 +145,10 @@ typedef enum
|
||||
@property(nonatomic) SDL3Cocoa_WindowListener *listener;
|
||||
@property(nonatomic) NSModalSession modal_session;
|
||||
@property(nonatomic) SDL_CocoaVideoData *videodata;
|
||||
@property(nonatomic) bool send_floating_size;
|
||||
@property(nonatomic) bool send_floating_position;
|
||||
@property(nonatomic) bool pending_size;
|
||||
@property(nonatomic) bool pending_position;
|
||||
@property(nonatomic) bool border_toggled;
|
||||
@property(nonatomic) BOOL checking_zoom;
|
||||
|
||||
#ifdef SDL_VIDEO_OPENGL_EGL
|
||||
@property(nonatomic) EGLSurface egl_surface;
|
||||
#endif
|
||||
|
||||
File diff suppressed because it is too large
Load Diff
@@ -57,13 +57,13 @@ static void DUMMY_VideoQuit(SDL_VideoDevice *_this);
|
||||
|
||||
static bool DUMMY_SetWindowPosition(SDL_VideoDevice *_this, SDL_Window *window)
|
||||
{
|
||||
SDL_SendWindowEvent(window, SDL_EVENT_WINDOW_MOVED, window->floating.x, window->floating.y);
|
||||
SDL_SendWindowEvent(window, SDL_EVENT_WINDOW_MOVED, window->pending.x, window->pending.y);
|
||||
return true;
|
||||
}
|
||||
|
||||
static void DUMMY_SetWindowSize(SDL_VideoDevice *_this, SDL_Window *window)
|
||||
{
|
||||
SDL_SendWindowEvent(window, SDL_EVENT_WINDOW_RESIZED, window->floating.w, window->floating.h);
|
||||
SDL_SendWindowEvent(window, SDL_EVENT_WINDOW_RESIZED, window->pending.w, window->pending.h);
|
||||
}
|
||||
|
||||
// DUMMY driver bootstrap functions
|
||||
|
||||
@@ -327,14 +327,14 @@ static void Emscripten_SetWindowSize(SDL_VideoDevice *_this, SDL_Window *window)
|
||||
if (window->flags & SDL_WINDOW_HIGH_PIXEL_DENSITY) {
|
||||
data->pixel_ratio = emscripten_get_device_pixel_ratio();
|
||||
}
|
||||
emscripten_set_canvas_element_size(data->canvas_id, SDL_lroundf(window->floating.w * data->pixel_ratio), SDL_lroundf(window->floating.h * data->pixel_ratio));
|
||||
emscripten_set_canvas_element_size(data->canvas_id, SDL_lroundf(window->pending.w * data->pixel_ratio), SDL_lroundf(window->pending.h * data->pixel_ratio));
|
||||
|
||||
// scale canvas down
|
||||
if (!data->external_size && data->pixel_ratio != 1.0f) {
|
||||
emscripten_set_element_css_size(data->canvas_id, window->floating.w, window->floating.h);
|
||||
emscripten_set_element_css_size(data->canvas_id, window->pending.w, window->pending.h);
|
||||
}
|
||||
|
||||
SDL_SendWindowEvent(window, SDL_EVENT_WINDOW_RESIZED, window->floating.w, window->floating.h);
|
||||
SDL_SendWindowEvent(window, SDL_EVENT_WINDOW_RESIZED, window->pending.w, window->pending.h);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -100,8 +100,8 @@ void HAIKU_SetWindowTitle(SDL_VideoDevice *_this, SDL_Window * window)
|
||||
bool HAIKU_SetWindowPosition(SDL_VideoDevice *_this, SDL_Window * window)
|
||||
{
|
||||
BMessage msg(BWIN_MOVE_WINDOW);
|
||||
msg.AddInt32("window-x", window->floating.x);
|
||||
msg.AddInt32("window-y", window->floating.y);
|
||||
msg.AddInt32("window-x", window->pending.x);
|
||||
msg.AddInt32("window-y", window->pending.y);
|
||||
_ToBeWin(window)->PostMessage(&msg);
|
||||
return true;
|
||||
}
|
||||
@@ -109,8 +109,8 @@ bool HAIKU_SetWindowPosition(SDL_VideoDevice *_this, SDL_Window * window)
|
||||
void HAIKU_SetWindowSize(SDL_VideoDevice *_this, SDL_Window * window)
|
||||
{
|
||||
BMessage msg(BWIN_RESIZE_WINDOW);
|
||||
msg.AddInt32("window-w", window->floating.w - 1);
|
||||
msg.AddInt32("window-h", window->floating.h - 1);
|
||||
msg.AddInt32("window-w", window->pending.w - 1);
|
||||
msg.AddInt32("window-h", window->pending.h - 1);
|
||||
_ToBeWin(window)->PostMessage(&msg);
|
||||
}
|
||||
|
||||
|
||||
@@ -85,6 +85,6 @@ void OFFSCREEN_DestroyWindow(SDL_VideoDevice *_this, SDL_Window *window)
|
||||
|
||||
void OFFSCREEN_SetWindowSize(SDL_VideoDevice *_this, SDL_Window *window)
|
||||
{
|
||||
SDL_SendWindowEvent(window, SDL_EVENT_WINDOW_RESIZED, window->floating.w, window->floating.h);
|
||||
SDL_SendWindowEvent(window, SDL_EVENT_WINDOW_RESIZED, window->pending.w, window->pending.h);
|
||||
}
|
||||
#endif // SDL_VIDEO_DRIVER_OFFSCREEN
|
||||
|
||||
@@ -1138,12 +1138,12 @@ static void OPENVR_SetWindowSize(SDL_VideoDevice *_this, SDL_Window *window)
|
||||
{
|
||||
SDL_VideoData *data = (SDL_VideoData *)_this->internal;
|
||||
|
||||
if (window->floating.w != window->w) {
|
||||
window->w = window->floating.w;
|
||||
if (window->pending.w != window->w) {
|
||||
window->w = window->pending.w;
|
||||
}
|
||||
|
||||
if (window->floating.h != window->h) {
|
||||
window->h = window->floating.h;
|
||||
if (window->pending.h != window->h) {
|
||||
window->h = window->pending.h;
|
||||
}
|
||||
|
||||
if (data->targh != window->h || data->targw != window->w) {
|
||||
|
||||
@@ -246,8 +246,8 @@ static void setWindowSize(SDL_VideoDevice *_this, SDL_Window *window)
|
||||
window_impl_t *impl = (window_impl_t *)window->internal;
|
||||
int size[2];
|
||||
|
||||
size[0] = window->floating.w;
|
||||
size[1] = window->floating.h;
|
||||
size[0] = window->pending.w;
|
||||
size[1] = window->pending.h;
|
||||
|
||||
screen_set_window_property_iv(impl->window, SCREEN_PROPERTY_SIZE, size);
|
||||
screen_set_window_property_iv(impl->window, SCREEN_PROPERTY_SOURCE_SIZE, size);
|
||||
|
||||
File diff suppressed because it is too large
Load Diff
@@ -176,7 +176,7 @@ struct SDL_WindowData
|
||||
|
||||
SDL_DisplayID last_displayID;
|
||||
int fullscreen_deadline_count;
|
||||
int maximized_deadline_count;
|
||||
int maximized_restored_deadline_count;
|
||||
Uint64 last_focus_event_time_ns;
|
||||
bool floating;
|
||||
bool suspended;
|
||||
@@ -190,7 +190,6 @@ struct SDL_WindowData
|
||||
bool show_hide_sync_required;
|
||||
bool scale_to_display;
|
||||
bool reparenting_required;
|
||||
bool pending_restored_size;
|
||||
bool double_buffer;
|
||||
|
||||
SDL_HitTestResult hit_test_result;
|
||||
|
||||
@@ -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;
|
||||
|
||||
@@ -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;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -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;
|
||||
|
||||
@@ -1772,16 +1772,23 @@ static void X11_DispatchEvent(SDL_VideoDevice *_this, XEvent *xevent)
|
||||
}
|
||||
if (!(flags & (SDL_WINDOW_MAXIMIZED | SDL_WINDOW_MINIMIZED))) {
|
||||
data->pending_operation &= ~X11_PENDING_OP_RESTORE;
|
||||
if (SDL_SendWindowEvent(data->window, SDL_EVENT_WINDOW_RESTORED, 0, 0)) {
|
||||
// Restore the last known floating state if leaving maximized mode
|
||||
if (!(flags & SDL_WINDOW_FULLSCREEN)) {
|
||||
data->pending_operation |= X11_PENDING_OP_MOVE | X11_PENDING_OP_RESIZE;
|
||||
data->expected.x = data->window->floating.x - data->border_left;
|
||||
data->expected.y = data->window->floating.y - data->border_top;
|
||||
data->expected.w = data->window->floating.w;
|
||||
data->expected.h = data->window->floating.h;
|
||||
X11_XMoveWindow(display, data->xwindow, data->window->floating.x - data->border_left, data->window->floating.y - data->border_top);
|
||||
X11_XResizeWindow(display, data->xwindow, data->window->floating.w, data->window->floating.h);
|
||||
SDL_SendWindowEvent(data->window, SDL_EVENT_WINDOW_RESTORED, 0, 0);
|
||||
|
||||
// Apply any pending state if restored.
|
||||
if (!(flags & SDL_WINDOW_FULLSCREEN)) {
|
||||
if (data->pending_position) {
|
||||
data->pending_position = false;
|
||||
data->pending_operation |= X11_PENDING_OP_MOVE;
|
||||
data->expected.x = data->window->pending.x - data->border_left;
|
||||
data->expected.y = data->window->pending.y - data->border_top;
|
||||
X11_XMoveWindow(display, data->xwindow, data->window->pending.x - data->border_left, data->window->pending.y - data->border_top);
|
||||
}
|
||||
if (data->pending_size) {
|
||||
data->pending_size = false;
|
||||
data->pending_operation |= X11_PENDING_OP_RESIZE;
|
||||
data->expected.w = data->window->pending.w;
|
||||
data->expected.h = data->window->pending.h;
|
||||
X11_XResizeWindow(display, data->xwindow, data->window->pending.w, data->window->pending.h);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1812,18 +1819,28 @@ static void X11_DispatchEvent(SDL_VideoDevice *_this, XEvent *xevent)
|
||||
X11_GetBorderValues(data);
|
||||
if (data->border_top != 0 || data->border_left != 0 || data->border_right != 0 || data->border_bottom != 0) {
|
||||
// Adjust if the window size/position changed to accommodate the borders.
|
||||
if (data->window->flags & SDL_WINDOW_MAXIMIZED) {
|
||||
data->pending_operation |= X11_PENDING_OP_RESIZE;
|
||||
data->pending_operation |= X11_PENDING_OP_MOVE | X11_PENDING_OP_RESIZE;
|
||||
|
||||
if (data->pending_position) {
|
||||
data->pending_position = false;
|
||||
data->expected.x = data->window->pending.x - data->border_left;
|
||||
data->expected.y = data->window->pending.y - data->border_top;
|
||||
|
||||
} else {
|
||||
data->expected.x = data->window->windowed.x - data->border_left;
|
||||
data->expected.y = data->window->windowed.y - data->border_top;
|
||||
}
|
||||
|
||||
if (data->pending_size) {
|
||||
data->pending_size = false;
|
||||
data->expected.w = data->window->pending.w;
|
||||
data->expected.h = data->window->pending.h;
|
||||
} else {
|
||||
data->expected.w = data->window->windowed.w;
|
||||
data->expected.h = data->window->windowed.h;
|
||||
X11_XResizeWindow(display, data->xwindow, data->window->windowed.w, data->window->windowed.h);
|
||||
} else {
|
||||
data->pending_operation |= X11_PENDING_OP_RESIZE | X11_PENDING_OP_MOVE;
|
||||
data->expected.w = data->window->floating.w;
|
||||
data->expected.h = data->window->floating.h;
|
||||
X11_XMoveWindow(display, data->xwindow, data->window->floating.x - data->border_left, data->window->floating.y - data->border_top);
|
||||
X11_XResizeWindow(display, data->xwindow, data->window->floating.w, data->window->floating.h);
|
||||
}
|
||||
X11_XMoveWindow(display, data->xwindow, data->expected.x, data->expected.y - data->border_top);
|
||||
X11_XResizeWindow(display, data->xwindow, data->expected.w, data->expected.h);
|
||||
}
|
||||
}
|
||||
if (!(data->window->flags & SDL_WINDOW_FULLSCREEN) && data->toggle_borders) {
|
||||
|
||||
File diff suppressed because it is too large
Load Diff
@@ -103,6 +103,8 @@ struct SDL_WindowData
|
||||
X11_PENDING_OP_RESIZE = 0x20
|
||||
} pending_operation;
|
||||
|
||||
bool pending_size;
|
||||
bool pending_position;
|
||||
bool window_was_maximized;
|
||||
bool disable_size_position_events;
|
||||
bool previous_borders_nonzero;
|
||||
|
||||
+58
-11
@@ -2133,7 +2133,54 @@ static int SDLCALL video_getSetWindowState(void *arg)
|
||||
SDLTest_AssertCheck(windowedW == currentW, "Verify returned width; expected: %d, got: %d", windowedW, currentW);
|
||||
SDLTest_AssertCheck(windowedH == currentH, "Verify returned height; expected: %d, got: %d", windowedH, currentH);
|
||||
|
||||
/* Maximize, change size, and restore */
|
||||
/* Maximize, restore, and change size */
|
||||
result = SDL_MaximizeWindow(window);
|
||||
SDLTest_AssertPass("SDL_MaximizeWindow()");
|
||||
SDLTest_AssertCheck(result == true, "Verify return value; expected: true, got: %d", result);
|
||||
|
||||
result = SDL_RestoreWindow(window);
|
||||
SDLTest_AssertPass("SDL_RestoreWindow()");
|
||||
SDLTest_AssertCheck(result == true, "Verify return value; expected: true, got: %d", result);
|
||||
|
||||
desiredW = windowedW + 10;
|
||||
desiredH = windowedH + 10;
|
||||
result = SDL_SetWindowSize(window, desiredW, desiredH);
|
||||
SDLTest_AssertPass("SDL_SetWindowSize()");
|
||||
SDLTest_AssertCheck(result == true, "Verify return value; expected: true, got: %d", result);
|
||||
|
||||
if (!skipPos) {
|
||||
desiredX = windowedX + 10;
|
||||
desiredY = windowedY + 10;
|
||||
result = SDL_SetWindowPosition(window, desiredX, desiredY);
|
||||
SDLTest_AssertPass("SDL_SetWindowPosition()");
|
||||
SDLTest_AssertCheck(result == true, "Verify return value; expected: true, got: %d", result);
|
||||
}
|
||||
|
||||
result = SDL_SyncWindow(window);
|
||||
SDLTest_AssertPass("SDL_SyncWindow()");
|
||||
SDLTest_AssertCheck(result == true, "Verify return value; expected: true, got: %d", result);
|
||||
|
||||
flags = SDL_GetWindowFlags(window);
|
||||
SDLTest_AssertPass("SDL_GetWindowFlags()");
|
||||
SDLTest_AssertCheck(!(flags & SDL_WINDOW_MAXIMIZED), "Verify that the `SDL_WINDOW_MAXIMIZED` flag is cleared: %s", !(flags & SDL_WINDOW_MAXIMIZED) ? "true" : "false");
|
||||
|
||||
if (!skipPos) {
|
||||
currentX = desiredX + 1;
|
||||
currentY = desiredY + 1;
|
||||
SDL_GetWindowPosition(window, ¤tX, ¤tY);
|
||||
SDLTest_AssertPass("Call to SDL_GetWindowPosition()");
|
||||
SDLTest_AssertCheck(desiredX == currentX, "Verify returned X coordinate; expected: %d, got: %d", desiredX, currentX);
|
||||
SDLTest_AssertCheck(desiredY == currentY, "Verify returned Y coordinate; expected: %d, got: %d", desiredY, currentY);
|
||||
}
|
||||
|
||||
currentW = desiredW + 1;
|
||||
currentH = desiredH + 1;
|
||||
SDL_GetWindowSize(window, ¤tW, ¤tH);
|
||||
SDLTest_AssertPass("Call to SDL_GetWindowSize()");
|
||||
SDLTest_AssertCheck(desiredW == currentW, "Verify returned width; expected: %d, got: %d", desiredW, currentW);
|
||||
SDLTest_AssertCheck(desiredH == currentH, "Verify returned height; expected: %d, got: %d", desiredH, currentH);
|
||||
|
||||
/* Maximize, change size/position (should be ignored), and restore. */
|
||||
result = SDL_MaximizeWindow(window);
|
||||
SDLTest_AssertPass("SDL_MaximizeWindow()");
|
||||
SDLTest_AssertCheck(result == true, "Verify return value; expected: true, got: %d", result);
|
||||
@@ -2165,20 +2212,20 @@ static int SDLCALL video_getSetWindowState(void *arg)
|
||||
SDLTest_AssertCheck(!(flags & SDL_WINDOW_MAXIMIZED), "Verify that the `SDL_WINDOW_MAXIMIZED` flag is cleared: %s", !(flags & SDL_WINDOW_MAXIMIZED) ? "true" : "false");
|
||||
|
||||
if (!skipPos) {
|
||||
currentX = desiredX + 1;
|
||||
currentY = desiredY + 1;
|
||||
SDL_GetWindowPosition(window, ¤tX, ¤tY);
|
||||
int previousX = desiredX + 1;
|
||||
int previousY = desiredY + 1;
|
||||
SDL_GetWindowPosition(window, &previousX, &previousY);
|
||||
SDLTest_AssertPass("Call to SDL_GetWindowPosition()");
|
||||
SDLTest_AssertCheck(desiredX == currentX, "Verify returned X coordinate; expected: %d, got: %d", desiredX, currentX);
|
||||
SDLTest_AssertCheck(desiredY == currentY, "Verify returned Y coordinate; expected: %d, got: %d", desiredY, currentY);
|
||||
SDLTest_AssertCheck(desiredX == currentX, "Verify returned X coordinate; expected: %d, got: %d", previousX, currentX);
|
||||
SDLTest_AssertCheck(desiredY == currentY, "Verify returned Y coordinate; expected: %d, got: %d", previousY, currentY);
|
||||
}
|
||||
|
||||
currentW = desiredW + 1;
|
||||
currentH = desiredH + 1;
|
||||
SDL_GetWindowSize(window, ¤tW, ¤tH);
|
||||
int previousW = desiredW + 1;
|
||||
int previousH = desiredH + 1;
|
||||
SDL_GetWindowSize(window, &previousW, &previousH);
|
||||
SDLTest_AssertPass("Call to SDL_GetWindowSize()");
|
||||
SDLTest_AssertCheck(desiredW == currentW, "Verify returned width; expected: %d, got: %d", desiredW, currentW);
|
||||
SDLTest_AssertCheck(desiredH == currentH, "Verify returned height; expected: %d, got: %d", desiredH, currentH);
|
||||
SDLTest_AssertCheck(desiredW == currentW, "Verify returned width; expected: %d, got: %d", previousW, currentW);
|
||||
SDLTest_AssertCheck(desiredH == currentH, "Verify returned height; expected: %d, got: %d", previousH, currentH);
|
||||
|
||||
/* Change size and position, maximize and restore */
|
||||
desiredW = windowedW - 5;
|
||||
|
||||
Reference in New Issue
Block a user