]> Dogcows Code - chaz/openbox/blob - openbox/prop.c
look for masks only where the themerc was read from
[chaz/openbox] / openbox / prop.c
1 #include "prop.h"
2 #include "openbox.h"
3
4 #include <X11/Xatom.h>
5
6 Atoms prop_atoms;
7
8 #define CREATE(var, name) (prop_atoms.var = \
9 XInternAtom(ob_display, name, FALSE))
10
11 void prop_startup()
12 {
13 CREATE(cardinal, "CARDINAL");
14 CREATE(window, "WINDOW");
15 CREATE(pixmap, "PIXMAP");
16 CREATE(atom, "ATOM");
17 CREATE(string, "STRING");
18 CREATE(utf8, "UTF8_STRING");
19
20 CREATE(manager, "MANAGER");
21
22 CREATE(wm_colormap_windows, "WM_COLORMAP_WINDOWS");
23 CREATE(wm_protocols, "WM_PROTOCOLS");
24 CREATE(wm_state, "WM_STATE");
25 CREATE(wm_change_state, "WM_CHANGE_STATE");
26 CREATE(wm_delete_window, "WM_DELETE_WINDOW");
27 CREATE(wm_take_focus, "WM_TAKE_FOCUS");
28 CREATE(wm_name, "WM_NAME");
29 CREATE(wm_icon_name, "WM_ICON_NAME");
30 CREATE(wm_class, "WM_CLASS");
31 CREATE(wm_window_role, "WM_WINDOW_ROLE");
32 CREATE(motif_wm_hints, "_MOTIF_WM_HINTS");
33
34 CREATE(sm_client_id, "SM_CLIENT_ID");
35
36 CREATE(net_supported, "_NET_SUPPORTED");
37 CREATE(net_client_list, "_NET_CLIENT_LIST");
38 CREATE(net_client_list_stacking, "_NET_CLIENT_LIST_STACKING");
39 CREATE(net_number_of_desktops, "_NET_NUMBER_OF_DESKTOPS");
40 CREATE(net_desktop_geometry, "_NET_DESKTOP_GEOMETRY");
41 CREATE(net_desktop_viewport, "_NET_DESKTOP_VIEWPORT");
42 CREATE(net_current_desktop, "_NET_CURRENT_DESKTOP");
43 CREATE(net_desktop_names, "_NET_DESKTOP_NAMES");
44 CREATE(net_active_window, "_NET_ACTIVE_WINDOW");
45 CREATE(net_workarea, "_NET_WORKAREA");
46 CREATE(net_supporting_wm_check, "_NET_SUPPORTING_WM_CHECK");
47 CREATE(net_desktop_layout, "_NET_DESKTOP_LAYOUT");
48 CREATE(net_showing_desktop, "_NET_SHOWING_DESKTOP");
49
50 CREATE(net_close_window, "_NET_CLOSE_WINDOW");
51 CREATE(net_wm_moveresize, "_NET_WM_MOVERESIZE");
52 CREATE(net_moveresize_window, "_NET_MOVERESIZE_WINDOW");
53
54 CREATE(net_wm_name, "_NET_WM_NAME");
55 CREATE(net_wm_visible_name, "_NET_WM_VISIBLE_NAME");
56 CREATE(net_wm_icon_name, "_NET_WM_ICON_NAME");
57 CREATE(net_wm_visible_icon_name, "_NET_WM_VISIBLE_ICON_NAME");
58 CREATE(net_wm_desktop, "_NET_WM_DESKTOP");
59 CREATE(net_wm_window_type, "_NET_WM_WINDOW_TYPE");
60 CREATE(net_wm_state, "_NET_WM_STATE");
61 CREATE(net_wm_strut, "_NET_WM_STRUT");
62 CREATE(net_wm_icon, "_NET_WM_ICON");
63 /* CREATE(net_wm_pid, "_NET_WM_PID"); */
64 CREATE(net_wm_allowed_actions, "_NET_WM_ALLOWED_ACTIONS");
65
66 /* CREATE(net_wm_ping, "_NET_WM_PING"); */
67
68 CREATE(net_wm_window_type_desktop, "_NET_WM_WINDOW_TYPE_DESKTOP");
69 CREATE(net_wm_window_type_dock, "_NET_WM_WINDOW_TYPE_DOCK");
70 CREATE(net_wm_window_type_toolbar, "_NET_WM_WINDOW_TYPE_TOOLBAR");
71 CREATE(net_wm_window_type_menu, "_NET_WM_WINDOW_TYPE_MENU");
72 CREATE(net_wm_window_type_utility, "_NET_WM_WINDOW_TYPE_UTILITY");
73 CREATE(net_wm_window_type_splash, "_NET_WM_WINDOW_TYPE_SPLASH");
74 CREATE(net_wm_window_type_dialog, "_NET_WM_WINDOW_TYPE_DIALOG");
75 CREATE(net_wm_window_type_normal, "_NET_WM_WINDOW_TYPE_NORMAL");
76
77 prop_atoms.net_wm_moveresize_size_topleft = 0;
78 prop_atoms.net_wm_moveresize_size_top = 1;
79 prop_atoms.net_wm_moveresize_size_topright = 2;
80 prop_atoms.net_wm_moveresize_size_right = 3;
81 prop_atoms.net_wm_moveresize_size_bottomright = 4;
82 prop_atoms.net_wm_moveresize_size_bottom = 5;
83 prop_atoms.net_wm_moveresize_size_bottomleft = 6;
84 prop_atoms.net_wm_moveresize_size_left = 7;
85 prop_atoms.net_wm_moveresize_move = 8;
86 prop_atoms.net_wm_moveresize_size_keyboard = 9;
87 prop_atoms.net_wm_moveresize_move_keyboard = 10;
88
89 CREATE(net_wm_action_move, "_NET_WM_ACTION_MOVE");
90 CREATE(net_wm_action_resize, "_NET_WM_ACTION_RESIZE");
91 CREATE(net_wm_action_minimize, "_NET_WM_ACTION_MINIMIZE");
92 CREATE(net_wm_action_shade, "_NET_WM_ACTION_SHADE");
93 CREATE(net_wm_action_stick, "_NET_WM_ACTION_STICK");
94 CREATE(net_wm_action_maximize_horz, "_NET_WM_ACTION_MAXIMIZE_HORZ");
95 CREATE(net_wm_action_maximize_vert, "_NET_WM_ACTION_MAXIMIZE_VERT");
96 CREATE(net_wm_action_fullscreen, "_NET_WM_ACTION_FULLSCREEN");
97 CREATE(net_wm_action_change_desktop, "_NET_WM_ACTION_CHANGE_DESKTOP");
98 CREATE(net_wm_action_close, "_NET_WM_ACTION_CLOSE");
99 CREATE(net_wm_state_modal, "_NET_WM_STATE_MODAL");
100 CREATE(net_wm_state_sticky, "_NET_WM_STATE_STICKY");
101 CREATE(net_wm_state_maximized_vert, "_NET_WM_STATE_MAXIMIZED_VERT");
102 CREATE(net_wm_state_maximized_horz, "_NET_WM_STATE_MAXIMIZED_HORZ");
103 CREATE(net_wm_state_shaded, "_NET_WM_STATE_SHADED");
104 CREATE(net_wm_state_skip_taskbar, "_NET_WM_STATE_SKIP_TASKBAR");
105 CREATE(net_wm_state_skip_pager, "_NET_WM_STATE_SKIP_PAGER");
106 CREATE(net_wm_state_hidden, "_NET_WM_STATE_HIDDEN");
107 CREATE(net_wm_state_fullscreen, "_NET_WM_STATE_FULLSCREEN");
108 CREATE(net_wm_state_above, "_NET_WM_STATE_ABOVE");
109 CREATE(net_wm_state_below, "_NET_WM_STATE_BELOW");
110
111 prop_atoms.net_wm_state_add = 1;
112 prop_atoms.net_wm_state_remove = 0;
113 prop_atoms.net_wm_state_toggle = 2;
114
115 prop_atoms.net_wm_orientation_horz = 0;
116 prop_atoms.net_wm_orientation_vert = 1;
117 prop_atoms.net_wm_topleft = 0;
118 prop_atoms.net_wm_topright = 1;
119 prop_atoms.net_wm_bottomright = 2;
120 prop_atoms.net_wm_bottomleft = 3;
121
122 CREATE(kde_net_system_tray_windows, "_KDE_NET_SYSTEM_TRAY_WINDOWS");
123 CREATE(kde_net_wm_system_tray_window_for,
124 "_KDE_NET_WM_SYSTEM_TRAY_WINDOW_FOR");
125 CREATE(kde_net_wm_window_type_override,
126 "_KDE_NET_WM_WINDOW_TYPE_OVERRIDE");
127
128 CREATE(kwm_win_icon, "KWM_WIN_ICON");
129
130 CREATE(rootpmapid, "_XROOTPMAP_ID");
131 CREATE(esetrootid, "ESETROOT_PMAP_ID");
132
133 CREATE(openbox_pid, "_OPENBOX_PID");
134 CREATE(openbox_premax, "_OPENBOX_PREMAX");
135 }
136
137 #include <X11/Xutil.h>
138 #include <glib.h>
139 #include <string.h>
140
141 /* this just isn't used... and it also breaks on 64bit, watch out
142 static gboolean get(Window win, Atom prop, Atom type, int size,
143 guchar **data, gulong num)
144 {
145 gboolean ret = FALSE;
146 int res;
147 guchar *xdata = NULL;
148 Atom ret_type;
149 int ret_size;
150 gulong ret_items, bytes_left;
151 long num32 = 32 / size * num; /\* num in 32-bit elements *\/
152
153 res = XGetWindowProperty(display, win, prop, 0l, num32,
154 FALSE, type, &ret_type, &ret_size,
155 &ret_items, &bytes_left, &xdata);
156 if (res == Success && ret_items && xdata) {
157 if (ret_size == size && ret_items >= num) {
158 *data = g_memdup(xdata, num * (size / 8));
159 ret = TRUE;
160 }
161 XFree(xdata);
162 }
163 return ret;
164 }
165 */
166
167 static gboolean get_prealloc(Window win, Atom prop, Atom type, int size,
168 guchar *data, gulong num)
169 {
170 gboolean ret = FALSE;
171 int res;
172 guchar *xdata = NULL;
173 Atom ret_type;
174 int ret_size;
175 gulong ret_items, bytes_left;
176 long num32 = 32 / size * num; /* num in 32-bit elements */
177
178 res = XGetWindowProperty(ob_display, win, prop, 0l, num32,
179 FALSE, type, &ret_type, &ret_size,
180 &ret_items, &bytes_left, &xdata);
181 if (res == Success && ret_items && xdata) {
182 if (ret_size == size && ret_items >= num) {
183 guint i;
184 for (i = 0; i < num; ++i)
185 switch (size) {
186 case 8:
187 data[i] = xdata[i];
188 break;
189 case 16:
190 ((guint16*)data)[i] = ((guint16*)xdata)[i];
191 break;
192 case 32:
193 ((guint32*)data)[i] = ((gulong*)xdata)[i];
194 break;
195 default:
196 g_assert_not_reached(); /* unhandled size */
197 }
198 ret = TRUE;
199 }
200 XFree(xdata);
201 }
202 return ret;
203 }
204
205 static gboolean get_all(Window win, Atom prop, Atom type, int size,
206 guchar **data, guint *num)
207 {
208 gboolean ret = FALSE;
209 int res;
210 guchar *xdata = NULL;
211 Atom ret_type;
212 int ret_size;
213 gulong ret_items, bytes_left;
214
215 res = XGetWindowProperty(ob_display, win, prop, 0l, G_MAXLONG,
216 FALSE, type, &ret_type, &ret_size,
217 &ret_items, &bytes_left, &xdata);
218 if (res == Success) {
219 if (ret_size == size && ret_items > 0) {
220 guint i;
221
222 *data = g_malloc(ret_items * (size / 8));
223 for (i = 0; i < ret_items; ++i)
224 switch (size) {
225 case 8:
226 (*data)[i] = xdata[i];
227 break;
228 case 16:
229 ((guint16*)*data)[i] = ((guint16*)xdata)[i];
230 break;
231 case 32:
232 ((guint32*)*data)[i] = ((gulong*)xdata)[i];
233 break;
234 default:
235 g_assert_not_reached(); /* unhandled size */
236 }
237 *num = ret_items;
238 ret = TRUE;
239 }
240 XFree(xdata);
241 }
242 return ret;
243 }
244
245 static gboolean get_stringlist(Window win, Atom prop, char ***list, int *nstr)
246 {
247 XTextProperty tprop;
248 gboolean ret = FALSE;
249
250 if (XGetTextProperty(ob_display, win, &tprop, prop) && tprop.nitems) {
251 if (XTextPropertyToStringList(&tprop, list, nstr))
252 ret = TRUE;
253 XFree(tprop.value);
254 }
255 return ret;
256 }
257
258 gboolean prop_get32(Window win, Atom prop, Atom type, guint32 *ret)
259 {
260 return get_prealloc(win, prop, type, 32, (guchar*)ret, 1);
261 }
262
263 gboolean prop_get_array32(Window win, Atom prop, Atom type, guint32 **ret,
264 guint *nret)
265 {
266 return get_all(win, prop, type, 32, (guchar**)ret, nret);
267 }
268
269 gboolean prop_get_string_locale(Window win, Atom prop, char **ret)
270 {
271 char **list;
272 int nstr;
273
274 if (get_stringlist(win, prop, &list, &nstr) && nstr) {
275 *ret = g_convert(list[0], strlen(list[0]), "UTF-8", "ISO-8859-1",
276 NULL, NULL, NULL);
277 XFreeStringList(list);
278 if (*ret) return TRUE;
279 }
280 return FALSE;
281 }
282
283 gboolean prop_get_strings_locale(Window win, Atom prop, char ***ret)
284 {
285 GSList *strs = NULL, *it;
286 char *raw, *p;
287 guint num, i, count = 0;
288
289 if (get_all(win, prop, prop_atoms.string, 8, (guchar**)&raw, &num)) {
290
291 p = raw;
292 while (p < raw + num - 1) {
293 ++count;
294 strs = g_slist_append(strs, p);
295 p += strlen(p) + 1; /* next string */
296 }
297
298 *ret = g_new0(char*, count + 1);
299 (*ret)[count] = NULL; /* null terminated list */
300
301 for (i = 0, it = strs; it; ++i, it = g_slist_next(it)) {
302 (*ret)[i] = g_convert(it->data, -1, "UTF-8", "ISO-8859-1",
303 NULL, NULL, NULL);
304 /* make sure translation did not fail */
305 if (!(*ret)[i])
306 (*ret)[i] = g_strdup("");
307 }
308 g_free(raw);
309 g_slist_free(strs);
310 return TRUE;
311 }
312 return FALSE;
313 }
314
315 gboolean prop_get_string_utf8(Window win, Atom prop, char **ret)
316 {
317 char *raw;
318 char *str;
319 guint num;
320
321 if (get_all(win, prop, prop_atoms.utf8, 8, (guchar**)&raw, &num)) {
322 str = g_strndup(raw, num); /* grab the first string from the list */
323 g_free(raw);
324 if (g_utf8_validate(str, -1, NULL)) {
325 *ret = str;
326 return TRUE;
327 }
328 g_free(str);
329 }
330 return FALSE;
331 }
332
333 gboolean prop_get_strings_utf8(Window win, Atom prop, char ***ret)
334 {
335 GSList *strs = NULL, *it;
336 char *raw, *p;
337 guint num, i, count = 0;
338
339 if (get_all(win, prop, prop_atoms.utf8, 8, (guchar**)&raw, &num)) {
340
341 p = raw;
342 while (p < raw + num - 1) {
343 ++count;
344 strs = g_slist_append(strs, p);
345 p += strlen(p) + 1; /* next string */
346 }
347
348 *ret = g_new0(char*, count + 1);
349
350 for (i = 0, it = strs; it; ++i, it = g_slist_next(it)) {
351 if (g_utf8_validate(it->data, -1, NULL))
352 (*ret)[i] = g_strdup(it->data);
353 else
354 (*ret)[i] = g_strdup("");
355 }
356 g_free(raw);
357 g_slist_free(strs);
358 return TRUE;
359 }
360 return FALSE;
361 }
362
363 void prop_set32(Window win, Atom prop, Atom type, guint32 val)
364 {
365 XChangeProperty(ob_display, win, prop, type, 32, PropModeReplace,
366 (guchar*)&val, 1);
367 }
368
369 void prop_set_array32(Window win, Atom prop, Atom type, guint32 *val,
370 guint num)
371 {
372 XChangeProperty(ob_display, win, prop, type, 32, PropModeReplace,
373 (guchar*)val, num);
374 }
375
376 void prop_set_string_utf8(Window win, Atom prop, char *val)
377 {
378 XChangeProperty(ob_display, win, prop, prop_atoms.utf8, 8,
379 PropModeReplace, (guchar*)val, strlen(val));
380 }
381
382 void prop_set_strings_utf8(Window win, Atom prop, char **strs)
383 {
384 GString *str;
385 char **s;
386
387 str = g_string_sized_new(0);
388 for (s = strs; *s; ++s) {
389 str = g_string_append(str, *s);
390 str = g_string_append_c(str, '\0');
391 }
392 XChangeProperty(ob_display, win, prop, prop_atoms.utf8, 8,
393 PropModeReplace, (guchar*)str->str, str->len);
394 }
395
396 void prop_erase(Window win, Atom prop)
397 {
398 XDeleteProperty(ob_display, win, prop);
399 }
400
401 void prop_message(Window about, Atom messagetype, long data0, long data1,
402 long data2, long data3, long mask)
403 {
404 XEvent ce;
405 ce.xclient.type = ClientMessage;
406 ce.xclient.message_type = messagetype;
407 ce.xclient.display = ob_display;
408 ce.xclient.window = about;
409 ce.xclient.format = 32;
410 ce.xclient.data.l[0] = data0;
411 ce.xclient.data.l[1] = data1;
412 ce.xclient.data.l[2] = data2;
413 ce.xclient.data.l[3] = data3;
414 XSendEvent(ob_display, RootWindow(ob_display, ob_screen), FALSE,
415 mask, &ce);
416 }
This page took 0.056213 seconds and 4 git commands to generate.