[calligra/calligra/2.9] krita/ui: This patch should probably fix Wacom Airbrush devices

Dmitry Kazakov dimula73 at gmail.com
Tue Feb 3 10:20:08 UTC 2015


Git commit 142b953c4d0f6b197435cfdcf424f88796e57c4c by Dmitry Kazakov.
Committed on 03/02/2015 at 10:18.
Pushed by dkazakov into branch 'calligra/2.9'.

This patch should probably fix Wacom Airbrush devices

This patch adds recognition of the device type on Linux, and tries to
fix the tangential pressure parameter.

If you happen to have an Airbrush device, please do test whether
tangential pressure starts working correctly.

Most probable bug: the range of the tangential pressure might be
wrong, since I don't know in which limits it is linked in the driver.
If you see any problems with it, please generate an event log file
for moving the button in all directions slowly. Here is a manual how
to do that:

https://answers.launchpad.net/krita-ru/+faq/2495

Thanks arturg for providing initial patches!

CCBUG:343545
CCMAIL:kimageshop at kde.org

M  +61   -9    krita/ui/input/wintab/kis_tablet_support_x11.cpp
M  +1    -1    krita/ui/tool/kis_painting_information_builder.cpp

http://commits.kde.org/calligra/142b953c4d0f6b197435cfdcf424f88796e57c4c

diff --git a/krita/ui/input/wintab/kis_tablet_support_x11.cpp b/krita/ui/input/wintab/kis_tablet_support_x11.cpp
index c8ab7df..cb7fa59 100644
--- a/krita/ui/input/wintab/kis_tablet_support_x11.cpp
+++ b/krita/ui/input/wintab/kis_tablet_support_x11.cpp
@@ -459,7 +459,7 @@ void kis_x11_init_tablet()
     }
 }
 
-void fetchWacomToolId(qint64 &serialId, QTabletDeviceData *tablet)
+void fetchWacomToolId(qint64 &serialId, qint64 &deviceId, QTabletDeviceData *tablet)
 {
     XDevice *dev = static_cast<XDevice*>(tablet->device);
     Atom prop = None, type;
@@ -483,7 +483,8 @@ void fetchWacomToolId(qint64 &serialId, QTabletDeviceData *tablet)
     }
 
     long *l = (long*)data;
-    serialId = l[3];
+    serialId = l[3]; // serial id of the stylus in proximity
+    deviceId = l[4]; // device if of the stylus in proximity
 }
 
 static Qt::MouseButtons translateMouseButtons(int s)
@@ -506,6 +507,48 @@ static Qt::MouseButton translateMouseButton(int b)
         Qt::LeftButton /* fallback */;
 }
 
+QTabletEvent::TabletDevice parseWacomDeviceId(quint32 deviceId)
+{
+    enum {
+        CSR_TYPE_SPECIFIC_MASK = 0x0F06,
+        CSR_TYPE_SPECIFIC_STYLUS_BITS = 0x0802,
+        CSR_TYPE_SPECIFIC_AIRBRUSH_BITS = 0x0902,
+        CSR_TYPE_SPECIFIC_4DMOUSE_BITS = 0x0004,
+        CSR_TYPE_SPECIFIC_LENSCURSOR_BITS = 0x0006,
+        CSR_TYPE_SPECIFIC_ROTATIONSTYLUS_BITS = 0x0804
+    };
+
+    QTabletEvent::TabletDevice device;
+
+    switch (deviceId & CSR_TYPE_SPECIFIC_MASK) {
+    case CSR_TYPE_SPECIFIC_STYLUS_BITS:
+        device = QTabletEvent::Stylus;
+        break;
+    case CSR_TYPE_SPECIFIC_AIRBRUSH_BITS:
+        device = QTabletEvent::Airbrush;
+        break;
+    case CSR_TYPE_SPECIFIC_4DMOUSE_BITS:
+        device = QTabletEvent::FourDMouse;
+        break;
+    case CSR_TYPE_SPECIFIC_LENSCURSOR_BITS:
+        device = QTabletEvent::Puck;
+        break;
+    case CSR_TYPE_SPECIFIC_ROTATIONSTYLUS_BITS:
+        device = QTabletEvent::RotationStylus;
+        break;
+    default:
+        if (deviceId != 0) {
+            qWarning() << "Unrecognized stylus device found! Falling back to usual \'Stylus\' definition";
+            qWarning() << ppVar(deviceId);
+            qWarning() << ppVar((deviceId & CSR_TYPE_SPECIFIC_MASK));
+        }
+
+        device = QTabletEvent::Stylus;
+    }
+
+    return device;
+}
+
 bool translateXinputEvent(const XEvent *ev, QTabletDeviceData *tablet, QWidget *defaultWidget)
 {
     Q_ASSERT(defaultWidget);
@@ -567,7 +610,8 @@ bool translateXinputEvent(const XEvent *ev, QTabletDeviceData *tablet, QWidget *
                "but we don't handle it here, so this is a bug");
     }
 
