Improve error handling of calls to XGrabKey #431

This commit is contained in:
Tomeu Vizoso 2009-02-26 13:01:58 +01:00
parent 6508128adc
commit 7d69328162

View File

@ -173,7 +173,7 @@ grab_key (SugarKeyGrabber *grabber, Key *key, gboolean grab)
int indexes[N_BITS];/*indexes of bits we need to flip*/
int i, bit, bits_set_cnt;
int uppervalue;
guint mask_to_traverse = IGNORED_MODS & ~ key->state;
guint mask_to_traverse = IGNORED_MODS & ~key->state & GDK_MODIFIER_MASK;
bit = 0;
for (i = 0; i < N_BITS; i++) {
@ -200,11 +200,13 @@ grab_key (SugarKeyGrabber *grabber, Key *key, gboolean grab)
void
sugar_key_grabber_grab_keys(SugarKeyGrabber *grabber, const char **keys)
{
char **cur = keys;
char *key;
Key *keyinfo;
const char **cur = keys;
const char *key;
Key *keyinfo = NULL;
int min_keycodes, max_keycodes;
gdk_error_trap_push();
XDisplayKeycodes(GDK_DISPLAY_XDISPLAY(gdk_display_get_default()),
&min_keycodes, &max_keycodes);
while (*cur != NULL) {
key = *cur;
@ -213,16 +215,34 @@ sugar_key_grabber_grab_keys(SugarKeyGrabber *grabber, const char **keys)
keyinfo = g_new0 (Key, 1);
keyinfo->key = g_strdup(key);
egg_accelerator_parse_virtual (key, &keyinfo->keysym,
&keyinfo->keycode, &keyinfo->state);
if (!egg_accelerator_parse_virtual (key, &keyinfo->keysym,
&keyinfo->keycode,
&keyinfo->state)) {
g_warning ("Invalid key specified: %s", key);
continue;
}
if (keyinfo->keycode < min_keycodes || keyinfo->keycode > max_keycodes) {
g_warning ("Keycode out of bounds: %d for key %s", keyinfo->keycode, key);
continue;
}
gdk_error_trap_push();
grab_key(grabber, keyinfo, TRUE);
grabber->keys = g_list_append(grabber->keys, keyinfo);
}
gdk_flush();
gdk_error_trap_push();
gint error_code = gdk_error_trap_pop ();
if(!error_code)
grabber->keys = g_list_append(grabber->keys, keyinfo);
else if(error_code == BadAccess)
g_warning ("Grab failed, another application may already have access to key '%s'", key);
else if(error_code == BadValue)
g_warning ("Grab failed, invalid key %s specified. keysym: %u keycode: %u state: %u",
key, keyinfo->keysym, keyinfo->keycode, keyinfo->state);
else
g_warning ("Grab failed for key '%s' for unknown reason '%d'", key, error_code);
}
}
gboolean