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 <julien@danjou.info>
This commit is contained in:
Julien Danjou 2009-04-11 18:02:31 +02:00
parent 40c300afed
commit cda33ca3e6
9 changed files with 34 additions and 102 deletions

View File

@ -330,7 +330,6 @@ main(int argc, char **argv)
const char *confpath = NULL; const char *confpath = NULL;
int xfd, i, screen_nbr, opt, colors_nbr; int xfd, i, screen_nbr, opt, colors_nbr;
xcolor_init_request_t colors_reqs[2]; xcolor_init_request_t colors_reqs[2];
xcb_get_modifier_mapping_cookie_t xmapping_cookie;
ssize_t cmdlen = 1; ssize_t cmdlen = 1;
xdgHandle xdg; xdgHandle xdg;
static struct option long_options[] = static struct option long_options[] =
@ -473,10 +472,6 @@ main(int argc, char **argv)
/* Allocate the key symbols */ /* Allocate the key symbols */
globalconf.keysyms = xcb_key_symbols_alloc(globalconf.connection); 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 */ /* init atom cache */
atoms_init(globalconf.connection); atoms_init(globalconf.connection);
@ -495,11 +490,6 @@ main(int argc, char **argv)
for(colors_nbr = 0; colors_nbr < 2; colors_nbr++) for(colors_nbr = 0; colors_nbr < 2; colors_nbr++)
xcolor_init_reply(colors_reqs[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 */ /* do this only for real screen */
for(screen_nbr = 0; for(screen_nbr = 0;
screen_nbr < xcb_setup_roots_length(xcb_get_setup(globalconf.connection)); screen_nbr < xcb_setup_roots_length(xcb_get_setup(globalconf.connection));

View File

@ -140,7 +140,7 @@ pkg_check_modules(AWESOME_REQUIRED REQUIRED
xcb-event>=0.3.0 xcb-event>=0.3.0
xcb-aux>=0.3.0 xcb-aux>=0.3.0
xcb-atom>=0.3.0 xcb-atom>=0.3.0
xcb-keysyms>=0.3.0 xcb-keysyms>=0.3.4
xcb-icccm>=0.3.3 xcb-icccm>=0.3.3
xcb-image>=0.3.0 xcb-image>=0.3.0
xcb-property>=0.3.0 xcb-property>=0.3.0

View File

@ -82,50 +82,6 @@ xutil_text_prop_get(xcb_connection_t *conn, xcb_window_t w, xcb_atom_t atom,
return true; 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 */ /* Number of different errors */
#define ERRORS_NBR 256 #define ERRORS_NBR 256

View File

@ -32,7 +32,7 @@
#include "array.h" #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 */ /* X error codes */
@ -83,10 +83,6 @@
bool xutil_text_prop_get(xcb_connection_t *, xcb_window_t, xcb_atom_t, char **, ssize_t *); 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 */ /** Set the same handler for all errors */
void xutil_error_handler_catch_all_set(xcb_event_handlers_t *, void xutil_error_handler_catch_all_set(xcb_event_handlers_t *,
xcb_generic_error_handler_t, void *); xcb_generic_error_handler_t, void *);

10
event.c
View File

@ -853,23 +853,13 @@ event_handle_mappingnotify(void *data,
xcb_connection_t *connection, xcb_connection_t *connection,
xcb_mapping_notify_event_t *ev) xcb_mapping_notify_event_t *ev)
{ {
xcb_get_modifier_mapping_cookie_t xmapping_cookie;
if(ev->request == XCB_MAPPING_MODIFIER if(ev->request == XCB_MAPPING_MODIFIER
|| ev->request == XCB_MAPPING_KEYBOARD) || 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 */ /* Free and then allocate the key symbols */
xcb_key_symbols_free(globalconf.keysyms); xcb_key_symbols_free(globalconf.keysyms);
globalconf.keysyms = xcb_key_symbols_alloc(globalconf.connection); 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)); int nscreen = xcb_setup_roots_length(xcb_get_setup(connection));
/* regrab everything */ /* regrab everything */

52
key.c
View File

@ -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); 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. /** Grab key on a window.
* \param win The window. * \param win The window.
* \param k The key. * \param k The key.
@ -98,21 +112,17 @@ key_cmp(const keyb_t *k1, const keyb_t *k2)
static void static void
window_grabkey(xcb_window_t win, keyb_t *k) window_grabkey(xcb_window_t win, keyb_t *k)
{ {
xcb_keycode_t kc; if(k->keycode)
window_grabkey_keycode(win, k->mod, k->keycode);
if((kc = k->keycode) else if(k->keysym)
|| (k->keysym
&& (kc = xcb_key_symbols_get_keycode(globalconf.keysyms, k->keysym))))
{ {
xcb_grab_key(globalconf.connection, true, win, xcb_keycode_t *keycodes = xcb_key_symbols_get_keycode(globalconf.keysyms, k->keysym);
k->mod, kc, XCB_GRAB_MODE_ASYNC, XCB_GRAB_MODE_ASYNC); if(keycodes)
xcb_grab_key(globalconf.connection, true, win, {
k->mod | XCB_MOD_MASK_LOCK, kc, XCB_GRAB_MODE_ASYNC, XCB_GRAB_MODE_ASYNC); for(xcb_keycode_t *kc = keycodes; *kc; kc++)
xcb_grab_key(globalconf.connection, true, win, window_grabkey_keycode(win, k->mod, *kc);
k->mod | globalconf.numlockmask, kc, XCB_GRAB_MODE_ASYNC, XCB_GRAB_MODE_ASYNC); p_delete(&keycodes);
xcb_grab_key(globalconf.connection, true, win, }
k->mod | globalconf.numlockmask | XCB_MOD_MASK_LOCK, kc, XCB_GRAB_MODE_ASYNC,
XCB_GRAB_MODE_ASYNC);
} }
} }
@ -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 /* The numlock modifier is on and the second KeySym is a keypad
* KeySym */ * 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 /* The Shift modifier is on, or if the Lock modifier is on and
* is interpreted as ShiftLock, use the first KeySym */ * is interpreted as ShiftLock, use the first KeySym */
if((state & XCB_MOD_MASK_SHIFT) || if((state & XCB_MOD_MASK_SHIFT) || (state & XCB_MOD_MASK_LOCK))
(state & XCB_MOD_MASK_LOCK && (state & globalconf.shiftlockmask)))
return k0; return k0;
else else
return k1; 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 /* The Shift modifier is off and the Lock modifier is on and is
* interpreted as CapsLock */ * interpreted as CapsLock */
else if(!(state & XCB_MOD_MASK_SHIFT) && else if(!(state & XCB_MOD_MASK_SHIFT) && (state & XCB_MOD_MASK_LOCK))
(state & XCB_MOD_MASK_LOCK && (state & globalconf.capslockmask)))
/* The first Keysym is used but if that KeySym is lowercase /* The first Keysym is used but if that KeySym is lowercase
* alphabetic, then the corresponding uppercase KeySym is used * alphabetic, then the corresponding uppercase KeySym is used
* instead */ * 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 /* The Shift modifier is on, and the Lock modifier is on and is
* interpreted as CapsLock */ * interpreted as CapsLock */
else if((state & XCB_MOD_MASK_SHIFT) && else if((state & XCB_MOD_MASK_SHIFT) && (state & XCB_MOD_MASK_LOCK))
(state & XCB_MOD_MASK_LOCK && (state & globalconf.capslockmask)))
/* The second Keysym is used but if that KeySym is lowercase /* The second Keysym is used but if that KeySym is lowercase
* alphabetic, then the corresponding uppercase KeySym is used * alphabetic, then the corresponding uppercase KeySym is used
* instead */ * 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 /* The Shift modifer is on, or the Lock modifier is on and is
* interpreted as ShiftLock, or both */ * interpreted as ShiftLock, or both */
else if((state & XCB_MOD_MASK_SHIFT) || else if((state & XCB_MOD_MASK_SHIFT) || (state & XCB_MOD_MASK_LOCK))
(state & XCB_MOD_MASK_LOCK && (state & globalconf.shiftlockmask)))
return k1; return k1;
return XCB_NO_SYMBOL; return XCB_NO_SYMBOL;

2
key.h
View File

@ -31,7 +31,7 @@ typedef struct keyb_t
/** Lua references */ /** Lua references */
luaA_ref_array_t refs; luaA_ref_array_t refs;
/** Key modifier */ /** Key modifier */
unsigned long mod; uint16_t mod;
/** Keysym */ /** Keysym */
xcb_keysym_t keysym; xcb_keysym_t keysym;
/** Keycode */ /** Keycode */

View File

@ -315,12 +315,6 @@ struct awesome_t
keybindings_t keys; keybindings_t keys;
/** Root window mouse bindings */ /** Root window mouse bindings */
button_array_t buttons; button_array_t buttons;
/** Numlock mask */
unsigned int numlockmask;
/** Numlock mask */
unsigned int shiftlockmask;
/** Numlock mask */
unsigned int capslockmask;
/** Check for XRandR extension */ /** Check for XRandR extension */
bool have_randr; bool have_randr;
/** Check for XTest extension */ /** Check for XTest extension */

View File

@ -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); buttons->tab[i]->button, buttons->tab[i]->mod | XCB_MOD_MASK_LOCK);
xcb_grab_button(globalconf.connection, false, win, BUTTONMASK, xcb_grab_button(globalconf.connection, false, win, BUTTONMASK,
XCB_GRAB_MODE_SYNC, XCB_GRAB_MODE_ASYNC, XCB_NONE, XCB_NONE, 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_button(globalconf.connection, false, win, BUTTONMASK,
XCB_GRAB_MODE_SYNC, XCB_GRAB_MODE_ASYNC, XCB_NONE, XCB_NONE, 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);
} }
} }