diff --git a/src/events/SDL_windowevents.c b/src/events/SDL_windowevents.c index cc8b891df..209295afc 100644 --- a/src/events/SDL_windowevents.c +++ b/src/events/SDL_windowevents.c @@ -27,15 +27,27 @@ #include "SDL_mouse_c.h" #include "SDL_hints.h" -static int SDLCALL -RemovePendingSizeChangedAndResizedEvents(void * userdata, SDL_Event *event) +typedef struct RemovePendingSizeChangedAndResizedEvents_Data { - SDL_Event *new_event = (SDL_Event *)userdata; + const SDL_Event *new_event; + SDL_bool saw_resized; +} RemovePendingSizeChangedAndResizedEvents_Data; + +static int SDLCALL +RemovePendingSizeChangedAndResizedEvents(void *_userdata, SDL_Event *event) +{ + RemovePendingSizeChangedAndResizedEvents_Data *userdata = (RemovePendingSizeChangedAndResizedEvents_Data *) _userdata; + const SDL_Event *new_event = userdata->new_event; if (event->type == SDL_WINDOWEVENT && (event->window.event == SDL_WINDOWEVENT_SIZE_CHANGED || event->window.event == SDL_WINDOWEVENT_RESIZED) && event->window.windowID == new_event->window.windowID) { + + if (event->window.event == SDL_WINDOWEVENT_RESIZED) { + userdata->saw_resized = SDL_TRUE; + } + /* We're about to post a new size event, drop the old one */ return 0; } @@ -188,7 +200,18 @@ SDL_SendWindowEvent(SDL_Window * window, Uint8 windowevent, int data1, /* Fixes queue overflow with resize events that aren't processed */ if (windowevent == SDL_WINDOWEVENT_SIZE_CHANGED) { - SDL_FilterEvents(RemovePendingSizeChangedAndResizedEvents, &event); + /* !!! FIXME: in SDL3, let's make RESIZED/SIZE_CHANGED into one event with a flag to distinguish between them, and remove all this tapdancing. */ + RemovePendingSizeChangedAndResizedEvents_Data userdata; + userdata.new_event = &event; + userdata.saw_resized = SDL_FALSE; + SDL_FilterEvents(RemovePendingSizeChangedAndResizedEvents, &userdata); + if (userdata.saw_resized) { /* if there was a pending resize, make sure one at the new dimensions remains. */ + event.window.event = SDL_WINDOWEVENT_RESIZED; + if (SDL_PushEvent(&event) <= 0) { + return 0; /* oh well. */ + } + event.window.event = SDL_WINDOWEVENT_SIZE_CHANGED; /* then push the actual event next. */ + } } if (windowevent == SDL_WINDOWEVENT_MOVED) { SDL_FilterEvents(RemovePendingMoveEvents, &event); @@ -207,7 +230,7 @@ SDL_SendWindowEvent(SDL_Window * window, Uint8 windowevent, int data1, } } - return (posted); + return posted; } /* vi: set ts=4 sw=4 expandtab: */