commit 73948efc1a0923d5aa36ff1c6d67ac4368cc74d3
parent 4f95adb238736e2070e0bf59ae4f294138eb429a
Author: Chris Guillott <chris@techfo.xyz>
Date: Sun, 19 Nov 2017 12:03:41 -0500
WIP on master: 4f95adb merge upstream
Diffstat:
2 files changed, 46 insertions(+), 2 deletions(-)
diff --git 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
@@ -40,6 +40,7 @@
#endif
#include <xcb/xcb_aux.h>
#include <xcb/randr.h>
+#include <X11/XKBlib.h>
#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) {