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