Fix for keyboard focus bug when <alt>f.

This commit is contained in:
Tomeu Vizoso 2007-03-07 22:23:11 +01:00
parent 44f00a9cd8
commit 08e6546489
2 changed files with 26 additions and 3 deletions

View File

@ -103,11 +103,27 @@ get_key_from_event(SugarKeyGrabber *grabber, XEvent *xev)
keycode = xev->xkey.keycode; keycode = xev->xkey.keycode;
state = xev->xkey.state; state = xev->xkey.state;
if(grabber->last_key_pressed == keycode) {
grabber->last_key_pressed = 0;
}
if(grabber->last_key_pressed_modifier == state) {
grabber->last_key_pressed_modifier = 0;
}
for (l = grabber->keys; l != NULL; l = l->next) { for (l = grabber->keys; l != NULL; l = l->next) {
Key *keyinfo = (Key *)l->data; Key *keyinfo = (Key *)l->data;
if (keyinfo->keycode == keycode && if (keyinfo->keycode == keycode) {
(state & USED_MODS) == keyinfo->state) { if (xev->type == KeyPress &&
return g_strdup(keyinfo->key); (state & USED_MODS) == keyinfo->state) {
return g_strdup(keyinfo->key);
} else if (xev->type == KeyRelease) {
if(!grabber->last_key_pressed &&
!grabber->last_key_pressed_modifier) {
return g_strdup(keyinfo->key);
}
}
} }
} }
@ -139,6 +155,9 @@ filter_events(GdkXEvent *xevent, GdkEvent *event, gpointer data)
key = get_key_from_event(grabber, xevent); key = get_key_from_event(grabber, xevent);
if (key) { if (key) {
grabber->last_key_pressed = xev->xkey.keycode;
grabber->last_key_pressed_modifier = xev->xkey.state;
g_signal_emit (grabber, signals[KEY_PRESSED], 0, key); g_signal_emit (grabber, signals[KEY_PRESSED], 0, key);
g_free(key); g_free(key);
@ -161,6 +180,8 @@ sugar_key_grabber_init(SugarKeyGrabber *grabber)
screen = gdk_screen_get_default(); screen = gdk_screen_get_default();
grabber->root = gdk_screen_get_root_window(screen); grabber->root = gdk_screen_get_root_window(screen);
grabber->keys = NULL; grabber->keys = NULL;
grabber->last_key_pressed = 0;
grabber->last_key_pressed_modifier = 0;
gdk_window_add_filter(grabber->root, filter_events, grabber); gdk_window_add_filter(grabber->root, filter_events, grabber);
} }

View File

@ -39,6 +39,8 @@ struct _SugarKeyGrabber {
GdkWindow *root; GdkWindow *root;
GList *keys; GList *keys;
guint last_key_pressed;
guint last_key_pressed_modifier;
}; };
struct _SugarKeyGrabberClass { struct _SugarKeyGrabberClass {