keybindings: Use display_get_keybinding() instead of looping explicitly
Instead of looping over an array of keybindings to find the correct binding, just use display_get_keybinding(). In the next commit, we'll change the array to be a hash map, so this helps the patch be cleaner. https://bugzilla.gnome.org/show_bug.cgi?id=725588
This commit is contained in:
parent
2b3fc741fb
commit
266ac00e56
@ -754,6 +754,8 @@ display_get_keybinding (MetaDisplay *display,
|
|||||||
{
|
{
|
||||||
int i;
|
int i;
|
||||||
|
|
||||||
|
mask = mask & 0xff & ~display->ignored_modifier_mask;
|
||||||
|
|
||||||
i = display->n_key_bindings - 1;
|
i = display->n_key_bindings - 1;
|
||||||
while (i >= 0)
|
while (i >= 0)
|
||||||
{
|
{
|
||||||
@ -917,7 +919,6 @@ meta_display_get_keybinding_action (MetaDisplay *display,
|
|||||||
if (keycode == (unsigned int)display->overlay_key_combo.keycode)
|
if (keycode == (unsigned int)display->overlay_key_combo.keycode)
|
||||||
return META_KEYBINDING_ACTION_OVERLAY_KEY;
|
return META_KEYBINDING_ACTION_OVERLAY_KEY;
|
||||||
|
|
||||||
mask = mask & 0xff & ~display->ignored_modifier_mask;
|
|
||||||
binding = display_get_keybinding (display, keycode, mask);
|
binding = display_get_keybinding (display, keycode, mask);
|
||||||
|
|
||||||
if (binding)
|
if (binding)
|
||||||
@ -1301,7 +1302,6 @@ meta_display_grab_accelerator (MetaDisplay *display,
|
|||||||
guint mask = 0;
|
guint mask = 0;
|
||||||
MetaVirtualModifier modifiers = 0;
|
MetaVirtualModifier modifiers = 0;
|
||||||
GSList *l;
|
GSList *l;
|
||||||
int i;
|
|
||||||
|
|
||||||
if (!meta_ui_parse_accelerator (accelerator, &keysym, &keycode, &modifiers))
|
if (!meta_ui_parse_accelerator (accelerator, &keysym, &keycode, &modifiers))
|
||||||
{
|
{
|
||||||
@ -1318,10 +1318,8 @@ meta_display_grab_accelerator (MetaDisplay *display,
|
|||||||
if (keycode == 0)
|
if (keycode == 0)
|
||||||
return META_KEYBINDING_ACTION_NONE;
|
return META_KEYBINDING_ACTION_NONE;
|
||||||
|
|
||||||
for (i = 0; i < display->n_key_bindings; i++)
|
if (display_get_keybinding (display, keycode, mask))
|
||||||
if (display->key_bindings[i].keycode == keycode &&
|
return META_KEYBINDING_ACTION_NONE;
|
||||||
display->key_bindings[i].mask == mask)
|
|
||||||
return META_KEYBINDING_ACTION_NONE;
|
|
||||||
|
|
||||||
for (l = display->screens; l; l = l->next)
|
for (l = display->screens; l; l = l->next)
|
||||||
{
|
{
|
||||||
@ -1359,9 +1357,9 @@ gboolean
|
|||||||
meta_display_ungrab_accelerator (MetaDisplay *display,
|
meta_display_ungrab_accelerator (MetaDisplay *display,
|
||||||
guint action)
|
guint action)
|
||||||
{
|
{
|
||||||
|
MetaKeyBinding *binding;
|
||||||
MetaKeyGrab *grab;
|
MetaKeyGrab *grab;
|
||||||
char *key;
|
char *key;
|
||||||
int i;
|
|
||||||
|
|
||||||
g_return_val_if_fail (action != META_KEYBINDING_ACTION_NONE, FALSE);
|
g_return_val_if_fail (action != META_KEYBINDING_ACTION_NONE, FALSE);
|
||||||
|
|
||||||
@ -1370,27 +1368,26 @@ meta_display_ungrab_accelerator (MetaDisplay *display,
|
|||||||
if (!grab)
|
if (!grab)
|
||||||
return FALSE;
|
return FALSE;
|
||||||
|
|
||||||
for (i = 0; i < display->n_key_bindings; i++)
|
binding = display_get_keybinding (display,
|
||||||
if (display->key_bindings[i].keysym == grab->combo->keysym &&
|
grab->combo->keycode,
|
||||||
display->key_bindings[i].keycode == grab->combo->keycode &&
|
grab->combo->modifiers);
|
||||||
display->key_bindings[i].modifiers == grab->combo->modifiers)
|
if (binding)
|
||||||
{
|
{
|
||||||
GSList *l;
|
GSList *l;
|
||||||
for (l = display->screens; l; l = l->next)
|
for (l = display->screens; l; l = l->next)
|
||||||
{
|
{
|
||||||
MetaScreen *screen = l->data;
|
MetaScreen *screen = l->data;
|
||||||
meta_change_keygrab (display, screen->xroot, FALSE,
|
meta_change_keygrab (display, screen->xroot, FALSE,
|
||||||
display->key_bindings[i].keysym,
|
binding->keysym,
|
||||||
display->key_bindings[i].keycode,
|
binding->keycode,
|
||||||
display->key_bindings[i].mask);
|
binding->mask);
|
||||||
}
|
}
|
||||||
|
|
||||||
display->key_bindings[i].keysym = 0;
|
binding->keysym = 0;
|
||||||
display->key_bindings[i].keycode = 0;
|
binding->keycode = 0;
|
||||||
display->key_bindings[i].modifiers = 0;
|
binding->modifiers = 0;
|
||||||
display->key_bindings[i].mask = 0;
|
binding->mask = 0;
|
||||||
break;
|
}
|
||||||
}
|
|
||||||
|
|
||||||
g_hash_table_remove (external_grabs, key);
|
g_hash_table_remove (external_grabs, key);
|
||||||
g_free (key);
|
g_free (key);
|
||||||
@ -1673,7 +1670,7 @@ process_event (MetaKeyBinding *bindings,
|
|||||||
XIDeviceEvent *event,
|
XIDeviceEvent *event,
|
||||||
gboolean on_window)
|
gboolean on_window)
|
||||||
{
|
{
|
||||||
int i;
|
MetaKeyBinding *binding;
|
||||||
|
|
||||||
/* we used to have release-based bindings but no longer. */
|
/* we used to have release-based bindings but no longer. */
|
||||||
if (event->evtype == XI_KeyRelease)
|
if (event->evtype == XI_KeyRelease)
|
||||||
@ -1683,46 +1680,43 @@ process_event (MetaKeyBinding *bindings,
|
|||||||
* TODO: This would be better done with a hash table;
|
* TODO: This would be better done with a hash table;
|
||||||
* it doesn't suit to use O(n) for such a common operation.
|
* it doesn't suit to use O(n) for such a common operation.
|
||||||
*/
|
*/
|
||||||
for (i=0; i<n_bindings; i++)
|
binding = display_get_keybinding (display,
|
||||||
{
|
event->detail,
|
||||||
MetaKeyHandler *handler = bindings[i].handler;
|
event->mods.effective);
|
||||||
|
if (!binding ||
|
||||||
|
(!on_window && binding->flags & META_KEY_BINDING_PER_WINDOW) ||
|
||||||
|
meta_compositor_filter_keybinding (display->compositor, screen, binding))
|
||||||
|
goto not_found;
|
||||||
|
|
||||||
if ((!on_window && handler->flags & META_KEY_BINDING_PER_WINDOW) ||
|
/*
|
||||||
bindings[i].keycode != event->detail ||
|
* window must be non-NULL for on_window to be true,
|
||||||
((event->mods.effective & 0xff & ~(display->ignored_modifier_mask)) !=
|
* and so also window must be non-NULL if we get here and
|
||||||
bindings[i].mask) ||
|
* this is a META_KEY_BINDING_PER_WINDOW binding.
|
||||||
meta_compositor_filter_keybinding (display->compositor, screen, &bindings[i]))
|
*/
|
||||||
continue;
|
|
||||||
|
|
||||||
/*
|
meta_topic (META_DEBUG_KEYBINDINGS,
|
||||||
* window must be non-NULL for on_window to be true,
|
"Binding keycode 0x%x mask 0x%x matches event 0x%x state 0x%x\n",
|
||||||
* and so also window must be non-NULL if we get here and
|
binding->keycode, binding->mask,
|
||||||
* this is a META_KEY_BINDING_PER_WINDOW binding.
|
event->detail, event->mods.effective);
|
||||||
*/
|
|
||||||
|
|
||||||
meta_topic (META_DEBUG_KEYBINDINGS,
|
if (binding->handler == NULL)
|
||||||
"Binding keycode 0x%x mask 0x%x matches event 0x%x state 0x%x\n",
|
meta_bug ("Binding %s has no handler\n", binding->name);
|
||||||
bindings[i].keycode, bindings[i].mask,
|
else
|
||||||
event->detail, event->mods.effective);
|
meta_topic (META_DEBUG_KEYBINDINGS,
|
||||||
|
"Running handler for %s\n",
|
||||||
|
binding->name);
|
||||||
|
|
||||||
if (handler == NULL)
|
/* Global keybindings count as a let-the-terminal-lose-focus
|
||||||
meta_bug ("Binding %s has no handler\n", bindings[i].name);
|
* due to new window mapping until the user starts
|
||||||
else
|
* interacting with the terminal again.
|
||||||
meta_topic (META_DEBUG_KEYBINDINGS,
|
*/
|
||||||
"Running handler for %s\n",
|
display->allow_terminal_deactivation = TRUE;
|
||||||
bindings[i].name);
|
|
||||||
|
|
||||||
/* Global keybindings count as a let-the-terminal-lose-focus
|
invoke_handler (display, screen, binding->handler, window, event, binding);
|
||||||
* due to new window mapping until the user starts
|
|
||||||
* interacting with the terminal again.
|
|
||||||
*/
|
|
||||||
display->allow_terminal_deactivation = TRUE;
|
|
||||||
|
|
||||||
invoke_handler (display, screen, handler, window, event, &bindings[i]);
|
return TRUE;
|
||||||
|
|
||||||
return TRUE;
|
|
||||||
}
|
|
||||||
|
|
||||||
|
not_found:
|
||||||
meta_topic (META_DEBUG_KEYBINDINGS,
|
meta_topic (META_DEBUG_KEYBINDINGS,
|
||||||
"No handler found for this event in this binding table\n");
|
"No handler found for this event in this binding table\n");
|
||||||
return FALSE;
|
return FALSE;
|
||||||
|
Loading…
x
Reference in New Issue
Block a user