Blame SOURCES/0001-clutter-x11-Implement-missing-ClutterInputDevice-pad.patch

e47e58
From 1d745a858470b29b44e5b0e308488a477c4526cb Mon Sep 17 00:00:00 2001
e47e58
From: Carlos Garnacho <carlosg@gnome.org>
e47e58
Date: Thu, 22 Feb 2018 17:48:17 +0100
e47e58
Subject: [PATCH 1/2] clutter/x11: Implement missing ClutterInputDevice pad
e47e58
 vmethods
e47e58
e47e58
Use libwacom to be able to find out modes, groups and button roles on
e47e58
pad devices.
e47e58
e47e58
https://gitlab.gnome.org/GNOME/mutter/issues/48
e47e58
e47e58
Closes: #48
e47e58
---
e47e58
 clutter/clutter/x11/clutter-device-manager-xi2.c | 11 +++
e47e58
 clutter/clutter/x11/clutter-device-manager-xi2.h |  8 ++
e47e58
 clutter/clutter/x11/clutter-input-device-xi2.c   | 97 ++++++++++++++++++++++++
e47e58
 clutter/clutter/x11/clutter-input-device-xi2.h   | 10 +++
e47e58
 clutter/configure.ac                             | 32 +++++++-
e47e58
 5 files changed, 156 insertions(+), 2 deletions(-)
e47e58
e47e58
diff --git a/clutter/clutter/x11/clutter-device-manager-xi2.c b/clutter/clutter/x11/clutter-device-manager-xi2.c
e47e58
index d2610cc..dee2604 100644
e47e58
--- a/clutter/clutter/x11/clutter-device-manager-xi2.c
e47e58
+++ b/clutter/clutter/x11/clutter-device-manager-xi2.c
e47e58
@@ -495,11 +495,18 @@ create_device (ClutterDeviceManagerXI2 *manager_xi2,
e47e58
                          "device-node", node_path,
e47e58
                          "n-rings", num_rings,
e47e58
                          "n-strips", num_strips,
e47e58
+                         "n-mode-groups", MAX (num_rings, num_strips),
e47e58
                          NULL);
e47e58
 
e47e58
   translate_device_classes (backend_x11->xdpy, retval,
e47e58
                             info->classes,
e47e58
                             info->num_classes);
e47e58
+
e47e58
+#ifdef HAVE_LIBWACOM
e47e58
+  if (source == CLUTTER_PAD_DEVICE)
e47e58
+    clutter_input_device_xi2_ensure_wacom_info (retval, manager_xi2->wacom_db);
e47e58
+#endif
e47e58
+
e47e58
   g_free (vendor_id);
e47e58
   g_free (product_id);
e47e58
 
e47e58
@@ -2063,4 +2070,8 @@ clutter_device_manager_xi2_init (ClutterDeviceManagerXI2 *self)
e47e58
                                                (GDestroyNotify) g_object_unref);
e47e58
   self->tools_by_serial = g_hash_table_new_full (NULL, NULL, NULL,
e47e58
                                                  (GDestroyNotify) g_object_unref);
e47e58
+
e47e58
+#ifdef HAVE_LIBWACOM
e47e58
+  self->wacom_db = libwacom_database_new ();
e47e58
+#endif
e47e58
 }
e47e58
diff --git a/clutter/clutter/x11/clutter-device-manager-xi2.h b/clutter/clutter/x11/clutter-device-manager-xi2.h
e47e58
index c8e66f9..be25759 100644
e47e58
--- a/clutter/clutter/x11/clutter-device-manager-xi2.h
e47e58
+++ b/clutter/clutter/x11/clutter-device-manager-xi2.h
e47e58
@@ -26,6 +26,10 @@
e47e58
 
e47e58
 #include <clutter/clutter-device-manager.h>
e47e58
 
e47e58
+#ifdef HAVE_LIBWACOM
e47e58
+#include <libwacom/libwacom.h>
e47e58
+#endif
e47e58
+
e47e58
 G_BEGIN_DECLS
