Move get_mod_mask to libi3, use it in i3 and i3-config-wizard

Also, the API changed a bit. There are two functions now, both assume you
already got the keysyms (which is the case for i3 and i3-config-wizard),
one gets the modifier mapping for you (aio_get_mod_mask_for) while the other
assumes you also got that. No roundtrips are required for the latter.
This commit is contained in:
Michael Stapelberg
2011-10-23 21:26:15 +01:00
parent a512b99a51
commit 91134f75c0
9 changed files with 109 additions and 130 deletions

View File

@ -57,7 +57,7 @@ enum { STEP_WELCOME, STEP_GENERATE } current_step = STEP_WELCOME;
enum { MOD_Mod1, MOD_Mod4 } modifier = MOD_Mod4;
static char *config_path;
static xcb_connection_t *conn;
xcb_connection_t *conn;
static xcb_get_modifier_mapping_reply_t *modmap_reply;
static uint32_t font_id;
static uint32_t font_bold_id;
@ -424,6 +424,7 @@ int main(int argc, char *argv[]) {
xcb_get_modifier_mapping_cookie_t modmap_cookie;
modmap_cookie = xcb_get_modifier_mapping(conn);
symbols = xcb_key_symbols_alloc(conn);
/* Place requests for the atoms we need as soon as possible */
#define xmacro(atom) \
@ -437,11 +438,7 @@ int main(int argc, char *argv[]) {
if (!(modmap_reply = xcb_get_modifier_mapping_reply(conn, modmap_cookie, NULL)))
errx(EXIT_FAILURE, "Could not get modifier mapping\n");
/* XXX: we should refactor xcb_get_numlock_mask so that it uses the
* modifier mapping we already have */
xcb_get_numlock_mask(conn);
symbols = xcb_key_symbols_alloc(conn);
xcb_numlock_mask = get_mod_mask_for(XCB_NUM_LOCK, symbols, modmap_reply);
font_id = get_font_id(conn, pattern, &font_height);
font_bold_id = get_font_id(conn, patternbold, &font_bold_height);

View File

@ -104,58 +104,3 @@ int get_font_id(xcb_connection_t *conn, char *pattern, int *font_height) {
return result;
}
/*
* Finds out which modifier mask is the one for numlock, as the user may change this.
*
*/
void xcb_get_numlock_mask(xcb_connection_t *conn) {
xcb_key_symbols_t *keysyms;
xcb_get_modifier_mapping_cookie_t cookie;
xcb_get_modifier_mapping_reply_t *reply;
xcb_keycode_t *modmap;
int mask, i;
const int masks[8] = { XCB_MOD_MASK_SHIFT,
XCB_MOD_MASK_LOCK,
XCB_MOD_MASK_CONTROL,
XCB_MOD_MASK_1,
XCB_MOD_MASK_2,
XCB_MOD_MASK_3,
XCB_MOD_MASK_4,
XCB_MOD_MASK_5 };
/* Request the modifier map */
cookie = xcb_get_modifier_mapping_unchecked(conn);
/* Get the keysymbols */
keysyms = xcb_key_symbols_alloc(conn);
if ((reply = xcb_get_modifier_mapping_reply(conn, cookie, NULL)) == NULL) {
xcb_key_symbols_free(keysyms);
return;
}
modmap = xcb_get_modifier_mapping_keycodes(reply);
/* Get the keycode for numlock */
#ifdef OLD_XCB_KEYSYMS_API
xcb_keycode_t numlock = xcb_key_symbols_get_keycode(keysyms, XCB_NUM_LOCK);
#else
/* For now, we only use the first keysymbol. */
xcb_keycode_t *numlock_syms = xcb_key_symbols_get_keycode(keysyms, XCB_NUM_LOCK);
if (numlock_syms == NULL)
return;
xcb_keycode_t numlock = *numlock_syms;
free(numlock_syms);
#endif
/* Check all modifiers (Mod1-Mod5, Shift, Control, Lock) */
for (mask = 0; mask < 8; mask++)
for (i = 0; i < reply->keycodes_per_modifier; i++)
if (modmap[(mask * reply->keycodes_per_modifier) + i] == numlock)
xcb_numlock_mask = masks[mask];
xcb_key_symbols_free(keysyms);
free(reply);
}

View File

@ -12,10 +12,5 @@ extern unsigned int xcb_numlock_mask;
xcb_window_t open_input_window(xcb_connection_t *conn, uint32_t width, uint32_t height);
int get_font_id(xcb_connection_t *conn, char *pattern, int *font_height);
/**
* Finds out which modifier mask is the one for numlock, as the user may change this.
*
*/
void xcb_get_numlock_mask(xcb_connection_t *conn);
#endif