-
Notifications
You must be signed in to change notification settings - Fork 3
/
xqp.c
62 lines (54 loc) · 1.22 KB
/
xqp.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
#include <stdio.h>
#include <stdlib.h>
#include <stdbool.h>
#include <getopt.h>
#include <err.h>
#include <xcb/xcb.h>
int main(int argc, char *argv[])
{
int ret = EXIT_SUCCESS;
int opt;
while ((opt = getopt(argc, argv, "hv")) != -1) {
switch (opt) {
case 'h':
printf("xqp [-h|-v] [WID ...]\n");
return EXIT_SUCCESS;
break;
case 'v':
printf("%s\n", VERSION);
return EXIT_SUCCESS;
break;
}
}
int num = argc - optind;
char **args = argv + optind;
xcb_connection_t *dpy = xcb_connect(NULL, NULL);
if (xcb_connection_has_error(dpy)) {
errx(1, "Can't open display.\n");
}
xcb_screen_t *screen = xcb_setup_roots_iterator(xcb_get_setup(dpy)).data;
if (screen == NULL) {
errx(1, "Can't acquire screen.\n");
}
xcb_window_t root = screen->root;
xcb_query_pointer_reply_t *qpr = xcb_query_pointer_reply(dpy, xcb_query_pointer(dpy, root), NULL);
if (qpr != NULL) {
if (num > 0) {
ret = EXIT_FAILURE;
for (int i = 0; i < num; i++) {
xcb_window_t win = strtoul(args[i], NULL, 0);
if (qpr->child == win) {
ret = EXIT_SUCCESS;
break;
}
}
} else {
printf("0x%08x\n", qpr->child);
}
} else {
ret = EXIT_FAILURE;
}
free(qpr);
xcb_disconnect(dpy);
return ret;
}