From 0bf0e5780cb6e43a5130fc1c04ba5b024bc12b46 Mon Sep 17 00:00:00 2001 From: Carlos Garnacho Date: Thu, 22 Feb 2018 17:50:42 +0100 Subject: [PATCH] clutter/x11: Communicate proper group/mode on pad events. So we can trigger actions for the right mode. https://gitlab.gnome.org/GNOME/mutter/issues/48 Closes: #48 --- .../clutter/x11/clutter-device-manager-xi2.c | 15 ++++- .../clutter/x11/clutter-input-device-xi2.c | 61 +++++++++++++++++++ .../clutter/x11/clutter-input-device-xi2.h | 9 +++ 3 files changed, 84 insertions(+), 1 deletion(-) diff --git a/clutter/clutter/x11/clutter-device-manager-xi2.c b/clutter/clutter/x11/clutter-device-manager-xi2.c index b5a836aff..62f558380 100644 --- a/clutter/clutter/x11/clutter-device-manager-xi2.c +++ b/clutter/clutter/x11/clutter-device-manager-xi2.c @@ -1134,7 +1134,7 @@ translate_pad_event (ClutterEvent *event, ClutterInputDevice *device) { gdouble value; - guint number; + guint number, mode = 0; if (!translate_pad_axis (device, &xev->valuators, &event->any.type, @@ -1148,15 +1148,21 @@ translate_pad_event (ClutterEvent *event, if (xev->evtype == XI_Motion) value = -1; +#ifdef HAVE_LIBWACOM + mode = clutter_input_device_xi2_get_pad_group_mode (device, number); +#endif + if (event->any.type == CLUTTER_PAD_RING) { event->pad_ring.ring_number = number; event->pad_ring.angle = value; + event->pad_ring.mode = mode; } else { event->pad_strip.strip_number = number; event->pad_strip.value = value; + event->pad_strip.mode = mode; } event->any.time = xev->time; @@ -1383,6 +1389,13 @@ clutter_device_manager_xi2_translate_event (ClutterEventTranslator *translator, /* Pad buttons are 0-indexed */ event->pad_button.button = xev->detail - 1; +#ifdef HAVE_LIBWACOM + clutter_input_device_xi2_update_pad_state (device, + event->pad_button.button, + (xi_event->evtype == XI_ButtonPress), + &event->pad_button.group, + &event->pad_button.mode); +#endif clutter_event_set_device (event, device); clutter_event_set_source_device (event, source_device); diff --git a/clutter/clutter/x11/clutter-input-device-xi2.c b/clutter/clutter/x11/clutter-input-device-xi2.c index 2d9b6d238..f62ba85dc 100644 --- a/clutter/clutter/x11/clutter-input-device-xi2.c +++ b/clutter/clutter/x11/clutter-input-device-xi2.c @@ -48,6 +48,7 @@ struct _ClutterInputDeviceXI2 #ifdef HAVE_LIBWACOM WacomDevice *wacom_device; + GArray *group_modes; #endif }; @@ -68,6 +69,15 @@ clutter_input_device_xi2_constructed (GObject *gobject) if (G_OBJECT_CLASS (clutter_input_device_xi2_parent_class)->constructed) G_OBJECT_CLASS (clutter_input_device_xi2_parent_class)->constructed (gobject); + +#ifdef HAVE_LIBWACOM + if (clutter_input_device_get_device_type (CLUTTER_INPUT_DEVICE (gobject)) == CLUTTER_PAD_DEVICE) + { + device_xi2->group_modes = g_array_new (FALSE, TRUE, sizeof (guint)); + g_array_set_size (device_xi2->group_modes, + clutter_input_device_get_n_mode_groups (CLUTTER_INPUT_DEVICE (gobject))); + } +#endif } static gboolean @@ -99,6 +109,8 @@ clutter_input_device_xi2_finalize (GObject *object) if (device_xi2->wacom_device) libwacom_destroy (device_xi2->wacom_device); + + g_array_unref (device_xi2->group_modes); #endif G_OBJECT_CLASS (clutter_input_device_xi2_parent_class)->finalize (object); @@ -292,4 +304,53 @@ clutter_input_device_xi2_ensure_wacom_info (ClutterInputDevice *device, device_xi2->wacom_device = libwacom_new_from_path (wacom_db, node_path, WFALLBACK_NONE, NULL); } + +guint +clutter_input_device_xi2_get_pad_group_mode (ClutterInputDevice *device, + guint group) +{ + ClutterInputDeviceXI2 *device_xi2 = CLUTTER_INPUT_DEVICE_XI2 (device); + + if (group >= device_xi2->group_modes->len) + return 0; + + return g_array_index (device_xi2->group_modes, guint, group); +} + +void +clutter_input_device_xi2_update_pad_state (ClutterInputDevice *device, + guint button, + guint state, + guint *group, + guint *mode) +{ + ClutterInputDeviceXI2 *device_xi2 = CLUTTER_INPUT_DEVICE_XI2 (device); + guint button_group, *group_mode; + gboolean is_mode_switch = FALSE; + + button_group = clutter_input_device_xi2_get_button_group (device, button); + is_mode_switch = button_group >= 0; + + /* Assign all non-mode-switch buttons to group 0 so far */ + button_group = MAX (0, button_group); + + if (button_group >= device_xi2->group_modes->len) + return; + + group_mode = &g_array_index (device_xi2->group_modes, guint, button_group); + + if (is_mode_switch && state) + { + guint next, n_modes; + + n_modes = clutter_input_device_get_group_n_modes (device, button_group); + next = (*group_mode + 1) % n_modes; + *group_mode = next; + } + + if (group) + *group = button_group; + if (mode) + *mode = *group_mode; +} #endif diff --git a/clutter/clutter/x11/clutter-input-device-xi2.h b/clutter/clutter/x11/clutter-input-device-xi2.h index e30fb4d18..2194e1ba2 100644 --- a/clutter/clutter/x11/clutter-input-device-xi2.h +++ b/clutter/clutter/x11/clutter-input-device-xi2.h @@ -53,6 +53,15 @@ ClutterInputDeviceTool * clutter_input_device_xi2_get_current_tool (ClutterInput void clutter_input_device_xi2_ensure_wacom_info (ClutterInputDevice *device, WacomDeviceDatabase *wacom_db); +guint clutter_input_device_xi2_get_pad_group_mode (ClutterInputDevice *device, + guint group); + +void clutter_input_device_xi2_update_pad_state (ClutterInputDevice *device, + guint button, + guint state, + guint *group, + guint *mode); + #endif G_END_DECLS