]> Dogcows Code - chaz/tint2/blob - src/systray/xproperty.c
New import
[chaz/tint2] / src / systray / xproperty.c
1 #include "xproperty.h"
2 #include "docker.h"
3
4 gboolean xprop_get8(Window window, Atom atom, Atom type, int size,
5 gulong *count, guchar **value)
6 {
7 Atom ret_type;
8 int ret_size;
9 unsigned long ret_bytes;
10 int result;
11 unsigned long nelements = *count;
12 unsigned long maxread = nelements;
13
14 *value = NULL;
15
16 /* try get the first element */
17 result = XGetWindowProperty(display, window, atom, 0l, 1l, False,
18 AnyPropertyType, &ret_type, &ret_size,
19 &nelements, &ret_bytes, value);
20 if (! (result == Success && ret_type == type &&
21 ret_size == size && nelements > 0)) {
22 if (*value) XFree(*value);
23 *value = NULL;
24 nelements = 0;
25 } else {
26 /* we didn't the whole property's value, more to get */
27 if (! (ret_bytes == 0 || maxread <= nelements)) {
28 int remain;
29
30 /* get the entire property since it is larger than one element long */
31 XFree(*value);
32 /*
33 the number of longs that need to be retreived to get the property's
34 entire value. The last + 1 is the first long that we retrieved above.
35 */
36 remain = (ret_bytes - 1)/sizeof(long) + 1 + 1;
37 /* dont get more than the max */
38 if (remain > size/8 * (signed)maxread)
39 remain = size/8 * (signed)maxread;
40 result = XGetWindowProperty(display, window, atom, 0l, remain,
41 False, type, &ret_type, &ret_size,
42 &nelements, &ret_bytes, value);
43 /*
44 If the property has changed type/size, or has grown since our first
45 read of it, then stop here and try again. If it shrank, then this will
46 still work.
47 */
48 if (!(result == Success && ret_type == type &&
49 ret_size == size && ret_bytes == 0)) {
50 if (*value) XFree(*value);
51 xprop_get8(window, atom, type, size, count, value);
52 }
53 }
54 }
55
56 *count = nelements;
57 return *value != NULL;
58 }
59
60 gboolean xprop_get32(Window window, Atom atom, Atom type, int size,
61 gulong *count, gulong **value)
62 {
63 return xprop_get8(window, atom, type, size, count, (guchar**)value);
64 }
This page took 0.039434 seconds and 4 git commands to generate.