Blame SOURCES/0004-xwayland-Handle-wp_tablet-events.patch

c40fb2
From 591b08b3311c5217969a8ceb3ed58b58fabc4891 Mon Sep 17 00:00:00 2001
c40fb2
From: Jason Gerecke <killertofu@gmail.com>
c40fb2
Date: Fri, 15 Jan 2016 17:01:38 -0800
c40fb2
Subject: [PATCH xserver 04/12] xwayland: Handle wp_tablet events
c40fb2
c40fb2
Creates and maintains the canonical trio of X devices (stylus, eraser,
c40fb2
and cursor) to be shared by all connected tablets. A per-tablet trio
c40fb2
could be created instead, but there are very few benefits to such a
c40fb2
configuration since all tablets still ultimately share control of a
c40fb2
single master pointer.
c40fb2
c40fb2
The three X devices are modeled after those created by xf86-input-wacom
c40fb2
but use a generic maximum X and Y that should be large enough to
c40fb2
accurately represent values from even the largest currently-available
c40fb2
tablets.
c40fb2
c40fb2
Signed-off-by: Jason Gerecke <jason.gerecke@wacom.com>
c40fb2
Signed-off-by: Carlos Garnacho <carlosg@gnome.org>
c40fb2
Reviewed-by: Peter Hutterer <peter.hutterer@who-t.net>
c40fb2
Signed-off-by: Peter Hutterer <peter.hutterer@who-t.net>
c40fb2
Acked-by: Ping Cheng <ping.cheng@wacom.com>
c40fb2
(cherry picked from commit 5812d1c28f4fb7b7de8b96a81415a21425561fd4)
c40fb2
---
c40fb2
 hw/xwayland/xwayland-input.c | 142 +++++++++++++++++++++++++++++++++++++++++++
c40fb2
 hw/xwayland/xwayland.h       |   3 +
c40fb2
 2 files changed, 145 insertions(+)
c40fb2
c40fb2
diff --git a/hw/xwayland/xwayland-input.c b/hw/xwayland/xwayland-input.c
c40fb2
index d5d12933c..64655de5f 100644
c40fb2
--- a/hw/xwayland/xwayland-input.c
c40fb2
+++ b/hw/xwayland/xwayland-input.c
c40fb2
@@ -294,6 +294,75 @@ xwl_touch_proc(DeviceIntPtr device, int what)
c40fb2
 #undef NTOUCHPOINTS
c40fb2
 }
c40fb2
 
