Add a new SDL_KEYMAPCHANGED SDL event to abstract notification of keyboard layout or input language changes.
authorSam Lantinga <slouken@libsdl.org>
Tue, 27 Oct 2015 11:17:32 -0700
changeset 98980da384bef562
parent 9897 b9b4c1bbb778
child 9899 25d1e99080ce
Add a new SDL_KEYMAPCHANGED SDL event to abstract notification of keyboard layout or input language changes.
include/SDL_events.h
src/events/SDL_events.c
src/events/SDL_events_c.h
src/video/cocoa/SDL_cocoakeyboard.m
src/video/windows/SDL_windowsevents.c
src/video/x11/SDL_x11events.c
     1.1 --- a/include/SDL_events.h	Fri Oct 23 03:37:53 2015 -0300
     1.2 +++ b/include/SDL_events.h	Tue Oct 27 11:17:32 2015 -0700
     1.3 @@ -94,6 +94,9 @@
     1.4      SDL_KEYUP,                  /**< Key released */
     1.5      SDL_TEXTEDITING,            /**< Keyboard text editing (composition) */
     1.6      SDL_TEXTINPUT,              /**< Keyboard text input */
     1.7 +    SDL_KEYMAPCHANGED,          /**< Keymap changed due to a system event such as an
     1.8 +                                     input language or keyboard layout change.
     1.9 +                                */
    1.10  
    1.11      /* Mouse events */
    1.12      SDL_MOUSEMOTION    = 0x400, /**< Mouse moved */
     2.1 --- a/src/events/SDL_events.c	Fri Oct 23 03:37:53 2015 -0300
     2.2 +++ b/src/events/SDL_events.c	Tue Oct 27 11:17:32 2015 -0700
     2.3 @@ -649,4 +649,10 @@
     2.4      return (posted);
     2.5  }
     2.6  
     2.7 +int
     2.8 +SDL_SendKeymapChangedEvent(void)
     2.9 +{
    2.10 +    return SDL_SendAppEvent(SDL_KEYMAPCHANGED);
    2.11 +}
    2.12 +
    2.13  /* vi: set ts=4 sw=4 expandtab: */
     3.1 --- a/src/events/SDL_events_c.h	Fri Oct 23 03:37:53 2015 -0300
     3.2 +++ b/src/events/SDL_events_c.h	Tue Oct 27 11:17:32 2015 -0700
     3.3 @@ -38,6 +38,7 @@
     3.4  
     3.5  extern int SDL_SendAppEvent(SDL_EventType eventType);
     3.6  extern int SDL_SendSysWMEvent(SDL_SysWMmsg * message);
     3.7 +extern int SDL_SendKeymapChangedEvent(void);
     3.8  
     3.9  extern int SDL_QuitInit(void);
    3.10  extern int SDL_SendQuit(void);
     4.1 --- a/src/video/cocoa/SDL_cocoakeyboard.m	Fri Oct 23 03:37:53 2015 -0300
     4.2 +++ b/src/video/cocoa/SDL_cocoakeyboard.m	Tue Oct 27 11:17:32 2015 -0700
     4.3 @@ -398,7 +398,7 @@
     4.4  }
     4.5  
     4.6  static void
     4.7 -UpdateKeymap(SDL_VideoData *data)
     4.8 +UpdateKeymap(SDL_VideoData *data, SDL_bool send_event)
     4.9  {
    4.10      TISInputSourceRef key_layout;
    4.11      const void *chr_data;
    4.12 @@ -454,6 +454,9 @@
    4.13              }
    4.14          }
    4.15          SDL_SetKeymap(0, keymap, SDL_NUM_SCANCODES);
    4.16 +        if (send_event) {
    4.17 +            SDL_SendKeymapChangedEvent();
    4.18 +        }
    4.19          return;
    4.20      }
    4.21  
    4.22 @@ -466,7 +469,7 @@
    4.23  {
    4.24      SDL_VideoData *data = (SDL_VideoData *) _this->driverdata;
    4.25  
    4.26 -    UpdateKeymap(data);
    4.27 +    UpdateKeymap(data, SDL_FALSE);
    4.28  
    4.29      /* Set our own names for the platform-dependent but layout-independent keys */
    4.30      /* This key is NumLock on the MacBook keyboard. :) */
    4.31 @@ -564,7 +567,7 @@
    4.32      case NSKeyDown:
    4.33          if (![event isARepeat]) {
    4.34              /* See if we need to rebuild the keyboard layout */
    4.35 -            UpdateKeymap(data);
    4.36 +            UpdateKeymap(data, SDL_TRUE);
    4.37          }
    4.38  
    4.39          SDL_SendKeyboardKey(SDL_PRESSED, code);
     5.1 --- a/src/video/windows/SDL_windowsevents.c	Fri Oct 23 03:37:53 2015 -0300
     5.2 +++ b/src/video/windows/SDL_windowsevents.c	Tue Oct 27 11:17:32 2015 -0700
     5.3 @@ -626,6 +626,7 @@
     5.4      case WM_INPUTLANGCHANGE:
     5.5          {
     5.6              WIN_UpdateKeymap();
     5.7 +            SDL_SendKeymapChangedEvent();
     5.8          }
     5.9          returnCode = 1;
    5.10          break;
     6.1 --- a/src/video/x11/SDL_x11events.c	Fri Oct 23 03:37:53 2015 -0300
     6.2 +++ b/src/video/x11/SDL_x11events.c	Tue Oct 27 11:17:32 2015 -0700
     6.3 @@ -625,6 +625,7 @@
     6.4              }
     6.5  
     6.6              X11_UpdateKeymap(_this);
     6.7 +            SDL_SendKeymapChangedEvent();
     6.8          }
     6.9          return;
    6.10      }
    6.11 @@ -1143,6 +1144,7 @@
    6.12                     notice and reinit our keymap here. This might not be the
    6.13                     right approach, but it seems to work. */
    6.14                  X11_UpdateKeymap(_this);
    6.15 +                SDL_SendKeymapChangedEvent();
    6.16              }
    6.17          }
    6.18          break;