From cda33ca3e63e91a550952807bd3c6d7db8d40c5e Mon Sep 17 00:00:00 2001 From: Julien Danjou Date: Sat, 11 Apr 2009 18:02:31 +0200 Subject: [PATCH] key: cleanup modifiers system We stop retrieving useless key, since we have constant. We also grab correctly all keycode for a keysym. Signed-off-by: Julien Danjou --- awesome.c | 10 --------- awesomeConfig.cmake | 2 +- common/xutil.c | 44 -------------------------------------- common/xutil.h | 6 +----- event.c | 10 --------- key.c | 52 +++++++++++++++++++++++++-------------------- key.h | 2 +- structs.h | 6 ------ window.c | 4 ++-- 9 files changed, 34 insertions(+), 102 deletions(-) diff --git a/awesome.c b/awesome.c index 01cce4c15..dbf25a9f0 100644 --- a/awesome.c +++ b/awesome.c @@ -330,7 +330,6 @@ main(int argc, char **argv) const char *confpath = NULL; int xfd, i, screen_nbr, opt, colors_nbr; xcolor_init_request_t colors_reqs[2]; - xcb_get_modifier_mapping_cookie_t xmapping_cookie; ssize_t cmdlen = 1; xdgHandle xdg; static struct option long_options[] = @@ -473,10 +472,6 @@ main(int argc, char **argv) /* Allocate the key symbols */ globalconf.keysyms = xcb_key_symbols_alloc(globalconf.connection); - /* Send the request to get the NumLock, ShiftLock and CapsLock - masks */ - xmapping_cookie = xcb_get_modifier_mapping_unchecked(globalconf.connection); - /* init atom cache */ atoms_init(globalconf.connection); @@ -495,11 +490,6 @@ main(int argc, char **argv) for(colors_nbr = 0; colors_nbr < 2; colors_nbr++) xcolor_init_reply(colors_reqs[colors_nbr]); - /* Process the reply of previously sent mapping request */ - xutil_lock_mask_get(globalconf.connection, xmapping_cookie, - globalconf.keysyms, &globalconf.numlockmask, - &globalconf.shiftlockmask, &globalconf.capslockmask); - /* do this only for real screen */ for(screen_nbr = 0; screen_nbr < xcb_setup_roots_length(xcb_get_setup(globalconf.connection)); diff --git a/awesomeConfig.cmake b/awesomeConfig.cmake index 61e4aae9b..3a122dba6 100644 --- a/awesomeConfig.cmake +++ b/awesomeConfig.cmake @@ -140,7 +140,7 @@ pkg_check_modules(AWESOME_REQUIRED REQUIRED xcb-event>=0.3.0 xcb-aux>=0.3.0 xcb-atom>=0.3.0 - xcb-keysyms>=0.3.0 + xcb-keysyms>=0.3.4 xcb-icccm>=0.3.3 xcb-image>=0.3.0 xcb-property>=0.3.0 diff --git a/common/xutil.c b/common/xutil.c index 4d46b6db0..c56afbb5b 100644 --- a/common/xutil.c +++ b/common/xutil.c @@ -82,50 +82,6 @@ xutil_text_prop_get(xcb_connection_t *conn, xcb_window_t w, xcb_atom_t atom, return true; } -/** Get the lock masks (shiftlock, numlock, capslock). - * \param connection The X connection. - * \param cookie The cookie of the request. - * \param keysyms Key symbols. - * \param numlockmask Numlock mask. - * \param shiftlockmask Shiftlock mask. - * \param capslockmask Capslock mask. - */ -void -xutil_lock_mask_get(xcb_connection_t *connection, - xcb_get_modifier_mapping_cookie_t cookie, - xcb_key_symbols_t *keysyms, - unsigned int *numlockmask, - unsigned int *shiftlockmask, - unsigned int *capslockmask) -{ - xcb_get_modifier_mapping_reply_t *modmap_r; - xcb_keycode_t *modmap, kc; - unsigned int mask; - int i, j; - - modmap_r = xcb_get_modifier_mapping_reply(connection, cookie, NULL); - modmap = xcb_get_modifier_mapping_keycodes(modmap_r); - - for(i = 0; i < 8; i++) - for(j = 0; j < modmap_r->keycodes_per_modifier; j++) - { - kc = modmap[i * modmap_r->keycodes_per_modifier + j]; - mask = (1 << i); - - if(numlockmask != NULL - && kc == xcb_key_symbols_get_keycode(keysyms, XK_Num_Lock)) - *numlockmask = mask; - else if(shiftlockmask != NULL - && kc == xcb_key_symbols_get_keycode(keysyms, XK_Shift_Lock)) - *shiftlockmask = mask; - else if(capslockmask != NULL - && kc == xcb_key_symbols_get_keycode(keysyms, XK_Caps_Lock)) - *capslockmask = mask; - } - - p_delete(&modmap_r); -} - /* Number of different errors */ #define ERRORS_NBR 256 diff --git a/common/xutil.h b/common/xutil.h index 3a5ca359e..3d823ccbc 100644 --- a/common/xutil.h +++ b/common/xutil.h @@ -32,7 +32,7 @@ #include "array.h" -#define XUTIL_MASK_CLEAN(mask) (mask & ~(globalconf.numlockmask | XCB_MOD_MASK_LOCK)) +#define XUTIL_MASK_CLEAN(mask) (mask & ~(XCB_MOD_MASK_LOCK | XCB_MOD_MASK_2)) /* X error codes */ @@ -83,10 +83,6 @@ bool xutil_text_prop_get(xcb_connection_t *, xcb_window_t, xcb_atom_t, char **, ssize_t *); -void xutil_lock_mask_get(xcb_connection_t *, xcb_get_modifier_mapping_cookie_t, - xcb_key_symbols_t *, unsigned int *, unsigned int *, - unsigned int *); - /** Set the same handler for all errors */ void xutil_error_handler_catch_all_set(xcb_event_handlers_t *, xcb_generic_error_handler_t, void *); diff --git a/event.c b/event.c index 9ee396559..466bce235 100644 --- a/event.c +++ b/event.c @@ -853,23 +853,13 @@ event_handle_mappingnotify(void *data, xcb_connection_t *connection, xcb_mapping_notify_event_t *ev) { - xcb_get_modifier_mapping_cookie_t xmapping_cookie; - if(ev->request == XCB_MAPPING_MODIFIER || ev->request == XCB_MAPPING_KEYBOARD) { - /* Send the request to get the NumLock, ShiftLock and CapsLock masks */ - xmapping_cookie = xcb_get_modifier_mapping_unchecked(globalconf.connection); - /* Free and then allocate the key symbols */ xcb_key_symbols_free(globalconf.keysyms); globalconf.keysyms = xcb_key_symbols_alloc(globalconf.connection); - /* Process the reply of previously sent mapping request */ - xutil_lock_mask_get(globalconf.connection, xmapping_cookie, - globalconf.keysyms, &globalconf.numlockmask, - &globalconf.shiftlockmask, &globalconf.capslockmask); - int nscreen = xcb_setup_roots_length(xcb_get_setup(connection)); /* regrab everything */ diff --git a/key.c b/key.c index fe0425444..cbfacdf5d 100644 --- a/key.c +++ b/key.c @@ -91,6 +91,20 @@ key_cmp(const keyb_t *k1, const keyb_t *k2) return k1->mod == k2->mod ? 0 : (k2->mod > k1->mod ? 1 : -1); } +static void +window_grabkey_keycode(xcb_window_t win, uint16_t mod, xcb_keycode_t kc) +{ + xcb_grab_key(globalconf.connection, true, win, + mod, kc, XCB_GRAB_MODE_ASYNC, XCB_GRAB_MODE_ASYNC); + xcb_grab_key(globalconf.connection, true, win, + mod | XCB_MOD_MASK_LOCK, kc, XCB_GRAB_MODE_ASYNC, XCB_GRAB_MODE_ASYNC); + xcb_grab_key(globalconf.connection, true, win, + mod | XCB_MOD_MASK_2, kc, XCB_GRAB_MODE_ASYNC, XCB_GRAB_MODE_ASYNC); + xcb_grab_key(globalconf.connection, true, win, + mod | XCB_MOD_MASK_2 | XCB_MOD_MASK_LOCK, kc, XCB_GRAB_MODE_ASYNC, + XCB_GRAB_MODE_ASYNC); +} + /** Grab key on a window. * \param win The window. * \param k The key. @@ -98,21 +112,17 @@ key_cmp(const keyb_t *k1, const keyb_t *k2) static void window_grabkey(xcb_window_t win, keyb_t *k) { - xcb_keycode_t kc; - - if((kc = k->keycode) - || (k->keysym - && (kc = xcb_key_symbols_get_keycode(globalconf.keysyms, k->keysym)))) + if(k->keycode) + window_grabkey_keycode(win, k->mod, k->keycode); + else if(k->keysym) { - xcb_grab_key(globalconf.connection, true, win, - k->mod, kc, XCB_GRAB_MODE_ASYNC, XCB_GRAB_MODE_ASYNC); - xcb_grab_key(globalconf.connection, true, win, - k->mod | XCB_MOD_MASK_LOCK, kc, XCB_GRAB_MODE_ASYNC, XCB_GRAB_MODE_ASYNC); - xcb_grab_key(globalconf.connection, true, win, - k->mod | globalconf.numlockmask, kc, XCB_GRAB_MODE_ASYNC, XCB_GRAB_MODE_ASYNC); - xcb_grab_key(globalconf.connection, true, win, - k->mod | globalconf.numlockmask | XCB_MOD_MASK_LOCK, kc, XCB_GRAB_MODE_ASYNC, - XCB_GRAB_MODE_ASYNC); + xcb_keycode_t *keycodes = xcb_key_symbols_get_keycode(globalconf.keysyms, k->keysym); + if(keycodes) + { + for(xcb_keycode_t *kc = keycodes; *kc; kc++) + window_grabkey_keycode(win, k->mod, *kc); + p_delete(&keycodes); + } } } @@ -189,12 +199,11 @@ key_getkeysym(xcb_keycode_t detail, uint16_t state) /* The numlock modifier is on and the second KeySym is a keypad * KeySym */ - if((state & globalconf.numlockmask) && xcb_is_keypad_key(k1)) + if((state & XCB_MOD_MASK_2) && xcb_is_keypad_key(k1)) { /* The Shift modifier is on, or if the Lock modifier is on and * is interpreted as ShiftLock, use the first KeySym */ - if((state & XCB_MOD_MASK_SHIFT) || - (state & XCB_MOD_MASK_LOCK && (state & globalconf.shiftlockmask))) + if((state & XCB_MOD_MASK_SHIFT) || (state & XCB_MOD_MASK_LOCK)) return k0; else return k1; @@ -207,8 +216,7 @@ key_getkeysym(xcb_keycode_t detail, uint16_t state) /* The Shift modifier is off and the Lock modifier is on and is * interpreted as CapsLock */ - else if(!(state & XCB_MOD_MASK_SHIFT) && - (state & XCB_MOD_MASK_LOCK && (state & globalconf.capslockmask))) + else if(!(state & XCB_MOD_MASK_SHIFT) && (state & XCB_MOD_MASK_LOCK)) /* The first Keysym is used but if that KeySym is lowercase * alphabetic, then the corresponding uppercase KeySym is used * instead */ @@ -216,8 +224,7 @@ key_getkeysym(xcb_keycode_t detail, uint16_t state) /* The Shift modifier is on, and the Lock modifier is on and is * interpreted as CapsLock */ - else if((state & XCB_MOD_MASK_SHIFT) && - (state & XCB_MOD_MASK_LOCK && (state & globalconf.capslockmask))) + else if((state & XCB_MOD_MASK_SHIFT) && (state & XCB_MOD_MASK_LOCK)) /* The second Keysym is used but if that KeySym is lowercase * alphabetic, then the corresponding uppercase KeySym is used * instead */ @@ -225,8 +232,7 @@ key_getkeysym(xcb_keycode_t detail, uint16_t state) /* The Shift modifer is on, or the Lock modifier is on and is * interpreted as ShiftLock, or both */ - else if((state & XCB_MOD_MASK_SHIFT) || - (state & XCB_MOD_MASK_LOCK && (state & globalconf.shiftlockmask))) + else if((state & XCB_MOD_MASK_SHIFT) || (state & XCB_MOD_MASK_LOCK)) return k1; return XCB_NO_SYMBOL; diff --git a/key.h b/key.h index 0c925c7c6..711924a5c 100644 --- a/key.h +++ b/key.h @@ -31,7 +31,7 @@ typedef struct keyb_t /** Lua references */ luaA_ref_array_t refs; /** Key modifier */ - unsigned long mod; + uint16_t mod; /** Keysym */ xcb_keysym_t keysym; /** Keycode */ diff --git a/structs.h b/structs.h index a6ddb5b5b..3031e53ec 100644 --- a/structs.h +++ b/structs.h @@ -315,12 +315,6 @@ struct awesome_t keybindings_t keys; /** Root window mouse bindings */ button_array_t buttons; - /** Numlock mask */ - unsigned int numlockmask; - /** Numlock mask */ - unsigned int shiftlockmask; - /** Numlock mask */ - unsigned int capslockmask; /** Check for XRandR extension */ bool have_randr; /** Check for XTest extension */ diff --git a/window.c b/window.c index 91f70a9ae..578d2e7b4 100644 --- a/window.c +++ b/window.c @@ -115,10 +115,10 @@ window_buttons_grab(xcb_window_t win, button_array_t *buttons) buttons->tab[i]->button, buttons->tab[i]->mod | XCB_MOD_MASK_LOCK); xcb_grab_button(globalconf.connection, false, win, BUTTONMASK, XCB_GRAB_MODE_SYNC, XCB_GRAB_MODE_ASYNC, XCB_NONE, XCB_NONE, - buttons->tab[i]->button, buttons->tab[i]->mod | globalconf.numlockmask); + buttons->tab[i]->button, buttons->tab[i]->mod | XCB_MOD_MASK_2); xcb_grab_button(globalconf.connection, false, win, BUTTONMASK, XCB_GRAB_MODE_SYNC, XCB_GRAB_MODE_ASYNC, XCB_NONE, XCB_NONE, - buttons->tab[i]->button, buttons->tab[i]->mod | globalconf.numlockmask | XCB_MOD_MASK_LOCK); + buttons->tab[i]->button, buttons->tab[i]->mod | XCB_MOD_MASK_2 | XCB_MOD_MASK_LOCK); } }