sdl12-compat: events: Don't send SDL_VIDEOEXPOSE events during window creation.

From f388224779a924108d97596e039d07b5fad7f2a6 Mon Sep 17 00:00:00 2001
From: "Ryan C. Gordon" <[EMAIL REDACTED]>
Date: Thu, 6 Oct 2022 23:44:02 -0400
Subject: [PATCH] events: Don't send SDL_VIDEOEXPOSE events during window
 creation.

SDL 1.2 doesn't do so either, at least on X11, and doing so triggers a bug
in Bloboats, so we'll avoid it to try to maximize compatibility.

Fixes #229.
---
 src/SDL12_compat.c | 22 +++++++++++++++++++---
 1 file changed, 19 insertions(+), 3 deletions(-)

diff --git a/src/SDL12_compat.c b/src/SDL12_compat.c
index dc230f3a5..a7dfa5c30 100644
--- a/src/SDL12_compat.c
+++ b/src/SDL12_compat.c
@@ -948,6 +948,7 @@ static SDL12_PixelFormat VideoInfoVfmt12;
 static SDL_PixelFormat *VideoInfoVfmt20 = NULL;
 static SDL_bool VideoWindowGrabbed = SDL_FALSE;
 static SDL_bool VideoCursorHidden = SDL_FALSE;
+static SDL_bool SetVideoModeInProgress = SDL_FALSE;
 static SDL_Window *VideoWindow20 = NULL;
 static SDL_Renderer *VideoRenderer20 = NULL;
 static SDL_mutex *VideoRendererLock = NULL;
@@ -4334,7 +4335,10 @@ EventFilter20to12(void *data, SDL_Event *event20)
 
                 case SDL_WINDOWEVENT_SHOWN:
                 case SDL_WINDOWEVENT_EXPOSED:
-                    event12.type = SDL12_VIDEOEXPOSE;
+                    /* drop these during window creation (see issue #229) */
+                    if (!SetVideoModeInProgress) {
+                        event12.type = SDL12_VIDEOEXPOSE;
+                    }
                     break;
 
                 case SDL_WINDOWEVENT_RESIZED: {
@@ -5695,8 +5699,8 @@ UnlockVideoRenderer(void)
 
 static void HandleInputGrab(SDL12_GrabMode mode);
 
-DECLSPEC12 SDL12_Surface * SDLCALL
-SDL_SetVideoMode(int width, int height, int bpp, Uint32 flags12)
+static SDL12_Surface *
+SetVideoModeImpl(int width, int height, int bpp, Uint32 flags12)
 {
     SDL_DisplayMode dmode;
     Uint32 fullscreen_flags20 = 0;
@@ -6130,9 +6134,21 @@ SDL_SetVideoMode(int width, int height, int bpp, Uint32 flags12)
         UnlockVideoRenderer();
     }
 
+    SDL_PumpEvents();  /* run this once at startup. */
+
     return VideoSurface12;
 }
 
+DECLSPEC12 SDL12_Surface * SDLCALL
+SDL_SetVideoMode(int width, int height, int bpp, Uint32 flags12)
+{
+    SDL12_Surface *retval;
+    SetVideoModeInProgress = SDL_TRUE;
+    retval = SetVideoModeImpl(width, height, bpp, flags12);
+    SetVideoModeInProgress = SDL_FALSE;
+    return retval;
+}
+
 DECLSPEC12 SDL12_Surface * SDLCALL
 SDL_GetVideoSurface(void)
 {