summaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorJüri Valdmann <juri.valdmann@qt.io>2018-08-27 14:36:12 +0200
committerJüri Valdmann <juri.valdmann@qt.io>2018-08-27 14:30:00 +0000
commitfd7c75505662340189c785de57cbd7d73593b32b (patch)
tree8735c685560db9012ebcd06613f43c0814ba6f20 /src
parentb99f2c8ed802ed22f785daace303787df031bce7 (diff)
WebEventFactory: Use runtime platform detection
Make sure that the platform specific code paths are only taken when the relevant QPA plugin is actually used. Also detect if eglfs plugin is using Xkb key codes. Task-number: QTBUG-69442 Change-Id: I9546b61ad8d9f15020a96f8c0006d056aa157fcc Reviewed-by: Kai Koehne <kai.koehne@qt.io>
Diffstat (limited to 'src')
-rw-r--r--src/core/web_event_factory.cpp46
1 files changed, 40 insertions, 6 deletions
diff --git a/src/core/web_event_factory.cpp b/src/core/web_event_factory.cpp
index 3018da006..bafdaecf1 100644
--- a/src/core/web_event_factory.cpp
+++ b/src/core/web_event_factory.cpp
@@ -70,6 +70,8 @@
#include "ui/events/keycodes/dom/dom_key.h"
#include "ui/events/keycodes/dom/keycode_converter.h"
+#include <QtGui/private/qtgui-config_p.h>
+
#include <QCoreApplication>
#include <QElapsedTimer>
#include <QGuiApplication>
@@ -83,6 +85,42 @@
using namespace blink;
+enum class KeyboardDriver { Unknown, Windows, Cocoa, Xkb, Evdev };
+
+static KeyboardDriver keyboardDriverImpl()
+{
+ QString platformName = QGuiApplication::platformName();
+
+ if (platformName == QLatin1Literal("windows"))
+ return KeyboardDriver::Windows;
+
+ if (platformName == QLatin1Literal("cocoa"))
+ return KeyboardDriver::Cocoa;
+
+ if (platformName == QLatin1Literal("xcb") || platformName == QLatin1Literal("wayland"))
+ return KeyboardDriver::Xkb;
+
+#if QT_CONFIG(libinput) && QT_CONFIG(xkbcommon_evdev)
+ // Based on QEglFSIntegration::createInputHandlers and QLibInputKeyboard::processKey.
+ if (platformName == QLatin1Literal("eglfs") && !qEnvironmentVariableIntValue("QT_QPA_EGLFS_NO_LIBINPUT"))
+ return KeyboardDriver::Xkb;
+#endif
+
+#if QT_CONFIG(evdev)
+ // Based on QEglFSIntegration::createInputHandlers.
+ if (platformName == QLatin1Literal("eglfs"))
+ return KeyboardDriver::Evdev;
+#endif
+
+ return KeyboardDriver::Unknown;
+}
+
+static KeyboardDriver keyboardDriver()
+{
+ static KeyboardDriver cached = keyboardDriverImpl();
+ return cached;
+}
+
// Qt swaps the Control and Meta keys on macOS (unless the attribute
// AA_MacDontSwapCtrlAndMeta is set). To preserve compatibility with Chromium we
// want to unswap them when forwarding events. The following two functions,
@@ -92,14 +130,12 @@ using namespace blink;
static int qtKeyForKeyEvent(const QKeyEvent *ev)
{
int key = ev->key();
-#ifdef Q_OS_MACOS
- if (!qApp->testAttribute(Qt::AA_MacDontSwapCtrlAndMeta)) {
+ if (keyboardDriver() == KeyboardDriver::Cocoa && !qApp->testAttribute(Qt::AA_MacDontSwapCtrlAndMeta)) {
if (key == Qt::Key_Control)
return Qt::Key_Meta;
if (key == Qt::Key_Meta)
return Qt::Key_Control;
}
-#endif
return key;
}
@@ -107,14 +143,12 @@ static int qtKeyForKeyEvent(const QKeyEvent *ev)
static Qt::KeyboardModifiers qtModifiersForEvent(const QInputEvent *ev)
{
Qt::KeyboardModifiers modifiers = ev->modifiers();
-#ifdef Q_OS_MACOS
- if (!qApp->testAttribute(Qt::AA_MacDontSwapCtrlAndMeta)) {
+ if (keyboardDriver() == KeyboardDriver::Cocoa && !qApp->testAttribute(Qt::AA_MacDontSwapCtrlAndMeta)) {
bool controlModifier = modifiers.testFlag(Qt::ControlModifier);
bool metaModifier = modifiers.testFlag(Qt::MetaModifier);
modifiers.setFlag(Qt::ControlModifier, metaModifier);
modifiers.setFlag(Qt::MetaModifier, controlModifier);
}
-#endif
return modifiers;
}