sdl2-compat: Drop some SDL3 events that incorrectly overlap SDL2 events

From c7a598732a72b8c0986f2715bc548437eb840fda Mon Sep 17 00:00:00 2001
From: Frank Praznik <[EMAIL REDACTED]>
Date: Mon, 24 Feb 2025 12:46:47 -0500
Subject: [PATCH] Drop some SDL3 events that incorrectly overlap SDL2 events

The SDL3 keyboard added event number overlaps the SDL2 SDL_TEXTEDITING_EXT event, which can cause a client to crash if it tries processing the keyboard added event as an IME text candidate event.

Just drop the keyboard added/removed events from the queue, as they have no SDL2 equivalent and would only be ignored.
---
 src/sdl2_compat.c | 7 +++++++
 1 file changed, 7 insertions(+)

diff --git a/src/sdl2_compat.c b/src/sdl2_compat.c
index fbb1a83..f128024 100644
--- a/src/sdl2_compat.c
+++ b/src/sdl2_compat.c
@@ -2091,6 +2091,13 @@ EventFilter3to2(void *userdata, SDL_Event *event3)
     SDL2_Event event2;  /* note that event filters do not receive events as const! So we have to convert or copy it for each one! */
     bool post_event = true;
 
+    /* Drop SDL3 events which have no SDL2 equivalent and may incorrectly overlap with SDL2 event numbers. */
+    switch (event3->type) {
+        case SDL_EVENT_KEYBOARD_ADDED: /* Overlaps with SDL_TEXTEDITING_EXT */
+        case SDL_EVENT_KEYBOARD_REMOVED:
+            return false;
+    }
+
     GestureProcessEvent(event3);  /* this might need to generate new gesture events from touch input. */
 
     /* Ensure joystick and haptic IDs are updated before calling Event3to2() */