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