quartz: make function keys work (again?)

The F keys have no unicode mapping, and UCKeyTranslate() returns
a bogus 0x10 as mapping to unicode. Instead of checking for this
random and undocumented return value, simply assign all function
keys explicitly. This patch also splits the ill-named "known_keys"
array into "modifier_keys" and "function_keys" which is much
more obvious.
(cherry picked from commit 55f9e5cbaf)
This commit is contained in:
Michael Natterer 2012-02-23 13:27:09 +01:00 committed by Michael Natterer
parent 80674d9dc0
commit 8bef74f8ff

View File

@ -136,7 +136,7 @@ const static struct {
guint keycode; guint keycode;
guint keyval; guint keyval;
unsigned int modmask; /* So we can tell when a mod key is pressed/released */ unsigned int modmask; /* So we can tell when a mod key is pressed/released */
} known_keys[] = { } modifier_keys[] = {
{ 54, GDK_KEY_Meta_R, NSCommandKeyMask }, { 54, GDK_KEY_Meta_R, NSCommandKeyMask },
{ 55, GDK_KEY_Meta_L, NSCommandKeyMask }, { 55, GDK_KEY_Meta_L, NSCommandKeyMask },
{ 56, GDK_KEY_Shift_L, NSShiftKeyMask }, { 56, GDK_KEY_Shift_L, NSShiftKeyMask },
@ -145,23 +145,29 @@ const static struct {
{ 59, GDK_KEY_Control_L, NSControlKeyMask }, { 59, GDK_KEY_Control_L, NSControlKeyMask },
{ 60, GDK_KEY_Shift_R, NSShiftKeyMask }, { 60, GDK_KEY_Shift_R, NSShiftKeyMask },
{ 61, GDK_KEY_Alt_R, NSAlternateKeyMask }, { 61, GDK_KEY_Alt_R, NSAlternateKeyMask },
{ 62, GDK_KEY_Control_R, NSControlKeyMask }, { 62, GDK_KEY_Control_R, NSControlKeyMask }
{ 122, GDK_KEY_F1, 0 }, };
{ 120, GDK_KEY_F2, 0 },
{ 99, GDK_KEY_F3, 0 }, const static struct {
{ 118, GDK_KEY_F4, 0 }, guint keycode;
{ 96, GDK_KEY_F5, 0 }, guint keyval;
{ 97, GDK_KEY_F6, 0 }, } function_keys[] = {
{ 98, GDK_KEY_F7, 0 }, { 122, GDK_KEY_F1 },
{ 100, GDK_KEY_F8, 0 }, { 120, GDK_KEY_F2 },
{ 101, GDK_KEY_F9, 0 }, { 99, GDK_KEY_F3 },
{ 109, GDK_KEY_F10, 0 }, { 118, GDK_KEY_F4 },
{ 103, GDK_KEY_F11, 0 }, { 96, GDK_KEY_F5 },
{ 111, GDK_KEY_F12, 0 }, { 97, GDK_KEY_F6 },
{ 105, GDK_KEY_F13, 0 }, { 98, GDK_KEY_F7 },
{ 107, GDK_KEY_F14, 0 }, { 100, GDK_KEY_F8 },
{ 113, GDK_KEY_F15, 0 }, { 101, GDK_KEY_F9 },
{ 106, GDK_KEY_F16, 0 } { 109, GDK_KEY_F10 },
{ 103, GDK_KEY_F11 },
{ 111, GDK_KEY_F12 },
{ 105, GDK_KEY_F13 },
{ 107, GDK_KEY_F14 },
{ 113, GDK_KEY_F15 },
{ 106, GDK_KEY_F16 }
}; };
const static struct { const static struct {
@ -404,7 +410,6 @@ maybe_update_keymap (void)
0, 0,
&state, 4, &nChars, chars); &state, 4, &nChars, chars);
/* FIXME: Theoretically, we can get multiple UTF-16 values; /* FIXME: Theoretically, we can get multiple UTF-16 values;
* we should convert them to proper unicode and figure * we should convert them to proper unicode and figure
* out whether there are really keyboard layouts that * out whether there are really keyboard layouts that
@ -470,13 +475,21 @@ maybe_update_keymap (void)
} }
#endif #endif
for (i = 0; i < G_N_ELEMENTS (known_keys); i++) for (i = 0; i < G_N_ELEMENTS (modifier_keys); i++)
{ {
p = keyval_array + known_keys[i].keycode * KEYVALS_PER_KEYCODE; p = keyval_array + modifier_keys[i].keycode * KEYVALS_PER_KEYCODE;
if (p[0] == 0 && p[1] == 0 && if (p[0] == 0 && p[1] == 0 &&
p[2] == 0 && p[3] == 0) p[2] == 0 && p[3] == 0)
p[0] = known_keys[i].keyval; p[0] = modifier_keys[i].keyval;
}
for (i = 0; i < G_N_ELEMENTS (function_keys); i++)
{
p = keyval_array + function_keys[i].keycode * KEYVALS_PER_KEYCODE;
p[0] = function_keys[i].keyval;
p[1] = p[2] = p[3] = 0;
} }
for (i = 0; i < G_N_ELEMENTS (known_numeric_keys); i++) for (i = 0; i < G_N_ELEMENTS (known_numeric_keys); i++)
@ -792,11 +805,11 @@ _gdk_quartz_keys_event_type (NSEvent *event)
keycode = [event keyCode]; keycode = [event keyCode];
flags = [event modifierFlags]; flags = [event modifierFlags];
for (i = 0; i < G_N_ELEMENTS (known_keys); i++) for (i = 0; i < G_N_ELEMENTS (modifier_keys); i++)
{ {
if (known_keys[i].keycode == keycode) if (modifier_keys[i].keycode == keycode)
{ {
if (flags & known_keys[i].modmask) if (flags & modifier_keys[i].modmask)
return GDK_KEY_PRESS; return GDK_KEY_PRESS;
else else
return GDK_KEY_RELEASE; return GDK_KEY_RELEASE;
@ -813,12 +826,12 @@ _gdk_quartz_keys_is_modifier (guint keycode)
{ {
gint i; gint i;
for (i = 0; i < G_N_ELEMENTS (known_keys); i++) for (i = 0; i < G_N_ELEMENTS (modifier_keys); i++)
{ {
if (known_keys[i].modmask == 0) if (modifier_keys[i].modmask == 0)
break; break;
if (known_keys[i].keycode == keycode) if (modifier_keys[i].keycode == keycode)
return TRUE; return TRUE;
} }