From 5b5cbd7f4b1f5ceafd338109d1c3d86082a30ca9 Mon Sep 17 00:00:00 2001 From: Patryk Obara Date: Sat, 11 Apr 2020 00:11:30 +0200 Subject: [PATCH] Watch window resize events --- src/gui/sdlmain.cpp | 34 ++++++++++++++++++++++++++++++++++ 1 file changed, 34 insertions(+) diff --git a/src/gui/sdlmain.cpp b/src/gui/sdlmain.cpp index f09878f4..3dc6633b 100644 --- a/src/gui/sdlmain.cpp +++ b/src/gui/sdlmain.cpp @@ -422,6 +422,37 @@ void GFX_SetTitle(Bit32s cycles, int /*frameskip*/, bool paused) SDL_SetWindowTitle(sdl.window, title); } +/* This function is SDL_EventFilter which is being called when event is + * pushed into the SDL event queue. + * + * WARNING: Be very careful of what you do in this function, as it may run in + * a different thread! + * + * Read documentation for SDL_AddEventWatch for more details. + */ +static int watch_sdl_events(void *userdata, SDL_Event *e) +{ + /* There's a significant difference in handling of window resize + * events in different OSes. When handling resize in main event loop + * we receive continuous stream of events (as expected) on Linux, + * but only single event after user stopped dragging cursor on Windows + * and macOS. + * + * Watching resize events here gives us continuous stream on + * every OS. + */ + if (e->type == SDL_WINDOWEVENT && e->window.event == SDL_WINDOWEVENT_RESIZED) { + SDL_Window *win = SDL_GetWindowFromID(e->window.windowID); + if (win == (SDL_Window *)userdata) { + const int w = e->window.data1; + const int h = e->window.data2; + DEBUG_LOG_MSG("SDL: Resizing window %d to %dx%d", + e->window.windowID, w, h); + } + } + return 0; +} + static unsigned char logo[32*32*4]= { #include "dosbox_logo.h" }; @@ -591,6 +622,9 @@ static SDL_Window *SetWindowMode(SCREEN_TYPES screen_type, const int sdl_pos = SDL_WINDOWPOS_UNDEFINED_DISPLAY(sdl.display_number); sdl.window = SDL_CreateWindow("", sdl_pos, sdl_pos, width, height, flags); + if (resizable) + SDL_AddEventWatch(watch_sdl_events, sdl.window); + if (!sdl.window) { return sdl.window; }