c40fb2
+static int
c40fb2
+xwl_tablet_proc(DeviceIntPtr device, int what)
c40fb2
+{
c40fb2
+#define NBUTTONS 9
c40fb2
+#define NAXES 6
c40fb2
+    Atom btn_labels[NBUTTONS] = { 0 };
c40fb2
+    Atom axes_labels[NAXES] = { 0 };
c40fb2
+    BYTE map[NBUTTONS + 1] = { 0 };
c40fb2
+    int i;
c40fb2
+
c40fb2
+    switch (what) {
c40fb2
+    case DEVICE_INIT:
c40fb2
+        device->public.on = FALSE;
c40fb2
+
c40fb2
+        for (i = 1; i <= NBUTTONS; i++)
c40fb2
+            map[i] = i;
c40fb2
+
c40fb2
+        axes_labels[0] = XIGetKnownProperty(AXIS_LABEL_PROP_ABS_X);
c40fb2
+        axes_labels[1] = XIGetKnownProperty(AXIS_LABEL_PROP_ABS_Y);
c40fb2
+        axes_labels[2] = XIGetKnownProperty(AXIS_LABEL_PROP_ABS_PRESSURE);
c40fb2
+        axes_labels[3] = XIGetKnownProperty(AXIS_LABEL_PROP_ABS_TILT_X);
c40fb2
+        axes_labels[4] = XIGetKnownProperty(AXIS_LABEL_PROP_ABS_TILT_Y);
c40fb2
+        axes_labels[5] = XIGetKnownProperty(AXIS_LABEL_PROP_ABS_WHEEL);
c40fb2
+
c40fb2
+        if (!InitValuatorClassDeviceStruct(device, NAXES, axes_labels,
c40fb2
+                                           GetMotionHistorySize(), Absolute))
c40fb2
+            return BadValue;
c40fb2
+
c40fb2
+        /* Valuators - match the xf86-input-wacom ranges */
c40fb2
+        InitValuatorAxisStruct(device, 0, axes_labels[0],
c40fb2
+                               0, 262143, 10000, 0, 10000, Absolute);
c40fb2
+        InitValuatorAxisStruct(device, 1, axes_labels[1],
c40fb2
+                               0, 262143, 10000, 0, 10000, Absolute);
c40fb2
+        /* pressure */
c40fb2
+        InitValuatorAxisStruct(device, 2, axes_labels[2],
c40fb2
+                               0, 65535, 1, 0, 1, Absolute);
c40fb2
+        /* tilt x */
c40fb2
+        InitValuatorAxisStruct(device, 3, axes_labels[3],
c40fb2
+                               -64, 63, 57, 0, 57, Absolute);
c40fb2
+        /* tilt y */
c40fb2
+        InitValuatorAxisStruct(device, 4, axes_labels[4],
c40fb2
+                               -64, 63, 57, 0, 57, Absolute);
c40fb2
+        /* abs wheel (airbrush) or rotation (artpen) */
c40fb2
+        InitValuatorAxisStruct(device, 5, axes_labels[5],
c40fb2
+                               -900, 899, 1, 0, 1, Absolute);
c40fb2
+
c40fb2
+        if (!InitPtrFeedbackClassDeviceStruct(device, xwl_pointer_control))
c40fb2
+            return BadValue;
c40fb2
+
c40fb2
+        if (!InitButtonClassDeviceStruct(device, NBUTTONS, btn_labels, map))
c40fb2
+            return BadValue;
c40fb2
+
c40fb2
+        return Success;
c40fb2
+
c40fb2
+    case DEVICE_ON:
c40fb2
+        device->public.on = TRUE;
c40fb2
+        return Success;
c40fb2
+
c40fb2
+    case DEVICE_OFF:
c40fb2
+    case DEVICE_CLOSE:
c40fb2
+        device->public.on = FALSE;
c40fb2
+        return Success;
c40fb2
+    }
c40fb2
+
c40fb2
+    return BadMatch;
c40fb2
+#undef NAXES
c40fb2
+#undef NBUTTONS
c40fb2
+}
c40fb2
+
c40fb2
 static void
c40fb2
 pointer_handle_enter(void *data, struct wl_pointer *pointer,
c40fb2
                      uint32_t serial, struct wl_surface *surface,
c40fb2
@@ -1189,6 +1258,77 @@ xwl_seat_destroy(struct xwl_seat *xwl_seat)
c40fb2
     free(xwl_seat);
c40fb2
 }
c40fb2
 
