Patch from Ed Catmur to fix keybindings with hex-values (coming from

2006-08-21  Elijah Newren  <newren gmail com>

	Patch from Ed Catmur to fix keybindings with hex-values (coming
	from special extended keyboard keys).  #140448.

	* src/keybindings.c (struct _MetaKeyBinding): change keycode from
	KeyCode to unsigned int (comment from Elijah: why???),
	(reload_keycodes): only grab keysyms for keybindings that have
	them, (count_bindings, rebuild_binding_table): bindings can be
	valid either due to a valid keysym or a valid keycode,
	(display_get_keybinding_action, meta_change_keygrab,
	process_tab_grab, process_workspace_switch_grab): handle keycode
	as well as keysym

	* src/prefs.[ch] (struct MetaKeyCombo, update_binding,
	update_list_binding): handle keycode as well as keysym

	* src/ui.[ch] (meta_ui_accelerator_parse): new function special
	cases strings of the form "0x[0-9a-fA-F]+" and otherwise calling
	gtk_accelerator_parse(), (meta_ui_parse_accelerator,
	meta_ui_parse_modifier): call meta_ui_accelerator_parse instead of
	gtk_accelerator_parse.
This commit is contained in:
Elijah Newren 2006-08-21 19:06:26 +00:00 committed by Elijah Newren
parent b42e848986
commit 88b9efd0b7
6 changed files with 88 additions and 23 deletions

View File

@ -1,3 +1,26 @@
2006-08-21 Elijah Newren <newren gmail com>
Patch from Ed Catmur to fix keybindings with hex-values (coming
from special extended keyboard keys). #140448.
* src/keybindings.c (struct _MetaKeyBinding): change keycode from
KeyCode to unsigned int (comment from Elijah: why???),
(reload_keycodes): only grab keysyms for keybindings that have
them, (count_bindings, rebuild_binding_table): bindings can be
valid either due to a valid keysym or a valid keycode,
(display_get_keybinding_action, meta_change_keygrab,
process_tab_grab, process_workspace_switch_grab): handle keycode
as well as keysym
* src/prefs.[ch] (struct MetaKeyCombo, update_binding,
update_list_binding): handle keycode as well as keysym
* src/ui.[ch] (meta_ui_accelerator_parse): new function special
cases strings of the form "0x[0-9a-fA-F]+" and otherwise calling
gtk_accelerator_parse(), (meta_ui_parse_accelerator,
meta_ui_parse_modifier): call meta_ui_accelerator_parse instead of
gtk_accelerator_parse.
2006-08-21 Elijah Newren <newren gmail com> 2006-08-21 Elijah Newren <newren gmail com>
Allow drags & resizes to be reverted by hitting escape. Based on Allow drags & resizes to be reverted by hitting escape. Based on

View File

@ -238,8 +238,8 @@ struct _MetaKeyBinding
{ {
const char *name; const char *name;
KeySym keysym; KeySym keysym;
KeyCode keycode;
unsigned int mask; unsigned int mask;
unsigned int keycode;
MetaVirtualModifier modifiers; MetaVirtualModifier modifiers;
const MetaKeyHandler *handler; const MetaKeyHandler *handler;
}; };
@ -563,8 +563,9 @@ reload_keycodes (MetaDisplay *display)
i = 0; i = 0;
while (i < display->n_screen_bindings) while (i < display->n_screen_bindings)
{ {
display->screen_bindings[i].keycode = XKeysymToKeycode (display->xdisplay, if (display->screen_bindings[i].keycode == 0)
display->screen_bindings[i].keysym); display->screen_bindings[i].keycode = XKeysymToKeycode (
display->xdisplay, display->screen_bindings[i].keysym);
++i; ++i;
} }
@ -577,8 +578,9 @@ reload_keycodes (MetaDisplay *display)
i = 0; i = 0;
while (i < display->n_window_bindings) while (i < display->n_window_bindings)
{ {
display->window_bindings[i].keycode = XKeysymToKeycode (display->xdisplay, if (display->window_bindings[i].keycode == 0)
display->window_bindings[i].keysym); display->window_bindings[i].keycode = XKeysymToKeycode (
display->xdisplay, display->window_bindings[i].keysym);
++i; ++i;
} }
@ -651,7 +653,7 @@ count_bindings (const MetaKeyPref *prefs,
{ {
MetaKeyCombo *combo = tmp->data; MetaKeyCombo *combo = tmp->data;
if (combo && combo->keysym != None) if (combo && (combo->keysym != None || combo->keycode != 0))
{ {
count += 1; count += 1;
@ -693,13 +695,13 @@ rebuild_binding_table (MetaDisplay *display,
{ {
MetaKeyCombo *combo = tmp->data; MetaKeyCombo *combo = tmp->data;
if (combo && combo->keysym != None) if (combo && (combo->keysym != None || combo->keycode != 0))
{ {
(*bindings_p)[dest].name = prefs[src].name; (*bindings_p)[dest].name = prefs[src].name;
(*bindings_p)[dest].keysym = combo->keysym; (*bindings_p)[dest].keysym = combo->keysym;
(*bindings_p)[dest].keycode = combo->keycode;
(*bindings_p)[dest].modifiers = combo->modifiers; (*bindings_p)[dest].modifiers = combo->modifiers;
(*bindings_p)[dest].mask = 0; (*bindings_p)[dest].mask = 0;
(*bindings_p)[dest].keycode = 0;
++dest; ++dest;
@ -712,10 +714,10 @@ rebuild_binding_table (MetaDisplay *display,
(*bindings_p)[dest].name = prefs[src].name; (*bindings_p)[dest].name = prefs[src].name;
(*bindings_p)[dest].keysym = combo->keysym; (*bindings_p)[dest].keysym = combo->keysym;
(*bindings_p)[dest].keycode = combo->keycode;
(*bindings_p)[dest].modifiers = combo->modifiers | (*bindings_p)[dest].modifiers = combo->modifiers |
META_VIRTUAL_SHIFT_MASK; META_VIRTUAL_SHIFT_MASK;
(*bindings_p)[dest].mask = 0; (*bindings_p)[dest].mask = 0;
(*bindings_p)[dest].keycode = 0;
++dest; ++dest;
} }
@ -816,6 +818,7 @@ regrab_window_bindings (MetaDisplay *display)
static MetaKeyBindingAction static MetaKeyBindingAction
display_get_keybinding_action (MetaDisplay *display, display_get_keybinding_action (MetaDisplay *display,
unsigned int keysym, unsigned int keysym,
unsigned int keycode,
unsigned long mask) unsigned long mask)
{ {
int i; int i;
@ -824,6 +827,7 @@ display_get_keybinding_action (MetaDisplay *display,
while (i >= 0) while (i >= 0)
{ {
if (display->screen_bindings[i].keysym == keysym && if (display->screen_bindings[i].keysym == keysym &&
display->screen_bindings[i].keycode == keycode &&
display->screen_bindings[i].mask == mask) display->screen_bindings[i].mask == mask)
{ {
return meta_prefs_get_keybinding_action (display->screen_bindings[i].name); return meta_prefs_get_keybinding_action (display->screen_bindings[i].name);
@ -982,9 +986,9 @@ meta_change_keygrab (MetaDisplay *display,
*/ */
meta_topic (META_DEBUG_KEYBINDINGS, meta_topic (META_DEBUG_KEYBINDINGS,
"%s keybinding %s mask 0x%x on 0x%lx\n", "%s keybinding %s keycode %d mask 0x%x on 0x%lx\n",
grab ? "Grabbing" : "Ungrabbing", grab ? "Grabbing" : "Ungrabbing",
keysym_name (keysym), keysym_name (keysym), keycode,
modmask, xwindow); modmask, xwindow);
/* efficiency, avoid so many XSync() */ /* efficiency, avoid so many XSync() */
@ -2421,6 +2425,7 @@ process_tab_grab (MetaDisplay *display,
prev_window = meta_display_lookup_x_window (display, prev_xwindow); prev_window = meta_display_lookup_x_window (display, prev_xwindow);
action = display_get_keybinding_action (display, action = display_get_keybinding_action (display,
keysym, keysym,
event->xkey.keycode,
display->grab_mask); display->grab_mask);
/* Cancel when alt-Escape is pressed during using alt-Tab, and vice /* Cancel when alt-Escape is pressed during using alt-Tab, and vice
@ -2881,6 +2886,7 @@ process_workspace_switch_grab (MetaDisplay *display,
action = display_get_keybinding_action (display, action = display_get_keybinding_action (display,
keysym, keysym,
event->xkey.keycode,
display->grab_mask); display->grab_mask);
switch (action) switch (action)

View File

@ -2151,6 +2151,7 @@ update_binding (MetaKeyPref *binding,
const char *value) const char *value)
{ {
unsigned int keysym; unsigned int keysym;
unsigned int keycode;
MetaVirtualModifier mods; MetaVirtualModifier mods;
MetaKeyCombo *combo; MetaKeyCombo *combo;
gboolean changed; gboolean changed;
@ -2160,10 +2161,11 @@ update_binding (MetaKeyPref *binding,
binding->name, value ? value : "none"); binding->name, value ? value : "none");
keysym = 0; keysym = 0;
keycode = 0;
mods = 0; mods = 0;
if (value) if (value)
{ {
if (!meta_ui_parse_accelerator (value, &keysym, &mods)) if (!meta_ui_parse_accelerator (value, &keysym, &keycode, &mods))
{ {
meta_topic (META_DEBUG_KEYBINDINGS, meta_topic (META_DEBUG_KEYBINDINGS,
"Failed to parse new gconf value\n"); "Failed to parse new gconf value\n");
@ -2246,16 +2248,19 @@ update_binding (MetaKeyPref *binding,
changed = FALSE; changed = FALSE;
if (keysym != combo->keysym || if (keysym != combo->keysym ||
keycode != combo->keycode ||
mods != combo->modifiers) mods != combo->modifiers)
{ {
changed = TRUE; changed = TRUE;
combo->keysym = keysym; combo->keysym = keysym;
combo->keycode = keycode;
combo->modifiers = mods; combo->modifiers = mods;
meta_topic (META_DEBUG_KEYBINDINGS, meta_topic (META_DEBUG_KEYBINDINGS,
"New keybinding for \"%s\" is keysym = 0x%x mods = 0x%x\n", "New keybinding for \"%s\" is keysym = 0x%x keycode = 0x%x mods = 0x%x\n",
binding->name, combo->keysym, combo->modifiers); binding->name, combo->keysym, combo->keycode,
combo->modifiers);
} }
else else
{ {
@ -2272,6 +2277,7 @@ update_list_binding (MetaKeyPref *binding,
MetaStringListType type_of_value) MetaStringListType type_of_value)
{ {
unsigned int keysym; unsigned int keysym;
unsigned int keycode;
MetaVirtualModifier mods; MetaVirtualModifier mods;
gboolean changed = FALSE; gboolean changed = FALSE;
const gchar *pref_string; const gchar *pref_string;
@ -2308,6 +2314,7 @@ update_list_binding (MetaKeyPref *binding,
while (pref_iterator) while (pref_iterator)
{ {
keysym = 0; keysym = 0;
keycode = 0;
mods = 0; mods = 0;
if (!pref_iterator->data) if (!pref_iterator->data)
@ -2328,7 +2335,7 @@ update_list_binding (MetaKeyPref *binding,
g_assert_not_reached (); g_assert_not_reached ();
} }
if (!meta_ui_parse_accelerator (pref_string, &keysym, &mods)) if (!meta_ui_parse_accelerator (pref_string, &keysym, &keycode, &mods))
{ {
meta_topic (META_DEBUG_KEYBINDINGS, meta_topic (META_DEBUG_KEYBINDINGS,
"Failed to parse new gconf value\n"); "Failed to parse new gconf value\n");
@ -2363,12 +2370,13 @@ update_list_binding (MetaKeyPref *binding,
combo = g_malloc0 (sizeof (MetaKeyCombo)); combo = g_malloc0 (sizeof (MetaKeyCombo));
combo->keysym = keysym; combo->keysym = keysym;
combo->keycode = keycode;
combo->modifiers = mods; combo->modifiers = mods;
binding->bindings->next = g_slist_prepend (binding->bindings->next, combo); binding->bindings->next = g_slist_prepend (binding->bindings->next, combo);
meta_topic (META_DEBUG_KEYBINDINGS, meta_topic (META_DEBUG_KEYBINDINGS,
"New keybinding for \"%s\" is keysym = 0x%x mods = 0x%x\n", "New keybinding for \"%s\" is keysym = 0x%x keycode = 0x%x mods = 0x%x\n",
binding->name, keysym, mods); binding->name, keysym, keycode, mods);
pref_iterator = pref_iterator->next; pref_iterator = pref_iterator->next;
} }

View File

@ -257,6 +257,7 @@ typedef enum _MetaKeyBindingAction
typedef struct typedef struct
{ {
unsigned int keysym; unsigned int keysym;
unsigned int keycode;
MetaVirtualModifier modifiers; MetaVirtualModifier modifiers;
} MetaKeyCombo; } MetaKeyCombo;

View File

@ -34,8 +34,13 @@
#include <pango/pangox.h> #include <pango/pangox.h>
#include <string.h> #include <string.h>
#include <stdlib.h>
static void meta_stock_icons_init (void); static void meta_stock_icons_init (void);
static void meta_ui_accelerator_parse (const char *accel,
guint *keysym,
guint *keycode,
GdkModifierType *keymask);
struct _MetaUI struct _MetaUI
{ {
@ -737,31 +742,51 @@ meta_ui_have_a_theme (void)
return meta_theme_get_current () != NULL; return meta_theme_get_current () != NULL;
} }
static void
meta_ui_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;
}
else
gtk_accelerator_parse (accel, keysym, keymask);
}
gboolean gboolean
meta_ui_parse_accelerator (const char *accel, meta_ui_parse_accelerator (const char *accel,
unsigned int *keysym, unsigned int *keysym,
unsigned int *keycode,
MetaVirtualModifier *mask) MetaVirtualModifier *mask)
{ {
GdkModifierType gdk_mask = 0; GdkModifierType gdk_mask = 0;
guint gdk_sym = 0; guint gdk_sym = 0;
guint gdk_code = 0;
*keysym = 0; *keysym = 0;
*keycode = 0;
*mask = 0; *mask = 0;
if (strcmp (accel, "disabled") == 0) if (strcmp (accel, "disabled") == 0)
return TRUE; return TRUE;
gtk_accelerator_parse (accel, &gdk_sym, &gdk_mask); meta_ui_accelerator_parse (accel, &gdk_sym, &gdk_code, &gdk_mask);
if (gdk_mask == 0 && gdk_sym == 0) if (gdk_mask == 0 && gdk_sym == 0 && gdk_code == 0)
return FALSE; return FALSE;
if (gdk_sym == None) if (gdk_sym == None && gdk_code == 0)
return FALSE; return FALSE;
if (gdk_mask & GDK_RELEASE_MASK) /* we don't allow this */ if (gdk_mask & GDK_RELEASE_MASK) /* we don't allow this */
return FALSE; return FALSE;
*keysym = gdk_sym; *keysym = gdk_sym;
*keycode = gdk_code;
if (gdk_mask & GDK_SHIFT_MASK) if (gdk_mask & GDK_SHIFT_MASK)
*mask |= META_VIRTUAL_SHIFT_MASK; *mask |= META_VIRTUAL_SHIFT_MASK;
@ -830,17 +855,18 @@ meta_ui_parse_modifier (const char *accel,
{ {
GdkModifierType gdk_mask = 0; GdkModifierType gdk_mask = 0;
guint gdk_sym = 0; guint gdk_sym = 0;
guint gdk_code = 0;
*mask = 0; *mask = 0;
if (strcmp (accel, "disabled") == 0) if (strcmp (accel, "disabled") == 0)
return TRUE; return TRUE;
gtk_accelerator_parse (accel, &gdk_sym, &gdk_mask); meta_ui_accelerator_parse (accel, &gdk_sym, &gdk_code, &gdk_mask);
if (gdk_mask == 0 && gdk_sym == 0) if (gdk_mask == 0 && gdk_sym == 0 && gdk_code == 0)
return FALSE; return FALSE;
if (gdk_sym != None) if (gdk_sym != None || gdk_code != 0)
return FALSE; return FALSE;
if (gdk_mask & GDK_RELEASE_MASK) /* we don't allow this */ if (gdk_mask & GDK_RELEASE_MASK) /* we don't allow this */

View File

@ -179,6 +179,7 @@ gboolean meta_ui_have_a_theme (void);
gboolean meta_ui_parse_accelerator (const char *accel, gboolean meta_ui_parse_accelerator (const char *accel,
unsigned int *keysym, unsigned int *keysym,
unsigned int *keycode,
MetaVirtualModifier *mask); MetaVirtualModifier *mask);
gboolean meta_ui_parse_modifier (const char *accel, gboolean meta_ui_parse_modifier (const char *accel,
MetaVirtualModifier *mask); MetaVirtualModifier *mask);