mirror of
https://github.com/davatorium/rofi.git
synced 2024-11-11 13:50:48 -05:00
x11-helper: Migrate to libxkbcommon
Signed-off-by: Quentin Glidic <sardemff7+git@sardemff7.net>
This commit is contained in:
parent
42e9709207
commit
6bb1d4b1a2
3 changed files with 37 additions and 48 deletions
|
@ -2,6 +2,8 @@
|
||||||
#define X11_ROFI_HELPER_H
|
#define X11_ROFI_HELPER_H
|
||||||
#include <cairo.h>
|
#include <cairo.h>
|
||||||
|
|
||||||
|
#include "xkb.h"
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @defgroup X11Helper X11Helper
|
* @defgroup X11Helper X11Helper
|
||||||
* @ingroup HELPERS
|
* @ingroup HELPERS
|
||||||
|
@ -130,7 +132,7 @@ void x11_set_window_opacity ( Display *display, Window box, unsigned int opacity
|
||||||
* * Numlock detection
|
* * Numlock detection
|
||||||
* * Cache
|
* * Cache
|
||||||
*/
|
*/
|
||||||
void x11_setup ( Display *display );
|
void x11_setup ( Display *display, xkb_stuff *xkb );
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @param display Connection to the X server.
|
* @param display Connection to the X server.
|
||||||
|
|
|
@ -767,7 +767,7 @@ int main ( int argc, char *argv[] )
|
||||||
exit ( EXIT_SUCCESS );
|
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 );
|
main_loop_source = g_water_xcb_source_new_for_connection ( NULL, xcb_connection, main_loop_x11_event_handler, NULL, NULL );
|
||||||
|
|
||||||
TICK_N ( "X11 Setup " );
|
TICK_N ( "X11 Setup " );
|
||||||
|
|
|
@ -349,53 +349,34 @@ void release_keyboard ( Display *display )
|
||||||
XUngrabKeyboard ( display, CurrentTime );
|
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 );
|
va_list names;
|
||||||
KeyCode kc_altl = XKeysymToKeycode ( display, XK_Alt_L );
|
const char *name;
|
||||||
KeyCode kc_altr = XKeysymToKeycode ( display, XK_Alt_R );
|
xkb_mod_index_t i;
|
||||||
KeyCode kc_superr = XKeysymToKeycode ( display, XK_Super_R );
|
unsigned int mask = 0;
|
||||||
KeyCode kc_superl = XKeysymToKeycode ( display, XK_Super_L );
|
va_start ( names, xkb );
|
||||||
KeyCode kc_hyperl = XKeysymToKeycode ( display, XK_Hyper_L );
|
while ( ( name = va_arg ( names, const char * ) ) != NULL ) {
|
||||||
KeyCode kc_hyperr = XKeysymToKeycode ( display, XK_Hyper_R );
|
i = xkb_keymap_mod_get_index ( xkb->keymap, name );
|
||||||
KeyCode kc_metal = XKeysymToKeycode ( display, XK_Meta_L );
|
if ( i != XKB_MOD_INVALID ) {
|
||||||
KeyCode kc_metar = XKeysymToKeycode ( display, XK_Meta_R );
|
mask |= 1 << i;
|
||||||
|
|
||||||
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 );
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
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;
|
gsize i;
|
||||||
for ( i = 0; i < X11MOD_ANY; ++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
|
// Bits 13 and 14 of the modifiers together are the group number, and
|
||||||
// should be ignored when looking up key bindings
|
// should be ignored when looking up key bindings
|
||||||
mask &= x11_mod_mask[X11MOD_ANY];
|
mask &= x11_mod_masks[X11MOD_ANY];
|
||||||
|
|
||||||
gsize i;
|
gsize i;
|
||||||
for ( i = 0; i < X11MOD_ANY; ++i ) {
|
for ( i = 0; i < X11MOD_ANY; ++i ) {
|
||||||
if ( mask & x11_mod_mask[i] ) {
|
if ( mask & x11_mod_masks[i] ) {
|
||||||
mask |= x11_mod_mask[i];
|
mask |= x11_mod_masks[i];
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return mask;
|
return mask;
|
||||||
|
@ -422,9 +403,15 @@ void x11_parse_key ( char *combo, unsigned int *mod, xkb_keysym_t *key )
|
||||||
|
|
||||||
if ( strcasestr ( combo, "shift" ) ) {
|
if ( strcasestr ( combo, "shift" ) ) {
|
||||||
modmask |= x11_mod_masks[X11MOD_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" ) ) {
|
if ( strcasestr ( combo, "control" ) ) {
|
||||||
modmask |= x11_mod_masks[X11MOD_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" ) ) {
|
if ( strcasestr ( combo, "alt" ) ) {
|
||||||
modmask |= x11_mod_masks[X11MOD_ALT];
|
modmask |= x11_mod_masks[X11MOD_ALT];
|
||||||
|
@ -524,7 +511,7 @@ static int display_oops ( Display *d, XErrorEvent *ee )
|
||||||
return xerror ( d, ee );
|
return xerror ( d, ee );
|
||||||
}
|
}
|
||||||
|
|
||||||
void x11_setup ( Display *display )
|
void x11_setup ( Display *display, xkb_stuff *xkb )
|
||||||
{
|
{
|
||||||
// Set error handle
|
// Set error handle
|
||||||
XSync ( display, False );
|
XSync ( display, False );
|
||||||
|
@ -532,7 +519,7 @@ void x11_setup ( Display *display )
|
||||||
XSync ( display, False );
|
XSync ( display, False );
|
||||||
|
|
||||||
// determine numlock mask so we can bind on keys with and without it
|
// 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 );
|
x11_create_frequently_used_atoms ( display );
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue