Call SDL_OnWindow* handlers after the event has been delivered

This guarantees that events which trigger other events will happen in dependency order, instead of being reversed.
main
Sam Lantinga 2023-01-28 15:27:20 -08:00
parent 432af82a88
commit df7639f100
3 changed files with 49 additions and 12 deletions

View File

@ -55,14 +55,12 @@ int SDL_SendWindowEvent(SDL_Window *window, SDL_EventType windowevent,
return 0; return 0;
} }
window->flags &= ~(SDL_WINDOW_HIDDEN | SDL_WINDOW_MINIMIZED); window->flags &= ~(SDL_WINDOW_HIDDEN | SDL_WINDOW_MINIMIZED);
SDL_OnWindowShown(window);
break; break;
case SDL_EVENT_WINDOW_HIDDEN: case SDL_EVENT_WINDOW_HIDDEN:
if (window->flags & SDL_WINDOW_HIDDEN) { if (window->flags & SDL_WINDOW_HIDDEN) {
return 0; return 0;
} }
window->flags |= SDL_WINDOW_HIDDEN; window->flags |= SDL_WINDOW_HIDDEN;
SDL_OnWindowHidden(window);
break; break;
case SDL_EVENT_WINDOW_MOVED: case SDL_EVENT_WINDOW_MOVED:
if (SDL_WINDOWPOS_ISUNDEFINED(data1) || if (SDL_WINDOWPOS_ISUNDEFINED(data1) ||
@ -78,7 +76,6 @@ int SDL_SendWindowEvent(SDL_Window *window, SDL_EventType windowevent,
} }
window->x = data1; window->x = data1;
window->y = data2; window->y = data2;
SDL_OnWindowMoved(window);
break; break;
case SDL_EVENT_WINDOW_RESIZED: case SDL_EVENT_WINDOW_RESIZED:
if ((window->flags & SDL_WINDOW_FULLSCREEN_MASK) == 0) { if ((window->flags & SDL_WINDOW_FULLSCREEN_MASK) == 0) {
@ -91,7 +88,6 @@ int SDL_SendWindowEvent(SDL_Window *window, SDL_EventType windowevent,
} }
window->w = data1; window->w = data1;
window->h = data2; window->h = data2;
SDL_OnWindowResized(window);
break; break;
case SDL_EVENT_WINDOW_PIXEL_SIZE_CHANGED: case SDL_EVENT_WINDOW_PIXEL_SIZE_CHANGED:
if (data1 == window->last_pixel_w && data2 == window->last_pixel_h) { if (data1 == window->last_pixel_w && data2 == window->last_pixel_h) {
@ -99,7 +95,6 @@ int SDL_SendWindowEvent(SDL_Window *window, SDL_EventType windowevent,
} }
window->last_pixel_w = data1; window->last_pixel_w = data1;
window->last_pixel_h = data2; window->last_pixel_h = data2;
SDL_OnWindowPixelSizeChanged(window);
break; break;
case SDL_EVENT_WINDOW_MINIMIZED: case SDL_EVENT_WINDOW_MINIMIZED:
if (window->flags & SDL_WINDOW_MINIMIZED) { if (window->flags & SDL_WINDOW_MINIMIZED) {
@ -107,7 +102,6 @@ int SDL_SendWindowEvent(SDL_Window *window, SDL_EventType windowevent,
} }
window->flags &= ~SDL_WINDOW_MAXIMIZED; window->flags &= ~SDL_WINDOW_MAXIMIZED;
window->flags |= SDL_WINDOW_MINIMIZED; window->flags |= SDL_WINDOW_MINIMIZED;
SDL_OnWindowMinimized(window);
break; break;
case SDL_EVENT_WINDOW_MAXIMIZED: case SDL_EVENT_WINDOW_MAXIMIZED:
if (window->flags & SDL_WINDOW_MAXIMIZED) { if (window->flags & SDL_WINDOW_MAXIMIZED) {
@ -121,42 +115,36 @@ int SDL_SendWindowEvent(SDL_Window *window, SDL_EventType windowevent,
return 0; return 0;
} }
window->flags &= ~(SDL_WINDOW_MINIMIZED | SDL_WINDOW_MAXIMIZED); window->flags &= ~(SDL_WINDOW_MINIMIZED | SDL_WINDOW_MAXIMIZED);
SDL_OnWindowRestored(window);
break; break;
case SDL_EVENT_WINDOW_MOUSE_ENTER: case SDL_EVENT_WINDOW_MOUSE_ENTER:
if (window->flags & SDL_WINDOW_MOUSE_FOCUS) { if (window->flags & SDL_WINDOW_MOUSE_FOCUS) {
return 0; return 0;
} }
window->flags |= SDL_WINDOW_MOUSE_FOCUS; window->flags |= SDL_WINDOW_MOUSE_FOCUS;
SDL_OnWindowEnter(window);
break; break;
case SDL_EVENT_WINDOW_MOUSE_LEAVE: case SDL_EVENT_WINDOW_MOUSE_LEAVE:
if (!(window->flags & SDL_WINDOW_MOUSE_FOCUS)) { if (!(window->flags & SDL_WINDOW_MOUSE_FOCUS)) {
return 0; return 0;
} }
window->flags &= ~SDL_WINDOW_MOUSE_FOCUS; window->flags &= ~SDL_WINDOW_MOUSE_FOCUS;
SDL_OnWindowLeave(window);
break; break;
case SDL_EVENT_WINDOW_FOCUS_GAINED: case SDL_EVENT_WINDOW_FOCUS_GAINED:
if (window->flags & SDL_WINDOW_INPUT_FOCUS) { if (window->flags & SDL_WINDOW_INPUT_FOCUS) {
return 0; return 0;
} }
window->flags |= SDL_WINDOW_INPUT_FOCUS; window->flags |= SDL_WINDOW_INPUT_FOCUS;
SDL_OnWindowFocusGained(window);
break; break;
case SDL_EVENT_WINDOW_FOCUS_LOST: case SDL_EVENT_WINDOW_FOCUS_LOST:
if (!(window->flags & SDL_WINDOW_INPUT_FOCUS)) { if (!(window->flags & SDL_WINDOW_INPUT_FOCUS)) {
return 0; return 0;
} }
window->flags &= ~SDL_WINDOW_INPUT_FOCUS; window->flags &= ~SDL_WINDOW_INPUT_FOCUS;
SDL_OnWindowFocusLost(window);
break; break;
case SDL_EVENT_WINDOW_DISPLAY_CHANGED: case SDL_EVENT_WINDOW_DISPLAY_CHANGED:
if (data1 < 0 || data1 == window->display_index) { if (data1 < 0 || data1 == window->display_index) {
return 0; return 0;
} }
window->display_index = data1; window->display_index = data1;
SDL_OnWindowDisplayChanged(window);
break; break;
default: default:
break; break;
@ -182,6 +170,50 @@ int SDL_SendWindowEvent(SDL_Window *window, SDL_EventType windowevent,
posted = (SDL_PushEvent(&event) > 0); posted = (SDL_PushEvent(&event) > 0);
} }
switch (windowevent) {
case SDL_EVENT_WINDOW_SHOWN:
SDL_OnWindowShown(window);
break;
case SDL_EVENT_WINDOW_HIDDEN:
SDL_OnWindowHidden(window);
break;
case SDL_EVENT_WINDOW_MOVED:
SDL_OnWindowMoved(window);
break;
case SDL_EVENT_WINDOW_RESIZED:
SDL_OnWindowResized(window);
break;
case SDL_EVENT_WINDOW_PIXEL_SIZE_CHANGED:
SDL_OnWindowPixelSizeChanged(window);
break;
case SDL_EVENT_WINDOW_MINIMIZED:
SDL_OnWindowMinimized(window);
break;
case SDL_EVENT_WINDOW_MAXIMIZED:
SDL_OnWindowMaximized(window);
break;
case SDL_EVENT_WINDOW_RESTORED:
SDL_OnWindowRestored(window);
break;
case SDL_EVENT_WINDOW_MOUSE_ENTER:
SDL_OnWindowEnter(window);
break;
case SDL_EVENT_WINDOW_MOUSE_LEAVE:
SDL_OnWindowLeave(window);
break;
case SDL_EVENT_WINDOW_FOCUS_GAINED:
SDL_OnWindowFocusGained(window);
break;
case SDL_EVENT_WINDOW_FOCUS_LOST:
SDL_OnWindowFocusLost(window);
break;
case SDL_EVENT_WINDOW_DISPLAY_CHANGED:
SDL_OnWindowDisplayChanged(window);
break;
default:
break;
}
if (windowevent == SDL_EVENT_WINDOW_CLOSE_REQUESTED) { if (windowevent == SDL_EVENT_WINDOW_CLOSE_REQUESTED) {
if (!window->prev && !window->next) { if (!window->prev && !window->next) {
if (SDL_GetHintBoolean(SDL_HINT_QUIT_ON_LAST_WINDOW_CLOSE, SDL_TRUE)) { if (SDL_GetHintBoolean(SDL_HINT_QUIT_ON_LAST_WINDOW_CLOSE, SDL_TRUE)) {

View File

@ -502,6 +502,7 @@ extern void SDL_OnWindowResized(SDL_Window *window);
extern void SDL_CheckWindowPixelSizeChanged(SDL_Window *window); extern void SDL_CheckWindowPixelSizeChanged(SDL_Window *window);
extern void SDL_OnWindowPixelSizeChanged(SDL_Window *window); extern void SDL_OnWindowPixelSizeChanged(SDL_Window *window);
extern void SDL_OnWindowMinimized(SDL_Window *window); extern void SDL_OnWindowMinimized(SDL_Window *window);
extern void SDL_OnWindowMaximized(SDL_Window *window);
extern void SDL_OnWindowRestored(SDL_Window *window); extern void SDL_OnWindowRestored(SDL_Window *window);
extern void SDL_OnWindowEnter(SDL_Window *window); extern void SDL_OnWindowEnter(SDL_Window *window);
extern void SDL_OnWindowLeave(SDL_Window *window); extern void SDL_OnWindowLeave(SDL_Window *window);

View File

@ -3079,6 +3079,10 @@ void SDL_OnWindowMinimized(SDL_Window *window)
} }
} }
void SDL_OnWindowMaximized(SDL_Window *window)
{
}
void SDL_OnWindowRestored(SDL_Window *window) void SDL_OnWindowRestored(SDL_Window *window)
{ {
/* /*