From 907460376f9516ae16d7d29fd2230425e8610bc4 Mon Sep 17 00:00:00 2001 From: Alessandro Bono Date: Thu, 26 Sep 2024 00:37:47 +0200 Subject: [PATCH] prefs: Introduce new parsing mechanism for special keys The overlay-key and locate-pointer-key are special keys. They can be used together with other keys to create a combo or they can be used as a single key. This means that we are treating a modifier key as a regular key while still allowing to use it as part of a combo. This requires a special treatment that we can't extend to an arbitrary list of keys. However, we would like to use both Super_L and Super_R to activate the overview. In order to allow this, introduce a new parsing mechanism. With the new mechanism, if we fail to parse the configured string, we will try to parse again by appending _L first and _R later. If both succeed then we will use their combos for handling the special key. With this in place, we can configure Super as overlay-key. The parsing of Super will fail, but Super_L and Super_R will succeed. Allowing us to use both. Closes: https://gitlab.gnome.org/GNOME/mutter/-/issues/1277 Part-of: --- src/core/prefs.c | 25 +++++++++++++++++++++++-- 1 file changed, 23 insertions(+), 2 deletions(-) diff --git a/src/core/prefs.c b/src/core/prefs.c index c8e99ffef..5f68f09d0 100644 --- a/src/core/prefs.c +++ b/src/core/prefs.c @@ -1465,6 +1465,27 @@ button_layout_handler (GVariant *value, return TRUE; } +static gboolean +parse_special_key (const gchar *string_value, + MetaKeyCombo combos[2]) +{ + g_autofree gchar *string_value_l = NULL; + g_autofree gchar *string_value_r = NULL; + + if (meta_parse_accelerator (string_value, &combos[0])) + return TRUE; + + string_value_l = g_strconcat (string_value, "_L", NULL); + if (!meta_parse_accelerator (string_value_l, &combos[0])) + return FALSE; + + string_value_r = g_strconcat (string_value, "_R", NULL); + if (!meta_parse_accelerator (string_value_r, &combos[1])) + return FALSE; + + return TRUE; +} + static gboolean overlay_key_handler (GVariant *value, gpointer *result, @@ -1477,7 +1498,7 @@ overlay_key_handler (GVariant *value, *result = NULL; /* ignored */ string_value = g_variant_get_string (value, NULL); - if (!string_value || !meta_parse_accelerator (string_value, &combos[0])) + if (!string_value || !parse_special_key (string_value, combos)) { meta_topic (META_DEBUG_KEYBINDINGS, "Failed to parse value for overlay-key"); @@ -1511,7 +1532,7 @@ locate_pointer_key_handler (GVariant *value, *result = NULL; /* ignored */ string_value = g_variant_get_string (value, NULL); - if (!string_value || !meta_parse_accelerator (string_value, &combos[0])) + if (!string_value || !parse_special_key (string_value, combos)) { meta_topic (META_DEBUG_KEYBINDINGS, "Failed to parse value for locate-pointer-key");