diff options
author | cc_benny <cc_benny@noemail.net> | 2003-12-15 16:15:44 (GMT) |
---|---|---|
committer | cc_benny <cc_benny@noemail.net> | 2003-12-15 16:15:44 (GMT) |
commit | 4efcc61e88a726bbf5fa0634f6e2889e1f03bedd (patch) | |
tree | a1850586657c27dfd492d1c54efaa903cd2d434b /macosx/tkMacOSXKeyboard.c | |
parent | 86ca27089d2dab0816ecb112cbd3f4c909fe5e26 (diff) | |
download | tk-4efcc61e88a726bbf5fa0634f6e2889e1f03bedd.zip tk-4efcc61e88a726bbf5fa0634f6e2889e1f03bedd.tar.gz tk-4efcc61e88a726bbf5fa0634f6e2889e1f03bedd.tar.bz2 |
* LATIN1_MAX and MAC_KEYCODE_MAX: Add and use for better
maintainability.
* General comment on keyArray: Add.
* (XKeycodeToKeysym): Replace garbled comment. Use symbols
instead of magic constants.
* (TkpGetKeySym): Reorder computations to make this more
logical.
FossilOrigin-Name: eaeb703b4200e8f8dac3524b67efa8709c7be126
Diffstat (limited to 'macosx/tkMacOSXKeyboard.c')
-rw-r--r-- | macosx/tkMacOSXKeyboard.c | 72 |
1 files changed, 47 insertions, 25 deletions
diff --git a/macosx/tkMacOSXKeyboard.c b/macosx/tkMacOSXKeyboard.c index 6fd5f91..1136b20 100644 --- a/macosx/tkMacOSXKeyboard.c +++ b/macosx/tkMacOSXKeyboard.c @@ -9,7 +9,7 @@ * See the file "license.terms" for information on usage and redistribution * of this file, and for a DISCLAIMER OF ALL WARRANTIES. * - * RCS: @(#) $Id: tkMacOSXKeyboard.c,v 1.7 2003/12/15 15:08:37 cc_benny Exp $ + * RCS: @(#) $Id: tkMacOSXKeyboard.c,v 1.8 2003/12/15 16:15:44 cc_benny Exp $ */ #include "tkInt.h" @@ -20,6 +20,20 @@ #include "tkMacOSXEvent.h" /* TkMacOSXKeycodeToUnicode() FIXME: That * function should probably move here. */ +/* + * A couple of simple definitions to make code a bit more self-explaining. + */ + +#define LATIN1_MAX 255 +#define MAC_KEYCODE_MAX 0x7F + + +/* + * Tables enumerating the special keys defined on Mac keyboards. These are + * necessary for correct keysym mappings for all keys where the keysyms are + * not identical with their ASCII or Latin-1 code points. + */ + typedef struct { int keycode; /* Macintosh keycode. */ KeySym keysym; /* X windows keysym. */ @@ -165,6 +179,8 @@ XKeycodeToKeysym( int newKeycode; UniChar newChar; + (void) display; /*unused*/ + if (!initialized) { InitKeyMaps(); } @@ -180,8 +196,8 @@ XKeycodeToKeysym( } virtualKey = keycode >> 16; - c = keycode & 0XFFFF; - if (c > 255) { + c = keycode & 0xFFFF; + if (c > MAC_KEYCODE_MAX) { return NoSymbol; } @@ -204,13 +220,12 @@ XKeycodeToKeysym( } /* - * Recompute the character based on the Shift key only. TODO: The index - * may also specify the NUM_LOCK. + * Add in the Mac modifier flag for shift. */ newKeycode = virtualKey; - if (index & 0x01) { - newKeycode += 0x0200; + if (index & 1) { + newKeycode |= shiftKey; } newChar = 0; @@ -223,7 +238,7 @@ XKeycodeToKeysym( * for other characters for now. */ - if ((newChar >= XK_space) && (newChar <= 0x255)) { + if ((newChar >= XK_space) && (newChar <= LATIN1_MAX)) { return newChar; } @@ -494,26 +509,11 @@ TkpGetKeySym( } /* - * Figure out which of the four slots in the keymap vector to use for - * this key. Refer to Xlib documentation for more info on how this - * computation works. + * Handle pure modifier keys specially. We use -1 as a signal for + * this. */ - index = 0; - if (eventPtr->xkey.state & dispPtr->modeModMask) { - index = 2; - } - if ((eventPtr->xkey.state & ShiftMask) - || ((dispPtr->lockUsage != LU_IGNORE) - && (eventPtr->xkey.state & LockMask))) { - index += 1; - } if (eventPtr->xany.send_event == -1) { - - /* - * We use -1 as a special signal for a pure modifier. - */ - int modifier = eventPtr->xkey.keycode; if (modifier == cmdKey) { return XK_Alt_L; @@ -540,6 +540,28 @@ TkpGetKeySym( return NoSymbol; } } + + /* + * Figure out which of the four slots in the keymap vector to use for + * this key. Refer to Xlib documentation for more info on how this + * computation works. (Note: We use "Option" in keymap columns 2 and 3 + * where other implementations have "Mode_switch".) + */ + + index = 0; + if (eventPtr->xkey.state & dispPtr->modeModMask) { + index |= 2; + } + if ((eventPtr->xkey.state & ShiftMask) + || ((dispPtr->lockUsage != LU_IGNORE) + && (eventPtr->xkey.state & LockMask))) { + index |= 1; + } + + /* + * First try of the actual translation. + */ + sym = XKeycodeToKeysym(dispPtr->display, eventPtr->xkey.keycode, index); /* |