SDL: Revert "x11: Avoid excess keymap reconstruction"

From a4ceb3a31c4ba992d3c01cba59c091bd25c4da6a Mon Sep 17 00:00:00 2001
From: Frank Praznik <[EMAIL REDACTED]>
Date: Sun, 23 Jun 2024 22:19:46 -0400
Subject: [PATCH] Revert "x11: Avoid excess keymap reconstruction"

Switching between layouts with the same group number (e.g. US to Japanese) were incorrectly filtered out with this change, as it doesn't trigger a MappingNotify event.

This reverts commit 3d42412650119a8e13a016e289e5860c034dde19.
---
 src/video/x11/SDL_x11events.c   | 15 +--------------
 src/video/x11/SDL_x11keyboard.c |  5 +++--
 src/video/x11/SDL_x11video.h    |  1 -
 3 files changed, 4 insertions(+), 17 deletions(-)

diff --git a/src/video/x11/SDL_x11events.c b/src/video/x11/SDL_x11events.c
index 1eef65fe5a13b..043db8de53a34 100644
--- a/src/video/x11/SDL_x11events.c
+++ b/src/video/x11/SDL_x11events.c
@@ -1131,20 +1131,7 @@ static void X11_DispatchEvent(SDL_VideoDevice *_this, XEvent *xevent)
             printf("window %p: KeymapNotify!\n", data);
 #endif
             if (SDL_GetKeyboardFocus() != NULL) {
-#ifdef SDL_VIDEO_DRIVER_X11_HAS_XKBLOOKUPKEYSYM
-                if (videodata->xkb) {
-                    XkbStateRec state;
-                    X11_XkbGetUpdatedMap(videodata->display, XkbAllClientInfoMask, videodata->xkb);
-
-                    if (X11_XkbGetState(videodata->display, XkbUseCoreKbd, &state) == Success) {
-                        unsigned int group = state.group;
-                        if (group != videodata->xkb_group) {
-                            /* Only rebuild the keymap if the layout has changed. */
-                            X11_UpdateKeymap(_this, SDL_TRUE);
-                        }
-                    }
-                }
-#endif
+                X11_UpdateKeymap(_this, SDL_TRUE);
                 X11_ReconcileKeyboardState(_this);
             }
         } else if (xevent->type == MappingNotify) {
diff --git a/src/video/x11/SDL_x11keyboard.c b/src/video/x11/SDL_x11keyboard.c
index 9a5d25c9a9832..543c36e4a866b 100644
--- a/src/video/x11/SDL_x11keyboard.c
+++ b/src/video/x11/SDL_x11keyboard.c
@@ -347,6 +347,7 @@ void X11_UpdateKeymap(SDL_VideoDevice *_this, SDL_bool send_event)
     int i;
     SDL_Scancode scancode;
     SDL_Keymap *keymap;
+    unsigned char group = 0;
 
     keymap = SDL_CreateKeymap();
 
@@ -356,7 +357,7 @@ void X11_UpdateKeymap(SDL_VideoDevice *_this, SDL_bool send_event)
         X11_XkbGetUpdatedMap(data->display, XkbAllClientInfoMask, data->xkb);
 
         if (X11_XkbGetState(data->display, XkbUseCoreKbd, &state) == Success) {
-            data->xkb_group = state.group;
+            group = state.group;
         }
     }
 #endif
@@ -371,7 +372,7 @@ void X11_UpdateKeymap(SDL_VideoDevice *_this, SDL_bool send_event)
                 continue;
             }
 
-            KeySym keysym = X11_KeyCodeToSym(_this, i, data->xkb_group, keymod_masks[m].xkb_mask);
+            KeySym keysym = X11_KeyCodeToSym(_this, i, group, keymod_masks[m].xkb_mask);
 
             /* Note: The default SDL scancode table sets this to right alt instead of AltGr/Mode, so handle it separately. */
             if (keysym != XK_ISO_Level3_Shift) {
diff --git a/src/video/x11/SDL_x11video.h b/src/video/x11/SDL_x11video.h
index f8e567c777cc2..80b5c47997923 100644
--- a/src/video/x11/SDL_x11video.h
+++ b/src/video/x11/SDL_x11video.h
@@ -125,7 +125,6 @@ struct SDL_VideoData
     XkbDescPtr xkb;
 #endif
     int xkb_event;
-    unsigned int xkb_group;
 
     KeyCode filter_code;
     Time filter_time;