diff options
author | Liang Qi <liang.qi@theqtcompany.com> | 2015-09-25 14:02:04 +0200 |
---|---|---|
committer | Liang Qi <liang.qi@theqtcompany.com> | 2015-09-25 14:02:04 +0200 |
commit | a1ad9a74ebb3c556c5f70f7e03be68b09598ac53 (patch) | |
tree | 615a96db418219a57a745a5899e39a9ac90744ec /src/platformsupport/input | |
parent | 6d78b7a0c46ea04f4bb771d960e2f7dff1362341 (diff) | |
parent | 462f355e4fb16cc7a1838fa2dda0f763eee58c84 (diff) |
Merge remote-tracking branch 'origin/5.6' into dev
Conflicts:
src/corelib/io/io.pri
src/corelib/io/qdatastream.cpp
src/corelib/io/qdatastream.h
src/network/socket/qabstractsocket.cpp
src/plugins/platforminputcontexts/ibus/qibusplatforminputcontext.cpp
src/plugins/platforms/cocoa/qcocoaaccessibilityelement.h
src/widgets/styles/qgtkstyle.cpp
tests/auto/corelib/mimetypes/qmimedatabase/qmimedatabase-cache/qmimedatabase-cache.pro
tests/auto/corelib/mimetypes/qmimedatabase/qmimedatabase-xml/qmimedatabase-xml.pro
tests/auto/dbus/qdbusconnection/qdbusconnection.pro
tests/auto/dbus/qdbuspendingcall/tst_qdbuspendingcall.cpp
tests/auto/network/access/qnetworkreply/tst_qnetworkreply.cpp
Change-Id: I347549a024eb5bfa986699e0a11f96cc55c797a7
Diffstat (limited to 'src/platformsupport/input')
6 files changed, 120 insertions, 41 deletions
diff --git a/src/platformsupport/input/evdevtouch/qevdevtouchhandler.cpp b/src/platformsupport/input/evdevtouch/qevdevtouchhandler.cpp index 1ca95074b9..ad348cc083 100644 --- a/src/platformsupport/input/evdevtouch/qevdevtouchhandler.cpp +++ b/src/platformsupport/input/evdevtouch/qevdevtouchhandler.cpp @@ -38,6 +38,7 @@ #include <QGuiApplication> #include <QLoggingCategory> #include <QtCore/private/qcore_unix_p.h> +#include <QtGui/private/qhighdpiscaling_p.h> #include <QtGui/private/qguiapplication_p.h> #include <linux/input.h> @@ -106,9 +107,8 @@ public: int m_currentSlot; int findClosestContact(const QHash<int, Contact> &contacts, int x, int y, int *dist); - void reportPoints(); - void registerDevice(); void addTouchPoint(const Contact &contact, Qt::TouchPointStates *combinedStates); + void reportPoints(); int hw_range_x_min; int hw_range_x_max; @@ -118,7 +118,6 @@ public: int hw_pressure_max; QString hw_name; bool m_forceToActiveWindow; - QTouchDevice *m_device; bool m_typeB; QTransform m_rotate; bool m_singleTouch; @@ -131,23 +130,11 @@ QEvdevTouchScreenData::QEvdevTouchScreenData(QEvdevTouchScreenHandler *q_ptr, co hw_range_x_min(0), hw_range_x_max(0), hw_range_y_min(0), hw_range_y_max(0), hw_pressure_min(0), hw_pressure_max(0), - m_device(0), m_typeB(false), m_singleTouch(false) + m_typeB(false), m_singleTouch(false) { m_forceToActiveWindow = args.contains(QLatin1String("force_window")); } -void QEvdevTouchScreenData::registerDevice() -{ - m_device = new QTouchDevice; - m_device->setName(hw_name); - m_device->setType(QTouchDevice::TouchScreen); - m_device->setCapabilities(QTouchDevice::Position | QTouchDevice::Area); - if (hw_pressure_max > hw_pressure_min) - m_device->setCapabilities(m_device->capabilities() | QTouchDevice::Pressure); - - QWindowSystemInterface::registerTouchDevice(m_device); -} - #define LONG_BITS (sizeof(long) << 3) #define NUM_LONGS(bits) (((bits) + LONG_BITS - 1) / LONG_BITS) @@ -159,9 +146,9 @@ static inline bool testBit(long bit, const long *array) #endif QEvdevTouchScreenHandler::QEvdevTouchScreenHandler(const QString &device, const QString &spec, QObject *parent) - : QObject(parent), m_notify(0), m_fd(-1), d(0) + : QObject(parent), m_notify(Q_NULLPTR), m_fd(-1), d(Q_NULLPTR), m_device(Q_NULLPTR) #if !defined(QT_NO_MTDEV) - , m_mtdev(0) + , m_mtdev(Q_NULLPTR) #endif { setObjectName(QLatin1String("Evdev Touch Handler")); @@ -298,7 +285,7 @@ QEvdevTouchScreenHandler::QEvdevTouchScreenHandler(const QString &device, const if (inverty) d->m_rotate *= QTransform::fromTranslate(0.5, 0.5).scale(1.0, -1.0).translate(-0.5, -0.5); - d->registerDevice(); + registerTouchDevice(); } QEvdevTouchScreenHandler::~QEvdevTouchScreenHandler() @@ -314,6 +301,13 @@ QEvdevTouchScreenHandler::~QEvdevTouchScreenHandler() QT_CLOSE(m_fd); delete d; + + unregisterTouchDevice(); +} + +QTouchDevice *QEvdevTouchScreenHandler::touchDevice() const +{ + return m_device; } void QEvdevTouchScreenHandler::readData() @@ -367,15 +361,44 @@ err: qErrnoWarning(errno, "evdevtouch: Could not read from input device"); if (errno == ENODEV) { // device got disconnected -> stop reading delete m_notify; - m_notify = 0; + m_notify = Q_NULLPTR; + QT_CLOSE(m_fd); m_fd = -1; + + unregisterTouchDevice(); } return; } } } +void QEvdevTouchScreenHandler::registerTouchDevice() +{ + if (m_device) + return; + + m_device = new QTouchDevice; + m_device->setName(d->hw_name); + m_device->setType(QTouchDevice::TouchScreen); + m_device->setCapabilities(QTouchDevice::Position | QTouchDevice::Area); + if (d->hw_pressure_max > d->hw_pressure_min) + m_device->setCapabilities(m_device->capabilities() | QTouchDevice::Pressure); + + QWindowSystemInterface::registerTouchDevice(m_device); +} + +void QEvdevTouchScreenHandler::unregisterTouchDevice() +{ + if (!m_device) + return; + + QWindowSystemInterface::unregisterTouchDevice(m_device); + + delete m_device; + m_device = Q_NULLPTR; +} + void QEvdevTouchScreenData::addTouchPoint(const Contact &contact, Qt::TouchPointStates *combinedStates) { QWindowSystemInterface::TouchPoint tp; @@ -604,9 +627,10 @@ void QEvdevTouchScreenData::reportPoints() QWindow *win = QGuiApplication::focusWindow(); if (!win) return; - winRect = win->geometry(); + winRect = QHighDpi::toNativePixels(win->geometry(), win); } else { - winRect = QGuiApplication::primaryScreen()->geometry(); + QScreen *primary = QGuiApplication::primaryScreen(); + winRect = QHighDpi::toNativePixels(primary->geometry(), primary); } const int hw_w = hw_range_x_max - hw_range_x_min; @@ -637,12 +661,12 @@ void QEvdevTouchScreenData::reportPoints() tp.pressure = (tp.pressure - hw_pressure_min) / qreal(hw_pressure_max - hw_pressure_min); } - QWindowSystemInterface::handleTouchEvent(0, m_device, m_touchPoints); + QWindowSystemInterface::handleTouchEvent(Q_NULLPTR, q->touchDevice(), m_touchPoints); } QEvdevTouchScreenHandlerThread::QEvdevTouchScreenHandlerThread(const QString &device, const QString &spec, QObject *parent) - : QDaemonThread(parent), m_device(device), m_spec(spec), m_handler(0) + : QDaemonThread(parent), m_device(device), m_spec(spec), m_handler(Q_NULLPTR), m_touchDeviceRegistered(false) { start(); } @@ -656,9 +680,24 @@ QEvdevTouchScreenHandlerThread::~QEvdevTouchScreenHandlerThread() void QEvdevTouchScreenHandlerThread::run() { m_handler = new QEvdevTouchScreenHandler(m_device, m_spec); + // Report the registration to the parent thread by invoking the method asynchronously + QMetaObject::invokeMethod(this, "notifyTouchDeviceRegistered", Qt::QueuedConnection); + exec(); + delete m_handler; - m_handler = 0; + m_handler = Q_NULLPTR; +} + +bool QEvdevTouchScreenHandlerThread::isTouchDeviceRegistered() const +{ + return m_touchDeviceRegistered; +} + +void QEvdevTouchScreenHandlerThread::notifyTouchDeviceRegistered() +{ + m_touchDeviceRegistered = true; + emit touchDeviceRegistered(); } diff --git a/src/platformsupport/input/evdevtouch/qevdevtouchhandler_p.h b/src/platformsupport/input/evdevtouch/qevdevtouchhandler_p.h index 8e7dfe59bb..ca9756d5de 100644 --- a/src/platformsupport/input/evdevtouch/qevdevtouchhandler_p.h +++ b/src/platformsupport/input/evdevtouch/qevdevtouchhandler_p.h @@ -66,16 +66,22 @@ class QEvdevTouchScreenHandler : public QObject Q_OBJECT public: - explicit QEvdevTouchScreenHandler(const QString &device, const QString &spec = QString(), QObject *parent = 0); + explicit QEvdevTouchScreenHandler(const QString &device, const QString &spec = QString(), QObject *parent = Q_NULLPTR); ~QEvdevTouchScreenHandler(); + QTouchDevice *touchDevice() const; + private slots: void readData(); private: + void registerTouchDevice(); + void unregisterTouchDevice(); + QSocketNotifier *m_notify; int m_fd; QEvdevTouchScreenData *d; + QTouchDevice *m_device; #if !defined(QT_NO_MTDEV) mtdev *m_mtdev; #endif @@ -83,16 +89,24 @@ private: class QEvdevTouchScreenHandlerThread : public QDaemonThread { + Q_OBJECT public: - explicit QEvdevTouchScreenHandlerThread(const QString &device, const QString &spec, QObject *parent = 0); + explicit QEvdevTouchScreenHandlerThread(const QString &device, const QString &spec, QObject *parent = Q_NULLPTR); ~QEvdevTouchScreenHandlerThread(); void run() Q_DECL_OVERRIDE; - QEvdevTouchScreenHandler *handler() { return m_handler; } + + bool isTouchDeviceRegistered() const; + +signals: + void touchDeviceRegistered(); private: + Q_INVOKABLE void notifyTouchDeviceRegistered(); + QString m_device; QString m_spec; QEvdevTouchScreenHandler *m_handler; + bool m_touchDeviceRegistered; }; QT_END_NAMESPACE diff --git a/src/platformsupport/input/evdevtouch/qevdevtouchmanager.cpp b/src/platformsupport/input/evdevtouch/qevdevtouchmanager.cpp index 98fc83700c..35a685ff21 100644 --- a/src/platformsupport/input/evdevtouch/qevdevtouchmanager.cpp +++ b/src/platformsupport/input/evdevtouch/qevdevtouchmanager.cpp @@ -91,17 +91,17 @@ QEvdevTouchManager::QEvdevTouchManager(const QString &key, const QString &specif QEvdevTouchManager::~QEvdevTouchManager() { qDeleteAll(m_activeDevices); + updateInputDeviceCount(); } void QEvdevTouchManager::addDevice(const QString &deviceNode) { - qCDebug(qLcEvdevTouch) << "Adding device at" << deviceNode; + qCDebug(qLcEvdevTouch) << "evdevtouch: Adding device at" << deviceNode; QEvdevTouchScreenHandlerThread *handler; handler = new QEvdevTouchScreenHandlerThread(deviceNode, m_spec); if (handler) { m_activeDevices.insert(deviceNode, handler); - QInputDeviceManagerPrivate::get(QGuiApplicationPrivate::inputDeviceManager())->setDeviceCount( - QInputDeviceManager::DeviceTypeTouch, m_activeDevices.count()); + connect(handler, &QEvdevTouchScreenHandlerThread::touchDeviceRegistered, this, &QEvdevTouchManager::updateInputDeviceCount); } else { qWarning("evdevtouch: Failed to open touch device %s", qPrintable(deviceNode)); } @@ -110,13 +110,28 @@ void QEvdevTouchManager::addDevice(const QString &deviceNode) void QEvdevTouchManager::removeDevice(const QString &deviceNode) { if (m_activeDevices.contains(deviceNode)) { - qCDebug(qLcEvdevTouch) << "Removing device at" << deviceNode; + qCDebug(qLcEvdevTouch) << "evdevtouch: Removing device at" << deviceNode; QEvdevTouchScreenHandlerThread *handler = m_activeDevices.value(deviceNode); m_activeDevices.remove(deviceNode); - QInputDeviceManagerPrivate::get(QGuiApplicationPrivate::inputDeviceManager())->setDeviceCount( - QInputDeviceManager::DeviceTypeTouch, m_activeDevices.count()); delete handler; + + updateInputDeviceCount(); } } +void QEvdevTouchManager::updateInputDeviceCount() +{ + int registeredTouchDevices = 0; + Q_FOREACH (QEvdevTouchScreenHandlerThread *handler, m_activeDevices) { + if (handler->isTouchDeviceRegistered()) + ++registeredTouchDevices; + } + + qCDebug(qLcEvdevTouch) << "evdevtouch: Updating QInputDeviceManager device count:" << registeredTouchDevices << " touch devices," + << m_activeDevices.count() - registeredTouchDevices << "pending handler(s)" ; + + QInputDeviceManagerPrivate::get(QGuiApplicationPrivate::inputDeviceManager())->setDeviceCount( + QInputDeviceManager::DeviceTypeTouch, registeredTouchDevices); +} + QT_END_NAMESPACE diff --git a/src/platformsupport/input/evdevtouch/qevdevtouchmanager_p.h b/src/platformsupport/input/evdevtouch/qevdevtouchmanager_p.h index bf484fd88b..289c345ac4 100644 --- a/src/platformsupport/input/evdevtouch/qevdevtouchmanager_p.h +++ b/src/platformsupport/input/evdevtouch/qevdevtouchmanager_p.h @@ -65,6 +65,8 @@ private slots: void addDevice(const QString &deviceNode); void removeDevice(const QString &deviceNode); + void updateInputDeviceCount(); + private: QString m_spec; QDeviceDiscovery *m_deviceDiscovery; diff --git a/src/platformsupport/input/libinput/qlibinputhandler.cpp b/src/platformsupport/input/libinput/qlibinputhandler.cpp index 1a64ad5a30..5aa66a4eaf 100644 --- a/src/platformsupport/input/libinput/qlibinputhandler.cpp +++ b/src/platformsupport/input/libinput/qlibinputhandler.cpp @@ -46,7 +46,7 @@ QT_BEGIN_NAMESPACE -Q_LOGGING_CATEGORY(qLcInput, "qt.qpa.input") +Q_LOGGING_CATEGORY(qLcLibInput, "qt.qpa.input") static int liOpen(const char *path, int flags, void *user_data) { @@ -75,7 +75,7 @@ static void liLogHandler(libinput *libinput, libinput_log_priority priority, con if (n > 0) { if (buf[n - 1] == '\n') buf[n - 1] = '\0'; - qCDebug(qLcInput, "libinput: %s", buf); + qCDebug(qLcLibInput, "libinput: %s", buf); } } @@ -93,7 +93,7 @@ QLibInputHandler::QLibInputHandler(const QString &key, const QString &spec) qFatal("Failed to get libinput context"); libinput_log_set_handler(m_li, liLogHandler); - if (qLcInput().isDebugEnabled()) + if (qLcLibInput().isDebugEnabled()) libinput_log_set_priority(m_li, LIBINPUT_LOG_PRIORITY_DEBUG); if (libinput_udev_assign_seat(m_li, "seat0")) diff --git a/src/platformsupport/input/libinput/qlibinputkeyboard.cpp b/src/platformsupport/input/libinput/qlibinputkeyboard.cpp index 5f1bc550b4..ec7ea7ef0d 100644 --- a/src/platformsupport/input/libinput/qlibinputkeyboard.cpp +++ b/src/platformsupport/input/libinput/qlibinputkeyboard.cpp @@ -33,6 +33,7 @@ #include "qlibinputkeyboard_p.h" #include <QtCore/QTextCodec> +#include <QtCore/QLoggingCategory> #include <qpa/qwindowsysteminterface.h> #include <libinput.h> #ifndef QT_NO_XKBCOMMON_EVDEV @@ -42,6 +43,8 @@ QT_BEGIN_NAMESPACE +Q_DECLARE_LOGGING_CATEGORY(qLcLibInput) + const int REPEAT_DELAY = 500; const int REPEAT_RATE = 100; @@ -128,6 +131,7 @@ QLibInputKeyboard::QLibInputKeyboard() #endif { #ifndef QT_NO_XKBCOMMON_EVDEV + qCDebug(qLcLibInput) << "Using xkbcommon for key mapping"; m_ctx = xkb_context_new(XKB_CONTEXT_NO_FLAGS); if (!m_ctx) { qWarning("Failed to create xkb context"); @@ -150,6 +154,8 @@ QLibInputKeyboard::QLibInputKeyboard() m_repeatTimer.setSingleShot(true); connect(&m_repeatTimer, &QTimer::timeout, this, &QLibInputKeyboard::handleRepeat); +#else + qCWarning(qLcLibInput) << "X-less xkbcommon not available, not performing key mapping"; #endif } @@ -174,10 +180,13 @@ void QLibInputKeyboard::processKey(libinput_event_keyboard *e) const uint32_t k = libinput_event_keyboard_get_key(e) + 8; const bool pressed = libinput_event_keyboard_get_key_state(e) == LIBINPUT_KEY_STATE_PRESSED; - QByteArray chars; - chars.resize(1 + xkb_state_key_get_utf8(m_state, k, Q_NULLPTR, 0)); - xkb_state_key_get_utf8(m_state, k, chars.data(), chars.size()); - const QString text = QString::fromUtf8(chars); + QVarLengthArray<char, 32> chars(32); + const int size = xkb_state_key_get_utf8(m_state, k, chars.data(), chars.size()); + if (Q_UNLIKELY(size + 1 > chars.size())) { // +1 for NUL + chars.resize(size + 1); + xkb_state_key_get_utf8(m_state, k, chars.data(), chars.size()); + } + const QString text = QString::fromUtf8(chars.constData(), size); const xkb_keysym_t sym = xkb_state_key_get_one_sym(m_state, k); |