-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathinds.c
72 lines (68 loc) · 1.68 KB
/
inds.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
60
61
62
63
64
65
66
67
68
69
70
71
72
// XkbGetIndicatorState
#include <X11/XKBlib.h>
#include <X11/Xlib.h>
#include <X11/Xresource.h>
#include <X11/Xutil.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
void output(unsigned char v) {
if (v == 0) {
printf("-");
return;
}
if (v & 128) {
printf("G");
}
if (v & 64) {
printf("W");
}
if (v & 8) {
printf("A");
}
if (v & 4) {
printf("C");
}
if (v & 1) {
printf("S");
}
}
int main(int argc, char **argv) {
if (argc > 1 && strcmp(argv[1], "-h") == 0) {
printf("\tReturns status of latched and locked mods.\n");
printf("\t\t'-' - no mods active.\n");
printf("\t\t'S' - 'Shift' active.\n");
printf("\t\t'C' - 'Control' active.\n");
printf("\t\t'A' - 'Alt' active.\n");
printf("\t\t'G' - 'AltGr' active.\n");
printf("\t\t'W' - 'Windows' active.\n");
printf("\n");
return (0);
}
int screen;
Display *dpy;
dpy = XOpenDisplay(NULL);
if (!dpy) {
fprintf(stderr, "unable to connect to display\n");
return 7;
}
screen = DefaultScreen(dpy);
// unsigned int *mask;
// int status = XkbGetIndicatorState(dpy, XkbUseCoreKbd, mask);
XkbStateRec state;
int status = XkbGetState(dpy, XkbUseCoreKbd, &state);
if (status > 0) {
printf("!\n");
return (status);
}
if (argc > 1 && strcmp(argv[1], "-r") == 0) {
printf("%d %d\n", state.latched_mods, state.locked_mods);
} else {
output(state.latched_mods);
printf(" ");
output(state.locked_mods);
printf("\n");
}
XCloseDisplay(dpy);
return 0;
}