diff --git a/clutter/clutter/clutter-device-manager-private.h b/clutter/clutter/clutter-device-manager-private.h index 108e8c5f4..a5544675f 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 2930e5625..89aa09ef6 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 66b2a58ba..f9b3edcfe 100644 --- a/clutter/clutter/clutter-input-device.h +++ b/clutter/clutter/clutter-input-device.h @@ -147,6 +147,14 @@ gint clutter_input_device_get_n_strips (ClutterInputDev 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); diff --git a/clutter/clutter/evdev/clutter-input-device-evdev.c b/clutter/clutter/evdev/clutter-input-device-evdev.c index cf7d117c2..9ad89357b 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",