src: fix case sensitive accelerator parsing
The gtk_accelerator_parse code is case sensitive when resolving key
names, however, the spice_hotkey_to_gtk_accelerator method converts
everything to uppercase. The latter allows the user to provide "f"
as the key and get it converted to "F" which matches a GDK key name.
The latter breaks for most other keys though, eg "comma" is required
to be all lowercase and "Menu" must have the initial capital.
To cope with this we try the gtk_accelerator_parse call twice, once
with the spice munged key name for back compat, and once with the
exact user specified key name.
https://gitlab.com/virt-viewer/virt-viewer/-/issues/30
Signed-off-by: Daniel P. Berrangé <berrange@redhat.com>
Daniel P. Berrangé
2 years ago
2845 | 2845 | guint accel_key; |
2846 | 2846 | GdkModifierType accel_mods; |
2847 | 2847 | const gchar *accels[] = { accel, NULL }; |
2848 | gtk_accelerator_parse(accel, &accel_key, &accel_mods); | |
2848 | ||
2849 | /* | |
2850 | * First try the spice translated accel. | |
2851 | * Works for basic modifiers and single letters/numbers | |
2852 | * where forced uppercasing matches GTK key names | |
2853 | */ | |
2854 | gtk_accelerator_parse(accels[0], &accel_key, &accel_mods); | |
2855 | ||
2856 | if (accel_key == 0 && accel_mods == 0) { | |
2857 | /* Fallback to native GTK accels to cope with | |
2858 | * case sensitive accels | |
2859 | */ | |
2860 | accels[0] = value; | |
2861 | gtk_accelerator_parse(accels[0], &accel_key, &accel_mods); | |
2862 | } | |
2849 | 2863 | |
2850 | 2864 | if (accel_key == 0 && accel_mods == 0) { |
2851 | 2865 | g_warning("Invalid value '%s' for key '%s'", value, *hotkey); |