Members of the KDE Community are recommended to subscribe to the kde-community mailing list at https://mail.kde.org/mailman/listinfo/kde-community to allow them to participate in important discussions and receive other important announcements

0051-Add-workaround-for-handling-table-press-correctly-in.patch 12.1 KB
Newer Older
1 2 3 4 5
diff --git a/qtbase/src/gui/kernel/qguiapplication.cpp b/qtbase/src/gui/kernel/qguiapplication.cpp
index fd01f8bb7..4d61d9fd8 100644
--- a/qtbase/src/gui/kernel/qguiapplication.cpp
+++ b/qtbase/src/gui/kernel/qguiapplication.cpp
@@ -2532,6 +2532,7 @@ void QGuiApplicationPrivate::processTabletEvent(QWindowSystemInterfacePrivate::T
6 7 8 9 10 11 12
     tabletEvent.setTimestamp(e->timestamp);
     QGuiApplication::sendSpontaneousEvent(window, &tabletEvent);
     pointData.state = e->buttons;
+    e->eventAccepted = tabletEvent.isAccepted();
     if (!tabletEvent.isAccepted()
         && !QWindowSystemInterfacePrivate::TabletEvent::platformSynthesizesMouse
         && qApp->testAttribute(Qt::AA_SynthesizeMouseForUnhandledTabletEvents)) {
13 14 15 16 17
diff --git a/qtbase/src/gui/kernel/qwindowsysteminterface.cpp b/qtbase/src/gui/kernel/qwindowsysteminterface.cpp
index b0f286912..b3b6167c9 100644
--- a/qtbase/src/gui/kernel/qwindowsysteminterface.cpp
+++ b/qtbase/src/gui/kernel/qwindowsysteminterface.cpp
@@ -949,7 +949,7 @@ void QWindowSystemInterfacePrivate::TabletEvent::setPlatformSynthesizesMouse(boo
18 19 20 21 22 23 24 25
     platformSynthesizesMouse = v;
 }
 
-void QWindowSystemInterface::handleTabletEvent(QWindow *window, ulong timestamp, const QPointF &local, const QPointF &global,
+bool QWindowSystemInterface::handleTabletEvent(QWindow *window, ulong timestamp, const QPointF &local, const QPointF &global,
                                                int device, int pointerType, Qt::MouseButtons buttons, qreal pressure, int xTilt, int yTilt,
                                                qreal tangentialPressure, qreal rotation, int z, qint64 uid,
                                                Qt::KeyboardModifiers modifiers)
26
@@ -960,36 +960,36 @@ void QWindowSystemInterface::handleTabletEvent(QWindow *window, ulong timestamp,
27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71
                                                        QHighDpi::fromNativePixels(global, window),
                                                        device, pointerType, buttons, pressure,
                                                        xTilt, yTilt, tangentialPressure, rotation, z, uid, modifiers);
-    QWindowSystemInterfacePrivate::handleWindowSystemEvent(e);
+    return QWindowSystemInterfacePrivate::handleWindowSystemEvent<QWindowSystemInterface::SynchronousDelivery>(e);
 }
 
-void QWindowSystemInterface::handleTabletEvent(QWindow *window, const QPointF &local, const QPointF &global,
+bool QWindowSystemInterface::handleTabletEvent(QWindow *window, const QPointF &local, const QPointF &global,
                                                int device, int pointerType, Qt::MouseButtons buttons, qreal pressure, int xTilt, int yTilt,
                                                qreal tangentialPressure, qreal rotation, int z, qint64 uid,
                                                Qt::KeyboardModifiers modifiers)
 {
     ulong time = QWindowSystemInterfacePrivate::eventTime.elapsed();
-    handleTabletEvent(window, time, local, global, device, pointerType, buttons, pressure,
+    return handleTabletEvent(window, time, local, global, device, pointerType, buttons, pressure,
                       xTilt, yTilt, tangentialPressure, rotation, z, uid, modifiers);
 }
 
 #if QT_DEPRECATED_SINCE(5, 10)
-void QWindowSystemInterface::handleTabletEvent(QWindow *window, ulong timestamp, bool down, const QPointF &local, const QPointF &global,
+bool QWindowSystemInterface::handleTabletEvent(QWindow *window, ulong timestamp, bool down, const QPointF &local, const QPointF &global,
                                                int device, int pointerType, qreal pressure, int xTilt, int yTilt,
                                                qreal tangentialPressure, qreal rotation, int z, qint64 uid,
                                                Qt::KeyboardModifiers modifiers)
 {
-    handleTabletEvent(window, timestamp, local, global, device, pointerType, (down ? Qt::LeftButton : Qt::NoButton), pressure,
-                      xTilt, yTilt, tangentialPressure, rotation, z, uid, modifiers);
+    return handleTabletEvent(window, timestamp, local, global, device, pointerType, (down ? Qt::LeftButton : Qt::NoButton), pressure,
+                             xTilt, yTilt, tangentialPressure, rotation, z, uid, modifiers);
 }
 
-void QWindowSystemInterface::handleTabletEvent(QWindow *window, bool down, const QPointF &local, const QPointF &global,
+bool QWindowSystemInterface::handleTabletEvent(QWindow *window, bool down, const QPointF &local, const QPointF &global,
                                                int device, int pointerType, qreal pressure, int xTilt, int yTilt,
                                                qreal tangentialPressure, qreal rotation, int z, qint64 uid,
                                                Qt::KeyboardModifiers modifiers)
 {
-    handleTabletEvent(window, local, global, device, pointerType, (down ? Qt::LeftButton : Qt::NoButton), pressure,
-                      xTilt, yTilt, tangentialPressure, rotation, z, uid, modifiers);
+    return handleTabletEvent(window, local, global, device, pointerType, (down ? Qt::LeftButton : Qt::NoButton), pressure,
+                             xTilt, yTilt, tangentialPressure, rotation, z, uid, modifiers);
 }
 #endif // QT_DEPRECATED_SINCE(5, 10)
 
72 73 74 75 76
diff --git a/qtbase/src/gui/kernel/qwindowsysteminterface.h b/qtbase/src/gui/kernel/qwindowsysteminterface.h
index bf98c33a1..fdc5a2fb5 100644
--- a/qtbase/src/gui/kernel/qwindowsysteminterface.h
+++ b/qtbase/src/gui/kernel/qwindowsysteminterface.h
@@ -247,20 +247,20 @@ public:
77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100
     static void handleFileOpenEvent(const QString& fileName);
     static void handleFileOpenEvent(const QUrl &url);
 
-    static void handleTabletEvent(QWindow *window, ulong timestamp, const QPointF &local, const QPointF &global,
+    static bool handleTabletEvent(QWindow *window, ulong timestamp, const QPointF &local, const QPointF &global,
                                   int device, int pointerType, Qt::MouseButtons buttons, qreal pressure, int xTilt, int yTilt,
                                   qreal tangentialPressure, qreal rotation, int z, qint64 uid,
                                   Qt::KeyboardModifiers modifiers = Qt::NoModifier);
-    static void handleTabletEvent(QWindow *window, const QPointF &local, const QPointF &global,
+    static bool handleTabletEvent(QWindow *window, const QPointF &local, const QPointF &global,
                                   int device, int pointerType, Qt::MouseButtons buttons, qreal pressure, int xTilt, int yTilt,
                                   qreal tangentialPressure, qreal rotation, int z, qint64 uid,
                                   Qt::KeyboardModifiers modifiers = Qt::NoModifier);
 #if QT_DEPRECATED_SINCE(5, 10)
-    QT_DEPRECATED static void handleTabletEvent(QWindow *window, ulong timestamp, bool down, const QPointF &local, const QPointF &global,
+    QT_DEPRECATED static bool handleTabletEvent(QWindow *window, ulong timestamp, bool down, const QPointF &local, const QPointF &global,
                                                 int device, int pointerType, qreal pressure, int xTilt, int yTilt,
                                                 qreal tangentialPressure, qreal rotation, int z, qint64 uid,
                                                 Qt::KeyboardModifiers modifiers = Qt::NoModifier);
-    QT_DEPRECATED static void handleTabletEvent(QWindow *window, bool down, const QPointF &local, const QPointF &global,
+    QT_DEPRECATED static bool handleTabletEvent(QWindow *window, bool down, const QPointF &local, const QPointF &global,
                                                 int device, int pointerType, qreal pressure, int xTilt, int yTilt,
                                                 qreal tangentialPressure, qreal rotation, int z, qint64 uid,
                                                 Qt::KeyboardModifiers modifiers = Qt::NoModifier);
101 102 103 104 105
diff --git a/qtbase/src/plugins/platforms/windows/qwindowspointerhandler.cpp b/qtbase/src/plugins/platforms/windows/qwindowspointerhandler.cpp
index 9a8b5d512..93498d58b 100644
--- a/qtbase/src/plugins/platforms/windows/qwindowspointerhandler.cpp
+++ b/qtbase/src/plugins/platforms/windows/qwindowspointerhandler.cpp
@@ -535,6 +535,58 @@ bool QWindowsPointerHandler::translateTouchEvent(QWindow *window, HWND hwnd,
106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163
     return false; // Allow mouse messages to be generated.
 }
 
+void synthesizeMouseEvent(QEvent::Type type, Qt::MouseButton button, const POINTER_PEN_INFO &penInfo)
+{
+    // Update the cursor position
+    BOOL result = SetCursorPos(penInfo.pointerInfo.ptPixelLocationRaw.x, penInfo.pointerInfo.ptPixelLocationRaw.y);
+    if (!result) {
+        qCDebug(lcQpaEvents).noquote().nospace() << showbase
+            << __FUNCTION__ << "SetCursorPos failed, err" << GetLastError();
+        return;
+    }
+    // Send mousebutton down/up events. Windows stores the button state.
+    DWORD inputDataFlags = 0;
+    switch (type) {
+    case QEvent::TabletPress:
+        switch (button) {
+        case Qt::LeftButton:
+            inputDataFlags = MOUSEEVENTF_LEFTDOWN;
+            break;
+        case Qt::RightButton:
+            inputDataFlags = MOUSEEVENTF_RIGHTDOWN;
+            break;
+        default:
+            return;
+        }
+        break;
+    case QEvent::TabletRelease:
+        switch (button) {
+        case Qt::LeftButton:
+            inputDataFlags = MOUSEEVENTF_LEFTUP;
+            break;
+        case Qt::RightButton:
+            inputDataFlags = MOUSEEVENTF_RIGHTUP;
+            break;
+        default:
+            return;
+        }
+        break;
+    case QEvent::TabletMove:
+    default:
+        return;
+    }
+    INPUT inputData = {};
+    inputData.type = INPUT_MOUSE;
+    inputData.mi.dwFlags = inputDataFlags;
+    inputData.mi.dwExtraInfo = 0xFF515700 | 0x01; // https://msdn.microsoft.com/en-us/library/windows/desktop/ms703320%28v=vs.85%29.aspx
+    UINT result2 = SendInput(1, &inputData, sizeof(inputData));
+    if (result2 != 1) {
+        qCDebug(lcQpaEvents).noquote().nospace() << showbase
+            << __FUNCTION__ << "SendInput failed, err" << GetLastError();
+        return;
+    }
+}
+
 bool QWindowsPointerHandler::translatePenEvent(QWindow *window, HWND hwnd, QtWindows::WindowsEventType et,
                                                MSG msg, PVOID vPenInfo)
 {
164
@@ -622,10 +674,38 @@ bool QWindowsPointerHandler::translatePenEvent(QWindow *window, HWND hwnd, QtWin
165 166 167 168 169 170 171
         }
         const Qt::KeyboardModifiers keyModifiers = QWindowsKeyMapper::queryKeyboardModifiers();
 
-        QWindowSystemInterface::handleTabletEvent(target, localPos, hiResGlobalPos, device, type, mouseButtons,
-                                                  pressure, xTilt, yTilt, tangentialPressure, rotation, z,
-                                                  sourceDevice, keyModifiers);
-        return false;  // Allow mouse messages to be generated.
172 173
+        const Qt::MouseButtons oldButtons = QGuiApplicationPrivate::tabletDevicePoint(sourceDevice).state;
+
174 175 176 177 178
+        const bool accepted =
+            QWindowSystemInterface::handleTabletEvent(target, localPos, hiResGlobalPos, device, type, mouseButtons,
+                                                      pressure, xTilt, yTilt, tangentialPressure, rotation, z,
+                                                      sourceDevice, keyModifiers);
+
179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196
+        const Qt::MouseButtons changedButtons =
+            oldButtons ^ QGuiApplicationPrivate::tabletDevicePoint(sourceDevice).state;
+
+        Qt::MouseButton pressedButton = Qt::NoButton;
+
+        const QVector<Qt::MouseButton> supportedButtons =
+            {Qt::LeftButton, Qt::RightButton, Qt::MiddleButton};
+
+        for (Qt::MouseButton button : supportedButtons) {
+            if (changedButtons & button) {
+                pressedButton = button;
+                break;
+            }
+        }
+
+        if (accepted && pressedButton != Qt::NoButton &&
+            (msg.message == WM_POINTERDOWN || msg.message == WM_POINTERUP)) {
+
197 198
+            QEvent::Type type = (msg.message == WM_POINTERDOWN) ? QEvent::TabletPress : QEvent::TabletRelease;
+
199
+            synthesizeMouseEvent(type, pressedButton, *penInfo);
200 201 202 203 204 205 206
+            return true;
+        } else {
+            return false; // Allow mouse messages to be generated by OS
+        }
     }
     }
     return true;