fix multiple redraw events (only handle last one)
authorkub <derkub@gmail.com>
Sun, 9 Feb 2025 18:45:33 +0000 (19:45 +0100)
committerkub <derkub@gmail.com>
Sun, 9 Feb 2025 22:57:36 +0000 (23:57 +0100)
in_sdl.c
plat_sdl.c
plat_sdl.h

index 9bde4fd..43d44c5 100644 (file)
--- a/in_sdl.c
+++ b/in_sdl.c
@@ -26,6 +26,7 @@ struct in_sdl_state {
        int axis_keydown[2];
 #ifdef SDL_REDRAW_EVT
        int rdraw;
+       SDL_Event redraw;
 #endif
        keybits_t keystate[SDLK_LAST / KEYBITS_WORD_BITS + 1];
        // emulator keys should always be processed immediately lest one is lost
@@ -382,8 +383,10 @@ static int collect_events(struct in_sdl_state *state, int *one_kc, int *one_down
                                                break;
                                        default:
 #ifdef SDL_REDRAW_EVT
-                                               state->rdraw |= (one_kc != NULL &&
-                                                       event->type == SDL_VIDEORESIZE);
+                                               if (event->type == SDL_VIDEORESIZE) {
+                                                       state->rdraw = 1;
+                                                       state->redraw = *event;
+                                               } else
 #endif
                                                if (ext_event_handler != NULL)
                                                        ext_event_handler(event);
@@ -403,6 +406,8 @@ static int collect_events(struct in_sdl_state *state, int *one_kc, int *one_down
 #ifdef SDL_REDRAW_EVT
        // if the event queue has been emptied and resize events were in it
        if (state->rdraw && count == 0) {
+               if (ext_event_handler != NULL)
+                       ext_event_handler(&state->redraw);
                state->rdraw = 0;
                // dummy key event to force returning from the key loop,
                // so the application has a chance to redraw the window
index f90827a..2c983d7 100644 (file)
@@ -154,6 +154,8 @@ int plat_sdl_change_video_mode(int w, int h, int force)
         plat_sdl_screen->w != win_w || plat_sdl_screen->h != win_h)
       plat_sdl_screen = SDL_SetVideoMode(win_w, win_h, 16, flags);
     screen_flags = flags;
+    window_w = win_w;
+    window_h = win_h;
     if (plat_sdl_screen == NULL) {
       fprintf(stderr, "SDL_SetVideoMode failed: %s\n", SDL_GetError());
       return -1;
@@ -383,4 +385,10 @@ int plat_sdl_is_windowed(void)
 {
   return window_b != 0;
 }
+
+int plat_sdl_is_fullscreen(void)
+{
+  // consider window title bar and screen menu here
+  return window_w >= fs_w && window_h >= fs_h - 2*window_b;
+}
 // vim:shiftwidth=2:expandtab
index 13e5197..5e6016d 100644 (file)
@@ -8,6 +8,7 @@ extern void (*plat_sdl_quit_cb)(void);
 
 int plat_sdl_init(void);
 int plat_sdl_is_windowed(void);
+int plat_sdl_is_fullscreen(void);
 int plat_sdl_change_video_mode(int w, int h, int force);
 void plat_sdl_overlay_clear(void);
 void plat_sdl_event_handler(void *event_);