Window event at initiation of window resize

This is related to the ongoing thread here but is a different and higher-level question, so I didn’t want to hijack that thread.

I’ve noticed and others here seem to confirm that SDL does not capture events during a window resize, or at the beginning of a resize action; an event is only emitted when the resize is done (when the user releases the mouse button). During resize, the rendered image is just stretched to fit the new size, and is only re-drawn when the resize is done (at least on macOS). The workaround being discussed in the other thread is platform-specific, which is not viable for my application, and I’d guess probably not for many applications that use SDL.

Without additional context, the absence of a window event at the start of a resize feels like an oversight. Do folks know if there is a reason SDL2 doesn’t or can’t do this? Is it something that might be added in the future? For now, I’m just living with the stretching during resize, but that isn’t how most users would expect an application to behave, so of course a viable course a cross-platform solution would be really helpful.

Is this the same issue that was discussed here? As far as I understand that problem, SDL_PollEvent simply blocks on some platforms while the resize is taking place. Have you tried the workaround described here? I asked some follow-up questions related to this in another thread.

2 Likes

@Peter87 Yes, it’s the same issue, and yes, that workaround works! Thank you! I had seen that bug report but dismissed it because I’m not using Windows; I see now the reference in the comments to the same issue existing on macos. I’m glad you asked about the thread-safety issue too, because that made me nervous when I first saw the workaround.

For anyone else who winds up here, this is the gist of the workaround:

/* Declare a callback function to handle SDL_WINDOWEVENT_EXPOSED */
static int SDLCALL special_event_callback(void *userdata, SDL_Event *event)
{
    if (event->type == SDL_WINDOWEVENT && event->window.event == SDL_WINDOWEVENT_EXPOSED) {
	/* Handle event here */
    }
    return 0;
}

/* Somewhere before the main event loop, add the event handler */
SDL_AddEventWatch(special_event_callback, NULL);