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.
This commit is contained in:
parent
9b03be644f
commit
c5df093f5d
|
@ -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);
|
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);
|
||||||
|
|
|
@ -308,12 +308,6 @@ struct Barconfig {
|
||||||
*/
|
*/
|
||||||
void load_configuration(xcb_connection_t *conn, const char *override_configfile, bool reload);
|
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
|
* Ungrabs all keys, to be called before re-grabbing the keys because of a
|
||||||
* mapping_notify event or a configuration file reload
|
* mapping_notify event or a configuration file reload
|
||||||
|
|
|
@ -179,3 +179,53 @@ Binding *get_keyboard_binding(uint16_t modifiers, bool key_release, xcb_keycode_
|
||||||
|
|
||||||
return (bind == TAILQ_END(bindings) ? NULL : bind);
|
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);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
49
src/config.c
49
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);
|
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
|
* Switches the key bindings to the given mode, if the mode exists
|
||||||
*
|
*
|
||||||
|
|
Loading…
Reference in New Issue