diff options
author | Giulio Camuffo <giulio.camuffo@kdab.com> | 2016-06-27 11:17:57 +0200 |
---|---|---|
committer | Giulio Camuffo <giulio.camuffo@kdab.com> | 2016-07-04 08:34:00 +0000 |
commit | 25df38cad562c458538037b9e50552b6885e5d05 (patch) | |
tree | 7e4e5eaff0bc12474584a216001c5b3d7bb1ab35 /src/shared | |
parent | 9134c1bd5bf464d00127103557a2289243dadd40 (diff) | |
download | qtwayland-25df38cad562c458538037b9e50552b6885e5d05.tar.gz |
Fix the key code of key events when control is pressed
Change-Id: I51a57a32d8263e663a48dac15881d685359bc91d
Reviewed-by: Jan Arne Petersen <jan.petersen@kdab.com>
Reviewed-by: Pier Luigi Fiorini <pierluigi.fiorini@hawaiios.org>
Diffstat (limited to 'src/shared')
-rw-r--r-- | src/shared/qwaylandxkb.cpp | 31 | ||||
-rw-r--r-- | src/shared/qwaylandxkb_p.h | 5 |
2 files changed, 16 insertions, 20 deletions
diff --git a/src/shared/qwaylandxkb.cpp b/src/shared/qwaylandxkb.cpp index 49925700..2afdcce8 100644 --- a/src/shared/qwaylandxkb.cpp +++ b/src/shared/qwaylandxkb.cpp @@ -293,8 +293,13 @@ static xkb_keysym_t toKeysymFromTable(uint32_t key) return 0; } -int QWaylandXkb::keysymToQtKey(xkb_keysym_t keysym, Qt::KeyboardModifiers &modifiers, const QString &text) +std::pair<int, QString> QWaylandXkb::keysymToQtKey(xkb_keysym_t keysym, Qt::KeyboardModifiers &modifiers) { + QString text; + uint utf32 = xkb_keysym_to_utf32(keysym); + if (utf32) + text = QString::fromUcs4(&utf32, 1); + int code = 0; if (keysym >= XKB_KEY_F1 && keysym <= XKB_KEY_F35) { @@ -316,7 +321,13 @@ int QWaylandXkb::keysymToQtKey(xkb_keysym_t keysym, Qt::KeyboardModifiers &modif code = lookupKeysym(keysym); } - return code; + // Map control + letter to proper text + if (utf32 >= 'A' && utf32 <= '~' && (modifiers & Qt::ControlModifier)) { + utf32 &= ~0x60; + text = QString::fromUcs4(&utf32, 1); + } + + return { code, text }; } Qt::KeyboardModifiers QWaylandXkb::modifiers(struct xkb_state *state) @@ -342,22 +353,6 @@ QEvent::Type QWaylandXkb::toQtEventType(uint32_t state) return state != 0 ? QEvent::KeyPress : QEvent::KeyRelease; } -QString QWaylandXkb::textFromKeysym(uint32_t keysym, Qt::KeyboardModifiers modifiers) -{ - uint utf32 = xkb_keysym_to_utf32(keysym); - - // Map control + letter to proper text - if (utf32 >= 'A' && utf32 <= '~' && (modifiers & Qt::ControlModifier)) { - utf32 &= ~0x60; - return QString::fromUcs4(&utf32, 1); - } - - if (utf32) - return QString::fromUcs4(&utf32, 1); - - return QString(); -} - QVector<xkb_keysym_t> QWaylandXkb::toKeysym(QKeyEvent *event) { QVector<xkb_keysym_t> keysyms; diff --git a/src/shared/qwaylandxkb_p.h b/src/shared/qwaylandxkb_p.h index 9b5c935a..cdebf1b0 100644 --- a/src/shared/qwaylandxkb_p.h +++ b/src/shared/qwaylandxkb_p.h @@ -47,6 +47,8 @@ #include <QEvent> #include <xkbcommon/xkbcommon.h> +#include <utility> + QT_BEGIN_NAMESPACE class QKeyEvent; @@ -54,11 +56,10 @@ class QKeyEvent; class QWaylandXkb { public: - static int keysymToQtKey(xkb_keysym_t keysym, Qt::KeyboardModifiers &modifiers, const QString &text); + static std::pair<int, QString> keysymToQtKey(xkb_keysym_t keysym, Qt::KeyboardModifiers &modifiers); static Qt::KeyboardModifiers modifiers(struct xkb_state *state); static QEvent::Type toQtEventType(uint32_t state); - static QString textFromKeysym(uint32_t keysym, Qt::KeyboardModifiers modifiers); static QVector<xkb_keysym_t> toKeysym(QKeyEvent *event); }; |