Browse Source

WIP on master: 4f95adb merge upstream

master
Chris Guillott 7 years ago
parent
commit
73948efc1a
  1. 4
      Makefile
  2. 44
      i3lock.c

4
Makefile

@ -20,8 +20,8 @@ SIMD_CFLAGS += -funroll-loops
SIMD_CFLAGS += -msse2 SIMD_CFLAGS += -msse2
CPPFLAGS += -D_GNU_SOURCE CPPFLAGS += -D_GNU_SOURCE
CPPFLAGS += -DXKBCOMPOSE=$(shell if test -e /usr/include/xkbcommon/xkbcommon-compose.h ; then echo 1 ; else echo 0 ; fi ) 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) 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) 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 += -lev
LIBS += -lm LIBS += -lm

44
i3lock.c

@ -40,6 +40,7 @@
#endif #endif
#include <xcb/xcb_aux.h> #include <xcb/xcb_aux.h>
#include <xcb/randr.h> #include <xcb/randr.h>
#include <X11/XKBlib.h>
#include "i3lock.h" #include "i3lock.h"
#include "xcb.h" #include "xcb.h"
@ -174,6 +175,47 @@ void u8_dec(char *s, int *i) {
* translate keypresses to utf-8. * 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) { static bool load_keymap(void) {
if (xkb_context == NULL) { if (xkb_context == NULL) {
if ((xkb_context = xkb_context_new(0)) == 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) if ((username = pw->pw_name) == NULL)
errx(EXIT_FAILURE, "pw->pw_name is NULL.\n"); errx(EXIT_FAILURE, "pw->pw_name is NULL.\n");
(void) get_keylayoutname();
char *optstring = "hvnbdc:p:ui:teI:frsS:kB:"; char *optstring = "hvnbdc:p:ui:teI:frsS:kB:";
while ((o = getopt_long(argc, argv, optstring, longopts, &longoptind)) != -1) { while ((o = getopt_long(argc, argv, optstring, longopts, &longoptind)) != -1) {
switch (o) { switch (o) {

Loading…
Cancel
Save