keybindings: Have meta_accelerator_parse take a MetaKeyCombo

This commit is contained in:
Jasper St. Pierre 2015-01-06 18:59:53 -08:00
parent 3beb187cac
commit 13acf9e35d
4 changed files with 32 additions and 46 deletions

View File

@ -1407,7 +1407,7 @@ meta_display_grab_accelerator (MetaDisplay *display,
MetaKeyCombo combo; MetaKeyCombo combo;
MetaKeyDevirtCombo devirt_combo; MetaKeyDevirtCombo devirt_combo;
if (!meta_parse_accelerator (accelerator, &combo.keysym, &combo.keycode, &combo.modifiers)) if (!meta_parse_accelerator (accelerator, &combo))
{ {
meta_topic (META_DEBUG_KEYBINDINGS, meta_topic (META_DEBUG_KEYBINDINGS,
"Failed to parse accelerator\n"); "Failed to parse accelerator\n");

View File

@ -25,6 +25,7 @@
#include "config.h" #include "config.h"
#include "meta-accel-parse.h" #include "meta-accel-parse.h"
#include "keybindings-private.h"
#include <xkbcommon/xkbcommon.h> #include <xkbcommon/xkbcommon.h>
#include <string.h> #include <string.h>
@ -173,21 +174,16 @@ is_keycode (const gchar *string)
static gboolean static gboolean
accelerator_parse (const gchar *accelerator, accelerator_parse (const gchar *accelerator,
guint *accelerator_key, MetaKeyCombo *combo)
guint *accelerator_keycode,
MetaVirtualModifier *accelerator_mods)
{ {
gboolean error = FALSE; gboolean error = FALSE;
guint keyval, keycode; guint keyval, keycode;
MetaVirtualModifier mods; MetaVirtualModifier mods;
gint len; gint len;
if (accelerator_key) combo->keysym = 0;
*accelerator_key = 0; combo->keycode = 0;
if (accelerator_keycode) combo->modifiers = 0;
*accelerator_keycode = 0;
if (accelerator_mods)
*accelerator_mods = 0;
if (accelerator == NULL) if (accelerator == NULL)
{ {
@ -330,34 +326,35 @@ out:
if (error) if (error)
return FALSE; return FALSE;
if (accelerator_key) combo->keysym = keyval;
*accelerator_key = keyval; combo->keycode = keycode;
if (accelerator_keycode) combo->modifiers = mods;
*accelerator_keycode = keycode;
if (accelerator_mods)
*accelerator_mods = mods;
return TRUE; return TRUE;
} }
gboolean gboolean
meta_parse_accelerator (const char *accel, meta_parse_accelerator (const char *accel,
unsigned int *keysym, MetaKeyCombo *combo)
unsigned int *keycode,
MetaVirtualModifier *mask)
{ {
if (!accel[0] || strcmp (accel, "disabled") == 0) if (!accel[0] || strcmp (accel, "disabled") == 0)
return TRUE; return TRUE;
return accelerator_parse (accel, keysym, keycode, mask); return accelerator_parse (accel, combo);
} }
gboolean gboolean
meta_parse_modifier (const char *accel, meta_parse_modifier (const char *accel,
MetaVirtualModifier *mask) MetaVirtualModifier *mask)
{ {
MetaKeyCombo combo;
if (accel == NULL || !accel[0] || strcmp (accel, "disabled") == 0) if (accel == NULL || !accel[0] || strcmp (accel, "disabled") == 0)
return TRUE; return TRUE;
return accelerator_parse (accel, NULL, NULL, mask); if (!accelerator_parse (accel, &combo))
return FALSE;
*mask = combo.modifiers;
return TRUE;
} }

View File

@ -27,16 +27,16 @@
#include <glib.h> #include <glib.h>
#include <meta/common.h> #include <meta/common.h>
typedef struct _MetaKeyCombo MetaKeyCombo;
/* Not a real key symbol but means "key above the tab key"; this is /* Not a real key symbol but means "key above the tab key"; this is
* used as the default keybinding for cycle_group. * used as the default keybinding for cycle_group.
* 0x2xxxxxxx is a range not used by GDK or X. the remaining digits are * 0x2xxxxxxx is a range not used by GDK or X. the remaining digits are
* randomly chosen */ * randomly chosen */
#define META_KEY_ABOVE_TAB 0x2f7259c9 #define META_KEY_ABOVE_TAB 0x2f7259c9
gboolean meta_parse_accelerator (const char *accel, gboolean meta_parse_accelerator (const char *accel,
unsigned int *keysym, MetaKeyCombo *combo);
unsigned int *keycode,
MetaVirtualModifier *mask);
gboolean meta_parse_modifier (const char *accel, gboolean meta_parse_modifier (const char *accel,
MetaVirtualModifier *mask); MetaVirtualModifier *mask);

View File

@ -1672,10 +1672,7 @@ overlay_key_handler (GVariant *value,
*result = NULL; /* ignored */ *result = NULL; /* ignored */
string_value = g_variant_get_string (value, NULL); string_value = g_variant_get_string (value, NULL);
if (string_value && meta_parse_accelerator (string_value, if (string_value && meta_parse_accelerator (string_value, &combo))
&combo.keysym,
&combo.keycode,
NULL))
; ;
else else
{ {
@ -1684,6 +1681,8 @@ overlay_key_handler (GVariant *value,
return FALSE; return FALSE;
} }
combo.modifiers = 0;
if (overlay_key_combo.keysym != combo.keysym || if (overlay_key_combo.keysym != combo.keysym ||
overlay_key_combo.keycode != combo.keycode) overlay_key_combo.keycode != combo.keycode)
{ {
@ -1916,10 +1915,6 @@ update_binding (MetaKeyPref *binding,
{ {
GSList *old_combos, *a, *b; GSList *old_combos, *a, *b;
gboolean changed; gboolean changed;
unsigned int keysym;
unsigned int keycode;
MetaVirtualModifier mods;
MetaKeyCombo *combo;
int i; int i;
meta_topic (META_DEBUG_KEYBINDINGS, meta_topic (META_DEBUG_KEYBINDINGS,
@ -1931,31 +1926,25 @@ update_binding (MetaKeyPref *binding,
for (i = 0; strokes && strokes[i]; i++) for (i = 0; strokes && strokes[i]; i++)
{ {
keysym = 0; MetaKeyCombo *combo;
keycode = 0;
mods = 0;
if (!meta_parse_accelerator (strokes[i], &keysym, &keycode, &mods)) combo = g_malloc0 (sizeof (MetaKeyCombo));
if (!meta_parse_accelerator (strokes[i], combo))
{ {
meta_topic (META_DEBUG_KEYBINDINGS, meta_topic (META_DEBUG_KEYBINDINGS,
"Failed to parse new GSettings value\n"); "Failed to parse new GSettings value\n");
meta_warning ("\"%s\" found in configuration database is not a valid value for keybinding \"%s\"\n", meta_warning ("\"%s\" found in configuration database is not a valid value for keybinding \"%s\"\n",
strokes[i], binding->name); strokes[i], binding->name);
g_free (combo);
/* Value is kept and will thus be removed next time we save the key. /* Value is kept and will thus be removed next time we save the key.
* Changing the key in response to a modification could lead to cyclic calls. */ * Changing the key in response to a modification could lead to cyclic calls. */
continue; continue;
} }
combo = g_malloc0 (sizeof (MetaKeyCombo));
combo->keysym = keysym;
combo->keycode = keycode;
combo->modifiers = mods;
binding->combos = g_slist_prepend (binding->combos, combo); binding->combos = g_slist_prepend (binding->combos, combo);
meta_topic (META_DEBUG_KEYBINDINGS,
"New keybinding for \"%s\" is keysym = 0x%x keycode = 0x%x mods = 0x%x\n",
binding->name, keysym, keycode, mods);
} }
binding->combos = g_slist_reverse (binding->combos); binding->combos = g_slist_reverse (binding->combos);