Commit f0d23431 authored by Dmitry Kazakov's avatar Dmitry Kazakov

Fix switching of pointer type by the stylus tip

We should check if any button is pressed by the already mapped value,
but not raw value of the buttons. Wintab will always report the button
to be pressed, although it is unmapped by CSR_SYSBTNMAP

BUG:408454
BUG:405747
parent 73ab3005
From 7d4d465771854cfa860b7cd2eb09f91cfdb8b5cd Mon Sep 17 00:00:00 2001
From e14383479e200b0a4871bead44d1a16cd0a2623d Mon Sep 17 00:00:00 2001
From: Dmitry Kazakov <dimula73@gmail.com>
Date: Sat, 13 Apr 2019 18:08:33 +0300
Subject: [PATCH 13/27] Fetch stylus button remapping from WinTab driver
Subject: [PATCH 1/4] Fetch stylus button remapping from WinTab driver
The user can remap the stylus buttons using tablet driver settings.
This information is available to the application via CSR_SYSBTNMAP
WinTab feature. We should fetch this information every time the
stylus gets into proximity, because the user can change these settings
on the fly.
Change-Id: Idc839905c3485179d782814f78fa862fd4a99127
---
.../windows/qwindowstabletsupport.cpp | 72 ++++++++++++++++++-
.../platforms/windows/qwindowstabletsupport.h | 2 +
2 files changed, 73 insertions(+), 1 deletion(-)
diff --git a/src/plugins/platforms/windows/qwindowstabletsupport.cpp b/src/plugins/platforms/windows/qwindowstabletsupport.cpp
index fa209f09..31655101 100644
index fa209f09c4..44b94d044d 100644
--- a/src/plugins/platforms/windows/qwindowstabletsupport.cpp
+++ b/src/plugins/platforms/windows/qwindowstabletsupport.cpp
@@ -435,6 +435,27 @@ bool QWindowsTabletSupport::translateTabletProximityEvent(WPARAM /* wParam */, L
......@@ -45,16 +47,19 @@ index fa209f09..31655101 100644
m_devices[m_currentDevice].currentPointerType = pointerType(currentCursor);
m_state = PenProximity;
qCDebug(lcQpaTablet) << "enter proximity for device #"
@@ -446,6 +467,50 @@ bool QWindowsTabletSupport::translateTabletProximityEvent(WPARAM /* wParam */, L
@@ -446,6 +467,52 @@ bool QWindowsTabletSupport::translateTabletProximityEvent(WPARAM /* wParam */, L
return true;
}
+Qt::MouseButton buttonValueToEnum(DWORD button,
+ const QWindowsTabletDeviceData &tdd) {
+ const int leftButtonValue = 0x1;
+ const int middleButtonValue = 0x2;
+ const int rightButtonValue = 0x4;
+ const int doubleClickButtonValue = 0x7;
+
+ enum : unsigned {
+ leftButtonValue = 0x1,
+ middleButtonValue = 0x2,
+ rightButtonValue = 0x4,
+ doubleClickButtonValue = 0x7
+ };
+
+ button = tdd.buttonsMap.value(button);
+
......@@ -66,20 +71,18 @@ index fa209f09..31655101 100644
+ Qt::NoButton;
+}
+
+void convertTabletButtons(DWORD btnNew,
+ Qt::MouseButtons *buttons,
+ const QWindowsTabletDeviceData &tdd,
+ const Qt::KeyboardModifiers keyboardModifiers) {
+Qt::MouseButtons convertTabletButtons(DWORD btnNew,
+ const QWindowsTabletDeviceData &tdd) {
+
+ *buttons = Qt::NoButton;
+ for (int i = 0; i < 3; i++) {
+ int btn = 0x1 << i;
+ Qt::MouseButtons buttons = Qt::NoButton;
+ for (unsigned int i = 0; i < 3; i++) {
+ unsigned int btn = 0x1 << i;
+
+ if (btn & btnNew) {
+ Qt::MouseButton convertedButton =
+ buttonValueToEnum(btn, tdd);
+
+ *buttons |= convertedButton;
+ buttons |= convertedButton;
+
+ /**
+ * If a button that is present in hardware input is
......@@ -91,19 +94,18 @@ index fa209f09..31655101 100644
+ */
+ }
+ }
+ return buttons;
+}
+
bool QWindowsTabletSupport::translateTabletPacketEvent()
{
static PACKET localPacketBuf[TabletPacketQSize]; // our own tablet packet queue.
@@ -552,9 +617,14 @@ bool QWindowsTabletSupport::translateTabletPacketEvent()
@@ -552,9 +619,12 @@ bool QWindowsTabletSupport::translateTabletPacketEvent()
<< tiltY << "tanP:" << tangentialPressure << "rotation:" << rotation;
}
+ Qt::MouseButtons buttons;
+ convertTabletButtons(packet.pkButtons, &buttons,
+ m_devices.at(m_currentDevice),
+ keyboardModifiers);
+ Qt::MouseButtons buttons =
+ convertTabletButtons(packet.pkButtons, m_devices.at(m_currentDevice));
+
QWindowSystemInterface::handleTabletEvent(target, packet.pkTime, QPointF(localPos), globalPosF,
currentDevice, currentPointer,
......@@ -113,14 +115,14 @@ index fa209f09..31655101 100644
tangentialPressure, rotation, z,
uniqueId,
diff --git a/src/plugins/platforms/windows/qwindowstabletsupport.h b/src/plugins/platforms/windows/qwindowstabletsupport.h
index d91701d6..5b1ddb52 100644
index d91701d6a5..8f97982308 100644
--- a/src/plugins/platforms/windows/qwindowstabletsupport.h
+++ b/src/plugins/platforms/windows/qwindowstabletsupport.h
@@ -45,6 +45,7 @@
#include <QtCore/qvector.h>
#include <QtCore/qpoint.h>
+#include <QtCore/qmap.h>
+#include <QtCore/qhash.h>
#include <wintab.h>
......@@ -128,10 +130,10 @@ index d91701d6..5b1ddb52 100644
qint64 uniqueId = 0;
int currentDevice = 0;
int currentPointerType = 0;
+ QMap<quint8, quint8> buttonsMap;
+ QHash<quint8, quint8> buttonsMap;
};
#ifndef QT_NO_DEBUG_STREAM
--
2.22.0.windows.1
2.20.1.windows.1
From b33666c064dc255e3d39a0646684445ab907d299 Mon Sep 17 00:00:00 2001
From 47be745d599f6cd11f3fe280b51c490682f7b2da Mon Sep 17 00:00:00 2001
From: Dmitry Kazakov <dimula73@gmail.com>
Date: Sat, 13 Apr 2019 23:24:01 +0300
Subject: [PATCH 15/27] Fetch mapped screen size from the Wintab driver
Subject: [PATCH 2/4] Fetch mapped screen size from the Wintab driver
Some devices, like Microsoft Surface Pro 5, don't map tablet's
input range to the entire virtual screen area, but map it to
......@@ -23,13 +23,15 @@ display is set to an external monitor) the user might want to override
mapping completely. Then the following variable can be used:
QT_WINTAB_DESKTOP_RECT=x;y;width;height
Change-Id: Idd8bcf0323ce0811d2ad8976eaed48ad13ac3af8
---
.../windows/qwindowstabletsupport.cpp | 89 ++++++++++++++++++-
.../platforms/windows/qwindowstabletsupport.h | 13 ++-
2 files changed, 99 insertions(+), 3 deletions(-)
diff --git a/src/plugins/platforms/windows/qwindowstabletsupport.cpp b/src/plugins/platforms/windows/qwindowstabletsupport.cpp
index 3e35b146..11e6769c 100644
index 44b94d044d..c39242917f 100644
--- a/src/plugins/platforms/windows/qwindowstabletsupport.cpp
+++ b/src/plugins/platforms/windows/qwindowstabletsupport.cpp
@@ -53,6 +53,7 @@
......@@ -145,7 +147,7 @@ index 3e35b146..11e6769c 100644
const UINT currentCursor = proximityBuffer[0].pkCursor;
UINT physicalCursorId;
QWindowsTabletSupport::m_winTab32DLL.wTInfo(WTI_CURSORS + currentCursor, CSR_PHYSID, &physicalCursorId);
@@ -535,8 +620,8 @@ bool QWindowsTabletSupport::translateTabletPacketEvent()
@@ -537,8 +622,8 @@ bool QWindowsTabletSupport::translateTabletPacketEvent()
// in which case we snap the position to the mouse position.
// It seems there is no way to find out the mode programmatically, the LOGCONTEXT orgX/Y/Ext
// area is always the virtual desktop.
......@@ -157,7 +159,7 @@ index 3e35b146..11e6769c 100644
if (QWindowsContext::verbose > 1) {
qCDebug(lcQpaTablet) << __FUNCTION__ << "processing" << packetCount
diff --git a/src/plugins/platforms/windows/qwindowstabletsupport.h b/src/plugins/platforms/windows/qwindowstabletsupport.h
index 5b1ddb52..e8b0c01b 100644
index 8f97982308..fe7e7815d6 100644
--- a/src/plugins/platforms/windows/qwindowstabletsupport.h
+++ b/src/plugins/platforms/windows/qwindowstabletsupport.h
@@ -45,7 +45,9 @@
......@@ -165,7 +167,7 @@ index 5b1ddb52..e8b0c01b 100644
#include <QtCore/qvector.h>
#include <QtCore/qpoint.h>
+#include <QtCore/qrect.h>
#include <QtCore/qmap.h>
#include <QtCore/qhash.h>
+#include <QtCore/qobject.h>
#include <wintab.h>
......@@ -213,5 +215,5 @@ index 5b1ddb52..e8b0c01b 100644
QT_END_NAMESPACE
--
2.22.0.windows.1
2.20.1.windows.1
From ebfe32b8fe8ff7ce8b8e4330af1191c16b0a8be0 Mon Sep 17 00:00:00 2001
From 10e1c6c6912ccd43fedd46c3f59a9b61043f4fec Mon Sep 17 00:00:00 2001
From: Dmitry Kazakov <dimula73@gmail.com>
Date: Wed, 17 Apr 2019 17:39:10 +0300
Subject: [PATCH 16/27] Switch stylus pointer type when the tablet is in the
tablet proximity
Subject: [PATCH] Switch stylus pointer type when the tablet is in the tablet
proximity
Some convertible tablet devices have a special stylus button that
converts the stylus into an eraser. Such button can be pressed right
......@@ -10,16 +10,21 @@ when the stylus is in tablet surface proximity, so we should check
that not only during proximity event handling, but also while parsing
normal wintab packets.
Make sure that we don't switch tablet pointer type while any **mapped**
stylus button is pressed. Pressing the "eraser" button is reported
in pkButtons, but it maps to none by CSR_SYSBTNMAP
https://bugs.kde.org/show_bug.cgi?id=405747
https://bugs.kde.org/show_bug.cgi?id=408454
---
.../windows/qwindowstabletsupport.cpp | 23 ++++++++++++++++++-
1 file changed, 22 insertions(+), 1 deletion(-)
.../windows/qwindowstabletsupport.cpp | 29 ++++++++++++++++---
1 file changed, 25 insertions(+), 4 deletions(-)
diff --git a/src/plugins/platforms/windows/qwindowstabletsupport.cpp b/src/plugins/platforms/windows/qwindowstabletsupport.cpp
index 11e6769c..b0431276 100644
index 45dc8a7d1a..4fc8e993d7 100644
--- a/src/plugins/platforms/windows/qwindowstabletsupport.cpp
+++ b/src/plugins/platforms/windows/qwindowstabletsupport.cpp
@@ -604,7 +604,6 @@ bool QWindowsTabletSupport::translateTabletPacketEvent()
@@ -614,7 +614,6 @@ bool QWindowsTabletSupport::translateTabletPacketEvent()
return false;
const int currentDevice = m_devices.at(m_currentDevice).currentDevice;
......@@ -27,14 +32,17 @@ index 11e6769c..b0431276 100644
const qint64 uniqueId = m_devices.at(m_currentDevice).uniqueId;
// The tablet can be used in 2 different modes (reflected in enum Mode),
@@ -634,6 +633,28 @@ bool QWindowsTabletSupport::translateTabletPacketEvent()
@@ -644,6 +643,31 @@ bool QWindowsTabletSupport::translateTabletPacketEvent()
for (int i = 0; i < packetCount ; ++i) {
const PACKET &packet = localPacketBuf[i];
+ int currentPointer = m_devices.at(m_currentDevice).currentPointerType;
+
+ const int packetPointerType = pointerType(packet.pkCursor);
+ if (!packet.pkButtons && packetPointerType != currentPointer) {
+ Qt::MouseButtons buttons =
+ convertTabletButtons(packet.pkButtons, m_devices.at(m_currentDevice));
+
+ if (buttons == Qt::NoButton && packetPointerType != currentPointer) {
+
+ QWindowSystemInterface::handleTabletLeaveProximityEvent(packet.pkTime,
+ m_devices.at(m_currentDevice).currentDevice,
......@@ -56,6 +64,16 @@ index 11e6769c..b0431276 100644
const int z = currentDevice == QTabletEvent::FourDMouse ? int(packet.pkZ) : 0;
QPointF globalPosF =
@@ -712,9 +736,6 @@ bool QWindowsTabletSupport::translateTabletPacketEvent()
<< tiltY << "tanP:" << tangentialPressure << "rotation:" << rotation;
}
- Qt::MouseButtons buttons =
- convertTabletButtons(packet.pkButtons, m_devices.at(m_currentDevice));
-
QWindowSystemInterface::handleTabletEvent(target, packet.pkTime, QPointF(localPos), globalPosF,
currentDevice, currentPointer,
buttons,
--
2.22.0.windows.1
2.20.1.windows.1
From a354a9a7f0cf081aae223dfff3f1734add050b18 Mon Sep 17 00:00:00 2001
From 41549d94ff3ad9a793c0c4c910a1a30976be9723 Mon Sep 17 00:00:00 2001
From: Dmitry Kazakov <dimula73@gmail.com>
Date: Thu, 18 Apr 2019 15:42:17 +0300
Subject: [PATCH 17/27] Fix updating tablet pressure resolution on every
Subject: [PATCH 3/4] Fix updating tablet pressure resolution on every
proximity enter event
The user can switch pressure sensitivity level in the driver,
......@@ -10,12 +10,14 @@ provided by Wacom drivers for compatibility reasons, and
it can be adjusted on the fly)
See the bug: https://bugs.kde.org/show_bug.cgi?id=391054
Change-Id: I6cfdff27eaf5a587bf714871f1495a7ea150c553
---
src/plugins/platforms/windows/qwindowstabletsupport.cpp | 8 ++++++++
1 file changed, 8 insertions(+)
diff --git a/src/plugins/platforms/windows/qwindowstabletsupport.cpp b/src/plugins/platforms/windows/qwindowstabletsupport.cpp
index b0431276..2de87758 100644
index c39242917f..45dc8a7d1a 100644
--- a/src/plugins/platforms/windows/qwindowstabletsupport.cpp
+++ b/src/plugins/platforms/windows/qwindowstabletsupport.cpp
@@ -519,6 +519,14 @@ bool QWindowsTabletSupport::translateTabletProximityEvent(WPARAM /* wParam */, L
......@@ -34,5 +36,5 @@ index b0431276..2de87758 100644
/**
--
2.22.0.windows.1
2.20.1.windows.1
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment