From d6fc41b73e80fe7b8320254650a3bc058fa955be Mon Sep 17 00:00:00 2001 From: Carlos Garnacho Date: Wed, 28 Dec 2016 11:44:27 +0100 Subject: [PATCH] clutter: Add function to find out the number of modes for a pad group This is obtained in backend-dependent ways in the upper layers, seems better to let ClutterInputDevice provide this information. https://bugzilla.gnome.org/show_bug.cgi?id=771098 --- .../clutter/clutter-device-manager-private.h | 2 ++ clutter/clutter/clutter-input-device.c | 19 +++++++++++++++++++ clutter/clutter/clutter-input-device.h | 4 ++++ .../evdev/clutter-input-device-evdev.c | 14 ++++++++++++++ 4 files changed, 39 insertions(+) diff --git a/clutter/clutter/clutter-device-manager-private.h b/clutter/clutter/clutter-device-manager-private.h index a5544675f..37b2eec6c 100644 --- a/clutter/clutter/clutter-device-manager-private.h +++ b/clutter/clutter/clutter-device-manager-private.h @@ -158,6 +158,8 @@ struct _ClutterInputDeviceClass gboolean (* is_mode_switch_button) (ClutterInputDevice *device, guint group, guint button); + gint (* get_group_n_modes) (ClutterInputDevice *device, + gint group); }; /* Platform-dependent interface */ diff --git a/clutter/clutter/clutter-input-device.c b/clutter/clutter/clutter-input-device.c index 89aa09ef6..686e5a804 100644 --- a/clutter/clutter/clutter-input-device.c +++ b/clutter/clutter/clutter-input-device.c @@ -2175,6 +2175,25 @@ clutter_input_device_get_n_mode_groups (ClutterInputDevice *device) return device->n_mode_groups; } +gint +clutter_input_device_get_group_n_modes (ClutterInputDevice *device, + gint group) +{ + ClutterInputDeviceClass *device_class; + + g_return_val_if_fail (CLUTTER_IS_INPUT_DEVICE (device), 0); + g_return_val_if_fail (clutter_input_device_get_device_type (device) == + CLUTTER_PAD_DEVICE, 0); + g_return_val_if_fail (group >= 0, 0); + + device_class = CLUTTER_INPUT_DEVICE_GET_CLASS (device); + + if (device_class->get_group_n_modes) + return device_class->get_group_n_modes (device, group); + + return 0; +} + gboolean clutter_input_device_is_mode_switch_button (ClutterInputDevice *device, guint group, diff --git a/clutter/clutter/clutter-input-device.h b/clutter/clutter/clutter-input-device.h index f9b3edcfe..f80a48ce1 100644 --- a/clutter/clutter/clutter-input-device.h +++ b/clutter/clutter/clutter-input-device.h @@ -147,6 +147,10 @@ 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 +gint clutter_input_device_get_group_n_modes (ClutterInputDevice *device, + gint group); + CLUTTER_AVAILABLE_IN_ALL gboolean clutter_input_device_is_mode_switch_button (ClutterInputDevice *device, guint group, diff --git a/clutter/clutter/evdev/clutter-input-device-evdev.c b/clutter/clutter/evdev/clutter-input-device-evdev.c index 9ad89357b..0dc578dde 100644 --- a/clutter/clutter/evdev/clutter-input-device-evdev.c +++ b/clutter/clutter/evdev/clutter-input-device-evdev.c @@ -180,6 +180,19 @@ clutter_input_device_evdev_is_mode_switch_button (ClutterInputDevice *device, return libinput_tablet_pad_mode_group_button_is_toggle (mode_group, button) != 0; } +static gint +clutter_input_device_evdev_get_group_n_modes (ClutterInputDevice *device, + gint group) +{ + 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_get_num_modes (mode_group); +} + static void clutter_input_device_evdev_class_init (ClutterInputDeviceEvdevClass *klass) { @@ -192,6 +205,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; + klass->get_group_n_modes = clutter_input_device_evdev_get_group_n_modes; obj_props[PROP_DEVICE_MATRIX] = g_param_spec_boxed ("device-matrix",