[mutter] clutter: Add functions to find out mode switch buttons, and their group



commit 9d38ffa6e399ac28279d9e45fa34a865b8374074
Author: Carlos Garnacho <carlosg gnome org>
Date:   Wed Dec 28 11:41:23 2016 +0100

    clutter: Add functions to find out mode switch buttons, and their group
    
    This is done in the upper layers through backend-dependent ways, seems
    better to let ClutterInputDevice provide this information.
    
    https://bugzilla.gnome.org/show_bug.cgi?id=771098

 clutter/clutter/clutter-device-manager-private.h   |    4 ++
 clutter/clutter/clutter-input-device.c             |   38 ++++++++++++++++++++
 clutter/clutter/clutter-input-device.h             |    8 ++++
 clutter/clutter/evdev/clutter-input-device-evdev.c |   15 ++++++++
 4 files changed, 65 insertions(+), 0 deletions(-)
---
diff --git a/clutter/clutter/clutter-device-manager-private.h 
b/clutter/clutter/clutter-device-manager-private.h
index 108e8c5..a554467 100644
--- a/clutter/clutter/clutter-device-manager-private.h
+++ b/clutter/clutter/clutter-device-manager-private.h
@@ -154,6 +154,10 @@ struct _ClutterInputDeviceClass
                                  guint              *evdev_keycode);
   void (* update_from_tool) (ClutterInputDevice     *device,
                              ClutterInputDeviceTool *tool);
+
+  gboolean (* is_mode_switch_button) (ClutterInputDevice *device,
+                                      guint               group,
+                                      guint               button);
 };
 
 /* Platform-dependent interface */
diff --git a/clutter/clutter/clutter-input-device.c b/clutter/clutter/clutter-input-device.c
index 2930e56..89aa09e 100644
--- a/clutter/clutter/clutter-input-device.c
+++ b/clutter/clutter/clutter-input-device.c
@@ -2175,6 +2175,44 @@ clutter_input_device_get_n_mode_groups (ClutterInputDevice *device)
   return device->n_mode_groups;
 }
 
+gboolean
+clutter_input_device_is_mode_switch_button (ClutterInputDevice *device,
+                                            guint               group,
+                                            guint               button)
+{
+  ClutterInputDeviceClass *device_class;
+
+  g_return_val_if_fail (CLUTTER_IS_INPUT_DEVICE (device), FALSE);
+  g_return_val_if_fail (clutter_input_device_get_device_type (device) ==
+                        CLUTTER_PAD_DEVICE, FALSE);
+
+  device_class = CLUTTER_INPUT_DEVICE_GET_CLASS (device);
+
+  if (device_class->is_mode_switch_button)
+    return device_class->is_mode_switch_button (device, group, button);
+
+  return FALSE;
+}
+
+gint
+clutter_input_device_get_mode_switch_button_group (ClutterInputDevice *device,
+                                                   guint               button)
+{
+  gint group;
+
+  g_return_val_if_fail (CLUTTER_IS_INPUT_DEVICE (device), -1);
+  g_return_val_if_fail (clutter_input_device_get_device_type (device) ==
+                        CLUTTER_PAD_DEVICE, -1);
+
+  for (group = 0; group < device->n_mode_groups; group++)
+    {
+      if (clutter_input_device_is_mode_switch_button (device, group, button))
+        return group;
+    }
+
+  return -1;
+}
+
 const gchar *
 clutter_input_device_get_device_node (ClutterInputDevice *device)
 {
diff --git a/clutter/clutter/clutter-input-device.h b/clutter/clutter/clutter-input-device.h
index 66b2a58..f9b3edc 100644
--- a/clutter/clutter/clutter-input-device.h
+++ b/clutter/clutter/clutter-input-device.h
@@ -148,6 +148,14 @@ CLUTTER_AVAILABLE_IN_ALL
 gint                    clutter_input_device_get_n_mode_groups  (ClutterInputDevice *device);
 
 CLUTTER_AVAILABLE_IN_ALL
+gboolean                clutter_input_device_is_mode_switch_button (ClutterInputDevice *device,
+                                                                    guint               group,
+                                                                   guint               button);
+CLUTTER_AVAILABLE_IN_ALL
+gint                    clutter_input_device_get_mode_switch_button_group (ClutterInputDevice *device,
+                                                                           guint               button);
+
+CLUTTER_AVAILABLE_IN_ALL
 const gchar *           clutter_input_device_get_device_node    (ClutterInputDevice *device);
 
 CLUTTER_AVAILABLE_IN_ALL
diff --git a/clutter/clutter/evdev/clutter-input-device-evdev.c 
b/clutter/clutter/evdev/clutter-input-device-evdev.c
index cf7d117..9ad8935 100644
--- a/clutter/clutter/evdev/clutter-input-device-evdev.c
+++ b/clutter/clutter/evdev/clutter-input-device-evdev.c
@@ -166,6 +166,20 @@ clutter_input_device_evdev_update_from_tool (ClutterInputDevice     *device,
   g_object_thaw_notify (G_OBJECT (device));
 }
 
+static gboolean
+clutter_input_device_evdev_is_mode_switch_button (ClutterInputDevice *device,
+                                                  guint               group,
+                                                  guint               button)
+{
+  struct libinput_device *libinput_device;
+  struct libinput_tablet_pad_mode_group *mode_group;
+
+  libinput_device = clutter_evdev_input_device_get_libinput_device (device);
+  mode_group = libinput_device_tablet_pad_get_mode_group (libinput_device, group);
+
+  return libinput_tablet_pad_mode_group_button_is_toggle (mode_group, button) != 0;
+}
+
 static void
 clutter_input_device_evdev_class_init (ClutterInputDeviceEvdevClass *klass)
 {
@@ -177,6 +191,7 @@ clutter_input_device_evdev_class_init (ClutterInputDeviceEvdevClass *klass)
 
   klass->keycode_to_evdev = clutter_input_device_evdev_keycode_to_evdev;
   klass->update_from_tool = clutter_input_device_evdev_update_from_tool;
+  klass->is_mode_switch_button = clutter_input_device_evdev_is_mode_switch_button;
 
   obj_props[PROP_DEVICE_MATRIX] =
     g_param_spec_boxed ("device-matrix",


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