diff options
author | Robert Griebl <robert.griebl@pelagicore.com> | 2017-11-30 15:27:57 +0100 |
---|---|---|
committer | Daniel d'Andrada <daniel.dandrada@luxoft.com> | 2018-02-28 15:58:05 +0100 |
commit | c96c81ff26561c9c1f6a053f5899d569dba1163d (patch) | |
tree | 19ba82ccc0d3c2f58b5362d56e59f9a3fa83ae62 | |
parent | 77a20d872502563bdd4b6aac079c6914f6e4af06 (diff) |
Use the touch emulation functionality in the application-manager
The touch emulation code was moved to the application-manager with
commit 9a67912, so we can remove the code from Neptune now.
-rw-r--r-- | am-config.yaml | 2 | ||||
-rw-r--r-- | src/MouseTouchAdaptor.cpp | 276 | ||||
-rw-r--r-- | src/MouseTouchAdaptor.h | 73 | ||||
-rw-r--r-- | src/main.cpp | 10 | ||||
-rw-r--r-- | src/src.pro | 7 | ||||
-rw-r--r-- | tests/triton-qmlscene/triton-qmlscene.cpp | 9 | ||||
-rw-r--r-- | tests/triton-qmlscene/triton-qmlscene.pro | 10 |
7 files changed, 2 insertions, 385 deletions
diff --git a/am-config.yaml b/am-config.yaml index cf027241..234f17b8 100644 --- a/am-config.yaml +++ b/am-config.yaml @@ -24,6 +24,8 @@ ui: mainQml: "${CONFIG_PWD}/Main.qml" importPaths: [ "${CONFIG_PWD}/imports/shared", "${CONFIG_PWD}/imports/system", "${CONFIG_PWD}/sysui" ] windowIcon: "${CONFIG_PWD}/imports/assets/icons/active/apps@96.png" + # convert mouse events to touch events if possible (currently only supported on X11) + enableTouchEmulation: yes systemProperties: public: diff --git a/src/MouseTouchAdaptor.cpp b/src/MouseTouchAdaptor.cpp deleted file mode 100644 index 12bbddd0..00000000 --- a/src/MouseTouchAdaptor.cpp +++ /dev/null @@ -1,276 +0,0 @@ -/**************************************************************************** -** -** Copyright (C) 2017 Pelagicore AG -** Contact: https://www.qt.io/licensing/ -** -** This file is part of the Triton IVI UI. -** -** $QT_BEGIN_LICENSE:GPL-QTAS$ -** Commercial License Usage -** Licensees holding valid commercial Qt Automotive Suite licenses may use -** this file in accordance with the commercial license agreement provided -** with the Software or, alternatively, in accordance with the terms -** contained in a written agreement between you and The Qt Company. For -** licensing terms and conditions see https://www.qt.io/terms-conditions. -** For further information use the contact form at https://www.qt.io/contact-us. -** -** GNU General Public License Usage -** Alternatively, this file may be used under the terms of the GNU -** General Public License version 3 or (at your option) any later version -** approved by the KDE Free Qt Foundation. The licenses are as published by -** the Free Software Foundation and appearing in the file LICENSE.GPL3 -** included in the packaging of this file. Please review the following -** information to ensure the GNU General Public License requirements will -** be met: https://www.gnu.org/licenses/gpl-3.0.html. -** -** $QT_END_LICENSE$ -** -** SPDX-License-Identifier: GPL-3.0 -** -****************************************************************************/ - -#include "MouseTouchAdaptor.h" - -#include <QGuiApplication> -#include <QMouseEvent> -#include <QTest> - -#include <qpa/qplatformnativeinterface.h> -#include <qpa/qwindowsysteminterface.h> - -#include <X11/extensions/XInput2.h> -#include <X11/extensions/XI2proto.h> - -Q_LOGGING_CATEGORY(mouseTouchAdaptor, "mousetouchadaptor") - -using QTest::QTouchEventSequence; - -namespace { - -Qt::MouseButton xcbButtonToQtMouseButton(xcb_button_t detail) -{ - switch (detail) { - case 1: return Qt::LeftButton; - case 2: return Qt::MidButton; - case 3: return Qt::RightButton; - // don't care about the rest - default: return Qt::NoButton; - } -} - -void xi2PrepareXIGenericDeviceEvent(xcb_ge_event_t *event) -{ - // xcb event structs contain stuff that wasn't on the wire, the full_sequence field - // adds an extra 4 bytes and generic events cookie data is on the wire right after the standard 32 bytes. - // Move this data back to have the same layout in memory as it was on the wire - // and allow casting, overwriting the full_sequence field. - memmove((char*) event + 32, (char*) event + 36, event->length * 4); -} - -qreal fixed1616ToReal(FP1616 val) -{ - return qreal(val) / 0x10000; -} - -} // anonymous namespace - -MouseTouchAdaptor *MouseTouchAdaptor::m_instance = nullptr; - -MouseTouchAdaptor *MouseTouchAdaptor::instance() -{ - if (!m_instance) { - new MouseTouchAdaptor; - } - return m_instance; -} - -MouseTouchAdaptor::MouseTouchAdaptor() -{ - Q_ASSERT(!m_instance); - m_instance = this; - - qGuiApp->installNativeEventFilter(this); - - // Create a fake touch device to deliver our synthesized events - m_touchDevice = new QTouchDevice; - m_touchDevice->setType(QTouchDevice::TouchScreen); - QWindowSystemInterface::registerTouchDevice(m_touchDevice); - - queryForXInput2(); -} - -MouseTouchAdaptor::~MouseTouchAdaptor() -{ - Q_ASSERT(m_instance); - m_instance = nullptr; -} - -void MouseTouchAdaptor::queryForXInput2() -{ - QPlatformNativeInterface *nativeInterface = qGuiApp->platformNativeInterface(); - Display *xDisplay = static_cast<Display*>(nativeInterface->nativeResourceForIntegration("Display")); - - int xiOpCode, xiEventBase, xiErrorBase; - if (xDisplay && XQueryExtension(xDisplay, "XInputExtension", &xiOpCode, &xiEventBase, &xiErrorBase)) { - // 2.0 is enough for our needs - int xiMajor = 2; - int xi2Minor = 0; - m_haveXInput2 = XIQueryVersion(xDisplay, &xiMajor, &xi2Minor) != BadRequest; - } -} - -bool MouseTouchAdaptor::nativeEventFilter(const QByteArray &eventType, void *message, long * /*result*/) -{ - if (eventType != "xcb_generic_event_t") { - qCDebug(mouseTouchAdaptor) << "Non XCB native event received. Ignoring."; - return false; - } - - xcb_generic_event_t *xcbEvent = static_cast<xcb_generic_event_t *>(message); - - switch (xcbEvent->response_type & ~0x80) { - case XCB_BUTTON_PRESS: { - auto xcbPress = reinterpret_cast<xcb_button_press_event_t *>(xcbEvent); - return handleButtonPress(static_cast<WId>(xcbPress->event), xcbPress->detail, 0, - xcbPress->event_x, xcbPress->event_y); - } - case XCB_BUTTON_RELEASE: { - auto xcbRelease = reinterpret_cast<xcb_button_release_event_t *>(xcbEvent); - return handleButtonRelease(static_cast<WId>(xcbRelease->event), xcbRelease->detail, 0, - xcbRelease->event_x, xcbRelease->event_y); - } - case XCB_MOTION_NOTIFY: { - auto xcbMotion = reinterpret_cast<xcb_motion_notify_event_t *>(xcbEvent); - return handleMotionNotify(static_cast<WId>(xcbMotion->event), 0, - xcbMotion->event_x, xcbMotion->event_y); - } - case XCB_GE_GENERIC: - if (m_haveXInput2) { - return handleXI2Event(reinterpret_cast<xcb_ge_event_t *>(xcbEvent)); - } else { - return false; - } - default: - return false; - }; -} - -bool MouseTouchAdaptor::handleButtonPress(WId windowId, uint32_t detail, uint32_t /*modifiers*/, int x, int y) -{ - Qt::MouseButton button = xcbButtonToQtMouseButton(detail); - - // Filter out the other mouse buttons - if (button != Qt::LeftButton) - return true; - - QWindow *targetWindow = findQWindowWithXWindowID(windowId); - - QPoint windowPos(x / targetWindow->devicePixelRatio(), y / targetWindow->devicePixelRatio()); - - QTouchEventSequence touchEvent = QTest::touchEvent(targetWindow, m_touchDevice, false /* autoCommit */); - touchEvent.press(0 /* touchId */, windowPos); - touchEvent.commit(false /* processEvents */); - - m_leftButtonIsPressed = true; - return true; -} - -bool MouseTouchAdaptor::handleButtonRelease(WId windowId, uint32_t detail, uint32_t, int x, int y) -{ - Qt::MouseButton button = xcbButtonToQtMouseButton(detail); - - // Don't eat the event if it wasn't a left mouse press - if (button != Qt::LeftButton) - return false; - - QWindow *targetWindow = findQWindowWithXWindowID(windowId); - - QPoint windowPos(x / targetWindow->devicePixelRatio(), y / targetWindow->devicePixelRatio()); - - QTouchEventSequence touchEvent = QTest::touchEvent(targetWindow, m_touchDevice, false /* autoCommit */); - touchEvent.release(0 /* touchId */, windowPos); - touchEvent.commit(false /* processEvents */); - - m_leftButtonIsPressed = false; - return true; -} - -bool MouseTouchAdaptor::handleMotionNotify(WId windowId, uint32_t /*modifiers*/, int x, int y) -{ - if (!m_leftButtonIsPressed) - return true; - - QWindow *targetWindow = findQWindowWithXWindowID(windowId); - - QPoint windowPos(x / targetWindow->devicePixelRatio(), y / targetWindow->devicePixelRatio()); - - QTouchEventSequence touchEvent = QTest::touchEvent(targetWindow, m_touchDevice, false /* autoCommit */); - touchEvent.move(0 /* touchId */, windowPos); - touchEvent.commit(false /* processEvents */); - - return true; -} - -QWindow *MouseTouchAdaptor::findQWindowWithXWindowID(WId windowId) -{ - QWindowList windowList = QGuiApplication::topLevelWindows(); - QWindow *foundWindow = nullptr; - - int i = 0; - while (!foundWindow && i < windowList.count()) { - QWindow *window = windowList[i]; - if (window->winId() == windowId) - foundWindow = window; - else - ++i; - } - - Q_ASSERT(foundWindow); - return foundWindow; -} - -bool MouseTouchAdaptor::handleXI2Event(xcb_ge_event_t *event) -{ - xi2PrepareXIGenericDeviceEvent(event); - xXIGenericDeviceEvent *xiEvent = reinterpret_cast<xXIGenericDeviceEvent *>(event); - xXIDeviceEvent *xiDeviceEvent = 0; - - switch (xiEvent->evtype) { - case XI_ButtonPress: - case XI_ButtonRelease: - case XI_Motion: - xiDeviceEvent = reinterpret_cast<xXIDeviceEvent *>(event); - break; - default: - break; - } - - if (!xiDeviceEvent) - return false; - - switch (xiDeviceEvent->evtype) { - case XI_ButtonPress: - return handleButtonPress( - static_cast<WId>(xiDeviceEvent->event), - xiDeviceEvent->detail, - xiDeviceEvent->mods.base_mods, - fixed1616ToReal(xiDeviceEvent->event_x), - fixed1616ToReal(xiDeviceEvent->event_y)); - case XI_ButtonRelease: - return handleButtonRelease( - static_cast<WId>(xiDeviceEvent->event), - xiDeviceEvent->detail, - xiDeviceEvent->mods.base_mods, - fixed1616ToReal(xiDeviceEvent->event_x), - fixed1616ToReal(xiDeviceEvent->event_y)); - case XI_Motion: - return handleMotionNotify( - static_cast<WId>(xiDeviceEvent->event), - xiDeviceEvent->mods.base_mods, - fixed1616ToReal(xiDeviceEvent->event_x), - fixed1616ToReal(xiDeviceEvent->event_y)); - return true; - default: - return false; - } -} diff --git a/src/MouseTouchAdaptor.h b/src/MouseTouchAdaptor.h deleted file mode 100644 index f16097b9..00000000 --- a/src/MouseTouchAdaptor.h +++ /dev/null @@ -1,73 +0,0 @@ -/**************************************************************************** -** -** Copyright (C) 2017 Pelagicore AG -** Contact: https://www.qt.io/licensing/ -** -** This file is part of the Triton IVI UI. -** -** $QT_BEGIN_LICENSE:GPL-QTAS$ -** Commercial License Usage -** Licensees holding valid commercial Qt Automotive Suite licenses may use -** this file in accordance with the commercial license agreement provided -** with the Software or, alternatively, in accordance with the terms -** contained in a written agreement between you and The Qt Company. For -** licensing terms and conditions see https://www.qt.io/terms-conditions. -** For further information use the contact form at https://www.qt.io/contact-us. -** -** GNU General Public License Usage -** Alternatively, this file may be used under the terms of the GNU -** General Public License version 3 or (at your option) any later version -** approved by the KDE Free Qt Foundation. The licenses are as published by -** the Free Software Foundation and appearing in the file LICENSE.GPL3 -** included in the packaging of this file. Please review the following -** information to ensure the GNU General Public License requirements will -** be met: https://www.gnu.org/licenses/gpl-3.0.html. -** -** $QT_END_LICENSE$ -** -** SPDX-License-Identifier: GPL-3.0 -** -****************************************************************************/ - -#ifndef MOUSETOUCHADAPTOR_H -#define MOUSETOUCHADAPTOR_H - -#include <QAbstractNativeEventFilter> -#include <QLoggingCategory> -#include <QObject> -#include <QTouchDevice> -#include <QWindow> - -#include <xcb/xcb.h> - -Q_DECLARE_LOGGING_CATEGORY(mouseTouchAdaptor) - -/* - Converts native mouse events into touch events - - Useful for emulating touch interaction using a mouse device since touch input - follows a completely different code path from mouse events in Qt. - */ -class MouseTouchAdaptor : public QObject, public QAbstractNativeEventFilter { -public: - static MouseTouchAdaptor *instance(); - virtual ~MouseTouchAdaptor(); - - bool nativeEventFilter(const QByteArray &eventType, void *message, long *result) override; -private: - MouseTouchAdaptor(); - void queryForXInput2(); - bool handleButtonPress(WId windowId, uint32_t detail, uint32_t modifiers, int x, int y); - bool handleButtonRelease(WId windowId, uint32_t detail, uint32_t, int x, int y); - bool handleMotionNotify(WId windowId, uint32_t modifiers, int x, int y); - QWindow *findQWindowWithXWindowID(WId windowId); - bool handleXI2Event(xcb_ge_event_t *event); - - static MouseTouchAdaptor *m_instance; - - QTouchDevice *m_touchDevice; - bool m_haveXInput2{false}; - bool m_leftButtonIsPressed{false}; -}; - -#endif // MOUSETOUCHADAPTOR_H diff --git a/src/main.cpp b/src/main.cpp index f0c7829f..fcd22c70 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -40,10 +40,6 @@ #include <QDebug> -#ifdef TRITON_ENABLE_TOUCH_EMULATION -# include "MouseTouchAdaptor.h" -#endif - #include "ApplicationInfo.h" #include "ApplicationModel.h" @@ -85,12 +81,6 @@ Q_DECL_EXPORT int main(int argc, char *argv[]) Main a(argc, argv); -#ifdef TRITON_ENABLE_TOUCH_EMULATION - QScopedPointer<MouseTouchAdaptor> mouseTouchAdaptor; - if (QTouchDevice::devices().isEmpty()) - mouseTouchAdaptor.reset(MouseTouchAdaptor::instance()); -#endif - QIcon::setThemeName("triton"); { QStringList searchPaths = QIcon::themeSearchPaths(); diff --git a/src/src.pro b/src/src.pro index 5553065d..1274f263 100644 --- a/src/src.pro +++ b/src/src.pro @@ -13,13 +13,6 @@ DEFINES *= TRITON_VERSION=\\\"$$VERSION\\\" SOURCES = main.cpp ApplicationInfo.cpp ApplicationModel.cpp HEADERS = ApplicationInfo.h ApplicationModel.h -unix:!macos:system($$pkgConfigExecutable() --libs x11 xi xcb) { - PKGCONFIG *= xcb x11 xi - SOURCES += MouseTouchAdaptor.cpp - HEADERS += MouseTouchAdaptor.h - DEFINES += TRITON_ENABLE_TOUCH_EMULATION -} - DESTDIR = $$OUT_PWD/../ DEFINES += "TRITON_ICONS_PATH=$$INSTALL_PREFIX/triton/imports/assets/icons" diff --git a/tests/triton-qmlscene/triton-qmlscene.cpp b/tests/triton-qmlscene/triton-qmlscene.cpp index 3ff74d3a..2b1a49e4 100644 --- a/tests/triton-qmlscene/triton-qmlscene.cpp +++ b/tests/triton-qmlscene/triton-qmlscene.cpp @@ -57,9 +57,6 @@ #include <QtCore/QTranslator> #include <QtCore/QLibraryInfo> -#ifdef TRITON_ENABLE_TOUCH_EMULATION -# include <MouseTouchAdaptor.h> -#endif #ifdef QML_RUNTIME_TESTING class RenderStatistics @@ -628,12 +625,6 @@ int main(int argc, char ** argv) } } -#ifdef TRITON_ENABLE_TOUCH_EMULATION - QScopedPointer<MouseTouchAdaptor> mouseTouchAdaptor; - if (QTouchDevice::devices().isEmpty()) - mouseTouchAdaptor.reset(MouseTouchAdaptor::instance()); -#endif - if (window) { setWindowTitle(options.verbose, topLevel, window.data()); #if QT_CONFIG(opengl) diff --git a/tests/triton-qmlscene/triton-qmlscene.pro b/tests/triton-qmlscene/triton-qmlscene.pro index f2fe3308..91cf2f5d 100644 --- a/tests/triton-qmlscene/triton-qmlscene.pro +++ b/tests/triton-qmlscene/triton-qmlscene.pro @@ -4,13 +4,3 @@ TARGET = triton-qmlscene QT += qml quick quick-private gui-private core-private SOURCES = triton-qmlscene.cpp - -unix:!macos:system($$pkgConfigExecutable() --libs x11 xi xcb) { - CONFIG += link_pkgconfig - PKGCONFIG += xcb x11 xi - SOURCES += ../../src/MouseTouchAdaptor.cpp - HEADERS += ../../src/MouseTouchAdaptor.h - DEFINES += TRITON_ENABLE_TOUCH_EMULATION - INCLUDEPATH += $$SOURCE_DIR/src - QT += testlib -} |