c40fb2
+static void
c40fb2
+tablet_handle_name(void *data, struct zwp_tablet_v2 *tablet, const char *name)
c40fb2
+{
c40fb2
+}
c40fb2
+
c40fb2
+static void
c40fb2
+tablet_handle_id(void *data, struct zwp_tablet_v2 *tablet, uint32_t vid,
c40fb2
+                  uint32_t pid)
c40fb2
+{
c40fb2
+}
c40fb2
+
c40fb2
+static void
c40fb2
+tablet_handle_path(void *data, struct zwp_tablet_v2 *tablet, const char *path)
c40fb2
+{
c40fb2
+}
c40fb2
+
c40fb2
+static void
c40fb2
+tablet_handle_done(void *data, struct zwp_tablet_v2 *tablet)
c40fb2
+{
c40fb2
+    struct xwl_tablet *xwl_tablet = data;
c40fb2
+    struct xwl_seat *xwl_seat = xwl_tablet->seat;
c40fb2
+
c40fb2
+    if (xwl_seat->stylus == NULL) {
c40fb2
+        xwl_seat->stylus = add_device(xwl_seat, "xwayland-stylus", xwl_tablet_proc);
c40fb2
+        ActivateDevice(xwl_seat->stylus, TRUE);
c40fb2
+    }
c40fb2
+    EnableDevice(xwl_seat->stylus, TRUE);
c40fb2
+
c40fb2
+    if (xwl_seat->eraser == NULL) {
c40fb2
+        xwl_seat->eraser = add_device(xwl_seat, "xwayland-eraser", xwl_tablet_proc);
c40fb2
+        ActivateDevice(xwl_seat->eraser, TRUE);
c40fb2
+    }
c40fb2
+    EnableDevice(xwl_seat->eraser, TRUE);
c40fb2
+
c40fb2
+    if (xwl_seat->puck == NULL) {
c40fb2
+        xwl_seat->puck = add_device(xwl_seat, "xwayland-cursor", xwl_tablet_proc);
c40fb2
+        ActivateDevice(xwl_seat->puck, TRUE);
c40fb2
+    }
c40fb2
+    EnableDevice(xwl_seat->puck, TRUE);
c40fb2
+}
c40fb2
+
c40fb2
+static void
c40fb2
+tablet_handle_removed(void *data, struct zwp_tablet_v2 *tablet)
c40fb2
+{
c40fb2
+    struct xwl_tablet *xwl_tablet = data;
c40fb2
+    struct xwl_seat *xwl_seat = xwl_tablet->seat;
c40fb2
+
c40fb2
+    xorg_list_del(&xwl_tablet->link);
c40fb2
+
c40fb2
+    /* The tablet is merely disabled, not removed. The next tablet
c40fb2
+       will re-use the same X devices */
c40fb2
+    if (xorg_list_is_empty(&xwl_seat->tablets)) {
c40fb2
+        if (xwl_seat->stylus)
c40fb2
+            DisableDevice(xwl_seat->stylus, TRUE);
c40fb2
+        if (xwl_seat->eraser)
c40fb2
+            DisableDevice(xwl_seat->eraser, TRUE);
c40fb2
+        if (xwl_seat->puck)
c40fb2
+            DisableDevice(xwl_seat->puck, TRUE);
c40fb2
+    }
c40fb2
+
c40fb2
+    zwp_tablet_v2_destroy(tablet);
c40fb2
+    free(xwl_tablet);
c40fb2
+}
c40fb2
+
c40fb2
+static const struct zwp_tablet_v2_listener tablet_listener = {
c40fb2
+    tablet_handle_name,
c40fb2
+    tablet_handle_id,
c40fb2
+    tablet_handle_path,
c40fb2
+    tablet_handle_done,
c40fb2
+    tablet_handle_removed
c40fb2
+};
c40fb2
 
c40fb2
 static void
c40fb2
 tablet_seat_handle_add_tablet(void *data, struct zwp_tablet_seat_v2 *tablet_seat,
c40fb2
@@ -1207,6 +1347,8 @@ tablet_seat_handle_add_tablet(void *data, struct zwp_tablet_seat_v2 *tablet_seat
c40fb2
     xwl_tablet->seat = xwl_seat;
c40fb2
 
c40fb2
     xorg_list_add(&xwl_tablet->link, &xwl_seat->tablets);
c40fb2
+
c40fb2
+    zwp_tablet_v2_add_listener(tablet, &tablet_listener, xwl_tablet);
c40fb2
 }
c40fb2
 
c40fb2
 static void
c40fb2
diff --git a/hw/xwayland/xwayland.h b/hw/xwayland/xwayland.h
c40fb2
index a7f30b3c8..e7e62882b 100644
c40fb2
--- a/hw/xwayland/xwayland.h
c40fb2
+++ b/hw/xwayland/xwayland.h
c40fb2
@@ -132,6 +132,9 @@ struct xwl_seat {
c40fb2
     DeviceIntPtr relative_pointer;
c40fb2
     DeviceIntPtr keyboard;
c40fb2
     DeviceIntPtr touch;
c40fb2
+    DeviceIntPtr stylus;
c40fb2
+    DeviceIntPtr eraser;
c40fb2
+    DeviceIntPtr puck;
c40fb2
     struct xwl_screen *xwl_screen;
c40fb2
     struct wl_seat *seat;
c40fb2
     struct wl_pointer *wl_pointer;
c40fb2
-- 
c40fb2
2.13.5
c40fb2