summaryrefslogtreecommitdiffstats
path: root/src/plugins
diff options
context:
space:
mode:
authorJames McDonnell <jmcdonnell@blackberry.com>2018-03-23 16:40:45 -0400
committerJames McDonnell <jmcdonnell@blackberry.com>2018-05-04 13:12:14 +0000
commite67671d7cb236944c6cd6fd72b353dad6b6d93bf (patch)
treee1021fb5bbed04ea17a104692108c461c625041f /src/plugins
parent5269f6d55e4cb804e0316f2239916f83001a7379 (diff)
Generate more Windows/Linux-like Qt keyboard events
The QKeyEvent::key values were significantly different on QNX and some QKeyEvent::text values were also different/missing. Also makes it possible to enter numbers via the numeric keypad. Change-Id: Ifcf6284b99a893a87974d37ec6d6976f88241e61 Reviewed-by: Rafael Roquetto <rafael.roquetto@kdab.com> Reviewed-by: Dan Cape <dcape@qnx.com>
Diffstat (limited to 'src/plugins')
-rw-r--r--src/plugins/platforms/qnx/qqnxkeytranslator.h245
-rw-r--r--src/plugins/platforms/qnx/qqnxscreeneventhandler.cpp75
2 files changed, 122 insertions, 198 deletions
diff --git a/src/plugins/platforms/qnx/qqnxkeytranslator.h b/src/plugins/platforms/qnx/qqnxkeytranslator.h
index 043e38fec9..9400b88dbb 100644
--- a/src/plugins/platforms/qnx/qqnxkeytranslator.h
+++ b/src/plugins/platforms/qnx/qqnxkeytranslator.h
@@ -48,179 +48,68 @@
QT_BEGIN_NAMESPACE
-Qt::Key keyTranslator( int key )
+int qtKeyForPrivateUseQnxKey( int key )
{
switch (key) {
- case KEYCODE_PAUSE:
- return Qt::Key_Pause;
-
- case KEYCODE_SCROLL_LOCK:
- return Qt::Key_ScrollLock;
-
- case KEYCODE_PRINT:
- return Qt::Key_Print;
-
- case KEYCODE_SYSREQ:
- return Qt::Key_SysReq;
-
+ case KEYCODE_PAUSE: return Qt::Key_Pause;
+ case KEYCODE_SCROLL_LOCK: return Qt::Key_ScrollLock;
+ case KEYCODE_PRINT: return Qt::Key_Print;
+ case KEYCODE_SYSREQ: return Qt::Key_SysReq;
// case KEYCODE_BREAK:
-
- case KEYCODE_ESCAPE:
- return Qt::Key_Escape;
-
- case KEYCODE_BACKSPACE:
- return Qt::Key_Backspace;
-
- case KEYCODE_TAB:
- return Qt::Key_Tab;
-
- case KEYCODE_BACK_TAB:
- return Qt::Key_Backtab;
-
- case KEYCODE_RETURN:
- return Qt::Key_Return;
-
- case KEYCODE_CAPS_LOCK:
- return Qt::Key_CapsLock;
-
- case KEYCODE_LEFT_SHIFT:
- case KEYCODE_RIGHT_SHIFT:
- return Qt::Key_Shift;
-
- case KEYCODE_LEFT_CTRL:
- case KEYCODE_RIGHT_CTRL:
- return Qt::Key_Control;
-
- case KEYCODE_LEFT_ALT:
- case KEYCODE_RIGHT_ALT:
- return Qt::Key_Alt;
-
- case KEYCODE_MENU:
- return Qt::Key_Menu;
-
- case KEYCODE_LEFT_HYPER:
- return Qt::Key_Hyper_L;
-
- case KEYCODE_RIGHT_HYPER:
- return Qt::Key_Hyper_R;
-
- case KEYCODE_INSERT:
- return Qt::Key_Insert;
-
- case KEYCODE_HOME:
- return Qt::Key_Home;
-
- case KEYCODE_PG_UP:
- return Qt::Key_PageUp;
-
- case KEYCODE_DELETE:
- return Qt::Key_Delete;
-
- case KEYCODE_END:
- return Qt::Key_End;
-
- case KEYCODE_PG_DOWN:
- return Qt::Key_PageDown;
-
- case KEYCODE_LEFT:
- return Qt::Key_Left;
-
- case KEYCODE_RIGHT:
- return Qt::Key_Right;
-
- case KEYCODE_UP:
- return Qt::Key_Up;
-
- case KEYCODE_DOWN:
- return Qt::Key_Down;
-
- case KEYCODE_NUM_LOCK:
- return Qt::Key_NumLock;
-
- case KEYCODE_KP_PLUS:
- return Qt::Key_Plus;
-
- case KEYCODE_KP_MINUS:
- return Qt::Key_Minus;
-
- case KEYCODE_KP_MULTIPLY:
- return Qt::Key_Asterisk;
-
- case KEYCODE_KP_DIVIDE:
- return Qt::Key_Slash;
-
- case KEYCODE_KP_ENTER:
- return Qt::Key_Enter;
-
- case KEYCODE_KP_HOME:
- return Qt::Key_Home;
-
- case KEYCODE_KP_UP:
- return Qt::Key_Up;
-
- case KEYCODE_KP_PG_UP:
- return Qt::Key_PageUp;
-
- case KEYCODE_KP_LEFT:
- return Qt::Key_Left;
-
- // Is this right?
- case KEYCODE_KP_FIVE:
- return Qt::Key_5;
-
- case KEYCODE_KP_RIGHT:
- return Qt::Key_Right;
-
- case KEYCODE_KP_END:
- return Qt::Key_End;
-
- case KEYCODE_KP_DOWN:
- return Qt::Key_Down;
-
- case KEYCODE_KP_PG_DOWN:
- return Qt::Key_PageDown;
-
- case KEYCODE_KP_INSERT:
- return Qt::Key_Insert;
-
- case KEYCODE_KP_DELETE:
- return Qt::Key_Delete;
-
- case KEYCODE_F1:
- return Qt::Key_F1;
-
- case KEYCODE_F2:
- return Qt::Key_F2;
-
- case KEYCODE_F3:
- return Qt::Key_F3;
-
- case KEYCODE_F4:
- return Qt::Key_F4;
-
- case KEYCODE_F5:
- return Qt::Key_F5;
-
- case KEYCODE_F6:
- return Qt::Key_F6;
-
- case KEYCODE_F7:
- return Qt::Key_F7;
-
- case KEYCODE_F8:
- return Qt::Key_F8;
-
- case KEYCODE_F9:
- return Qt::Key_F9;
-
- case KEYCODE_F10:
- return Qt::Key_F10;
-
- case KEYCODE_F11:
- return Qt::Key_F11;
-
- case KEYCODE_F12:
- return Qt::Key_F12;
+ case KEYCODE_ESCAPE: return Qt::Key_Escape;
+ case KEYCODE_BACKSPACE: return Qt::Key_Backspace;
+ case KEYCODE_TAB: return Qt::Key_Tab;
+ case KEYCODE_BACK_TAB: return Qt::Key_Backtab;
+ case KEYCODE_RETURN: return Qt::Key_Return;
+ case KEYCODE_CAPS_LOCK: return Qt::Key_CapsLock;
+ case KEYCODE_LEFT_SHIFT: return Qt::Key_Shift;
+ case KEYCODE_RIGHT_SHIFT: return Qt::Key_Shift;
+ case KEYCODE_LEFT_CTRL: return Qt::Key_Control;
+ case KEYCODE_RIGHT_CTRL: return Qt::Key_Control;
+ case KEYCODE_LEFT_ALT: return Qt::Key_Alt;
+ case KEYCODE_RIGHT_ALT: return Qt::Key_Alt;
+ case KEYCODE_MENU: return Qt::Key_Menu;
+ case KEYCODE_LEFT_HYPER: return Qt::Key_Hyper_L;
+ case KEYCODE_RIGHT_HYPER: return Qt::Key_Hyper_R;
+ case KEYCODE_INSERT: return Qt::Key_Insert;
+ case KEYCODE_HOME: return Qt::Key_Home;
+ case KEYCODE_PG_UP: return Qt::Key_PageUp;
+ case KEYCODE_DELETE: return Qt::Key_Delete;
+ case KEYCODE_END: return Qt::Key_End;
+ case KEYCODE_PG_DOWN: return Qt::Key_PageDown;
+ case KEYCODE_LEFT: return Qt::Key_Left;
+ case KEYCODE_RIGHT: return Qt::Key_Right;
+ case KEYCODE_UP: return Qt::Key_Up;
+ case KEYCODE_DOWN: return Qt::Key_Down;
+ case KEYCODE_NUM_LOCK: return Qt::Key_NumLock;
+ case KEYCODE_KP_PLUS: return Qt::Key_Plus;
+ case KEYCODE_KP_MINUS: return Qt::Key_Minus;
+ case KEYCODE_KP_MULTIPLY: return Qt::Key_Asterisk;
+ case KEYCODE_KP_DIVIDE: return Qt::Key_Slash;
+ case KEYCODE_KP_ENTER: return Qt::Key_Enter;
+ case KEYCODE_KP_HOME: return Qt::Key_Home;
+ case KEYCODE_KP_UP: return Qt::Key_Up;
+ case KEYCODE_KP_PG_UP: return Qt::Key_PageUp;
+ case KEYCODE_KP_LEFT: return Qt::Key_Left;
+ case KEYCODE_KP_FIVE: return Qt::Key_5;
+ case KEYCODE_KP_RIGHT: return Qt::Key_Right;
+ case KEYCODE_KP_END: return Qt::Key_End;
+ case KEYCODE_KP_DOWN: return Qt::Key_Down;
+ case KEYCODE_KP_PG_DOWN: return Qt::Key_PageDown;
+ case KEYCODE_KP_INSERT: return Qt::Key_Insert;
+ case KEYCODE_KP_DELETE: return Qt::Key_Delete;
+ case KEYCODE_F1: return Qt::Key_F1;
+ case KEYCODE_F2: return Qt::Key_F2;
+ case KEYCODE_F3: return Qt::Key_F3;
+ case KEYCODE_F4: return Qt::Key_F4;
+ case KEYCODE_F5: return Qt::Key_F5;
+ case KEYCODE_F6: return Qt::Key_F6;
+ case KEYCODE_F7: return Qt::Key_F7;
+ case KEYCODE_F8: return Qt::Key_F8;
+ case KEYCODE_F9: return Qt::Key_F9;
+ case KEYCODE_F10: return Qt::Key_F10;
+ case KEYCODE_F11: return Qt::Key_F11;
+ case KEYCODE_F12: return Qt::Key_F12;
// See keycodes.h for more, but these are all the basics. And printables are already included.
@@ -231,7 +120,21 @@ Qt::Key keyTranslator( int key )
break;
}
- return Qt::Key_Escape;
+ return Qt::Key_unknown;
+}
+
+QString keyStringForPrivateUseQnxKey( int key )
+{
+ switch (key) {
+ case KEYCODE_ESCAPE: return QStringLiteral("\x1B");
+ case KEYCODE_BACKSPACE: return QStringLiteral("\b");
+ case KEYCODE_TAB: return QStringLiteral("\t");
+ case KEYCODE_RETURN: return QStringLiteral("\r");
+ case KEYCODE_DELETE: return QStringLiteral("\x7F");
+ case KEYCODE_KP_ENTER: return QStringLiteral("\r");
+ }
+
+ return QString();
}
bool isKeypadKey( int key )
diff --git a/src/plugins/platforms/qnx/qqnxscreeneventhandler.cpp b/src/plugins/platforms/qnx/qqnxscreeneventhandler.cpp
index f211883e4f..ff1133aaa7 100644
--- a/src/plugins/platforms/qnx/qqnxscreeneventhandler.cpp
+++ b/src/plugins/platforms/qnx/qqnxscreeneventhandler.cpp
@@ -58,6 +58,37 @@
#define qScreenEventDebug QT_NO_QDEBUG_MACRO
#endif
+static int qtKey(int virtualKey, QChar::Category category)
+{
+ if (Q_UNLIKELY(category == QChar::Other_NotAssigned))
+ return virtualKey;
+ else if (category == QChar::Other_PrivateUse)
+ return qtKeyForPrivateUseQnxKey(virtualKey);
+ else
+ return QChar::toUpper(virtualKey);
+}
+
+static QString keyString(int sym, QChar::Category category)
+{
+ if (Q_UNLIKELY(category == QChar::Other_NotAssigned)) {
+ return QString();
+ } else if (category == QChar::Other_PrivateUse) {
+ return keyStringForPrivateUseQnxKey(sym);
+ } else {
+ uint ucs4_sym = sym;
+ return QString::fromUcs4(&ucs4_sym, 1);
+ }
+}
+
+static QString capKeyString(int cap, int modifiers, int key)
+{
+ if (cap >= 0x20 && cap <= 0x0ff) {
+ if (modifiers & KEYMOD_CTRL)
+ return QChar((int)(key & 0x3f));
+ }
+ return QString();
+}
+
QT_BEGIN_NAMESPACE
QQnxScreenEventHandler::QQnxScreenEventHandler(QQnxIntegration *integration)
@@ -154,6 +185,13 @@ void QQnxScreenEventHandler::injectKeyboardEvent(int flags, int sym, int modifie
{
Q_UNUSED(scan);
+ if (!(flags & KEY_CAP_VALID))
+ return;
+
+ // Correct erroneous information.
+ if ((flags & KEY_SYM_VALID) && sym == static_cast<int>(0xFFFFFFFF))
+ flags &= ~(KEY_SYM_VALID);
+
Qt::KeyboardModifiers qtMod = Qt::NoModifier;
if (modifiers & KEYMOD_SHIFT)
qtMod |= Qt::ShiftModifier;
@@ -161,37 +199,20 @@ void QQnxScreenEventHandler::injectKeyboardEvent(int flags, int sym, int modifie
qtMod |= Qt::ControlModifier;
if (modifiers & KEYMOD_ALT)
qtMod |= Qt::AltModifier;
+ if (isKeypadKey(cap))
+ qtMod |= Qt::KeypadModifier;
- // determine event type
QEvent::Type type = (flags & KEY_DOWN) ? QEvent::KeyPress : QEvent::KeyRelease;
- // Check if the key cap is valid
- if (flags & KEY_CAP_VALID) {
- Qt::Key key;
- QString keyStr;
+ int virtualKey = (flags & KEY_SYM_VALID) ? sym : cap;
+ QChar::Category category = QChar::category(virtualKey);
+ int key = qtKey(virtualKey, category);
+ QString keyStr = (flags & KEY_SYM_VALID) ? keyString(sym, category) :
+ capKeyString(cap, modifiers, key);
- if (cap >= 0x20 && cap <= 0x0ff) {
- key = Qt::Key(std::toupper(cap)); // Qt expects the CAP to be upper case.
-
- if ( qtMod & Qt::ControlModifier ) {
- keyStr = QChar((int)(key & 0x3f));
- } else {
- if (flags & KEY_SYM_VALID)
- keyStr = QChar(sym);
- }
- } else if ((cap > 0x0ff && cap < UNICODE_PRIVATE_USE_AREA_FIRST) || cap > UNICODE_PRIVATE_USE_AREA_LAST) {
- key = (Qt::Key)cap;
- keyStr = QChar(sym);
- } else {
- if (isKeypadKey(cap))
- qtMod |= Qt::KeypadModifier; // Is this right?
- key = keyTranslator(cap);
- }
-
- QWindowSystemInterface::handleExtendedKeyEvent(QGuiApplication::focusWindow(), type, key, qtMod,
- scan, sym, modifiers, keyStr);
- qScreenEventDebug() << "Qt key t=" << type << ", k=" << key << ", s=" << keyStr;
- }
+ QWindowSystemInterface::handleExtendedKeyEvent(QGuiApplication::focusWindow(), type, key, qtMod,
+ scan, virtualKey, modifiers, keyStr);
+ qScreenEventDebug() << "Qt key t=" << type << ", k=" << key << ", s=" << keyStr;
}
void QQnxScreenEventHandler::setScreenEventThread(QQnxScreenEventThread *eventThread)