]> icculus.org git repositories - mikachu/openbox.git/blob - cwmcc/root_props.c
complete the root property get functions
[mikachu/openbox.git] / cwmcc / root_props.c
1 #include "cwmcc_internal.h"
2 #include "atom.h"
3 #include "prop.h"
4 #include "root_props.h"
5
6 #ifdef HAVE_STRING_H
7 #  include <string.h>
8 #endif
9
10 void cwmcc_root_get_supported(Window win, Atom **atoms)
11 {
12     gulong num;
13
14     if (!prop_get_array32(win, CWMCC_ATOM(root, net_supported),
15                           CWMCC_ATOM(type, atom), atoms, &num)) {
16         g_warning("Failed to read NET_SUPPORTED from 0x%lx", win);
17         *atoms = NULL;
18     }
19 }
20
21 void cwmcc_root_get_client_list(Window win, Window **windows)
22 {
23     gulong num;
24
25     if (!prop_get_array32(win, CWMCC_ATOM(root, net_client_list),
26                           CWMCC_ATOM(type, window), windows, &num)) {
27         g_warning("Failed to read NET_CLIENT_LIST from 0x%lx", win);
28         *windows = NULL;
29     }
30 }
31
32 void cwmcc_root_get_client_list_stacking(Window win, Window **windows)
33 {
34     gulong num;
35
36     if (!prop_get_array32(win, CWMCC_ATOM(root, net_client_list_stacking),
37                           CWMCC_ATOM(type, window), windows, &num)) {
38         g_warning("Failed to read NET_CLIENT_LIST_STACKING from 0x%lx", win);
39         *windows = NULL;
40     }
41 }
42
43 void cwmcc_root_get_number_of_desktops(Window win, gulong *desktops)
44 {
45     if (!prop_get32(win, CWMCC_ATOM(root, net_number_of_desktops),
46                     CWMCC_ATOM(type, cardinal), desktops)) {
47         g_warning("Failed to read NET_NUMBER_OF_DESKTOPS from 0x%lx", win);
48         *desktops = 1;
49     }
50 }
51
52 void cwmcc_root_get_desktop_geometry(Window win, gulong *w, gulong *h)
53 {
54     gulong *data = NULL, num;
55
56     if (!prop_get_array32(win, CWMCC_ATOM(root, net_desktop_geometry),
57                     CWMCC_ATOM(type, cardinal), &data, &num)) {
58         g_warning("Failed to read NET_DESKTOP_GEOMETRY from 0x%lx", win);
59         *w = *h = 0;
60     } else if (num != 2) {
61         g_warning("Read invalid NET_DESKTOP_GEOMETRY from 0x%lx", win);
62         *w = *h = 0;
63     } else {
64         *w = data[0];
65         *h = data[1];
66     }
67     g_free(data);
68 }
69
70 void cwmcc_root_get_desktop_viewport(Window win, gulong *x, gulong *y)
71 {
72     gulong *data = NULL, num;
73
74     if (!prop_get_array32(win, CWMCC_ATOM(root, net_desktop_viewport),
75                     CWMCC_ATOM(type, cardinal), &data, &num)) {
76         g_warning("Failed to read NET_DESKTOP_VIEWPORT from 0x%lx", win);
77         *x = *y = 0;
78     } else if (num != 2) {
79         g_warning("Read invalid NET_DESKTOP_VIEWPORT from 0x%lx", win);
80         *x = *y = 0;
81     } else {
82         *x = data[0];
83         *y = data[1];
84     }
85     g_free(data);
86 }
87
88 void cwmcc_root_get_current_desktop(Window win, gulong *desktop)
89 {
90     if (!prop_get32(win, CWMCC_ATOM(root, net_current_desktop),
91                     CWMCC_ATOM(type, cardinal), desktop)) {
92         g_warning("Failed to read NET_CURRENT_DESKTOP from 0x%lx", win);
93         *desktop = 0;
94     }
95 }
96
97 void cwmcc_root_get_desktop_names(Window win, char ***names)
98 {
99     if (!prop_get_strings_utf8(win,
100                                CWMCC_ATOM(root, net_desktop_names), names)) {
101         g_warning("Failed to read NET_DESKTOP_NAMES from 0x%lx", win);
102         *names = NULL;
103     }
104 }
105
106 void cwmcc_root_get_active_window(Window win, Window *window)
107 {
108     if (!prop_get32(win, CWMCC_ATOM(root, net_active_window),
109                     CWMCC_ATOM(type, window), window)) {
110         g_warning("Failed to read NET_ACTIVE_WINDOW from 0x%lx", win);
111         *window = None;
112     }
113 }
114
115 void cwmcc_root_get_workarea(Window win, int **x, int **y, int **w, int **h)
116 {
117     gulong *data = NULL, num;
118     gulong desks, i;
119
120     /* need the number of desktops */
121     cwmcc_root_get_number_of_desktops(win, &desks);
122
123     if (!prop_get_array32(win, CWMCC_ATOM(root, net_workarea),
124                     CWMCC_ATOM(type, cardinal), &data, &num)) {
125         g_warning("Failed to read NET_DESKTOP_LAYOUT from 0x%lx", win);
126     } else if (num != 4 * desks) {
127         g_warning("Read invalid NET_DESKTOP_LAYOUT from 0x%lx", win);
128     } else {
129         *x = g_new(int, desks);
130         *y = g_new(int, desks);
131         *w = g_new(int, desks);
132         *h = g_new(int, desks);
133         for (i = 0; i < desks; ++i) {
134             (*x)[i] = data[i * 4];
135             (*y)[i] = data[i * 4 + 1];
136             (*w)[i] = data[i * 4 + 2];
137             (*h)[i] = data[i * 4 + 3];
138         }
139     }
140 }
141
142 void cwmcc_root_get_supporting_wm_check(Window win, Window *window)
143 {
144     if (!prop_get32(win, CWMCC_ATOM(root, net_supporting_wm_check),
145                     CWMCC_ATOM(type, window), window)) {
146         g_warning("Failed to read NET_SUPPORTING_WM_CHECK from 0x%lx", win);
147         *window = None;
148     }
149 }
150
151 void cwmcc_root_get_desktop_layout(Window win,
152                                    struct Cwmcc_DesktopLayout *layout)
153 {
154     gulong *data = NULL, num;
155     gulong desks;
156
157     /* need the number of desktops */
158     cwmcc_root_get_number_of_desktops(win, &desks);
159
160     layout->orientation = Cwmcc_Orientation_Horz;
161     layout->start_corner = Cwmcc_Corner_TopLeft;
162     layout->rows = 1;
163     layout->columns = desks;
164
165     if (!prop_get_array32(win, CWMCC_ATOM(root, net_desktop_layout),
166                     CWMCC_ATOM(type, cardinal), &data, &num)) {
167         g_warning("Failed to read NET_DESKTOP_LAYOUT from 0x%lx", win);
168     } else if (num != 4) {
169         g_warning("Read invalid NET_DESKTOP_LAYOUT from 0x%lx", win);
170     } else {
171         if (data[0] == Cwmcc_Orientation_Horz ||
172             data[0] == Cwmcc_Orientation_Vert)
173             layout->orientation = data[0];
174         if (data[3] == Cwmcc_Corner_TopLeft ||
175             data[3] == Cwmcc_Corner_TopRight ||
176             data[3] == Cwmcc_Corner_BottomLeft ||
177             data[3] == Cwmcc_Corner_BottomRight)
178             layout->start_corner = data[3];
179         layout->rows = data[2];
180         layout->columns = data[1];
181
182         /* bounds checking */
183         if (layout->orientation == Cwmcc_Orientation_Horz) {
184             if (layout->rows > desks)
185                 layout->rows = desks;
186             if (layout->columns > ((desks + desks % layout->rows) /
187                                    layout->rows))
188                 layout->columns = ((desks + desks % layout->rows) /
189                                    layout->rows);
190         } else {
191             if (layout->columns > desks)
192                 layout->columns = desks;
193             if (layout->rows > ((desks + desks % layout->columns) /
194                                 layout->columns))
195                 layout->rows = ((desks + desks % layout->columns) /
196                                 layout->columns);
197         }
198     }
199     g_free(data);
200 }
201
202 void cwmcc_root_get_showing_desktop(Window win, gboolean *showing)
203 {
204     gulong a;
205
206     if (!prop_get32(win, CWMCC_ATOM(root, net_showing_desktop),
207                     CWMCC_ATOM(type, cardinal), &a)) {
208         g_warning("Failed to read NET_SHOWING_DESKTOP from 0x%lx", win);
209         a = FALSE;
210     }
211     *showing = !!a;
212 }
213
214 void cwmcc_root_get_openbox_pid(Window win, gulong *pid)
215 {
216     if (!prop_get32(win, CWMCC_ATOM(root, openbox_pid),
217                     CWMCC_ATOM(type, cardinal), pid)) {
218         g_warning("Failed to read OPENBOX_PID from 0x%lx", win);
219         *pid = 0;
220     }
221 }
222