[modules/layout] add a new - generic - layout module
Add a new module "layout" that will eventually evolve into the only keyboard layout module. Right now, it uses an external binary (get-kbd-layout) to determine the layout of a keyboard device (because I did not manage to call libX11 with ctypes correctly). see #788 see #790
This commit is contained in:
parent
902288f30d
commit
dfd23a44de
5 changed files with 93 additions and 0 deletions
39
util/layout.c
Normal file
39
util/layout.c
Normal file
|
@ -0,0 +1,39 @@
|
|||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
|
||||
#include <X11/XKBlib.h>
|
||||
|
||||
void err_if(int condition, const char* msg)
|
||||
{
|
||||
if (condition) {
|
||||
fprintf(stderr, "fatal: %s\n", msg);
|
||||
exit(1);
|
||||
}
|
||||
}
|
||||
|
||||
int main(int argc, char** argv)
|
||||
{
|
||||
Display* display = XOpenDisplay(NULL);
|
||||
err_if(!display, "unable to open display");
|
||||
|
||||
int kbd = argc == 1 ? XkbUseCoreKbd : atoi(argv[1]);
|
||||
|
||||
XkbStateRec state;
|
||||
XkbGetState(display, kbd, &state);
|
||||
|
||||
XkbDescPtr desc = XkbGetKeyboard(display, XkbAllComponentsMask, kbd);
|
||||
char* symbols = XGetAtomName(display, desc->names->symbols);
|
||||
printf("%s\n", symbols);
|
||||
|
||||
#if 0
|
||||
char *group = XGetAtomName(display, desc->names->groups[state.group]);
|
||||
XFree(group);
|
||||
#endif
|
||||
XFree(symbols);
|
||||
XFree(desc);
|
||||
|
||||
XCloseDisplay(display);
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
Loading…
Add table
Add a link
Reference in a new issue