-
Notifications
You must be signed in to change notification settings - Fork 24
/
util.c
101 lines (78 loc) · 1.76 KB
/
util.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
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
#include <err.h>
#include <stdlib.h>
#include <xcb/xcb.h>
#include "util.h"
void
init_xcb(xcb_connection_t **con)
{
*con = xcb_connect(NULL, NULL);
if (xcb_connection_has_error(*con))
errx(1, "unable connect to the X server");
}
void
kill_xcb(xcb_connection_t **con)
{
if (*con)
xcb_disconnect(*con);
}
void
get_screen(xcb_connection_t *con, xcb_screen_t **scr)
{
*scr = xcb_setup_roots_iterator(xcb_get_setup(con)).data;
if (*scr == NULL)
errx(1, "unable to retrieve screen informations");
}
int
exists(xcb_connection_t *con, xcb_window_t w)
{
xcb_get_window_attributes_cookie_t c;
xcb_get_window_attributes_reply_t *r;
c = xcb_get_window_attributes(con, w);
r = xcb_get_window_attributes_reply(con, c, NULL);
if (r == NULL)
return 0;
return 1;
}
int
mapped(xcb_connection_t *con, xcb_window_t w)
{
int ms;
xcb_get_window_attributes_cookie_t c;
xcb_get_window_attributes_reply_t *r;
c = xcb_get_window_attributes(con, w);
r = xcb_get_window_attributes_reply(con, c, NULL);
if (r == NULL)
return 0;
ms = r->map_state;
free(r);
return ms == XCB_MAP_STATE_VIEWABLE;
}
int
ignore(xcb_connection_t *con, xcb_window_t w)
{
int or;
xcb_get_window_attributes_cookie_t c;
xcb_get_window_attributes_reply_t *r;
c = xcb_get_window_attributes(con, w);
r = xcb_get_window_attributes_reply(con, c, NULL);
if (r == NULL)
return 0;
or = r->override_redirect;
free(r);
return or;
}
int
get_windows(xcb_connection_t *con, xcb_window_t w, xcb_window_t **l)
{
int childnum = 0;
xcb_query_tree_cookie_t c;
xcb_query_tree_reply_t *r;
c = xcb_query_tree(con, w);
r = xcb_query_tree_reply(con, c, NULL);
if (r == NULL)
errx(1, "0x%08x: no such window", w);
*l = xcb_query_tree_children(r);
childnum = r->children_len;
free(r);
return childnum;
}