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