testautomation_video: if SDL_SetWindowSize/Position isn't honored, we should check there is an event

x11: send the events if various occasions
This commit is contained in:
Sylvain
2023-03-20 11:25:10 +01:00
committed by Sylvain Becker
parent 4b1378fe8e
commit d4d26e0ddb
2 changed files with 90 additions and 16 deletions

View File

@@ -894,6 +894,7 @@ void X11_UpdateWindowPosition(SDL_Window *window)
Window childReturn, root, parent;
Window *children;
XWindowAttributes attrs;
int x, y;
int dest_x, dest_y;
int orig_x, orig_y;
Uint64 timeout;
@@ -918,8 +919,6 @@ void X11_UpdateWindowPosition(SDL_Window *window)
timeout = SDL_GetTicks() + 100;
while (SDL_TRUE) {
int x, y;
caught_x11_error = SDL_FALSE;
X11_XSync(display, False);
X11_XGetWindowAttributes(display, data->xwindow, &attrs);
@@ -931,8 +930,6 @@ void X11_UpdateWindowPosition(SDL_Window *window)
if (SDL_WINDOW_IS_POPUP(window)) {
SDL_GlobalToRelativeForWindow(window, x, y, &x, &y);
}
window->x = x;
window->y = y;
break; /* window moved, time to go. */
} else if ((x == dest_x) && (y == dest_y)) {
break; /* we're at the place we wanted to be anyhow, drop out. */
@@ -946,6 +943,11 @@ void X11_UpdateWindowPosition(SDL_Window *window)
SDL_Delay(10);
}
if (!caught_x11_error) {
SDL_SendWindowEvent(window, SDL_EVENT_WINDOW_MOVED, x, y);
SDL_SendWindowEvent(window, SDL_EVENT_WINDOW_RESIZED, attrs.width, attrs.height);
}
X11_XSetErrorHandler(prev_handler);
caught_x11_error = SDL_FALSE;
@@ -1087,8 +1089,6 @@ void X11_SetWindowSize(_THIS, SDL_Window *window)
if (!caught_x11_error) {
if ((attrs.width != orig_w) || (attrs.height != orig_h)) {
window->w = attrs.width;
window->h = attrs.height;
break; /* window changed, time to go. */
} else if ((attrs.width == window->w) && (attrs.height == window->h)) {
break; /* we're at the place we wanted to be anyhow, drop out. */
@@ -1097,15 +1097,24 @@ void X11_SetWindowSize(_THIS, SDL_Window *window)
if (SDL_GetTicks() >= timeout) {
/* Timeout occurred and window size didn't change
* window manager likely denied the resize. */
window->w = orig_w;
window->h = orig_h;
* window manager likely denied the resize,
* or the new size is the same as the existing:
* - current width: is 'full width'.
* - try to set new width at 'full width + 1', which get truncated to 'full width'.
* - new width is/remains 'full width'
* So, even if we break here as a timeout, we can send an event, since the requested size isn't the same
* as the final size. (even if final size is same as original size).
*/
break;
}
SDL_Delay(10);
}
if (!caught_x11_error) {
SDL_SendWindowEvent(window, SDL_EVENT_WINDOW_RESIZED, attrs.width, attrs.height);
}
X11_XSetErrorHandler(prev_handler);
caught_x11_error = SDL_FALSE;
}
@@ -1455,6 +1464,7 @@ static void X11_SetWindowFullscreenViaWM(_THIS, SDL_Window *window, SDL_VideoDis
Window childReturn, root, parent;
Window *children;
XWindowAttributes attrs;
int x, y;
int orig_w, orig_h, orig_x, orig_y;
Uint64 timeout;
@@ -1542,7 +1552,6 @@ static void X11_SetWindowFullscreenViaWM(_THIS, SDL_Window *window, SDL_VideoDis
timeout = SDL_GetTicks() + 100;
while (SDL_TRUE) {
int x, y;
caught_x11_error = SDL_FALSE;
X11_XSync(display, False);
@@ -1554,14 +1563,12 @@ static void X11_SetWindowFullscreenViaWM(_THIS, SDL_Window *window, SDL_VideoDis
if ((x != orig_x) || (y != orig_y)) {
orig_x = x;
orig_y = y;
SDL_SendWindowEvent(data->window, SDL_EVENT_WINDOW_MOVED, x, y);
window_position_changed += 1;
}
if ((attrs.width != orig_w) || (attrs.height != orig_h)) {
orig_w = attrs.width;
orig_h = attrs.height;
SDL_SendWindowEvent(data->window, SDL_EVENT_WINDOW_RESIZED, attrs.width, attrs.height);
window_size_changed = SDL_TRUE;
}
@@ -1578,6 +1585,11 @@ static void X11_SetWindowFullscreenViaWM(_THIS, SDL_Window *window, SDL_VideoDis
SDL_Delay(10);
}
if (!caught_x11_error) {
SDL_SendWindowEvent(window, SDL_EVENT_WINDOW_MOVED, x, y);
SDL_SendWindowEvent(window, SDL_EVENT_WINDOW_RESIZED, attrs.width, attrs.height);
}
X11_XSetErrorHandler(prev_handler);
caught_x11_error = SDL_FALSE;
} else {