Blame SOURCES/0001-virtual-input-evdev-Translate-from-button-codes-inte.patch

776610
From f73524d6fcc45f42790d1fdad718f52f98ef793a Mon Sep 17 00:00:00 2001
776610
From: =?UTF-8?q?Jonas=20=C3=85dahl?= <jadahl@gmail.com>
776610
Date: Mon, 6 Aug 2018 21:00:23 +0200
776610
Subject: [PATCH] virtual-input/evdev: Translate from button codes internal to
776610
 evdev
776610
776610
Sending button events to a ClutterVirtualInputDevice, the API expects
776610
button codes to be of the internal clutter type. The evdev
776610
implementation incorrectly assumed it was already prepared evdev event
776610
codes, which was not the case. Fix the evdev implementation to translate
776610
from the internal representation to evdev before passing it along to
776610
ClutterSeatEvdev.
776610
---
776610
 .../clutter-virtual-input-device-evdev.c      | 31 +++++++++++++++----
776610
 1 file changed, 25 insertions(+), 6 deletions(-)
776610
776610
diff --git a/clutter/clutter/evdev/clutter-virtual-input-device-evdev.c b/clutter/clutter/evdev/clutter-virtual-input-device-evdev.c
776610
index fe628da855..e491416c4c 100644
776610
--- a/clutter/clutter/evdev/clutter-virtual-input-device-evdev.c
776610
+++ b/clutter/clutter/evdev/clutter-virtual-input-device-evdev.c
776610
@@ -185,6 +185,22 @@ clutter_virtual_input_device_evdev_notify_absolute_motion (ClutterVirtualInputDe
776610
                                              NULL);
776610
 }
776610
 
776610
+static int
776610
+translate_to_evdev_button (int button)
776610
+{
776610
+  switch (button)
776610
+    {
776610
+    case CLUTTER_BUTTON_PRIMARY:
776610
+      return BTN_LEFT;
776610
+    case CLUTTER_BUTTON_SECONDARY:
776610
+      return BTN_RIGHT;
776610
+    case CLUTTER_BUTTON_MIDDLE:
776610
+      return BTN_MIDDLE;
776610
+    default:
776610
+      return button + (BTN_LEFT - 1) - 4;
776610
+    }
776610
+}
776610
+
776610
 static void
776610
 clutter_virtual_input_device_evdev_notify_button (ClutterVirtualInputDevice *virtual_device,
776610
                                                   uint64_t                   time_us,
776610
@@ -194,30 +210,33 @@ clutter_virtual_input_device_evdev_notify_button (ClutterVirtualInputDevice *vir
776610
   ClutterVirtualInputDeviceEvdev *virtual_evdev =
776610
     CLUTTER_VIRTUAL_INPUT_DEVICE_EVDEV (virtual_device);
776610
   int button_count;
776610
+  int evdev_button;
776610
 
776610
   if (time_us == CLUTTER_CURRENT_TIME)
776610
     time_us = g_get_monotonic_time ();
776610
 
776610
-  if (get_button_type (button) != EVDEV_BUTTON_TYPE_BUTTON)
776610
+  evdev_button = translate_to_evdev_button (button);
776610
+
776610
+  if (get_button_type (evdev_button) != EVDEV_BUTTON_TYPE_BUTTON)
776610
     {
776610
       g_warning ("Unknown/invalid virtual device button 0x%x pressed",
776610
-                 button);
776610
+                 evdev_button);
776610
       return;
776610
     }
776610
 
776610
-  button_count = update_button_count (virtual_evdev, button, button_state);
776610
+  button_count = update_button_count (virtual_evdev, evdev_button, button_state);
776610
   if (button_count < 0 || button_count > 1)
776610
     {
776610
-      g_warning ("Received multiple virtual 0x%x button %s (ignoring)", button,
776610
+      g_warning ("Received multiple virtual 0x%x button %s (ignoring)", evdev_button,
776610
                  button_state == CLUTTER_BUTTON_STATE_PRESSED ? "presses" : "releases");
776610
-      update_button_count (virtual_evdev, button, 1 - button_state);
776610
+      update_button_count (virtual_evdev, evdev_button, 1 - button_state);
776610
       return;
776610
     }
776610
 
776610
   clutter_seat_evdev_notify_button (virtual_evdev->seat,
776610
                                     virtual_evdev->device,
776610
                                     time_us,
776610
-                                    button,
776610
+                                    evdev_button,
776610
                                     button_state);
776610
 }
776610
 
776610
-- 
776610
2.17.1
776610