diff options
author | Quentin Glidic <sardemff7+git@sardemff7.net> | 2016-02-22 11:39:52 +0100 |
---|---|---|
committer | Quentin Glidic <sardemff7+git@sardemff7.net> | 2016-02-23 17:34:38 +0100 |
commit | 6bb1d4b1a2b451ded41616ff56fdde94a5b46d5c (patch) | |
tree | 40dc3238a97858964ea8aa50b2aa536d11744a46 | |
parent | 42e97092076340e2e481514d4aad13b314df6fbb (diff) |
x11-helper: Migrate to libxkbcommon
Signed-off-by: Quentin Glidic <sardemff7+git@sardemff7.net>
-rw-r--r-- | include/x11-helper.h | 4 | ||||
-rw-r--r-- | source/rofi.c | 2 | ||||
-rw-r--r-- | source/x11-helper.c | 79 |
3 files changed, 37 insertions, 48 deletions
diff --git a/include/x11-helper.h b/include/x11-helper.h index 6e4a9d29..6bcf62ae 100644 --- a/include/x11-helper.h +++ b/include/x11-helper.h @@ -2,6 +2,8 @@ #define X11_ROFI_HELPER_H #include <cairo.h> +#include "xkb.h" + /** * @defgroup X11Helper X11Helper * @ingroup HELPERS @@ -130,7 +132,7 @@ void x11_set_window_opacity ( Display *display, Window box, unsigned int opacity * * Numlock detection * * Cache */ -void x11_setup ( Display *display ); +void x11_setup ( Display *display, xkb_stuff *xkb ); /** * @param display Connection to the X server. diff --git a/source/rofi.c b/source/rofi.c index bb7b8853..c5efab96 100644 --- a/source/rofi.c +++ b/source/rofi.c @@ -767,7 +767,7 @@ int main ( int argc, char *argv[] ) exit ( EXIT_SUCCESS ); } - x11_setup ( display ); + x11_setup ( display, &xkb ); main_loop_source = g_water_xcb_source_new_for_connection ( NULL, xcb_connection, main_loop_x11_event_handler, NULL, NULL ); TICK_N ( "X11 Setup " ); diff --git a/source/x11-helper.c b/source/x11-helper.c index 24fc1856..43cfdddd 100644 --- a/source/x11-helper.c +++ b/source/x11-helper.c @@ -349,53 +349,34 @@ void release_keyboard ( Display *display ) XUngrabKeyboard ( display, CurrentTime ); } -static void x11_figure_out_masks ( Display *display ) +static unsigned int x11_find_mod_mask ( xkb_stuff *xkb, ... ) { - XModifierKeymap *modmap = XGetModifierMapping ( display ); - KeyCode kc_altl = XKeysymToKeycode ( display, XK_Alt_L ); - KeyCode kc_altr = XKeysymToKeycode ( display, XK_Alt_R ); - KeyCode kc_superr = XKeysymToKeycode ( display, XK_Super_R ); - KeyCode kc_superl = XKeysymToKeycode ( display, XK_Super_L ); - KeyCode kc_hyperl = XKeysymToKeycode ( display, XK_Hyper_L ); - KeyCode kc_hyperr = XKeysymToKeycode ( display, XK_Hyper_R ); - KeyCode kc_metal = XKeysymToKeycode ( display, XK_Meta_L ); - KeyCode kc_metar = XKeysymToKeycode ( display, XK_Meta_R ); - - x11_mod_masks[X11MOD_SHIFT] |= ShiftMask; - x11_mod_masks[X11MOD_CONTROL] |= ControlMask; - for ( int i = 0; i < 8; i++ ) { - for ( int j = 0; j < ( int ) modmap->max_keypermod; j++ ) { - if ( kc_altl && modmap->modifiermap[i * modmap->max_keypermod + j] == kc_altl ) { - x11_mod_masks[X11MOD_ALT] |= ( 1 << i ); - } - if ( kc_altr && modmap->modifiermap[i * modmap->max_keypermod + j] == kc_altr ) { - x11_mod_masks[X11MOD_ALT] |= ( 1 << i ); - } - if ( kc_superr && modmap->modifiermap[i * modmap->max_keypermod + j] == kc_superr ) { - x11_mod_masks[X11MOD_SUPER] |= ( 1 << i ); - } - if ( kc_superl && modmap->modifiermap[i * modmap->max_keypermod + j] == kc_superl ) { - x11_mod_masks[X11MOD_SUPER] |= ( 1 << i ); - } - if ( kc_hyperr && modmap->modifiermap[i * modmap->max_keypermod + j] == kc_hyperr ) { - x11_mod_masks[X11MOD_HYPER] |= ( 1 << i ); - } - if ( kc_hyperl && modmap->modifiermap[i * modmap->max_keypermod + j] == kc_hyperl ) { - x11_mod_masks[X11MOD_HYPER] |= ( 1 << i ); - } - if ( kc_metar && modmap->modifiermap[i * modmap->max_keypermod + j] == kc_metar ) { - x11_mod_masks[X11MOD_META] |= ( 1 << i ); - } - if ( kc_metal && modmap->modifiermap[i * modmap->max_keypermod + j] == kc_metal ) { - x11_mod_masks[X11MOD_META] |= ( 1 << i ); - } + va_list names; + const char *name; + xkb_mod_index_t i; + unsigned int mask = 0; + va_start ( names, xkb ); + while ( ( name = va_arg ( names, const char * ) ) != NULL ) { + i = xkb_keymap_mod_get_index ( xkb->keymap, name ); + if ( i != XKB_MOD_INVALID ) { + mask |= 1 << i; } } - XFreeModifiermap ( modmap ); + return mask; +} + +static void x11_figure_out_masks ( xkb_stuff *xkb ) +{ + x11_mod_masks[X11MOD_SHIFT] = x11_find_mod_mask ( xkb, XKB_MOD_NAME_SHIFT, NULL ); + x11_mod_masks[X11MOD_CONTROL] = x11_find_mod_mask ( xkb, XKB_MOD_NAME_CTRL, "RControl", "LControl", NULL ); + x11_mod_masks[X11MOD_ALT] = x11_find_mod_mask ( xkb, XKB_MOD_NAME_ALT, "Alt", "LAlt", "RAlt", "AltGr", "Mod5", "LevelThree", NULL ); + x11_mod_masks[X11MOD_META] = x11_find_mod_mask ( xkb, "Meta", NULL ); + x11_mod_masks[X11MOD_SUPER] = x11_find_mod_mask ( xkb, XKB_MOD_NAME_LOGO, "Super", NULL ); + x11_mod_masks[X11MOD_HYPER] = x11_find_mod_mask ( xkb, "Hyper", NULL ); gsize i; for ( i = 0; i < X11MOD_ANY; ++i ) { - x11_mod_masks[X11MOD_ANY] |= x11_mod_mask[i]; + x11_mod_masks[X11MOD_ANY] |= x11_mod_masks[i]; } } @@ -403,12 +384,12 @@ unsigned int x11_canonalize_mask ( unsigned int mask ) { // Bits 13 and 14 of the modifiers together are the group number, and // should be ignored when looking up key bindings - mask &= x11_mod_mask[X11MOD_ANY]; + mask &= x11_mod_masks[X11MOD_ANY]; gsize i; for ( i = 0; i < X11MOD_ANY; ++i ) { - if ( mask & x11_mod_mask[i] ) { - mask |= x11_mod_mask[i]; + if ( mask & x11_mod_masks[i] ) { + mask |= x11_mod_masks[i]; } } return mask; @@ -422,9 +403,15 @@ void x11_parse_key ( char *combo, unsigned int *mod, xkb_keysym_t *key ) if ( strcasestr ( combo, "shift" ) ) { modmask |= x11_mod_masks[X11MOD_SHIFT]; + if ( x11_mod_masks[X11MOD_SHIFT] == 0 ) { + g_string_append_printf ( str, "X11 configured keyboard has no <b>Shift</b> key.\n" ); + } } if ( strcasestr ( combo, "control" ) ) { modmask |= x11_mod_masks[X11MOD_CONTROL]; + if ( x11_mod_masks[X11MOD_CONTROL] == 0 ) { + g_string_append_printf ( str, "X11 configured keyboard has no <b>Control</b> key.\n" ); + } } if ( strcasestr ( combo, "alt" ) ) { modmask |= x11_mod_masks[X11MOD_ALT]; @@ -524,7 +511,7 @@ static int display_oops ( Display *d, XErrorEvent *ee ) return xerror ( d, ee ); } -void x11_setup ( Display *display ) +void x11_setup ( Display *display, xkb_stuff *xkb ) { // Set error handle XSync ( display, False ); @@ -532,7 +519,7 @@ void x11_setup ( Display *display ) XSync ( display, False ); // determine numlock mask so we can bind on keys with and without it - x11_figure_out_masks ( display ); + x11_figure_out_masks ( xkb ); x11_create_frequently_used_atoms ( display ); } |