Add a new SDL_KEYMAPCHANGED SDL event to abstract notification of keyboard layout or input language changes.

This commit is contained in:
Sam Lantinga 2015-10-27 11:17:32 -07:00
parent f8824cb99b
commit 2b0140a91f
6 changed files with 19 additions and 3 deletions

View File

@ -94,6 +94,9 @@ typedef enum
SDL_KEYUP, /**< Key released */ SDL_KEYUP, /**< Key released */
SDL_TEXTEDITING, /**< Keyboard text editing (composition) */ SDL_TEXTEDITING, /**< Keyboard text editing (composition) */
SDL_TEXTINPUT, /**< Keyboard text input */ SDL_TEXTINPUT, /**< Keyboard text input */
SDL_KEYMAPCHANGED, /**< Keymap changed due to a system event such as an
input language or keyboard layout change.
*/
/* Mouse events */ /* Mouse events */
SDL_MOUSEMOTION = 0x400, /**< Mouse moved */ SDL_MOUSEMOTION = 0x400, /**< Mouse moved */

View File

@ -649,4 +649,10 @@ SDL_SendSysWMEvent(SDL_SysWMmsg * message)
return (posted); return (posted);
} }
int
SDL_SendKeymapChangedEvent(void)
{
return SDL_SendAppEvent(SDL_KEYMAPCHANGED);
}
/* vi: set ts=4 sw=4 expandtab: */ /* vi: set ts=4 sw=4 expandtab: */

View File

@ -38,6 +38,7 @@ extern void SDL_QuitInterrupt(void);
extern int SDL_SendAppEvent(SDL_EventType eventType); extern int SDL_SendAppEvent(SDL_EventType eventType);
extern int SDL_SendSysWMEvent(SDL_SysWMmsg * message); extern int SDL_SendSysWMEvent(SDL_SysWMmsg * message);
extern int SDL_SendKeymapChangedEvent(void);
extern int SDL_QuitInit(void); extern int SDL_QuitInit(void);
extern int SDL_SendQuit(void); extern int SDL_SendQuit(void);

View File

@ -398,7 +398,7 @@ HandleModifiers(_THIS, unsigned short scancode, unsigned int modifierFlags)
} }
static void static void
UpdateKeymap(SDL_VideoData *data) UpdateKeymap(SDL_VideoData *data, SDL_bool send_event)
{ {
TISInputSourceRef key_layout; TISInputSourceRef key_layout;
const void *chr_data; const void *chr_data;
@ -454,6 +454,9 @@ UpdateKeymap(SDL_VideoData *data)
} }
} }
SDL_SetKeymap(0, keymap, SDL_NUM_SCANCODES); SDL_SetKeymap(0, keymap, SDL_NUM_SCANCODES);
if (send_event) {
SDL_SendKeymapChangedEvent();
}
return; return;
} }
@ -466,7 +469,7 @@ Cocoa_InitKeyboard(_THIS)
{ {
SDL_VideoData *data = (SDL_VideoData *) _this->driverdata; SDL_VideoData *data = (SDL_VideoData *) _this->driverdata;
UpdateKeymap(data); UpdateKeymap(data, SDL_FALSE);
/* Set our own names for the platform-dependent but layout-independent keys */ /* Set our own names for the platform-dependent but layout-independent keys */
/* This key is NumLock on the MacBook keyboard. :) */ /* This key is NumLock on the MacBook keyboard. :) */
@ -564,7 +567,7 @@ Cocoa_HandleKeyEvent(_THIS, NSEvent *event)
case NSKeyDown: case NSKeyDown:
if (![event isARepeat]) { if (![event isARepeat]) {
/* See if we need to rebuild the keyboard layout */ /* See if we need to rebuild the keyboard layout */
UpdateKeymap(data); UpdateKeymap(data, SDL_TRUE);
} }
SDL_SendKeyboardKey(SDL_PRESSED, code); SDL_SendKeyboardKey(SDL_PRESSED, code);

View File

@ -626,6 +626,7 @@ WIN_WindowProc(HWND hwnd, UINT msg, WPARAM wParam, LPARAM lParam)
case WM_INPUTLANGCHANGE: case WM_INPUTLANGCHANGE:
{ {
WIN_UpdateKeymap(); WIN_UpdateKeymap();
SDL_SendKeymapChangedEvent();
} }
returnCode = 1; returnCode = 1;
break; break;

View File

@ -625,6 +625,7 @@ X11_DispatchEvent(_THIS)
} }
X11_UpdateKeymap(_this); X11_UpdateKeymap(_this);
SDL_SendKeymapChangedEvent();
} }
return; return;
} }
@ -1143,6 +1144,7 @@ X11_DispatchEvent(_THIS)
notice and reinit our keymap here. This might not be the notice and reinit our keymap here. This might not be the
right approach, but it seems to work. */ right approach, but it seems to work. */
X11_UpdateKeymap(_this); X11_UpdateKeymap(_this);
SDL_SendKeymapChangedEvent();
} }
} }
break; break;