Blame SOURCES/0006-xwayland-handle-button-events-after-motion-events.patch

c40fb2
From 317ce1201a2ec848f9066294ea544b756f735385 Mon Sep 17 00:00:00 2001
c40fb2
From: Peter Hutterer <peter.hutterer@who-t.net>
c40fb2
Date: Tue, 7 Feb 2017 12:23:46 +1000
c40fb2
Subject: [PATCH xserver 06/12] xwayland: handle button events after motion
c40fb2
 events
c40fb2
c40fb2
Make sure the button events are sent after the motion events into the new
c40fb2
position.
c40fb2
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 773b04748d0c839bc8b12e33f74bb8d11c447f5b)
c40fb2
---
c40fb2
 hw/xwayland/xwayland-input.c | 44 +++++++++++++++++++++++++++++++++++++-------
c40fb2
 hw/xwayland/xwayland.h       |  3 +++
c40fb2
 2 files changed, 40 insertions(+), 7 deletions(-)
c40fb2
c40fb2
diff --git a/hw/xwayland/xwayland-input.c b/hw/xwayland/xwayland-input.c
c40fb2
index 142862f7e..50da10839 100644
c40fb2
--- a/hw/xwayland/xwayland-input.c
c40fb2
+++ b/hw/xwayland/xwayland-input.c
c40fb2
@@ -34,6 +34,7 @@
c40fb2
 #include <inpututils.h>
c40fb2
 #include <mipointer.h>
c40fb2
 #include <mipointrst.h>
c40fb2
+#include <misc.h>
c40fb2
 #include "tablet-unstable-v2-client-protocol.h"
c40fb2
 
c40fb2
 /* Copied from mipointer.c */
c40fb2
@@ -1543,8 +1544,8 @@ tablet_tool_button_state(void *data, struct zwp_tablet_tool_v2 *tool,
c40fb2
 {
c40fb2
     struct xwl_tablet_tool *xwl_tablet_tool = data;
c40fb2
     struct xwl_seat *xwl_seat = xwl_tablet_tool->seat;
c40fb2
+    uint32_t *mask = &xwl_tablet_tool->buttons_now;
c40fb2
     int xbtn = 0;
c40fb2
-    ValuatorMask mask;
c40fb2
 
c40fb2
     /* BTN_0 .. BTN_9 */
c40fb2
     if (button >= 0x100 && button <= 0x109) {
c40fb2
@@ -1592,11 +1593,14 @@ tablet_tool_button_state(void *data, struct zwp_tablet_tool_v2 *tool,
c40fb2
         return;
c40fb2
     }
c40fb2
 
c40fb2
-    xwl_seat->xwl_screen->serial = serial;
c40fb2
+    BUG_RETURN(xbtn >= 8 * sizeof(*mask));
c40fb2
 
c40fb2
-    valuator_mask_zero(&mask);
c40fb2
-    QueuePointerEvents(xwl_tablet_tool->xdevice,
c40fb2
-                       state ? ButtonPress : ButtonRelease, xbtn, 0, &mask);
c40fb2
+    if (state)
c40fb2
+        SetBit(mask, xbtn);
c40fb2
+    else
c40fb2
+        ClearBit(mask, xbtn);
c40fb2
+
c40fb2
+    xwl_seat->xwl_screen->serial = serial;
c40fb2
 }
c40fb2
 
c40fb2
 static void
c40fb2
@@ -1604,6 +1608,8 @@ tablet_tool_frame(void *data, struct zwp_tablet_tool_v2 *tool, uint32_t time)
c40fb2
 {
c40fb2
     struct xwl_tablet_tool *xwl_tablet_tool = data;
c40fb2
     ValuatorMask mask;
c40fb2
+    uint32_t released, pressed, diff;
c40fb2
+    int button;
c40fb2
 
c40fb2
     valuator_mask_zero(&mask);
c40fb2
     valuator_mask_set(&mask, 0, xwl_tablet_tool->x);
c40fb2
@@ -1613,10 +1619,34 @@ tablet_tool_frame(void *data, struct zwp_tablet_tool_v2 *tool, uint32_t time)
c40fb2
     valuator_mask_set(&mask, 4, xwl_tablet_tool->tilt_y);
c40fb2
     valuator_mask_set(&mask, 5, xwl_tablet_tool->rotation + xwl_tablet_tool->slider);
c40fb2
 
c40fb2
-    /* FIXME: Store button mask in xwl_tablet_tool and send events *HERE* if
c40fb2
-       changed */
c40fb2
     QueuePointerEvents(xwl_tablet_tool->xdevice, MotionNotify, 0,
c40fb2
                POINTER_ABSOLUTE | POINTER_SCREEN, &mask);
c40fb2
+
c40fb2
+    valuator_mask_zero(&mask);
c40fb2
+
c40fb2
+    diff = xwl_tablet_tool->buttons_prev ^ xwl_tablet_tool->buttons_now;
c40fb2
+    released = diff & ~xwl_tablet_tool->buttons_now;
c40fb2
+    pressed = diff & xwl_tablet_tool->buttons_now;
c40fb2
+
c40fb2
+    button = 1;
c40fb2
+    while (released) {
c40fb2
+        if (released & 0x1)
c40fb2
+            QueuePointerEvents(xwl_tablet_tool->xdevice,
c40fb2
+                               ButtonRelease, button, 0, &mask);
c40fb2
+        button++;
c40fb2
+        released >>= 1;
c40fb2
+    }
c40fb2
+
c40fb2
+    button = 1;
c40fb2
+    while (pressed) {
c40fb2
+        if (pressed & 0x1)
c40fb2
+            QueuePointerEvents(xwl_tablet_tool->xdevice,
c40fb2
+                               ButtonPress, button, 0, &mask);
c40fb2
+        button++;
c40fb2
+        pressed >>= 1;
c40fb2
+    }
c40fb2
+
c40fb2
+    xwl_tablet_tool->buttons_prev = xwl_tablet_tool->buttons_now;
c40fb2
 }
c40fb2
 
c40fb2
 static const struct zwp_tablet_tool_v2_listener tablet_tool_listener = {
c40fb2
diff --git a/hw/xwayland/xwayland.h b/hw/xwayland/xwayland.h
c40fb2
index fb9ac4804..bb119dad7 100644
c40fb2
--- a/hw/xwayland/xwayland.h
c40fb2
+++ b/hw/xwayland/xwayland.h
c40fb2
@@ -202,6 +202,9 @@ struct xwl_tablet_tool {
c40fb2
     float tilt_y;
c40fb2
     float rotation;
c40fb2
     float slider;
c40fb2
+
c40fb2
+    uint32_t buttons_now,
c40fb2
+             buttons_prev;
c40fb2
 };
c40fb2
 
c40fb2
 struct xwl_tablet_pad {
c40fb2
-- 
c40fb2
2.13.5
c40fb2