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
This commit is contained in:
Carlos Garnacho 2016-12-28 11:41:23 +01:00
parent 8bcdf9ba61
commit 9d38ffa6e3
4 changed files with 65 additions and 0 deletions

View File

@ -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 */

View File

@ -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)
{

View File

@ -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);

View File

@ -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",