diff options
author | Jeremy Huddleston <jeremyhu@freedesktop.org> | 2009-09-28 17:05:29 -0700 |
---|---|---|
committer | Jeremy Huddleston <jeremyhu@freedesktop.org> | 2009-09-28 23:08:36 -0700 |
commit | b9dfed9e88389cbd29406a20d38ee4297638649b (patch) | |
tree | 5f17c609f2d24d4ff3ca016c4e18f880540526f7 /hw | |
parent | d2263645d839c9edeedea0835d26f1f41b37f70e (diff) |
XQuartz: Cleaned up keymap setting for easier maintenance
Diffstat (limited to 'hw')
-rw-r--r-- | hw/xquartz/quartzKeyboard.c | 113 |
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); } //----------------------------------------------------------------------------- |