]> icculus.org git repositories - mikachu/rspanel.git/blob - xprop.c
fix a XXX for drawing icons
[mikachu/rspanel.git] / xprop.c
1 #include "xprop.h"
2 #include "rspanel.h"
3
4 char *xprop_names[] = {
5     /* types */
6     "UTF8_STRING",
7     /* clients */
8     "KWM_WIN_ICON",
9     "WM_STATE",
10     "WM_NAME",
11     "_MOTIF_WM_HINTS",
12     "_NET_WM_STATE",
13     "_NET_WM_STATE_SKIP_TASKBAR",
14     "_NET_WM_STATE_SHADED",
15     "_NET_WM_STATE_BELOW",
16     "_NET_WM_STATE_HIDDEN",
17     "_NET_WM_DESKTOP",
18     "_NET_WM_WINDOW_TYPE",
19     "_NET_WM_WINDOW_TYPE_DOCK",
20     "_NET_WM_STRUT",
21     "_NET_WM_ICON_GEOMETRY",
22     "_NET_WM_ICON",
23     "_WIN_HINTS",
24     /* root */
25     "_NET_CLIENT_LIST",
26     "_NET_CLIENT_LIST_STACKING",
27     "_NET_NUMBER_OF_DESKTOPS",
28     "_NET_CURRENT_DESKTOP",
29     "_OB_WM_ACTION",
30     "_NET_WM_NAME",
31     "_NET_ACTIVE_WINDOW",
32     "_NET_RESTACK_WINDOW",
33     "_OB_FOCUS",
34 };
35
36 void xprop_init(screen *sc)
37 {
38     XInternAtoms(sc->dd, xprop_names, XPROP_COUNT, False, sc->atoms);
39 }
40
41 void* xprop_get_data(screen *sc, Window win, xprop_t prop, Atom type, int *items)
42 {
43     Atom type_ret;
44     int format_ret;
45     unsigned long items_ret;
46     unsigned long after_ret;
47     unsigned char *prop_data;
48
49     prop_data = 0;
50
51     XGetWindowProperty(sc->dd, win, sc->atoms[prop], 0, 0x7fffffff, False, type, &type_ret,
52                        &format_ret, &items_ret, &after_ret, &prop_data);
53     if (items)
54         *items = items_ret;
55
56     return prop_data;
57 }
58
59 int xprop_get_num(screen *sc, Window win, xprop_t p)
60 {
61     int num = 0;
62     unsigned long *data;
63
64     data = xprop_get_data(sc, win, p, XA_CARDINAL, 0);
65     if (data) {
66         num = *data;
67         XFree(data);
68     }
69     return num;
70 }
71
72 char* xprop_get_utf8(screen *sc, Window win, xprop_t p)
73 {
74     return xprop_get_data(sc, win, p, sc->atoms[UTF8_STRING], 0);
75 }
76
77 char* xprop_get_string(screen *sc, Window win, xprop_t p)
78 {
79     return xprop_get_data(sc, win, p, XA_STRING, 0);
80 }
81
82 void xprop_set_num(screen *sc, Window win, xprop_t p, long val)
83 {
84     XChangeProperty(sc->dd, win, sc->atoms[p], XA_CARDINAL, 32,
85                     PropModeReplace, (unsigned char *)&val, 1);
86 }
87
88 void xprop_set_atom(screen *sc, Window win, xprop_t p, xprop_t at)
89 {
90     XChangeProperty(sc->dd, win, sc->atoms[p], XA_ATOM, 32,
91                     PropModeReplace, (unsigned char *)&sc->atoms[at], 1);
92 }
93
94 void xprop_set_array(screen *sc, Window win, xprop_t p, const long *vals, int num)
95 {
96     XChangeProperty(sc->dd, win, sc->atoms[p], XA_CARDINAL, 32, PropModeReplace,
97                     (unsigned char *)vals, num);
98 }
99
100 void xprop_set_string(screen *sc, Window win, xprop_t p, const char *s)
101 {
102     XChangeProperty(sc->dd, win, sc->atoms[p], XA_STRING, 8, PropModeReplace,
103                     (unsigned char *)s, strlen(s));
104 }