accel-parse: Add keycode parsing as well

This commit is contained in:
Jasper St. Pierre 2014-04-07 11:05:46 -04:00
parent 50e69109b6
commit 616f1a09b1

View File

@ -182,17 +182,20 @@ is_keycode (const gchar *string)
} }
static void static void
do_accelerator_parse (const gchar *accelerator, accelerator_parse (const gchar *accelerator,
guint *accelerator_key, guint *accelerator_key,
guint *accelerator_keycode,
GdkModifierType *accelerator_mods) GdkModifierType *accelerator_mods)
{ {
guint keyval; guint keyval, keycode;
GdkModifierType mods; GdkModifierType mods;
gint len; gint len;
gboolean error; gboolean error;
if (accelerator_key) if (accelerator_key)
*accelerator_key = 0; *accelerator_key = 0;
if (accelerator_keycode)
*accelerator_keycode = 0;
if (accelerator_mods) if (accelerator_mods)
*accelerator_mods = 0; *accelerator_mods = 0;
g_return_if_fail (accelerator != NULL); g_return_if_fail (accelerator != NULL);
@ -301,9 +304,7 @@ do_accelerator_parse (const gchar *accelerator,
{ {
if (len >= 4 && is_keycode (accelerator)) if (len >= 4 && is_keycode (accelerator))
{ {
/* There was a keycode in the string, but keycode = strtoul (accelerator, NULL, 16);
* we cannot store it, so we have an error */
error = TRUE;
goto out; goto out;
} }
else if (strcmp (accelerator, "Above_Tab") == 0) else if (strcmp (accelerator, "Above_Tab") == 0)
@ -328,32 +329,16 @@ do_accelerator_parse (const gchar *accelerator,
out: out:
if (error) if (error)
keyval = mods = 0; keyval = keycode = mods = 0;
if (accelerator_key) if (accelerator_key)
*accelerator_key = gdk_keyval_to_lower (keyval); *accelerator_key = gdk_keyval_to_lower (keyval);
if (accelerator_keycode)
*accelerator_keycode = keycode;
if (accelerator_mods) if (accelerator_mods)
*accelerator_mods = mods; *accelerator_mods = mods;
} }
static void
accelerator_parse (const char *accel,
guint *keysym,
guint *keycode,
GdkModifierType *keymask)
{
if (accel[0] == '0' && accel[1] == 'x')
{
*keysym = 0;
*keycode = (guint) strtoul (accel, NULL, 16);
*keymask = 0;
return;
}
do_accelerator_parse (accel, keysym, keymask);
}
gboolean gboolean
meta_parse_accelerator (const char *accel, meta_parse_accelerator (const char *accel,
unsigned int *keysym, unsigned int *keysym,