到目前为止的答案对我没有用。我使用setkbmap
两种布局english和czech,所以any -print
或-query
总是返回两者。抓住LED的状态xset -q
也不起作用,因为该状态会显示所有键盘指示灯的状态。
迄今为止最好的方法是快速编写此小实用程序:https :
//gist.github.com/fikovnik/ef428e82a26774280c4fdf8f96ce8eeb
#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);
XkbDescPtr desc = XkbGetKeyboard(dpy, XkbAllComponentsMask, XkbUseCoreKbd);
char *group = XGetAtomName(dpy, desc->names->groups[state.group]);
printf("Full name: %s\n", group);
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("Layout name: %s\n", tok);
return 0;
}
并使用编译
gcc -I/usr/include getxkblayout.c -lX11 -lxkbfile