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: <https://gitlab.gnome.org/GNOME/mutter/-/merge_requests/4050>
This commit is contained in:
Alessandro Bono 2024-09-26 00:37:47 +02:00 committed by Marge Bot
parent c051c2ff69
commit 907460376f

View File

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