X11: Handle keyboard layout changing during app's run on Ubuntu 12.04 (etc).
authorRyan C. Gordon <icculus@icculus.org>
Sat, 15 Aug 2015 00:36:39 -0400
changeset 9845 41ce18cb4b3b
parent 9844 7e9624bde3a7
child 9846 9f0a0c7de41a
X11: Handle keyboard layout changing during app's run on Ubuntu 12.04 (etc). Fixes Bugzilla #3050 (in addition to Jason Wyatt's patch, prior to this).
src/video/x11/SDL_x11events.c
src/video/x11/SDL_x11video.c
src/video/x11/SDL_x11video.h
--- a/src/video/x11/SDL_x11events.c	Fri Aug 14 23:38:40 2015 -0400
+++ b/src/video/x11/SDL_x11events.c	Sat Aug 15 00:36:39 2015 -0400
@@ -1134,8 +1134,15 @@
                     } else {
                         SDL_SendWindowEvent(data->window, SDL_WINDOWEVENT_RESTORED, 0, 0);
                     }
-                 }
-
+                }
+            } else if (xevent.xproperty.atom == videodata->XKLAVIER_STATE) {
+                /* Hack for Ubuntu 12.04 (etc) that doesn't send MappingNotify
+                   events when the keyboard layout changes (for example,
+                   changing from English to French on the menubar's keyboard
+                   icon). Since it changes the XKLAVIER_STATE property, we
+                   notice and reinit our keymap here. This might not be the
+                   right approach, but it seems to work. */
+                X11_UpdateKeymap(_this);
             }
         }
         break;
--- a/src/video/x11/SDL_x11video.c	Fri Aug 14 23:38:40 2015 -0400
+++ b/src/video/x11/SDL_x11video.c	Sat Aug 15 00:36:39 2015 -0400
@@ -408,6 +408,7 @@
     GET_ATOM(XdndDrop);
     GET_ATOM(XdndFinished);
     GET_ATOM(XdndSelection);
+    GET_ATOM(XKLAVIER_STATE);
 
     /* Detect the window manager */
     X11_CheckWindowManager(_this);
--- a/src/video/x11/SDL_x11video.h	Fri Aug 14 23:38:40 2015 -0400
+++ b/src/video/x11/SDL_x11video.h	Sat Aug 15 00:36:39 2015 -0400
@@ -111,6 +111,7 @@
     Atom XdndDrop;
     Atom XdndFinished;
     Atom XdndSelection;
+    Atom XKLAVIER_STATE;
 
     SDL_Scancode key_layout[256];
     SDL_bool selection_waiting;