-    qint64 uid = 0;
+    qint64 wacomSerialId = 0;
+    qint64 wacomDeviceId = 0;
 #if defined (Q_OS_IRIX)
 #else
     // We've been passed in data for a tablet device that handles this type
@@ -597,7 +641,11 @@ bool translateXinputEvent(const XEvent *ev, QTabletDeviceData *tablet, QWidget *
      */
     if (tablet->isTouchWacomTablet) return false;
 
-    fetchWacomToolId(uid, tablet);
+    fetchWacomToolId(wacomSerialId, wacomDeviceId, tablet);
+
+    if (wacomDeviceId && deviceType == QTabletEvent::Stylus) {
+        deviceType = parseWacomDeviceId(wacomDeviceId);
+    }
 
     QRect screenArea = qApp->desktop()->rect();
 
@@ -627,13 +675,17 @@ bool translateXinputEvent(const XEvent *ev, QTabletDeviceData *tablet, QWidget *
     xTilt = tablet->savedAxesData.xTilt();
     yTilt = tablet->savedAxesData.yTilt();
 
-    rotation = std::fmod(qreal(tablet->savedAxesData.rotation() - tablet->minRotation) /
-                         (tablet->maxRotation - tablet->minRotation) + 0.5, 1.0) * 360.0;
+
+    qreal normalizedRotation =
+        std::fmod(qreal(tablet->savedAxesData.rotation() - tablet->minRotation) /
+                  (tablet->maxRotation - tablet->minRotation) + 0.5, 1.0);
 
     if (deviceType == QTabletEvent::Airbrush) {
-        tangentialPressure = rotation;
-        rotation = 0.;
+        tangentialPressure = normalizedRotation;
+    } else {
+        rotation = normalizedRotation * 360;
     }
+
 #endif
 
     if (tablet->widgetToGetPress) {
@@ -666,7 +718,7 @@ bool translateXinputEvent(const XEvent *ev, QTabletDeviceData *tablet, QWidget *
     KisTabletEvent e(t, curr, global, hiRes,
                      deviceType, pointerType,
                      qreal(pressure / qreal(tablet->maxPressure - tablet->minPressure)),
-                     xTilt, yTilt, tangentialPressure, rotation, z, modifiers, uid,
+                     xTilt, yTilt, tangentialPressure, rotation, z, modifiers, wacomSerialId,
                      qtbutton, qtbuttons);
 
     e.ignore();
diff --git a/krita/ui/tool/kis_painting_information_builder.cpp b/krita/ui/tool/kis_painting_information_builder.cpp
index afcd21b..d9fe055 100644
--- a/krita/ui/tool/kis_painting_information_builder.cpp
+++ b/krita/ui/tool/kis_painting_information_builder.cpp
@@ -108,7 +108,7 @@ KisPaintInformation KisPaintingInformationBuilder::hover(const QPointF &imagePoi
                                                            PRESSURE_DEFAULT,
                                                            event->xTilt(), event->yTilt(),
                                                            event->rotation(),
-                                                           0.0,
+                                                           event->tangentialPressure(),
                                                            perspective);
     } else {
         return KisPaintInformation::createHoveringModeInfo(imagePoint);


More information about the kimageshop mailing list