diff options
author | Carlos Garnacho <carlosg@gnome.org> | 2021-07-16 13:10:48 +0200 |
---|---|---|
committer | Carlos Garnacho <carlosg@gnome.org> | 2021-09-20 16:44:17 +0200 |
commit | ba7fecf57986b888be613e166a2a98d3df2ead92 (patch) | |
tree | 436ed792e051832e0c83c94fee74cb0164b7899f | |
parent | 7c828ef500292658f5f5255a89a38e90b63a21ad (diff) | |
download | mutter-wip/carlosg/pad-ring-strip-action-labels.tar.gz |
core: Mark both directions in rings/strips as (un)handled altogetherwip/carlosg/pad-ring-strip-action-labels
If going on a direction has a keycombo associated and the other does
not, it does not make sense to let the wayland bits handle pad
ring/strip events that only go in one direction.
Ensure that's the case, and also while figuring out the ring/strip
direction based on the initial events.
Fixes: https://gitlab.gnome.org/GNOME/mutter/-/issues/1889
-rw-r--r-- | src/core/meta-pad-action-mapper.c | 122 |
1 files changed, 89 insertions, 33 deletions
diff --git a/src/core/meta-pad-action-mapper.c b/src/core/meta-pad-action-mapper.c index 5b479a67d..ac34ea98f 100644 --- a/src/core/meta-pad-action-mapper.c +++ b/src/core/meta-pad-action-mapper.c @@ -640,27 +640,51 @@ meta_pad_action_mapper_handle_action (MetaPadActionMapper *mapper, guint number, guint mode) { - MetaPadDirection direction = = META_PAD_DIRECTION_NONE; - GSettings *settings; - gboolean handled = FALSE; - char *accel; + MetaPadDirection direction = META_PAD_DIRECTION_NONE; + g_autoptr (GSettings) settings1 = NULL, settings2 = NULL; + g_autofree char *accel1, *accel2; + gboolean handled; - if (!meta_pad_action_mapper_get_action_direction (mapper, - event, &direction)) - return FALSE; + if (action == META_PAD_ACTION_RING) + { + settings1 = lookup_pad_action_settings (pad, action, number, + META_PAD_DIRECTION_CW, mode); + settings2 = lookup_pad_action_settings (pad, action, number, + META_PAD_DIRECTION_CCW, mode); + } + else if (action == META_PAD_ACTION_STRIP) + { + settings1 = lookup_pad_action_settings (pad, action, number, + META_PAD_DIRECTION_UP, mode); + settings2 = lookup_pad_action_settings (pad, action, number, + META_PAD_DIRECTION_DOWN, mode); + } + else + { + return FALSE; + } - settings = lookup_pad_action_settings (pad, action, number, direction, mode); - accel = g_settings_get_string (settings, "keybinding"); + accel1 = g_settings_get_string (settings1, "keybinding"); + accel2 = g_settings_get_string (settings2, "keybinding"); + handled = ((accel1 && *accel1) || (accel2 && *accel2)); - if (accel && *accel) + if (meta_pad_action_mapper_get_action_direction (mapper, event, &direction)) { - meta_pad_action_mapper_emulate_keybinding (mapper, accel, TRUE); - meta_pad_action_mapper_emulate_keybinding (mapper, accel, FALSE); - handled = TRUE; - } + const gchar *accel; - g_object_unref (settings); - g_free (accel); + if (direction == META_PAD_DIRECTION_UP || + direction == META_PAD_DIRECTION_CW) + accel = accel1; + else if (direction == META_PAD_DIRECTION_DOWN || + direction == META_PAD_DIRECTION_CCW) + accel = accel2; + + if (accel && *accel) + { + meta_pad_action_mapper_emulate_keybinding (mapper, accel, TRUE); + meta_pad_action_mapper_emulate_keybinding (mapper, accel, FALSE); + } + } return handled; } @@ -694,29 +718,59 @@ meta_pad_action_mapper_handle_event (MetaPadActionMapper *mapper, } } +static void +format_directional_action (GString *str, + MetaPadDirection direction, + const gchar *action) +{ + switch (direction) + { + case META_PAD_DIRECTION_CW: + g_string_append_printf (str, "⭮ %s", action); + break; + case META_PAD_DIRECTION_CCW: + g_string_append_printf (str, "⭯ %s", action); + break; + case META_PAD_DIRECTION_UP: + g_string_append_printf (str, "↥ %s", action); + break; + case META_PAD_DIRECTION_DOWN: + g_string_append_printf (str, "↧ %s", action); + break; + case META_PAD_DIRECTION_NONE: + g_assert_not_reached (); + } +} static char * -compose_directional_action_label (GSettings *direction1, - GSettings *direction2) +compose_directional_action_label (MetaPadDirection direction1, + GSettings *value1, + MetaPadDirection direction2, + GSettings *value2) { - char *accel1, *accel2, *str = NULL; - /* TRANSLATORS: This is a (non) action on an input device gadget */ - const char *none_label = N_("None"); + g_autofree char *accel1, *accel2; + GString *str; + + accel1 = g_settings_get_string (value1, "keybinding"); + accel2 = g_settings_get_string (value2, "keybinding"); + + if ((!accel1 || !*accel1) && ((!accel2 || !*accel2))) + return NULL; - accel1 = g_settings_get_string (direction1, "keybinding"); - accel2 = g_settings_get_string (direction2, "keybinding"); + str = g_string_new (NULL); - if ((accel1 && *accel1) || (accel2 && *accel2)) + if (accel1 && *accel1) + format_directional_action (str, direction1, accel1); + + if (accel2 && *accel2) { - str = g_strdup_printf ("%s / %s", - (accel1 && *accel1) ? accel1 : _(none_label), - (accel2 && *accel2) ? accel2 : _(none_label)); - } + if (str->len != 0) + g_string_append (str, " / "); - g_free (accel1); - g_free (accel2); + format_directional_action (str, direction2, accel2); + } - return str; + return g_string_free (str, FALSE); } static char * @@ -733,7 +787,8 @@ meta_pad_action_mapper_get_ring_label (MetaPadActionMapper *mapper, META_PAD_DIRECTION_CW, mode); settings2 = lookup_pad_action_settings (pad, META_PAD_ACTION_RING, number, META_PAD_DIRECTION_CCW, mode); - label = compose_directional_action_label (settings1, settings2); + label = compose_directional_action_label (META_PAD_DIRECTION_CW, settings1, + META_PAD_DIRECTION_CCW, settings2); g_object_unref (settings1); g_object_unref (settings2); @@ -754,7 +809,8 @@ meta_pad_action_mapper_get_strip_label (MetaPadActionMapper *mapper, META_PAD_DIRECTION_UP, mode); settings2 = lookup_pad_action_settings (pad, META_PAD_ACTION_STRIP, number, META_PAD_DIRECTION_DOWN, mode); - label = compose_directional_action_label (settings1, settings2); + label = compose_directional_action_label (META_PAD_DIRECTION_UP, settings1, + META_PAD_DIRECTION_DOWN, settings2); g_object_unref (settings1); g_object_unref (settings2); |