]> icculus.org git repositories - mikachu/rspanel.git/blob - xprop.c
nothing really
[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     "_NET_WM_WINDOW_TYPE_DESKTOP",
18     "_NET_WM_WINDOW_TYPE_DOCK",
19     "_NET_WM_WINDOW_TYPE_TOOLBAR",
20     "_NET_WM_WINDOW_TYPE_MENU",
21     "_NET_WM_WINDOW_TYPE_UTILITY",
22     "_NET_WM_WINDOW_TYPE_SPLASH",
23     "_NET_WM_WINDOW_TYPE_DIALOG",
24     "_NET_WM_WINDOW_TYPE_NORMAL",
25     "_NET_WM_STRUT",
26     "_NET_WM_ICON_GEOMETRY",
27     "_NET_WM_ICON",
28     "_WIN_HINTS",
29     "_NET_CLIENT_LIST",
30     "_NET_CLIENT_LIST_STACKING",
31     "_NET_NUMBER_OF_DESKTOPS",
32     "_NET_CURRENT_DESKTOP",
33     "_OB_WM_ACTION",
34     "_NET_WM_NAME",
35     "_NET_ACTIVE_WINDOW",
36     "_NET_RESTACK_WINDOW",
37     "_OB_FOCUS",
38     "_OB_THEME"
39 };
40
41 void xprop_init(screen *sc)
42 {
43     XInternAtoms(sc->dd, xprop_names, XPROP_COUNT, False, sc->atoms);
44 }
45
46 void* xprop_get_data(screen *sc, Window win, xprop_t prop,
47                      Atom type, int *items)
48 {
49     Atom type_ret;
50     int format_ret;
51     unsigned long items_ret;
52     unsigned long after_ret;
53     unsigned char *prop_data;
54
55     prop_data = 0;
56
57     XGetWindowProperty(sc->dd, win, sc->atoms[prop], 0, 0x7fffffff,
58                        False, type, &type_ret, &format_ret, &items_ret,
59                        &after_ret, &prop_data);
60     if (items)
61         *items = items_ret;
62
63     return prop_data;
64 }
65
66 int xprop_get_num(screen *sc, Window win, xprop_t p)
67 {
68     int num = 0;
69     unsigned long *data;
70
71     data = xprop_get_data(sc, win, p, XA_CARDINAL, 0);
72     if (data) {
73         num = *data;
74         XFree(data);
75     }
76     return num;
77 }
78
79 char* xprop_get_utf8(screen *sc, Window win, xprop_t p)
80 {
81     return xprop_get_data(sc, win, p, sc->atoms[UTF8_STRING], 0);
82 }
83
84 char* xprop_get_string(screen *sc, Window win, xprop_t p)
85 {
86     return xprop_get_data(sc, win, p, XA_STRING, 0);
87 }
88
89 void xprop_set_num(screen *sc, Window win, xprop_t p, long val)
90 {
91     XChangeProperty(sc->dd, win, sc->atoms[p], XA_CARDINAL, 32,
92                     PropModeReplace, (unsigned char *)&val, 1);
93 }
94
95 void xprop_set_atom(screen *sc, Window win, xprop_t p, xprop_t at)
96 {
97     XChangeProperty(sc->dd, win, sc->atoms[p], XA_ATOM, 32,
98                     PropModeReplace, (unsigned char *)&sc->atoms[at], 1);
99 }
100
101 void xprop_set_array(screen *sc, Window win, xprop_t p,
102                      const long *vals, int num)
103 {
104     XChangeProperty(sc->dd, win, sc->atoms[p], XA_CARDINAL, 32, PropModeReplace,
105                     (unsigned char *)vals, num);
106 }
107
108 void xprop_set_string(screen *sc, Window win, xprop_t p, const char *s)
109 {
110     XChangeProperty(sc->dd, win, sc->atoms[p], XA_STRING, 8, PropModeReplace,
111                     (unsigned char *)s, strlen(s));
112 }