formatting cleanup

This commit is contained in:
Ben Byer 2007-11-05 20:25:10 -08:00
parent 67e96be13c
commit a6ac900295

View File

@ -1,8 +1,7 @@
/* /*
quartzKeyboard.c quartzKeyboard.c
Code to build a keymap using the Carbon Keyboard Layout API, Code to build a keymap using the Carbon Keyboard Layout API.
which is supported on Mac OS X 10.2 and newer.
Copyright (c) 2003, 2007 Apple Inc. Copyright (c) 2003, 2007 Apple Inc.
@ -150,15 +149,11 @@ unsigned int
DarwinModeSystemKeymapSeed (void) DarwinModeSystemKeymapSeed (void)
{ {
static unsigned int seed; static unsigned int seed;
static KeyboardLayoutRef last_key_layout; static KeyboardLayoutRef last_key_layout;
KeyboardLayoutRef key_layout; KeyboardLayoutRef key_layout;
KLGetCurrentKeyboardLayout (&key_layout); KLGetCurrentKeyboardLayout (&key_layout);
if (key_layout != last_key_layout) seed++;
if (key_layout != last_key_layout)
seed++;
last_key_layout = key_layout; last_key_layout = key_layout;
return seed; return seed;
@ -190,10 +185,8 @@ macroman2ucs (unsigned char c)
0xaf, 0x2d8, 0x2d9, 0x2da, 0xb8, 0x2dd, 0x2db, 0x2c7, 0xaf, 0x2d8, 0x2d9, 0x2da, 0xb8, 0x2dd, 0x2db, 0x2c7,
}; };
if (c < 128) if (c < 128) return c;
return c; else return table[c - 128];
else
return table[c - 128];
} }
static KeySym static KeySym
@ -202,10 +195,7 @@ make_dead_key (KeySym in)
int i; int i;
for (i = 0; i < sizeof (dead_keys) / sizeof (dead_keys[0]); i++) for (i = 0; i < sizeof (dead_keys) / sizeof (dead_keys[0]); i++)
{ if (dead_keys[i].normal == in) return dead_keys[i].dead;
if (dead_keys[i].normal == in)
return dead_keys[i].dead;
}
return in; return in;
} }
@ -249,53 +239,39 @@ DarwinModeReadSystemKeymap (darwinKeyboardInfo *info)
an X11 keysym (which may just the bit that says "this is an X11 keysym (which may just the bit that says "this is
Unicode" if it can't find the real symbol.) */ Unicode" if it can't find the real symbol.) */
for (i = 0; i < num_keycodes; i++) for (i = 0; i < num_keycodes; i++) {
{
static const int mods[4] = {0, MOD_SHIFT, MOD_OPTION, static const int mods[4] = {0, MOD_SHIFT, MOD_OPTION,
MOD_OPTION | MOD_SHIFT}; MOD_OPTION | MOD_SHIFT};
k = info->keyMap + i * GLYPHS_PER_KEY; k = info->keyMap + i * GLYPHS_PER_KEY;
for (j = 0; j < 4; j++) for (j = 0; j < 4; j++) {
{ if (is_uchr) {
if (is_uchr)
{
UniChar s[8]; UniChar s[8];
UniCharCount len; UniCharCount len;
UInt32 dead_key_state, extra_dead; UInt32 dead_key_state = 0, extra_dead = 0;
dead_key_state = 0;
err = UCKeyTranslate (chr_data, i, kUCKeyActionDown, err = UCKeyTranslate (chr_data, i, kUCKeyActionDown,
mods[j] >> 8, keyboard_type, 0, mods[j] >> 8, keyboard_type, 0,
&dead_key_state, 8, &len, s); &dead_key_state, 8, &len, s);
if (err != noErr) if (err != noErr) continue;
continue;
if (len == 0 && dead_key_state != 0) if (len == 0 && dead_key_state != 0) {
{
/* Found a dead key. Work out which one it is, but /* Found a dead key. Work out which one it is, but
remembering that it's dead. */ remembering that it's dead. */
extra_dead = 0;
err = UCKeyTranslate (chr_data, i, kUCKeyActionDown, err = UCKeyTranslate (chr_data, i, kUCKeyActionDown,
mods[j] >> 8, keyboard_type, mods[j] >> 8, keyboard_type,
kUCKeyTranslateNoDeadKeysMask, kUCKeyTranslateNoDeadKeysMask,
&extra_dead, 8, &len, s); &extra_dead, 8, &len, s);
if (err != noErr) if (err != noErr) continue;
continue;
} }
if (len > 0 && s[0] != 0x0010) if (len > 0 && s[0] != 0x0010) {
{
k[j] = ucs2keysym (s[0]); k[j] = ucs2keysym (s[0]);
if (dead_key_state != 0) k[j] = make_dead_key (k[j]);
if (dead_key_state != 0)
k[j] = make_dead_key (k[j]);
} }
} } else { // kchr
else UInt32 c, state = 0, state2 = 0;
{
UInt32 c, state = 0;
UInt16 code; UInt16 code;
code = i | mods[j]; code = i | mods[j];
@ -307,67 +283,50 @@ DarwinModeReadSystemKeymap (darwinKeyboardInfo *info)
us the actual dead character. */ us the actual dead character. */
if (state != 0) if (state != 0)
{
UInt32 state2 = 0;
c = KeyTranslate (chr_data, code | 128, &state2); c = KeyTranslate (chr_data, code | 128, &state2);
}
/* Characters seem to be in MacRoman encoding. */ /* Characters seem to be in MacRoman encoding. */
if (c != 0 && c != 0x0010) if (c != 0 && c != 0x0010) {
{
k[j] = ucs2keysym (macroman2ucs (c & 255)); k[j] = ucs2keysym (macroman2ucs (c & 255));
if (state != 0) if (state != 0) k[j] = make_dead_key (k[j]);
k[j] = make_dead_key (k[j]);
} }
} }
} }
if (k[3] == k[2]) if (k[3] == k[2]) k[3] = NoSymbol;
k[3] = NoSymbol; if (k[2] == k[1]) k[2] = NoSymbol;
if (k[2] == k[1]) if (k[1] == k[0]) k[1] = NoSymbol;
k[2] = NoSymbol; if (k[0] == k[2] && k[1] == k[3]) k[2] = k[3] = NoSymbol;
if (k[1] == k[0])
k[1] = NoSymbol;
if (k[0] == k[2] && k[1] == k[3])
k[2] = k[3] = NoSymbol;
} }
/* Fix up some things that are normally missing.. */ /* Fix up some things that are normally missing.. */
if (HACK_MISSING) if (HACK_MISSING) {
{ for (i = 0; i < sizeof (known_keys) / sizeof (known_keys[0]); i++) {
for (i = 0; i < sizeof (known_keys) / sizeof (known_keys[0]); i++)
{
k = info->keyMap + known_keys[i].keycode * GLYPHS_PER_KEY; k = info->keyMap + known_keys[i].keycode * GLYPHS_PER_KEY;
if (k[0] == NoSymbol && k[1] == NoSymbol if (k[0] == NoSymbol && k[1] == NoSymbol
&& k[2] == NoSymbol && k[3] == NoSymbol) && k[2] == NoSymbol && k[3] == NoSymbol)
{ k[0] = known_keys[i].keysym;
k[0] = known_keys[i].keysym;
}
} }
} }
/* And some more things. We find the right symbols for the numeric /* And some more things. We find the right symbols for the numeric
keypad, but not the KP_ keysyms. So try to convert known keycodes. */ keypad, but not the KP_ keysyms. So try to convert known keycodes. */
if (HACK_KEYPAD) if (HACK_KEYPAD) {
{
for (i = 0; i < sizeof (known_numeric_keys) for (i = 0; i < sizeof (known_numeric_keys)
/ sizeof (known_numeric_keys[0]); i++) / sizeof (known_numeric_keys[0]); i++) {
{
k = info->keyMap + known_numeric_keys[i].keycode * GLYPHS_PER_KEY; k = info->keyMap + known_numeric_keys[i].keycode * GLYPHS_PER_KEY;
if (k[0] == known_numeric_keys[i].normal) if (k[0] == known_numeric_keys[i].normal)
{
k[0] = known_numeric_keys[i].keypad; k[0] = known_numeric_keys[i].keypad;
}
} }
} }
if(currentKeyLayoutRef) CFRelease(currentKeyLayoutRef); if(currentKeyLayoutRef) CFRelease(currentKeyLayoutRef);
return TRUE; return TRUE;
} }