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