return VKEY_UNKNOWN;
}
+// Check for TTY function keys or space key which should always be mapped
+// based on KeySym, and never fall back to MAP0~MAP3, since some layouts
+// generate them by applying the Control/AltGr modifier to some other key.
+// e.g. in de(neo), AltGr+V generates XK_Enter.
+bool IsTtyFunctionOrSpaceKey(KeySym keysym) {
+ KeySym keysyms[] = {
+ XK_BackSpace,
+ XK_Tab,
+ XK_Linefeed,
+ XK_Clear,
+ XK_Return,
+ XK_Pause,
+ XK_Scroll_Lock,
+ XK_Sys_Req,
+ XK_Escape,
+ XK_Delete,
+ XK_space
+ };
+
+ for (size_t i = 0; i < arraysize(keysyms); ++i) {
+ if (keysyms[i] == keysym)
+ return true;
+ }
+ return false;
+}
+
} // namespace
// Get an ui::KeyboardCode from an X keyevent
} else {
xkeyevent.xkey = xev->xkey;
}
+ KeyboardCode keycode = VKEY_UNKNOWN;
XKeyEvent* xkey = &xkeyevent.xkey;
- xkey->state &= (~0xFF | Mod2Mask); // Clears the xkey's state except numlock.
// XLookupKeysym does not take into consideration the state of the lock/shift
// etc. keys. So it is necessary to use XLookupString instead.
XLookupString(xkey, NULL, 0, &keysym, NULL);
+ if (IsKeypadKey(keysym) || IsPrivateKeypadKey(keysym) ||
+ IsCursorKey(keysym) || IsPFKey(keysym) || IsFunctionKey(keysym) ||
+ IsModifierKey(keysym) || IsTtyFunctionOrSpaceKey(keysym)) {
+ return KeyboardCodeFromXKeysym(keysym);
+ }
+
+ // If |xkey| has modifiers set, other than NumLock, then determine the
+ // un-modified KeySym and use that to map, so that e.g. Ctrl+D correctly
+ // generates VKEY_D.
+ if (xkey->state & 0xFF & ~Mod2Mask) {
+ xkey->state &= (~0xFF | Mod2Mask);
+ XLookupString(xkey, NULL, 0, &keysym, NULL);
+ }
// [a-z] cases.
if (keysym >= XK_a && keysym <= XK_z)
if (keysym >= XK_0 && keysym <= XK_9)
return static_cast<KeyboardCode>(VKEY_0 + keysym - XK_0);
- KeyboardCode keycode = VKEY_UNKNOWN;
-
if (!IsKeypadKey(keysym) && !IsPrivateKeypadKey(keysym) &&
!IsCursorKey(keysym) && !IsPFKey(keysym) && !IsFunctionKey(keysym) &&
!IsModifierKey(keysym)) {
// On Linux some keys has AltGr char but not on Windows.
// So if cannot find VKEY with (ch0+sc+ch1+ch2) in map3, tries to fallback
// to just find VKEY with (ch0+sc+ch1). This is the best we could do.
- MAP3 key4 = {keysym & 0xFFFF, xkey->keycode, keysym_shift & 0xFFFF, 0xFFFF,
+ MAP3 key4 = {keysym & 0xFFFF, xkey->keycode, keysym_shift & 0xFFFF, 0,
0};
const MAP3* p =
std::lower_bound(map3, map3 + arraysize(map3), key4, MAP3());
// TODO(sad): some keycodes are still missing.
}
- DLOG(WARNING) << "Unknown keysym: " << base::StringPrintf("0x%x", keysym);
+ DVLOG(1) << "Unknown keysym: " << base::StringPrintf("0x%x", keysym);
return VKEY_UNKNOWN;
}