diff --git a/Makefile b/Makefile index 4be5ef3..d0aa1e8 100644 --- a/Makefile +++ b/Makefile @@ -20,8 +20,8 @@ SIMD_CFLAGS += -funroll-loops SIMD_CFLAGS += -msse2 CPPFLAGS += -D_GNU_SOURCE CPPFLAGS += -DXKBCOMPOSE=$(shell if test -e /usr/include/xkbcommon/xkbcommon-compose.h ; then echo 1 ; else echo 0 ; fi ) -CFLAGS += $(shell $(PKG_CONFIG) --cflags cairo xcb-composite xcb-xinerama xcb-randr xcb-atom xcb-image xcb-xkb xkbcommon xkbcommon-x11) -LIBS += $(shell $(PKG_CONFIG) --libs cairo xcb-composite xcb-xinerama xcb-randr xcb-atom xcb-image xcb-xkb xkbcommon xkbcommon-x11) +CFLAGS += $(shell $(PKG_CONFIG) --cflags cairo xcb-composite xcb-xinerama xcb-randr xcb-atom xcb-image xcb-xkb xkbcommon xkbcommon-x11 x11) +LIBS += $(shell $(PKG_CONFIG) --libs cairo xcb-composite xcb-xinerama xcb-randr xcb-atom xcb-image xcb-xkb xkbcommon xkbcommon-x11 x11) LIBS += -lev LIBS += -lm diff --git a/i3lock.c b/i3lock.c index e6f9355..b62849c 100644 --- a/i3lock.c +++ b/i3lock.c @@ -40,6 +40,7 @@ #endif #include #include +#include #include "i3lock.h" #include "xcb.h" @@ -174,6 +175,47 @@ void u8_dec(char *s, int *i) { * translate keypresses to utf-8. * */ + +char* get_keylayoutname(void) { + Display *display; + XkbDescPtr keyboard; + XkbStateRec state; + int result; + + display = XkbOpenDisplay( getenv("DISPLAY") , NULL, NULL, NULL, NULL, &result ); + if( !display ) { + errx(1, "X server unreachable"); + } + + keyboard = XkbAllocKeyboard(); + + if ( XkbGetNames(display, XkbGroupNamesMask, keyboard) != Success ) { + errx(1, "Error obtaining symbolic names"); + } + + if( XkbGetState(display, XkbUseCoreKbd, &state) != Success ) { + errx(1, "Error getting keyboard state"); + } + + printf( "aaa: %s\n", XGetAtomName(display, keyboard->names->groups[state.group]) ); + + Atom current_group; + int i = 0; + for (; i < XkbNumKbdGroups; i++) { + if ( (current_group = keyboard->names->groups[i]) != 0 ) { + char* group_name = XGetAtomName(display, current_group); + if (group_name != NULL) { + printf( "bbb: %d. %s\n", i, group_name ); + } + XFree(group_name); + } + } + + // Free symbolic names structures + XkbFreeNames(keyboard, XkbGroupNamesMask, True); + return NULL; +} + static bool load_keymap(void) { if (xkb_context == NULL) { if ((xkb_context = xkb_context_new(0)) == NULL) { @@ -963,6 +1005,8 @@ int main(int argc, char *argv[]) { if ((username = pw->pw_name) == NULL) errx(EXIT_FAILURE, "pw->pw_name is NULL.\n"); + (void) get_keylayoutname(); + char *optstring = "hvnbdc:p:ui:teI:frsS:kB:"; while ((o = getopt_long(argc, argv, optstring, longopts, &longoptind)) != -1) { switch (o) {