e47e58
 
e47e58
 #define CLUTTER_TYPE_DEVICE_MANAGER_XI2            (_clutter_device_manager_xi2_get_type ())
e47e58
@@ -51,6 +55,10 @@ struct _ClutterDeviceManagerXI2
e47e58
   GList *slave_devices;
e47e58
 
e47e58
   int opcode;
e47e58
+
e47e58
+#ifdef HAVE_LIBWACOM
e47e58
+  WacomDeviceDatabase *wacom_db;
e47e58
+#endif
e47e58
 };
e47e58
 
e47e58
 struct _ClutterDeviceManagerXI2Class
e47e58
diff --git a/clutter/clutter/x11/clutter-input-device-xi2.c b/clutter/clutter/x11/clutter-input-device-xi2.c
e47e58
index 7fb0e05..2d9b6d2 100644
e47e58
--- a/clutter/clutter/x11/clutter-input-device-xi2.c
e47e58
+++ b/clutter/clutter/x11/clutter-input-device-xi2.c
e47e58
@@ -45,6 +45,10 @@ struct _ClutterInputDeviceXI2
e47e58
 
e47e58
   gint device_id;
e47e58
   ClutterInputDeviceTool *current_tool;
e47e58
+
e47e58
+#ifdef HAVE_LIBWACOM
e47e58
+  WacomDevice *wacom_device;
e47e58
+#endif
e47e58
 };
e47e58
 
e47e58
 #define N_BUTTONS       5
e47e58
@@ -88,15 +92,94 @@ clutter_input_device_xi2_is_grouped (ClutterInputDevice *device,
e47e58
 }
e47e58
 
e47e58
 static void
e47e58
+clutter_input_device_xi2_finalize (GObject *object)
e47e58
+{
e47e58
+#ifdef HAVE_LIBWACOM
e47e58
+  ClutterInputDeviceXI2 *device_xi2 = CLUTTER_INPUT_DEVICE_XI2 (object);
e47e58
+
e47e58
+  if (device_xi2->wacom_device)
e47e58
+    libwacom_destroy (device_xi2->wacom_device);
e47e58
+#endif
e47e58
+
e47e58
+  G_OBJECT_CLASS (clutter_input_device_xi2_parent_class)->finalize (object);
e47e58
+}
e47e58
+
e47e58
+static gint
e47e58
+clutter_input_device_xi2_get_group_n_modes (ClutterInputDevice *device,
e47e58
+                                            gint                group)
e47e58
+{
e47e58
+#ifdef HAVE_LIBWACOM
e47e58
+  ClutterInputDeviceXI2 *device_xi2 = CLUTTER_INPUT_DEVICE_XI2 (device);
e47e58
+
e47e58
+  if (device_xi2->wacom_device)
e47e58
+    {
e47e58
+      if (group == 0)
e47e58
+        {
e47e58
+          if (libwacom_has_ring (device_xi2->wacom_device))
e47e58
+            return libwacom_get_ring_num_modes (device_xi2->wacom_device);
e47e58
+          else if (libwacom_get_num_strips (device_xi2->wacom_device) >= 1)
e47e58
+            return libwacom_get_strips_num_modes (device_xi2->wacom_device);
e47e58
+        }
e47e58
+      else if (group == 1)
e47e58
+        {
e47e58
+          if (libwacom_has_ring2 (device_xi2->wacom_device))
e47e58
+            return libwacom_get_ring2_num_modes (device_xi2->wacom_device);
e47e58
+          else if (libwacom_get_num_strips (device_xi2->wacom_device) >= 2)
e47e58
+            return libwacom_get_strips_num_modes (device_xi2->wacom_device);
e47e58
+        }
e47e58
+    }
e47e58
+#endif
e47e58
+
e47e58
+  return -1;
e47e58
+}
e47e58
+
e47e58
+#ifdef HAVE_LIBWACOM
e47e58
+static int
e47e58
+clutter_input_device_xi2_get_button_group (ClutterInputDevice *device,
e47e58
+                                           guint               button)
e47e58
+{
e47e58
+  ClutterInputDeviceXI2 *device_xi2 = CLUTTER_INPUT_DEVICE_XI2 (device);
e47e58
+
e47e58
+  if (device_xi2->wacom_device)
e47e58
+    {
e47e58
+      if (button >= libwacom_get_num_buttons (device_xi2->wacom_device))
e47e58
+        return -1;
e47e58
+
e47e58
+      return libwacom_get_button_led_group (device_xi2->wacom_device,
e47e58
+                                            'A' + button);
e47e58
+    }
e47e58
+  else
e47e58
+    return -1;
e47e58
+}
e47e58
+#endif
e47e58
+
e47e58
+static gboolean
e47e58
+clutter_input_device_xi2_is_mode_switch_button (ClutterInputDevice *device,
e47e58
+                                                guint               group,
e47e58
+                                                guint               button)
e47e58
+{
e47e58
+  int button_group = -1;
e47e58
+
e47e58
+#ifdef HAVE_LIBWACOM
e47e58
+  button_group = clutter_input_device_xi2_get_button_group (device, button);
e47e58
+#endif
e47e58
+
e47e58
+  return button_group == (int) group;
e47e58
+}
e47e58
+
e47e58
+static void
e47e58
 clutter_input_device_xi2_class_init (ClutterInputDeviceXI2Class *klass)
e47e58
 {
e47e58
   GObjectClass *gobject_class = G_OBJECT_CLASS (klass);
e47e58
   ClutterInputDeviceClass *device_class = CLUTTER_INPUT_DEVICE_CLASS (klass);
e47e58
 
e47e58
   gobject_class->constructed = clutter_input_device_xi2_constructed;
e47e58
+  gobject_class->finalize = clutter_input_device_xi2_finalize;
e47e58
 
e47e58
   device_class->keycode_to_evdev = clutter_input_device_xi2_keycode_to_evdev;
e47e58
   device_class->is_grouped = clutter_input_device_xi2_is_grouped;
e47e58
+  device_class->get_group_n_modes = clutter_input_device_xi2_get_group_n_modes;
e47e58
+  device_class->is_mode_switch_button = clutter_input_device_xi2_is_mode_switch_button;
e47e58
 }
e47e58
 
e47e58
 static void
e47e58
@@ -196,3 +279,17 @@ clutter_input_device_xi2_get_current_tool (ClutterInputDevice *device)
e47e58
   ClutterInputDeviceXI2 *device_xi2 = CLUTTER_INPUT_DEVICE_XI2 (device);
e47e58
   return device_xi2->current_tool;
e47e58
 }
e47e58
+
e47e58
+#ifdef HAVE_LIBWACOM
e47e58
+void
e47e58
+clutter_input_device_xi2_ensure_wacom_info (ClutterInputDevice  *device,
e47e58
+                                            WacomDeviceDatabase *wacom_db)
e47e58
+{
e47e58
+  ClutterInputDeviceXI2 *device_xi2 = CLUTTER_INPUT_DEVICE_XI2 (device);
e47e58
+  const gchar *node_path;
e47e58
+
e47e58
+  node_path = clutter_input_device_get_device_node (device);
e47e58
+  device_xi2->wacom_device = libwacom_new_from_path (wacom_db, node_path,
e47e58
+                                                     WFALLBACK_NONE, NULL);
e47e58
+}
e47e58
+#endif
e47e58
diff --git a/clutter/clutter/x11/clutter-input-device-xi2.h b/clutter/clutter/x11/clutter-input-device-xi2.h
e47e58
index b93684f..e30fb4d 100644
e47e58
--- a/clutter/clutter/x11/clutter-input-device-xi2.h
e47e58
+++ b/clutter/clutter/x11/clutter-input-device-xi2.h
e47e58
@@ -27,6 +27,10 @@
e47e58
 #include <clutter/clutter-input-device.h>
e47e58
 #include <X11/extensions/XInput2.h>
e47e58
 
e47e58
+#ifdef HAVE_LIBWACOM
e47e58
+#include <libwacom/libwacom.h>
e47e58
+#endif
e47e58
+
e47e58
 G_BEGIN_DECLS
e47e58
 
e47e58
 #define CLUTTER_TYPE_INPUT_DEVICE_XI2           (_clutter_input_device_xi2_get_type ())
e47e58
@@ -45,6 +49,12 @@ void  clutter_input_device_xi2_update_tool      (ClutterInputDevice     *device,
e47e58
                                                  ClutterInputDeviceTool *tool);
e47e58
 ClutterInputDeviceTool * clutter_input_device_xi2_get_current_tool (ClutterInputDevice *device);
e47e58
 
e47e58
+#ifdef HAVE_LIBWACOM
e47e58
+void clutter_input_device_xi2_ensure_wacom_info (ClutterInputDevice  *device,
e47e58
+                                                 WacomDeviceDatabase *wacom_db);
e47e58
+
e47e58
+#endif
e47e58
+
e47e58
 G_END_DECLS
e47e58
 
e47e58
 #endif /* __CLUTTER_INPUT_DEVICE_XI2_H__ */
e47e58
diff --git a/clutter/configure.ac b/clutter/configure.ac
e47e58
index 3c3d0c5..5474fa0 100644
e47e58
--- a/clutter/configure.ac
e47e58
+++ b/clutter/configure.ac
e47e58
@@ -121,6 +121,7 @@ m4_define([xcomposite_req_version],     [0.4])
e47e58
 m4_define([gdk_req_version],            [3.3.18])
e47e58
 m4_define([libinput_req_version],       [1.4.0])
e47e58
 m4_define([libudev_req_version],        [136])
e47e58
+m4_define([libwacom_req_version],       [0.13])
e47e58
 
e47e58
 AC_SUBST([GLIB_REQ_VERSION],       [glib_req_version])
e47e58
 AC_SUBST([COGL_REQ_VERSION],       [cogl_req_version])
e47e58
@@ -133,6 +134,7 @@ AC_SUBST([XCOMPOSITE_REQ_VERSION], [xcomposite_req_version])
e47e58
 AC_SUBST([GDK_REQ_VERSION],        [gdk_req_version])
e47e58
 AC_SUBST([LIBINPUT_REQ_VERSION],   [libinput_req_version])
e47e58
 AC_SUBST([LIBUDEV_REQ_VERSION],    [libudev_req_version])
e47e58
+AC_SUBST([LIBWACOM_REQ_VERSION],   [libwacom_req_version])
e47e58
 
e47e58
 # Checks for typedefs, structures, and compiler characteristics.
e47e58
 AM_PATH_GLIB_2_0([glib_req_version],
e47e58
@@ -508,6 +510,32 @@ X11_EXTS=${X11_EXTS#* }
e47e58
 
e47e58
 AC_CACHE_SAVE
e47e58
 
e47e58
+dnl === Libwacom support for X11 ===============================================
e47e58
+AC_ARG_WITH(libwacom,
e47e58
+  AC_HELP_STRING([--without-libwacom],
e47e58
+                 [disable the use of libwacom for advanced tablet management]),,
e47e58
+  with_libwacom=auto)
e47e58
+
e47e58
+have_libwacom=no
e47e58
+AC_MSG_CHECKING([libwacom])
e47e58
+if test x$with_libwacom = xno ; then
e47e58
+  AC_MSG_RESULT([disabled])
e47e58
+else
e47e58
+  if $PKG_CONFIG --exists libwacom '>=' $LIBWACOM_REQ_VERSION; then
e47e58
+    have_libwacom=yes
e47e58
+    AC_MSG_RESULT(yes)
e47e58
+    PKG_CHECK_MODULES([LIBWACOM], [libwacom])
e47e58
+    AC_SUBST(LIBWACOM_CFLAGS)
e47e58
+    AC_SUBST(LIBWACOM_LIBS)
e47e58
+    AC_DEFINE([HAVE_LIBWACOM], 1, [Building with libwacom for advanced tablet management])
e47e58
+  else
e47e58
+    AC_MSG_RESULT(no)
e47e58
+    if test x$with_libwacom = xyes ; then
e47e58
+      AC_MSG_ERROR([libwacom forced but not found])
e47e58
+    fi
e47e58
+  fi
e47e58
+fi
e47e58
+
e47e58
 dnl === Enable GDK-Pixbuf in tests ============================================
e47e58
 
e47e58
 m4_define([pixbuf_default], [yes])
e47e58
@@ -679,8 +707,8 @@ AS_IF([test "x$CLUTTER_BASE_PC_FILES_PRIVATE" = "x" && test "x$BACKEND_PC_FILES_
e47e58
 AC_SUBST(CLUTTER_REQUIRES)
e47e58
 AC_SUBST(CLUTTER_REQUIRES_PRIVATE)
e47e58
 
e47e58
-CLUTTER_CFLAGS="$FLAVOUR_CFLAGS $CLUTTER_DEPS_CFLAGS $CLUTTER_DEPS_PRIVATE_CFLAGS $GLIB_CFLAGS"
e47e58
-CLUTTER_LIBS="$FLAVOUR_LIBS $CLUTTER_DEPS_LIBS $CLUTTER_DEPS_PRIVATE_LIBS $GLIB_LIBS"
e47e58
+CLUTTER_CFLAGS="$FLAVOUR_CFLAGS $CLUTTER_DEPS_CFLAGS $CLUTTER_DEPS_PRIVATE_CFLAGS $GLIB_CFLAGS $LIBWACOM_CFLAGS"
e47e58
+CLUTTER_LIBS="$FLAVOUR_LIBS $CLUTTER_DEPS_LIBS $CLUTTER_DEPS_PRIVATE_LIBS $GLIB_LIBS $LIBWACOM_LIBS"
e47e58
 AC_SUBST(CLUTTER_CFLAGS)
e47e58
 AC_SUBST(CLUTTER_LIBS)
e47e58
 
e47e58
-- 
e47e58
1.8.3.1
e47e58
e47e58
e47e58
From f8fa4b8fa13fba9ed484be74fb7fc82499d46261 Mon Sep 17 00:00:00 2001
e47e58
From: Carlos Garnacho <carlosg@gnome.org>
e47e58
Date: Thu, 22 Feb 2018 17:50:42 +0100
e47e58
Subject: [PATCH 2/2] clutter/x11: Communicate proper group/mode on pad events.
e47e58
e47e58
So we can trigger actions for the right mode.
e47e58
e47e58
https://gitlab.gnome.org/GNOME/mutter/issues/48
e47e58
e47e58
Closes: #48
e47e58
---
e47e58
 clutter/clutter/x11/clutter-device-manager-xi2.c | 15 +++++-
e47e58
 clutter/clutter/x11/clutter-input-device-xi2.c   | 61 ++++++++++++++++++++++++
e47e58
 clutter/clutter/x11/clutter-input-device-xi2.h   |  9 ++++
e47e58
 3 files changed, 84 insertions(+), 1 deletion(-)
e47e58
e47e58
diff --git a/clutter/clutter/x11/clutter-device-manager-xi2.c b/clutter/clutter/x11/clutter-device-manager-xi2.c
e47e58
index dee2604..d269a38 100644
e47e58
--- a/clutter/clutter/x11/clutter-device-manager-xi2.c
e47e58
+++ b/clutter/clutter/x11/clutter-device-manager-xi2.c
e47e58
@@ -1133,7 +1133,7 @@ translate_pad_event (ClutterEvent       *event,
e47e58
                      ClutterInputDevice *device)
e47e58
 {
e47e58
   gdouble value;
e47e58
-  guint number;
e47e58
+  guint number, mode = 0;
e47e58
 
e47e58
   if (!translate_pad_axis (device, &xev->valuators,
e47e58
                            &event->any.type,
e47e58
@@ -1147,15 +1147,21 @@ translate_pad_event (ClutterEvent       *event,
e47e58
   if (xev->evtype == XI_Motion)
e47e58
     value = -1;
e47e58
 
e47e58
+#ifdef HAVE_LIBWACOM
e47e58
+  mode = clutter_input_device_xi2_get_pad_group_mode (device, number);
e47e58
+#endif
e47e58
+
e47e58
   if (event->any.type == CLUTTER_PAD_RING)
e47e58
     {
e47e58
       event->pad_ring.ring_number = number;
e47e58
       event->pad_ring.angle = value;
e47e58
+      event->pad_ring.mode = mode;
e47e58
     }
e47e58
   else
e47e58
     {
e47e58
       event->pad_strip.strip_number = number;
e47e58
       event->pad_strip.value = value;
e47e58
+      event->pad_strip.mode = mode;
e47e58
     }
e47e58
 
e47e58
   event->any.time = xev->time;
e47e58
@@ -1382,6 +1388,13 @@ clutter_device_manager_xi2_translate_event (ClutterEventTranslator *translator,
e47e58
 
e47e58
             /* Pad buttons are 0-indexed */
e47e58
             event->pad_button.button = xev->detail - 1;
e47e58
+#ifdef HAVE_LIBWACOM
e47e58
+            clutter_input_device_xi2_update_pad_state (device,
e47e58
+                                                       event->pad_button.button,
e47e58
+                                                       (xi_event->evtype == XI_ButtonPress),
e47e58
+                                                       &event->pad_button.group,
e47e58
+                                                       &event->pad_button.mode);
e47e58
+#endif
e47e58
             clutter_event_set_device (event, device);
e47e58
             clutter_event_set_source_device (event, source_device);
e47e58
 
e47e58
diff --git a/clutter/clutter/x11/clutter-input-device-xi2.c b/clutter/clutter/x11/clutter-input-device-xi2.c
e47e58
index 2d9b6d2..f62ba85 100644
e47e58
--- a/clutter/clutter/x11/clutter-input-device-xi2.c
e47e58
+++ b/clutter/clutter/x11/clutter-input-device-xi2.c
e47e58
@@ -48,6 +48,7 @@ struct _ClutterInputDeviceXI2
e47e58
 
e47e58
 #ifdef HAVE_LIBWACOM
e47e58
   WacomDevice *wacom_device;
e47e58
+  GArray *group_modes;
e47e58
 #endif
e47e58
 };
e47e58
 
e47e58
@@ -68,6 +69,15 @@ clutter_input_device_xi2_constructed (GObject *gobject)
e47e58
 
e47e58
   if (G_OBJECT_CLASS (clutter_input_device_xi2_parent_class)->constructed)
e47e58
     G_OBJECT_CLASS (clutter_input_device_xi2_parent_class)->constructed (gobject);
e47e58
+
e47e58
+#ifdef HAVE_LIBWACOM
e47e58
+  if (clutter_input_device_get_device_type (CLUTTER_INPUT_DEVICE (gobject)) == CLUTTER_PAD_DEVICE)
e47e58
+    {
e47e58
+      device_xi2->group_modes = g_array_new (FALSE, TRUE, sizeof (guint));
e47e58
+      g_array_set_size (device_xi2->group_modes,
e47e58
+                        clutter_input_device_get_n_mode_groups (CLUTTER_INPUT_DEVICE (gobject)));
e47e58
+    }
e47e58
+#endif
e47e58
 }
e47e58
 
e47e58
 static gboolean
e47e58
@@ -99,6 +109,8 @@ clutter_input_device_xi2_finalize (GObject *object)
e47e58
 
e47e58
   if (device_xi2->wacom_device)
e47e58
     libwacom_destroy (device_xi2->wacom_device);
e47e58
+
e47e58
+  g_array_unref (device_xi2->group_modes);
e47e58
 #endif
e47e58
 
e47e58
   G_OBJECT_CLASS (clutter_input_device_xi2_parent_class)->finalize (object);
e47e58
@@ -292,4 +304,53 @@ clutter_input_device_xi2_ensure_wacom_info (ClutterInputDevice  *device,
e47e58
   device_xi2->wacom_device = libwacom_new_from_path (wacom_db, node_path,
e47e58
                                                      WFALLBACK_NONE, NULL);
e47e58
 }
e47e58
+
e47e58
+guint
e47e58
+clutter_input_device_xi2_get_pad_group_mode (ClutterInputDevice *device,
e47e58
+                                             guint               group)
e47e58
+{
e47e58
+  ClutterInputDeviceXI2 *device_xi2 = CLUTTER_INPUT_DEVICE_XI2 (device);
e47e58
+
e47e58
+  if (group >= device_xi2->group_modes->len)
e47e58
+    return 0;
e47e58
+
e47e58
+  return g_array_index (device_xi2->group_modes, guint, group);
e47e58
+}
e47e58
+
e47e58
+void
e47e58
+clutter_input_device_xi2_update_pad_state (ClutterInputDevice *device,
e47e58
+                                           guint               button,
e47e58
+                                           guint               state,
e47e58
+                                           guint              *group,
e47e58
+                                           guint              *mode)
e47e58
+{
e47e58
+  ClutterInputDeviceXI2 *device_xi2 = CLUTTER_INPUT_DEVICE_XI2 (device);
e47e58
+  guint button_group, *group_mode;
e47e58
+  gboolean is_mode_switch = FALSE;
e47e58
+
e47e58
+  button_group = clutter_input_device_xi2_get_button_group (device, button);
e47e58
+  is_mode_switch = button_group >= 0;
e47e58
+
e47e58
+  /* Assign all non-mode-switch buttons to group 0 so far */
e47e58
+  button_group = MAX (0, button_group);
e47e58
+
e47e58
+  if (button_group >= device_xi2->group_modes->len)
e47e58
+    return;
e47e58
+
e47e58
+  group_mode = &g_array_index (device_xi2->group_modes, guint, button_group);
e47e58
+
e47e58
+  if (is_mode_switch && state)
e47e58
+    {
e47e58
+      guint next, n_modes;
e47e58
+
e47e58
+      n_modes = clutter_input_device_get_group_n_modes (device, button_group);
e47e58
+      next = (*group_mode + 1) % n_modes;
e47e58
+      *group_mode = next;
e47e58
+    }
e47e58
+
e47e58
+  if (group)
e47e58
+    *group = button_group;
e47e58
+  if (mode)
e47e58
+    *mode = *group_mode;
e47e58
+}
e47e58
 #endif
e47e58
diff --git a/clutter/clutter/x11/clutter-input-device-xi2.h b/clutter/clutter/x11/clutter-input-device-xi2.h
e47e58
index e30fb4d..2194e1b 100644
e47e58
--- a/clutter/clutter/x11/clutter-input-device-xi2.h
e47e58
+++ b/clutter/clutter/x11/clutter-input-device-xi2.h
e47e58
@@ -53,6 +53,15 @@ ClutterInputDeviceTool * clutter_input_device_xi2_get_current_tool (ClutterInput
e47e58
 void clutter_input_device_xi2_ensure_wacom_info (ClutterInputDevice  *device,
e47e58
                                                  WacomDeviceDatabase *wacom_db);
e47e58
 
e47e58
+guint clutter_input_device_xi2_get_pad_group_mode (ClutterInputDevice *device,
e47e58
+                                                   guint               group);
e47e58
+
e47e58
+void clutter_input_device_xi2_update_pad_state (ClutterInputDevice *device,
e47e58
+                                                guint               button,
e47e58
+                                                guint               state,
e47e58
+                                                guint              *group,
e47e58
+                                                guint              *mode);
e47e58
+
e47e58
 #endif
e47e58
 
e47e58
 G_END_DECLS
e47e58
-- 
e47e58
1.8.3.1
e47e58