Send the native codes of the key events

Change-Id: I58343ebf931d946a9d1dfc1f0949ba296d97ec52
Reviewed-by: Gunnar Sletta <gunnar.sletta@jollamobile.com>
Reviewed-by: Robin Burchell <robin+qt@viroteck.net>
This commit is contained in:
Giulio Camuffo 2014-04-11 15:09:45 +03:00 committed by The Qt Project
parent 7fb846e5f2
commit e295df8b1d

View File

@ -81,6 +81,7 @@ public:
, mXkbState(0) , mXkbState(0)
#endif #endif
, mFocusCallback(0) , mFocusCallback(0)
, mNativeModifiers(0)
{ {
#ifndef QT_NO_WAYLAND_XKB #ifndef QT_NO_WAYLAND_XKB
xkb_rule_names names; xkb_rule_names names;
@ -139,11 +140,15 @@ public:
xkb_state *mXkbState; xkb_state *mXkbState;
#endif #endif
struct wl_callback *mFocusCallback; struct wl_callback *mFocusCallback;
uint32_t mNativeModifiers;
int mRepeatKey; int mRepeatKey;
uint32_t mRepeatCode; uint32_t mRepeatCode;
uint32_t mRepeatTime; uint32_t mRepeatTime;
QString mRepeatText; QString mRepeatText;
#ifndef QT_NO_WAYLAND_XKB
xkb_keysym_t mRepeatSym;
#endif
static const wl_callback_listener callback; static const wl_callback_listener callback;
static void focusCallback(void *data, struct wl_callback *callback, uint32_t time); static void focusCallback(void *data, struct wl_callback *callback, uint32_t time);
@ -749,44 +754,37 @@ void QWaylandInputDevice::Keyboard::keyboard_key(uint32_t serial, uint32_t time,
QString text; QString text;
int qtkey = key + 8; // qt-compositor substracts 8 for some reason int qtkey = key + 8; // qt-compositor substracts 8 for some reason
#ifndef QT_NO_WAYLAND_XKB
if (!mXkbMap)
return;
const xkb_keysym_t *syms;
uint32_t numSyms = xkb_key_get_syms(mXkbState, code, &syms);
xkb_state_update_key(mXkbState, code,
isDown ? XKB_KEY_DOWN : XKB_KEY_UP);
if (!window) { if (!window) {
// We destroyed the keyboard focus surface, but the server // We destroyed the keyboard focus surface, but the server
// didn't get the message yet. // didn't get the message yet.
return; return;
} }
if (numSyms == 1) { #ifndef QT_NO_WAYLAND_XKB
xkb_keysym_t sym = syms[0]; if (!mXkbMap)
Qt::KeyboardModifiers modifiers = mParent->modifiers(); return;
uint utf32 = xkb_keysym_to_utf32(sym); const xkb_keysym_t sym = xkb_state_key_get_one_sym(mXkbState, code);
text = QString::fromUcs4(&utf32, 1); xkb_state_update_key(mXkbState, code, isDown ? XKB_KEY_DOWN : XKB_KEY_UP);
qtkey = keysymToQtKey(sym, modifiers, text); Qt::KeyboardModifiers modifiers = mParent->modifiers();
QWindowSystemInterface::handleExtendedKeyEvent(window->window(), uint utf32 = xkb_keysym_to_utf32(sym);
time, type, qtkey, text = QString::fromUcs4(&utf32, 1);
modifiers,
code, 0, 0, text); qtkey = keysymToQtKey(sym, modifiers, text);
}
QWindowSystemInterface::handleExtendedKeyEvent(window->window(),
time, type, qtkey,
modifiers,
code, sym, mNativeModifiers, text);
#else #else
// Generic fallback for single hard keys: Assume 'key' is a Qt key code. // Generic fallback for single hard keys: Assume 'key' is a Qt key code.
if (window) { QWindowSystemInterface::handleExtendedKeyEvent(window->window(),
QWindowSystemInterface::handleExtendedKeyEvent(window->window(), time, type,
time, type, qtkey,
qtkey, Qt::NoModifier,
Qt::NoModifier, code, 0, 0);
code, 0, 0);
}
#endif #endif
if (state == WL_KEYBOARD_KEY_STATE_PRESSED) { if (state == WL_KEYBOARD_KEY_STATE_PRESSED) {
@ -794,6 +792,9 @@ void QWaylandInputDevice::Keyboard::keyboard_key(uint32_t serial, uint32_t time,
mRepeatCode = code; mRepeatCode = code;
mRepeatTime = time; mRepeatTime = time;
mRepeatText = text; mRepeatText = text;
#ifndef QT_NO_WAYLAND_XKB
mRepeatSym = sym;
#endif
mParent->mRepeatTimer.setInterval(400); mParent->mRepeatTimer.setInterval(400);
mParent->mRepeatTimer.start(); mParent->mRepeatTimer.start();
} else if (mRepeatCode == code) { } else if (mRepeatCode == code) {
@ -807,7 +808,13 @@ void QWaylandInputDevice::repeatKey()
QWindowSystemInterface::handleExtendedKeyEvent(mKeyboard->mFocus->window(), QWindowSystemInterface::handleExtendedKeyEvent(mKeyboard->mFocus->window(),
mKeyboard->mRepeatTime, QEvent::KeyPress, mKeyboard->mRepeatKey, mKeyboard->mRepeatTime, QEvent::KeyPress, mKeyboard->mRepeatKey,
modifiers(), modifiers(),
mKeyboard->mRepeatCode, 0, 0, mKeyboard->mRepeatText); mKeyboard->mRepeatCode,
#ifndef QT_NO_WAYLAND_XKB
mKeyboard->mRepeatSym, mKeyboard->mNativeModifiers,
#else
0, 0,
#endif
mKeyboard->mRepeatText, true);
} }
void QWaylandInputDevice::Keyboard::keyboard_modifiers(uint32_t serial, void QWaylandInputDevice::Keyboard::keyboard_modifiers(uint32_t serial,
@ -822,6 +829,7 @@ void QWaylandInputDevice::Keyboard::keyboard_modifiers(uint32_t serial,
xkb_state_update_mask(mXkbState, xkb_state_update_mask(mXkbState,
mods_depressed, mods_latched, mods_locked, mods_depressed, mods_latched, mods_locked,
0, 0, group); 0, 0, group);
mNativeModifiers = mods_depressed | mods_latched | mods_locked;
#else #else
Q_UNUSED(serial); Q_UNUSED(serial);
Q_UNUSED(mods_depressed); Q_UNUSED(mods_depressed);