/** Startup key bindings. */ void StartupKeys(void) { XModifierKeymap *modmap; KeyNode *np; TrayType *tp; int x; /* Get the keys that we don't care about (num lock, etc). */ modmap = JXGetModifierMapping(display); for(x = 0; x < sizeof(lockMods) / sizeof(lockMods[0]); x++) { lockMods[x].mask = GetModifierMask(modmap, lockMods[x].symbol); lockMask |= lockMods[x].mask; } JXFreeModifiermap(modmap); /* Look up and grab the keys. */ for(np = bindings; np; np = np->next) { /* Determine the key code. */ if(!np->code) { np->code = JXKeysymToKeycode(display, np->symbol); } /* Grab the key if needed. */ if(ShouldGrab(np->key)) { /* Grab on the root. */ GrabKey(np, rootWindow); /* Grab on the trays. */ for(tp = GetTrays(); tp; tp = tp->next) { GrabKey(np, tp->window); } } } }
void KeymapWrapper::Init() { if (mInitialized) { return; } mInitialized = true; PR_LOG(gKeymapWrapperLog, PR_LOG_ALWAYS, ("KeymapWrapper(%p): Init, mGdkKeymap=%p", this, mGdkKeymap)); mModifierKeys.Clear(); memset(mModifierMasks, 0, sizeof(mModifierMasks)); InitBySystemSettings(); PR_LOG(gKeymapWrapperLog, PR_LOG_ALWAYS, ("KeymapWrapper(%p): Init, CapsLock=0x%X, NumLock=0x%X, " "ScrollLock=0x%X, Level3=0x%X, Level5=0x%X, " "Shift=0x%X, Ctrl=0x%X, Alt=0x%X, Meta=0x%X, Super=0x%X, Hyper=0x%X", this, GetModifierMask(CAPS_LOCK), GetModifierMask(NUM_LOCK), GetModifierMask(SCROLL_LOCK), GetModifierMask(LEVEL3), GetModifierMask(LEVEL5), GetModifierMask(SHIFT), GetModifierMask(CTRL), GetModifierMask(ALT), GetModifierMask(META), GetModifierMask(SUPER), GetModifierMask(HYPER))); }
void KeymapWrapper::InitKeypressEvent(nsKeyEvent& aKeyEvent, GdkEventKey* aGdkKeyEvent) { NS_ENSURE_TRUE_VOID(aKeyEvent.message == NS_KEY_PRESS); aKeyEvent.charCode = GetCharCodeFor(aGdkKeyEvent); if (!aKeyEvent.charCode) { PR_LOG(gKeymapWrapperLog, PR_LOG_ALWAYS, ("KeymapWrapper(%p): InitKeypressEvent, " "keyCode=0x%02X, charCode=0x%08X", this, aKeyEvent.keyCode, aKeyEvent.charCode)); return; } // If the event causes inputting a character, keyCode must be zero. aKeyEvent.keyCode = 0; // If Ctrl or Alt or Meta or OS is pressed, we need to append the key // details for handling shortcut key. Otherwise, we have no additional // work. if (!aKeyEvent.IsControl() && !aKeyEvent.IsAlt() && !aKeyEvent.IsMeta() && !aKeyEvent.IsOS()) { PR_LOG(gKeymapWrapperLog, PR_LOG_ALWAYS, ("KeymapWrapper(%p): InitKeypressEvent, " "keyCode=0x%02X, charCode=0x%08X", this, aKeyEvent.keyCode, aKeyEvent.charCode)); return; } gint level = GetKeyLevel(aGdkKeyEvent); if (level != 0 && level != 1) { PR_LOG(gKeymapWrapperLog, PR_LOG_ALWAYS, ("KeymapWrapper(%p): InitKeypressEvent, " "keyCode=0x%02X, charCode=0x%08X, level=%d", this, aKeyEvent.keyCode, aKeyEvent.charCode, level)); return; } guint baseState = aGdkKeyEvent->state & ~(GetModifierMask(SHIFT) | GetModifierMask(CTRL) | GetModifierMask(ALT) | GetModifierMask(META) | GetModifierMask(SUPER) | GetModifierMask(HYPER)); // We shold send both shifted char and unshifted char, all keyboard layout // users can use all keys. Don't change event.charCode. On some keyboard // layouts, Ctrl/Alt/Meta keys are used for inputting some characters. nsAlternativeCharCode altCharCodes(0, 0); // unshifted charcode of current keyboard layout. altCharCodes.mUnshiftedCharCode = GetCharCodeFor(aGdkKeyEvent, baseState, aGdkKeyEvent->group); bool isLatin = (altCharCodes.mUnshiftedCharCode <= 0xFF); // shifted charcode of current keyboard layout. altCharCodes.mShiftedCharCode = GetCharCodeFor(aGdkKeyEvent, baseState | GetModifierMask(SHIFT), aGdkKeyEvent->group); isLatin = isLatin && (altCharCodes.mShiftedCharCode <= 0xFF); if (altCharCodes.mUnshiftedCharCode || altCharCodes.mShiftedCharCode) { aKeyEvent.alternativeCharCodes.AppendElement(altCharCodes); } bool needLatinKeyCodes = !isLatin; if (!needLatinKeyCodes) { needLatinKeyCodes = (IS_ASCII_ALPHABETICAL(altCharCodes.mUnshiftedCharCode) != IS_ASCII_ALPHABETICAL(altCharCodes.mShiftedCharCode)); } // If current keyboard layout can input Latin characters, we don't need // more information. if (!needLatinKeyCodes) { PR_LOG(gKeymapWrapperLog, PR_LOG_ALWAYS, ("KeymapWrapper(%p): InitKeypressEvent, keyCode=0x%02X, " "charCode=0x%08X, level=%d, altCharCodes={ " "mUnshiftedCharCode=0x%08X, mShiftedCharCode=0x%08X }", this, aKeyEvent.keyCode, aKeyEvent.charCode, level, altCharCodes.mUnshiftedCharCode, altCharCodes.mShiftedCharCode)); return; } // Next, find Latin inputtable keyboard layout. gint minGroup = GetFirstLatinGroup(); if (minGroup < 0) { PR_LOG(gKeymapWrapperLog, PR_LOG_ALWAYS, ("KeymapWrapper(%p): InitKeypressEvent, " "Latin keyboard layout isn't found: " "keyCode=0x%02X, charCode=0x%08X, level=%d, " "altCharCodes={ mUnshiftedCharCode=0x%08X, " "mShiftedCharCode=0x%08X }", this, aKeyEvent.keyCode, aKeyEvent.charCode, level, altCharCodes.mUnshiftedCharCode, altCharCodes.mShiftedCharCode)); return; } nsAlternativeCharCode altLatinCharCodes(0, 0); uint32_t unmodifiedCh = aKeyEvent.IsShift() ? altCharCodes.mShiftedCharCode : altCharCodes.mUnshiftedCharCode; // unshifted charcode of found keyboard layout. uint32_t ch = GetCharCodeFor(aGdkKeyEvent, baseState, minGroup); altLatinCharCodes.mUnshiftedCharCode = IsBasicLatinLetterOrNumeral(ch) ? ch : 0; // shifted charcode of found keyboard layout. ch = GetCharCodeFor(aGdkKeyEvent, baseState | GetModifierMask(SHIFT), minGroup); altLatinCharCodes.mShiftedCharCode = IsBasicLatinLetterOrNumeral(ch) ? ch : 0; if (altLatinCharCodes.mUnshiftedCharCode || altLatinCharCodes.mShiftedCharCode) { aKeyEvent.alternativeCharCodes.AppendElement(altLatinCharCodes); } // If the charCode is not Latin, and the level is 0 or 1, we should // replace the charCode to Latin char if Alt and Meta keys are not // pressed. (Alt should be sent the localized char for accesskey // like handling of Web Applications.) ch = aKeyEvent.IsShift() ? altLatinCharCodes.mShiftedCharCode : altLatinCharCodes.mUnshiftedCharCode; if (ch && !(aKeyEvent.IsAlt() || aKeyEvent.IsMeta()) && aKeyEvent.charCode == unmodifiedCh) { aKeyEvent.charCode = ch; } PR_LOG(gKeymapWrapperLog, PR_LOG_ALWAYS, ("KeymapWrapper(%p): InitKeypressEvent, " "keyCode=0x%02X, charCode=0x%08X, level=%d, minGroup=%d, " "altCharCodes={ mUnshiftedCharCode=0x%08X, " "mShiftedCharCode=0x%08X } " "altLatinCharCodes={ mUnshiftedCharCode=0x%08X, " "mShiftedCharCode=0x%08X }", this, aKeyEvent.keyCode, aKeyEvent.charCode, level, minGroup, altCharCodes.mUnshiftedCharCode, altCharCodes.mShiftedCharCode, altLatinCharCodes.mUnshiftedCharCode, altLatinCharCodes.mShiftedCharCode)); }