Created
March 13, 2018 11:30
-
-
Save Libbum/fc867edc24fc16c66acfa89c8ea901f2 to your computer and use it in GitHub Desktop.
`gcc -I/usr/include getxkblayout.c -lX11 -lxkbfile`
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include <stdio.h> | |
#include <stdlib.h> | |
#include <string.h> | |
#include <X11/XKBlib.h> | |
#include <X11/extensions/XKBrules.h> | |
int main(int argc, char **argv) { | |
Display *dpy = XOpenDisplay(NULL); | |
if (dpy == NULL) { | |
fprintf(stderr, "Cannot open display\n"); | |
exit(1); | |
} | |
XkbStateRec state; | |
XkbGetState(dpy, XkbUseCoreKbd, &state); | |
XkbRF_VarDefsRec vd; | |
XkbRF_GetNamesProp(dpy, NULL, &vd); | |
char *tok = strtok(vd.layout, ","); | |
for (int i = 0; i < state.group; i++) { | |
tok = strtok(NULL, ","); | |
if (tok == NULL) { | |
return 1; | |
} | |
} | |
printf("%s\n", tok); | |
return 0; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment