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
This commit is contained in:
parent
d7c5e57134
commit
0bf0e5780c
@ -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);
|
||||
|
||||
|
@ -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
|
||||
|
@ -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
|
||||
|
Loading…
Reference in New Issue
Block a user