[mutter/wip/tablet-protocol-v2: 19/48] clutter/evdev: Translate/emit libinput pad events



commit 0c778eb2267e7f6e9a24855013c43ae2c1024297
Author: Carlos Garnacho <carlosg gnome org>
Date:   Tue May 10 17:05:19 2016 +0200

    clutter/evdev: Translate/emit libinput pad events

 .../clutter/evdev/clutter-device-manager-evdev.c   |  171 ++++++++++++++++++++
 1 files changed, 171 insertions(+), 0 deletions(-)
---
diff --git a/clutter/clutter/evdev/clutter-device-manager-evdev.c 
b/clutter/clutter/evdev/clutter-device-manager-evdev.c
index 7d7f577..92801af 100644
--- a/clutter/clutter/evdev/clutter-device-manager-evdev.c
+++ b/clutter/clutter/evdev/clutter-device-manager-evdev.c
@@ -951,6 +951,127 @@ notify_proximity (ClutterInputDevice *input_device,
 }
 
 static void
+notify_pad_button (ClutterInputDevice *input_device,
+                   guint64             time_us,
+                   guint32             button,
+                   guint32             pressed)
+{
+  ClutterInputDeviceEvdev *device_evdev;
+  ClutterSeatEvdev *seat;
+  ClutterStage *stage;
+  ClutterEvent *event;
+
+  /* We can drop the event on the floor if no stage has been
+   * associated with the device yet. */
+  stage = _clutter_input_device_get_stage (input_device);
+  if (stage == NULL)
+    return;
+
+  if (pressed)
+    event = clutter_event_new (CLUTTER_PAD_BUTTON_PRESS);
+  else
+    event = clutter_event_new (CLUTTER_PAD_BUTTON_RELEASE);
+
+  device_evdev = CLUTTER_INPUT_DEVICE_EVDEV (input_device);
+  seat = _clutter_input_device_evdev_get_seat (device_evdev);
+
+  _clutter_evdev_event_set_time_usec (event, time_us);
+  event->pad_button.stage = stage;
+  event->pad_button.button = button;
+  clutter_event_set_device (event, input_device);
+  clutter_event_set_source_device (event, input_device);
+  clutter_event_set_time (event, us2ms (time_us));
+
+  _clutter_input_device_set_stage (seat->core_pointer, stage);
+
+  queue_event (event);
+}
+
+static void
+notify_pad_strip (ClutterInputDevice *input_device,
+                  guint64             time_us,
+                  guint32             strip_number,
+                  guint32             strip_source,
+                  gdouble             value)
+{
+  ClutterInputDeviceEvdev *device_evdev;
+  ClutterInputDevicePadSource source;
+  ClutterSeatEvdev *seat;
+  ClutterStage *stage;
+  ClutterEvent *event;
+
+  /* We can drop the event on the floor if no stage has been
+   * associated with the device yet. */
+  stage = _clutter_input_device_get_stage (input_device);
+  if (stage == NULL)
+    return;
+
+  if (strip_source == LIBINPUT_TABLET_PAD_STRIP_SOURCE_FINGER)
+    source = CLUTTER_INPUT_DEVICE_PAD_SOURCE_FINGER;
+  else
+    source = CLUTTER_INPUT_DEVICE_PAD_SOURCE_UNKNOWN;
+
+  device_evdev = CLUTTER_INPUT_DEVICE_EVDEV (input_device);
+  seat = _clutter_input_device_evdev_get_seat (device_evdev);
+
+  event = clutter_event_new (CLUTTER_PAD_STRIP);
+  _clutter_evdev_event_set_time_usec (event, time_us);
+  event->pad_strip.strip_source = source;
+  event->pad_strip.stage = stage;
+  event->pad_strip.strip_number = strip_number;
+  event->pad_strip.value = value;
+  clutter_event_set_device (event, input_device);
+  clutter_event_set_source_device (event, input_device);
+  clutter_event_set_time (event, us2ms (time_us));
+
+  _clutter_input_device_set_stage (seat->core_pointer, stage);
+
+  queue_event (event);
+}
+
+static void
+notify_pad_ring (ClutterInputDevice *input_device,
+                 guint64             time_us,
+                 guint32             ring_number,
+                 guint32             ring_source,
+                 gdouble             angle)
+{
+  ClutterInputDeviceEvdev *device_evdev;
+  ClutterInputDevicePadSource source;
+  ClutterSeatEvdev *seat;
+  ClutterStage *stage;
+  ClutterEvent *event;
+
+  /* We can drop the event on the floor if no stage has been
+   * associated with the device yet. */
+  stage = _clutter_input_device_get_stage (input_device);
+  if (stage == NULL)
+    return;
+
+  if (ring_source == LIBINPUT_TABLET_PAD_RING_SOURCE_FINGER)
+    source = CLUTTER_INPUT_DEVICE_PAD_SOURCE_FINGER;
+  else
+    source = CLUTTER_INPUT_DEVICE_PAD_SOURCE_UNKNOWN;
+
+  device_evdev = CLUTTER_INPUT_DEVICE_EVDEV (input_device);
+  seat = _clutter_input_device_evdev_get_seat (device_evdev);
+
+  event = clutter_event_new (CLUTTER_PAD_RING);
+  _clutter_evdev_event_set_time_usec (event, time_us);
+  event->pad_ring.ring_source = source;
+  event->pad_ring.stage = stage;
+  event->pad_ring.ring_number = ring_number;
+  event->pad_ring.angle = angle;
+  clutter_event_set_device (event, input_device);
+  clutter_event_set_source_device (event, input_device);
+  clutter_event_set_time (event, us2ms (time_us));
+
+  _clutter_input_device_set_stage (seat->core_pointer, stage);
+
+  queue_event (event);
+}
+
+static void
 dispatch_libinput (ClutterDeviceManagerEvdev *manager_evdev)
 {
   ClutterDeviceManagerEvdevPrivate *priv = manager_evdev->priv;
@@ -2085,6 +2206,56 @@ process_device_event (ClutterDeviceManagerEvdev *manager_evdev,
         notify_button (device, time, BTN_TOUCH, button_state);
         break;
       }
+    case LIBINPUT_EVENT_TABLET_PAD_BUTTON:
+      {
+        guint64 time;
+        guint32 button_state, button;
+        struct libinput_event_tablet_pad *pad_event =
+          libinput_event_get_tablet_pad_event (event);
+
+        device = libinput_device_get_user_data (libinput_device);
+        time = libinput_event_tablet_pad_get_time_usec (pad_event);
+
+        button = libinput_event_tablet_pad_get_button_number (pad_event);
+        button_state = libinput_event_tablet_pad_get_button_state (pad_event) ==
+                       LIBINPUT_BUTTON_STATE_PRESSED;
+        notify_pad_button (device, time, button, button_state);
+        break;
+      }
+    case LIBINPUT_EVENT_TABLET_PAD_STRIP:
+      {
+        guint64 time;
+        guint32 number, source;
+        struct libinput_event_tablet_pad *pad_event =
+          libinput_event_get_tablet_pad_event (event);
+        gdouble value;
+
+        device = libinput_device_get_user_data (libinput_device);
+        time = libinput_event_tablet_pad_get_time_usec (pad_event);
+        number = libinput_event_tablet_pad_get_strip_number (pad_event);
+        value = libinput_event_tablet_pad_get_strip_position (pad_event);
+        source = libinput_event_tablet_pad_get_strip_source (pad_event);
+
+        notify_pad_strip (device, time, number, source, value);
+        break;
+      }
+    case LIBINPUT_EVENT_TABLET_PAD_RING:
+      {
+        guint64 time;
+        guint32 number, source;
+        struct libinput_event_tablet_pad *pad_event =
+          libinput_event_get_tablet_pad_event (event);
+        gdouble angle;
+
+        device = libinput_device_get_user_data (libinput_device);
+        time = libinput_event_tablet_pad_get_time_usec (pad_event);
+        number = libinput_event_tablet_pad_get_ring_number (pad_event);
+        angle = libinput_event_tablet_pad_get_ring_position (pad_event);
+        source = libinput_event_tablet_pad_get_ring_source (pad_event);
+
+        notify_pad_ring (device, time, number, source, angle);
+        break;
+      }
     default:
       handled = FALSE;
     }


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]