]> icculus.org git repositories - mikachu/rspanel.git/blob - xprop.c
this XXX was fixed already
[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,
42                      Atom type, int *items)
43 {
44     Atom type_ret;
45     int format_ret;
46     unsigned long items_ret;
47     unsigned long after_ret;
48     unsigned char *prop_data;
49
50     prop_data = 0;
51
52     XGetWindowProperty(sc->dd, win, sc->atoms[prop], 0, 0x7fffffff,
53                        False, type, &type_ret, &format_ret, &items_ret,
54                        &after_ret, &prop_data);
55     if (items)
56         *items = items_ret;
57
58     return prop_data;
59 }
60
61 int xprop_get_num(screen *sc, Window win, xprop_t p)
62 {
63     int num = 0;
64     unsigned long *data;
65
66     data = xprop_get_data(sc, win, p, XA_CARDINAL, 0);
67     if (data) {
68         num = *data;
69         XFree(data);
70     }
71     return num;
72 }
73
74 char* xprop_get_utf8(screen *sc, Window win, xprop_t p)
75 {
76     return xprop_get_data(sc, win, p, sc->atoms[UTF8_STRING], 0);
77 }
78
79 char* xprop_get_string(screen *sc, Window win, xprop_t p)
80 {
81     return xprop_get_data(sc, win, p, XA_STRING, 0);
82 }
83
84 void xprop_set_num(screen *sc, Window win, xprop_t p, long val)
85 {
86     XChangeProperty(sc->dd, win, sc->atoms[p], XA_CARDINAL, 32,
87                     PropModeReplace, (unsigned char *)&val, 1);
88 }
89
90 void xprop_set_atom(screen *sc, Window win, xprop_t p, xprop_t at)
91 {
92     XChangeProperty(sc->dd, win, sc->atoms[p], XA_ATOM, 32,
93                     PropModeReplace, (unsigned char *)&sc->atoms[at], 1);
94 }
95
96 void xprop_set_array(screen *sc, Window win, xprop_t p,
97                      const long *vals, int num)
98 {
99     XChangeProperty(sc->dd, win, sc->atoms[p], XA_CARDINAL, 32, PropModeReplace,
100                     (unsigned char *)vals, num);
101 }
102
103 void xprop_set_string(screen *sc, Window win, xprop_t p, const char *s)
104 {
105     XChangeProperty(sc->dd, win, sc->atoms[p], XA_STRING, 8, PropModeReplace,
106                     (unsigned char *)s, strlen(s));
107 }