From: Tony Crisci Date: Thu, 13 Mar 2014 12:02:07 +0000 (-0400) Subject: Move translate_keysyms to bindings.[ch] X-Git-Tag: 4.8~100 X-Git-Url: https://git.sur5r.net/?a=commitdiff_plain;h=c5df093f5db1ccae70c900408d74a6d5b0ad2c97;p=i3%2Fi3 Move translate_keysyms to bindings.[ch] Additionally add a check so the function only handles bindings of type B_KEYBOARD to prepare for the new bindmouse feature. --- diff --git a/include/bindings.h b/include/bindings.h index bae31132..26532024 100644 --- a/include/bindings.h +++ b/include/bindings.h @@ -36,3 +36,9 @@ void grab_all_keys(xcb_connection_t *conn, bool bind_mode_switch); * */ Binding *get_keyboard_binding(uint16_t modifiers, bool key_release, xcb_keycode_t keycode); + +/** + * Translates keysymbols to keycodes for all bindings which use keysyms. + * + */ +void translate_keysyms(void); diff --git a/include/config.h b/include/config.h index f307874d..0c3e25db 100644 --- a/include/config.h +++ b/include/config.h @@ -308,12 +308,6 @@ struct Barconfig { */ void load_configuration(xcb_connection_t *conn, const char *override_configfile, bool reload); -/** - * Translates keysymbols to keycodes for all bindings which use keysyms. - * - */ -void translate_keysyms(void); - /** * Ungrabs all keys, to be called before re-grabbing the keys because of a * mapping_notify event or a configuration file reload diff --git a/src/bindings.c b/src/bindings.c index 9dd24ffa..5dfe5472 100644 --- a/src/bindings.c +++ b/src/bindings.c @@ -179,3 +179,53 @@ Binding *get_keyboard_binding(uint16_t modifiers, bool key_release, xcb_keycode_ return (bind == TAILQ_END(bindings) ? NULL : bind); } + +/* + * Translates keysymbols to keycodes for all bindings which use keysyms. + * + */ +void translate_keysyms(void) { + Binding *bind; + xcb_keysym_t keysym; + int col; + xcb_keycode_t i, min_keycode, max_keycode; + + min_keycode = xcb_get_setup(conn)->min_keycode; + max_keycode = xcb_get_setup(conn)->max_keycode; + + TAILQ_FOREACH(bind, bindings, bindings) { + if (bind->input_type != B_KEYBOARD || bind->keycode > 0) + continue; + + /* We need to translate the symbol to a keycode */ + keysym = XStringToKeysym(bind->symbol); + if (keysym == NoSymbol) { + ELOG("Could not translate string to key symbol: \"%s\"\n", + bind->symbol); + continue; + } + + /* Base column we use for looking up key symbols. We always consider + * the base column and the corresponding shift column, so without + * mode_switch, we look in 0 and 1, with mode_switch we look in 2 and + * 3. */ + col = (bind->mods & BIND_MODE_SWITCH ? 2 : 0); + + FREE(bind->translated_to); + bind->number_keycodes = 0; + + for (i = min_keycode; i && i <= max_keycode; i++) { + if ((xcb_key_symbols_get_keysym(keysyms, i, col) != keysym) && + (xcb_key_symbols_get_keysym(keysyms, i, col+1) != keysym)) + continue; + bind->number_keycodes++; + bind->translated_to = srealloc(bind->translated_to, + (sizeof(xcb_keycode_t) * + bind->number_keycodes)); + bind->translated_to[bind->number_keycodes-1] = i; + } + + DLOG("Translated symbol \"%s\" to %d keycode\n", bind->symbol, + bind->number_keycodes); + } +} diff --git a/src/config.c b/src/config.c index fb1f4984..a8e66314 100644 --- a/src/config.c +++ b/src/config.c @@ -30,55 +30,6 @@ void ungrab_all_keys(xcb_connection_t *conn) { xcb_ungrab_key(conn, XCB_GRAB_ANY, root, XCB_BUTTON_MASK_ANY); } -/* - * Translates keysymbols to keycodes for all bindings which use keysyms. - * - */ -void translate_keysyms(void) { - Binding *bind; - xcb_keysym_t keysym; - int col; - xcb_keycode_t i, - min_keycode = xcb_get_setup(conn)->min_keycode, - max_keycode = xcb_get_setup(conn)->max_keycode; - - TAILQ_FOREACH(bind, bindings, bindings) { - if (bind->keycode > 0) - continue; - - /* We need to translate the symbol to a keycode */ - keysym = XStringToKeysym(bind->symbol); - if (keysym == NoSymbol) { - ELOG("Could not translate string to key symbol: \"%s\"\n", - bind->symbol); - continue; - } - - /* Base column we use for looking up key symbols. We always consider - * the base column and the corresponding shift column, so without - * mode_switch, we look in 0 and 1, with mode_switch we look in 2 and - * 3. */ - col = (bind->mods & BIND_MODE_SWITCH ? 2 : 0); - - FREE(bind->translated_to); - bind->number_keycodes = 0; - - for (i = min_keycode; i && i <= max_keycode; i++) { - if ((xcb_key_symbols_get_keysym(keysyms, i, col) != keysym) && - (xcb_key_symbols_get_keysym(keysyms, i, col+1) != keysym)) - continue; - bind->number_keycodes++; - bind->translated_to = srealloc(bind->translated_to, - (sizeof(xcb_keycode_t) * - bind->number_keycodes)); - bind->translated_to[bind->number_keycodes-1] = i; - } - - DLOG("Translated symbol \"%s\" to %d keycode\n", bind->symbol, - bind->number_keycodes); - } -} - /* * Switches the key bindings to the given mode, if the mode exists *