-
Notifications
You must be signed in to change notification settings - Fork 3
/
xkbswitch.c
59 lines (50 loc) · 1.38 KB
/
xkbswitch.c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
#include <stdlib.h>
#include <stdio.h>
#include <err.h>
#include <X11/Xlib.h>
#include <X11/XKBlib.h>
void PrintUsage();
int
main(int argc, char **argv)
{
int xkbGroup;
if (argc < 2 || (xkbGroup = atoi(argv[1])) < 0 || xkbGroup > 3)
{
PrintUsage();
exit(0);
}
int xkbEventType, xkbError, xkbReason;
int mjr = XkbMajorVersion, mnr = XkbMinorVersion;
Display *display = NULL;
display = XkbOpenDisplay(NULL, &xkbEventType, &xkbError,
&mjr, &mnr, &xkbReason);
if (NULL == display)
{
warnx("Cannot open X display %s", XDisplayName(NULL));
switch (xkbReason)
{
case XkbOD_BadServerVersion:
case XkbOD_BadLibraryVersion:
warnx("Incomatible versions of client and server xkb libraries");
break;
case XkbOD_ConnectionRefused:
warnx("Connection to X server refused");
break;
case XkbOD_NonXkbServer:
warnx("XKB extension is not present");
break;
default:
warnx("Unknown error from XkbOpenDisplay: %d", xkbReason);
break;
}
exit(1);
}
Bool status = XkbLockGroup(display, XkbUseCoreKbd, xkbGroup);
XCloseDisplay(display);
return status ? 0 : 1;
}
void
PrintUsage()
{
printf("Usage: xkbswitch [0-3] sets keyboard layout\n");
}