diff options
author | culler <culler> | 2017-12-01 19:17:55 (GMT) |
---|---|---|
committer | culler <culler> | 2017-12-01 19:17:55 (GMT) |
commit | 5cf1afc8bda65903f6d36e65ca4f60f646275675 (patch) | |
tree | d2988b9fd280869bb04b3c6b1ad0c4f0b05a2c1f /macosx | |
parent | ece2d7c38de06e372c38ecd93d09a97b36a449da (diff) | |
download | tk-5cf1afc8bda65903f6d36e65ca4f60f646275675.zip tk-5cf1afc8bda65903f6d36e65ca4f60f646275675.tar.gz tk-5cf1afc8bda65903f6d36e65ca4f60f646275675.tar.bz2 |
On macOS, add a modKeyCodes array to the display so key events for modifier keys can be generated.
Diffstat (limited to 'macosx')
-rw-r--r-- | macosx/tkMacOSXKeyboard.c | 56 |
1 files changed, 45 insertions, 11 deletions
diff --git a/macosx/tkMacOSXKeyboard.c b/macosx/tkMacOSXKeyboard.c index bbbbf96..1abbbba 100644 --- a/macosx/tkMacOSXKeyboard.c +++ b/macosx/tkMacOSXKeyboard.c @@ -96,6 +96,24 @@ static KeyInfo virtualkeyArray[] = { {0, 0} }; +#define NUM_MOD_KEYCODES 14 +static KeyCode modKeyArray[NUM_MOD_KEYCODES] = { + XK_Shift_L, + XK_Shift_R, + XK_Control_L, + XK_Control_R, + XK_Caps_Lock, + XK_Shift_Lock, + XK_Meta_L, + XK_Meta_R, + XK_Alt_L, + XK_Alt_R, + XK_Super_L, + XK_Super_R, + XK_Hyper_L, + XK_Hyper_R, +}; + static int initialized = 0; static Tcl_HashTable keycodeTable; /* keyArray hashed by keycode value. */ static Tcl_HashTable vkeyTable; /* virtualkeyArray hashed by virtual @@ -457,7 +475,6 @@ XGetModifierMapping( * MacOSX doesn't use the key codes for the modifiers for anything, and we * don't generate them either. So there is no modifier map. */ - modmap = ckalloc(sizeof(XModifierKeymap)); modmap->max_keypermod = 0; modmap->modifiermap = NULL; @@ -548,7 +565,6 @@ XKeysymToMacKeycode( KeySym keysym) { KeyInfo *kPtr; - if (keysym <= LATIN1_MAX) { /* * Handle keysyms in the Latin-1 range where keysym and Unicode @@ -580,6 +596,17 @@ XKeysymToMacKeycode( } /* + * Modifier keycodes only come from generated events. No translation + * is needed. + */ + + for (int i=0; i < NUM_MOD_KEYCODES; i++) { + if (keysym == modKeyArray[i]) { + return keysym; + } + } + + /* * For other keysyms (not Latin-1 and not special keys), we'd need a * generic keysym-to-unicode table. We don't have that, so we give up here. */ @@ -661,6 +688,13 @@ TkpSetKeycodeAndState( { if (keysym == NoSymbol) { eventPtr->xkey.keycode = 0; + } else if ( modKeyArray[0] <= keysym && + keysym <= modKeyArray[NUM_MOD_KEYCODES - 1]) { + /* + * Keysyms for pure modifiers only arise in generated events. + * We should just copy them to the keycode. + */ + eventPtr->xkey.keycode = keysym; } else { Display *display = Tk_Display(tkwin); int macKeycode = XKeysymToMacKeycode(display, keysym); @@ -668,7 +702,6 @@ TkpSetKeycodeAndState( /* * See also XKeysymToKeycode. */ - if ((keysym >= XK_F1) && (keysym <= XK_F35)) { eventPtr->xkey.keycode = 0x0010; } else { @@ -734,7 +767,6 @@ TkpGetKeySym( */ if (eventPtr->xany.send_event == -1) { - int modifier = eventPtr->xkey.keycode & NSDeviceIndependentModifierFlagsMask; if (modifier == NSCommandKeyMask) { @@ -891,18 +923,20 @@ TkpInitKeymapInfo( #endif /* - * MacOSX doesn't use the keycodes for the modifiers for anything, and we - * don't generate them either (the keycodes actually given in the simulated - * modifier events are bogus). So there is no modifier map. If we ever want - * to simulate real modifier keycodes, the list will be constant in the - * Carbon implementation. + * MacOSX doesn't create a key event when a modifier key is pressed or + * released. However, it is possible to generate key events for + * modifier keys, and this is done in the tests. So we construct an array + * containing the keycodes of the standard modifier keys from static data. */ if (dispPtr->modKeyCodes != NULL) { ckfree(dispPtr->modKeyCodes); } - dispPtr->numModKeyCodes = 0; - dispPtr->modKeyCodes = NULL; + dispPtr->numModKeyCodes = NUM_MOD_KEYCODES; + dispPtr->modKeyCodes = (KeyCode *)ckalloc(NUM_MOD_KEYCODES * sizeof(KeyCode)); + for (int i = 0; i < NUM_MOD_KEYCODES; i++) { + dispPtr->modKeyCodes[i] = modKeyArray[i]; + } } /* |