diff options
author | Samuel Rødal <samuel.rodal@nokia.com> | 2011-02-09 11:36:16 (GMT) |
---|---|---|
committer | Samuel Rødal <samuel.rodal@nokia.com> | 2011-02-09 11:46:15 (GMT) |
commit | 69a0d3bdbfecdbf559aa6d0132281ad64b88fac8 (patch) | |
tree | af922f4f0e6a3dbb3054b15369d2a37118a93d85 /src | |
parent | bb0480a03bba6b23dd1e35ea1a8cc62e4f4a0219 (diff) | |
download | Qt-69a0d3bdbfecdbf559aa6d0132281ad64b88fac8.zip Qt-69a0d3bdbfecdbf559aa6d0132281ad64b88fac8.tar.gz Qt-69a0d3bdbfecdbf559aa6d0132281ad64b88fac8.tar.bz2 |
Better handling of key codes in XCB backend.
Using xcb_key_symbols_get_keysym seems to give better results compared
to xcb_key_press_lookup_keysym xcb_key_release_lookup_keysym.
Diffstat (limited to 'src')
-rw-r--r-- | src/plugins/platforms/xcb/qxcbkeyboard.cpp | 29 | ||||
-rw-r--r-- | src/plugins/platforms/xcb/qxcbkeyboard.h | 2 |
2 files changed, 19 insertions, 12 deletions
diff --git a/src/plugins/platforms/xcb/qxcbkeyboard.cpp b/src/plugins/platforms/xcb/qxcbkeyboard.cpp index 83f053a..67039a7 100644 --- a/src/plugins/platforms/xcb/qxcbkeyboard.cpp +++ b/src/plugins/platforms/xcb/qxcbkeyboard.cpp @@ -911,18 +911,29 @@ QXcbKeyboard::~QXcbKeyboard() xcb_key_symbols_free(m_key_symbols); } -void QXcbKeyboard::handleKeyEvent(QWidget *widget, QEvent::Type type, xcb_keysym_t sym, quint16 state, xcb_timestamp_t time) +void QXcbKeyboard::handleKeyEvent(QWidget *widget, QEvent::Type type, xcb_keycode_t code, quint16 state, xcb_timestamp_t time) { + int col = state & XCB_MOD_MASK_SHIFT ? 1 : 0; + + const int altGrOffset = 4; + if (state & 128) + col += altGrOffset; + + xcb_keysym_t sym = xcb_key_symbols_get_keysym(m_key_symbols, code, col); + + if (state & XCB_MOD_MASK_LOCK && sym <= 0x7f && isprint(sym)) { + if (isupper(sym)) + sym = tolower(sym); + else + sym = toupper(sym); + } + QByteArray chars; - chars.resize(513); Qt::KeyboardModifiers modifiers; int qtcode = 0; int count = 0; - if (state & XCB_MOD_MASK_SHIFT && sym <= 0x7f && isalpha(sym)) - sym = toupper(sym); - QString string = translateKeySym(sym, state, qtcode, modifiers, chars, count); QWindowSystemInterface::handleKeyEvent(widget, time, type, qtcode, modifiers, string.left(count)); @@ -930,16 +941,12 @@ void QXcbKeyboard::handleKeyEvent(QWidget *widget, QEvent::Type type, xcb_keysym void QXcbKeyboard::handleKeyPressEvent(QWidget *widget, const xcb_key_press_event_t *event) { - xcb_keysym_t sym = xcb_key_press_lookup_keysym(m_key_symbols, const_cast<xcb_key_press_event_t *>(event), 0); - - handleKeyEvent(widget, QEvent::KeyPress, sym, event->state, event->time); + handleKeyEvent(widget, QEvent::KeyPress, event->detail, event->state, event->time); } void QXcbKeyboard::handleKeyReleaseEvent(QWidget *widget, const xcb_key_release_event_t *event) { - xcb_keysym_t sym = xcb_key_release_lookup_keysym(m_key_symbols, const_cast<xcb_key_release_event_t *>(event), 0); - - handleKeyEvent(widget, QEvent::KeyRelease, sym, event->state, event->time); + handleKeyEvent(widget, QEvent::KeyRelease, event->detail, event->state, event->time); } void QXcbKeyboard::handleMappingNotifyEvent(const xcb_mapping_notify_event_t *event) diff --git a/src/plugins/platforms/xcb/qxcbkeyboard.h b/src/plugins/platforms/xcb/qxcbkeyboard.h index 89c7418..2a17e48 100644 --- a/src/plugins/platforms/xcb/qxcbkeyboard.h +++ b/src/plugins/platforms/xcb/qxcbkeyboard.h @@ -62,7 +62,7 @@ public: Qt::KeyboardModifiers translateModifiers(int s); private: - void handleKeyEvent(QWidget *widget, QEvent::Type type, xcb_keysym_t sym, quint16 state, xcb_timestamp_t time); + void handleKeyEvent(QWidget *widget, QEvent::Type type, xcb_keycode_t code, quint16 state, xcb_timestamp_t time); int translateKeySym(uint key) const; QString translateKeySym(xcb_keysym_t keysym, uint xmodifiers, |