summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJeremy Huddleston <jeremyhu@freedesktop.org>2009-09-28 17:05:29 -0700
committerJeremy Huddleston <jeremyhu@freedesktop.org>2009-09-29 00:34:41 -0700
commitf11a356bcef1bc0a6440325019d5967b745a42dd (patch)
tree32dff4ad893940ec4764a28a1747e0092ed94bed
parentf3223c71cfc638e695981e527517d48ea00d124d (diff)
XQuartz: Cleaned up keymap setting for easier maintenance
(cherry picked from commit b9dfed9e88389cbd29406a20d38ee4297638649b)
-rw-r--r--hw/xquartz/quartzKeyboard.c113
1 files changed, 52 insertions, 61 deletions
diff --git a/hw/xquartz/quartzKeyboard.c b/hw/xquartz/quartzKeyboard.c
index d36d967a2..ea0ebe5d8 100644
--- a/hw/xquartz/quartzKeyboard.c
+++ b/hw/xquartz/quartzKeyboard.c
@@ -280,98 +280,89 @@ static void DarwinBuildModifierMaps(darwinKeyboardInfo *info) {
}
/*
- * DarwinLoadKeyboardMapping
- * Load the keyboard map from a file or system and convert
- * it to an equivalent X keyboard map and modifier map.
- */
-static void DarwinLoadKeyboardMapping(KeySymsRec *keySyms) {
- DarwinBuildModifierMaps(&keyInfo);
-
- keySyms->map = keyInfo.keyMap;
- keySyms->mapWidth = GLYPHS_PER_KEY;
- keySyms->minKeyCode = MIN_KEYCODE;
- keySyms->maxKeyCode = MAX_KEYCODE;
-}
-
-/*
- * DarwinKeyboardSetDeviceKeyMap
- * Load a keymap into the keyboard device
- */
-static void DarwinKeyboardSetDeviceKeyMap(KeySymsRec *keySyms, CARD8 *modmap) {
- DeviceIntPtr pDev;
-
- for (pDev = inputInfo.devices; pDev; pDev = pDev->next)
- if ((pDev->coreEvents || pDev == inputInfo.keyboard) && pDev->key)
- XkbApplyMappingChange(pDev, keySyms, keySyms->minKeyCode,
- keySyms->maxKeyCode - keySyms->minKeyCode + 1,
- modmap, serverClient);
-}
-
-/*
* DarwinKeyboardInit
* Get the Darwin keyboard map and compute an equivalent
* X keyboard map and modifier map. Set the new keyboard
* device structure.
*/
void DarwinKeyboardInit(DeviceIntPtr pDev) {
- KeySymsRec keySyms;
- XkbComponentNamesRec names;
- CFIndex value;
- BOOL ok;
-
// Open a shared connection to the HID System.
// Note that the Event Status Driver is really just a wrapper
// for a kIOHIDParamConnectType connection.
assert(darwinParamConnect = NXOpenEventStatus());
- bzero(&names, sizeof(names));
-
/* We need to really have rules... or something... */
//XkbSetRulesDflts("base", "pc105", "us", NULL, NULL);
InitKeyboardDeviceStruct(pDev, NULL, NULL, DarwinChangeKeyboardControl);
- pthread_mutex_lock(&keyInfo_mutex);
- DarwinLoadKeyboardMapping(&keySyms);
- DarwinKeyboardSetDeviceKeyMap(&keySyms, keyInfo.modMap);
- pthread_mutex_unlock(&keyInfo_mutex);
+ DarwinKeyboardReloadHandler();
- /* Get our key repeat settings from GlobalPreferences */
- (void)CFPreferencesAppSynchronize(CFSTR(".GlobalPreferences"));
- value = CFPreferencesGetAppIntegerValue(CFSTR("InitialKeyRepeat"), CFSTR(".GlobalPreferences"), &ok);
- if(!ok)
- value = 35;
+ CopyKeyClass(pDev, inputInfo.keyboard);
+}
- if(value == 300000) { // off
+/* Set the repeat rates based on global preferences and keycodes for modifiers.
+ * Precondition: Has the keyInfo_mutex lock.
+ */
+static void DarwinKeyboardSetRepeat(DeviceIntPtr pDev, CFIndex initialKeyRepeatValue, CFIndex keyRepeatValue) {
+ if(initialKeyRepeatValue == 300000) { // off
XkbSetRepeatKeys(pDev, -1, AutoRepeatModeOff);
} else {
- pDev->key->xkbInfo->desc->ctrls->repeat_delay = value * 15;
-
- value = CFPreferencesGetAppIntegerValue(CFSTR("KeyRepeat"), CFSTR(".GlobalPreferences"), &ok);
- if(!ok)
- value = 6;
- pDev->key->xkbInfo->desc->ctrls->repeat_interval = value * 15;
+ pDev->key->xkbInfo->desc->ctrls->repeat_delay = initialKeyRepeatValue * 15;
+ pDev->key->xkbInfo->desc->ctrls->repeat_interval = keyRepeatValue * 15;
XkbSetRepeatKeys(pDev, -1, AutoRepeatModeOn);
- }
- CopyKeyClass(pDev, inputInfo.keyboard);
+ /* TODO: Turn off key-repeat for modifier keys, on for others */
+ // Test: Shouldn't this turn off all the key repeats???
+ //for(i=MIN_KEYCODE; i <= MAX_KEYCODE; i++)
+ // XkbSetRepeatKeys(pDev, i, AutoRepeatModeOff);
+ }
}
void DarwinKeyboardReloadHandler(void) {
KeySymsRec keySyms;
+ CFIndex initialKeyRepeatValue, keyRepeatValue;
+ BOOL ok;
+ DeviceIntPtr pDev = darwinKeyboard;
DEBUG_LOG("DarwinKeyboardReloadHandler\n");
-// if (pDev->key) {
-// if (pDev->key->curKeySyms.map) xfree(pDev->key->curKeySyms.map);
-// xfree(pDev->key);
-// }
+ /* Get our key repeat settings from GlobalPreferences */
+ (void)CFPreferencesAppSynchronize(CFSTR(".GlobalPreferences"));
- pthread_mutex_lock(&keyInfo_mutex);
- DarwinLoadKeyboardMapping(&keySyms);
- DarwinKeyboardSetDeviceKeyMap(&keySyms, keyInfo.modMap);
- pthread_mutex_unlock(&keyInfo_mutex);
+ initialKeyRepeatValue = CFPreferencesGetAppIntegerValue(CFSTR("InitialKeyRepeat"), CFSTR(".GlobalPreferences"), &ok);
+ if(!ok)
+ initialKeyRepeatValue = 35;
+
+ keyRepeatValue = CFPreferencesGetAppIntegerValue(CFSTR("KeyRepeat"), CFSTR(".GlobalPreferences"), &ok);
+ if(!ok)
+ keyRepeatValue = 6;
+
+ pthread_mutex_lock(&keyInfo_mutex); {
+ /* Initialize our keySyms */
+ DarwinBuildModifierMaps(&keyInfo);
+ keySyms.map = keyInfo.keyMap;
+ keySyms.mapWidth = GLYPHS_PER_KEY;
+ keySyms.minKeyCode = MIN_KEYCODE;
+ keySyms.maxKeyCode = MAX_KEYCODE;
+
+ /* Apply the mappings to darwinKeyboard */
+ XkbApplyMappingChange(darwinKeyboard, &keySyms, keySyms.minKeyCode,
+ keySyms.maxKeyCode - keySyms.minKeyCode + 1,
+ keyInfo.modMap, serverClient);
+ DarwinKeyboardSetRepeat(darwinKeyboard, initialKeyRepeatValue, keyRepeatValue);
+
+ /* Apply the mappings to the core keyboard */
+ for (pDev = inputInfo.devices; pDev; pDev = pDev->next) {
+ if ((pDev->coreEvents || pDev == inputInfo.keyboard) && pDev->key) {
+ XkbApplyMappingChange(pDev, &keySyms, keySyms.minKeyCode,
+ keySyms.maxKeyCode - keySyms.minKeyCode + 1,
+ keyInfo.modMap, serverClient);
+ DarwinKeyboardSetRepeat(pDev, initialKeyRepeatValue, keyRepeatValue);
+ }
+ }
+ } pthread_mutex_unlock(&keyInfo_mutex);
}
//-----------------------------------------------------------------------------