Line 0
Link Here
|
|
|
1 |
/* -*- c-basic-offset: 8 -*- |
2 |
rdesktop: A Remote Desktop Protocol client. |
3 |
|
4 |
Support functions for Extended Window Manager Hints, |
5 |
http://www.freedesktop.org/wiki/Standards_2fwm_2dspec |
6 |
|
7 |
Copyright 2005 Peter Astrand <astrand@cendio.se> for Cendio AB |
8 |
Copyright 2007 Pierre Ossman <ossman@cendio.se> for Cendio AB |
9 |
|
10 |
This program is free software: you can redistribute it and/or modify |
11 |
it under the terms of the GNU General Public License as published by |
12 |
the Free Software Foundation, either version 3 of the License, or |
13 |
(at your option) any later version. |
14 |
|
15 |
This program is distributed in the hope that it will be useful, |
16 |
but WITHOUT ANY WARRANTY; without even the implied warranty of |
17 |
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
18 |
GNU General Public License for more details. |
19 |
|
20 |
You should have received a copy of the GNU General Public License |
21 |
along with this program. If not, see <http://www.gnu.org/licenses/>. |
22 |
*/ |
23 |
|
24 |
#include <stdlib.h> |
25 |
#include <stdio.h> |
26 |
#include <string.h> |
27 |
#include <X11/Xlib.h> |
28 |
#include <X11/Xatom.h> |
29 |
#include <X11/Xutil.h> |
30 |
|
31 |
#define _NET_WM_STATE_REMOVE 0 /* remove/unset property */ |
32 |
#define _NET_WM_STATE_ADD 1 /* add/set property */ |
33 |
#define _NET_WM_STATE_TOGGLE 2 /* toggle property */ |
34 |
|
35 |
typedef unsigned int uint32; |
36 |
|
37 |
// FIXME: Remove, this file shouldn't depend on seamlessrdp! |
38 |
#define SEAMLESSRDP_NORMAL 0 |
39 |
#define SEAMLESSRDP_MINIMIZED 1 |
40 |
#define SEAMLESSRDP_MAXIMIZED 2 |
41 |
|
42 |
#ifndef EX_UNAVAILABLE |
43 |
#define EX_UNAVAILABLE 69 |
44 |
#endif |
45 |
|
46 |
// FIXME: Need to think about this one... |
47 |
/* malloc; exit if out of memory */ |
48 |
static void * |
49 |
xmalloc(int size) |
50 |
{ |
51 |
void *mem = malloc(size); |
52 |
if (mem == NULL) |
53 |
{ |
54 |
fprintf(stderr, "ERROR: xmalloc %d\n", size); |
55 |
exit(EX_UNAVAILABLE); |
56 |
} |
57 |
return mem; |
58 |
} |
59 |
|
60 |
|
61 |
static Display *g_display; |
62 |
|
63 |
static Atom g_net_wm_state_maximized_vert_atom, g_net_wm_state_maximized_horz_atom, |
64 |
g_net_wm_state_hidden_atom, g_net_wm_name_atom, g_utf8_string_atom, |
65 |
g_net_wm_state_skip_taskbar_atom, g_net_wm_state_skip_pager_atom, |
66 |
g_net_wm_state_modal_atom, g_net_wm_icon_atom, g_net_wm_state_above_atom, |
67 |
g_net_wm_state_fullscreen_atom; |
68 |
|
69 |
Atom g_net_wm_state_atom, g_net_wm_desktop_atom; |
70 |
|
71 |
/* |
72 |
Get window property value (32 bit format) |
73 |
Returns zero on success, -1 on error |
74 |
*/ |
75 |
static int |
76 |
get_property_value(Window wnd, char *propname, long max_length, |
77 |
unsigned long *nitems_return, unsigned char **prop_return, int nowarn) |
78 |
{ |
79 |
int result; |
80 |
Atom property; |
81 |
Atom actual_type_return; |
82 |
int actual_format_return; |
83 |
unsigned long bytes_after_return; |
84 |
|
85 |
property = XInternAtom(g_display, propname, True); |
86 |
if (property == None) |
87 |
{ |
88 |
fprintf(stderr, "Atom %s does not exist\n", propname); |
89 |
return (-1); |
90 |
} |
91 |
|
92 |
result = XGetWindowProperty(g_display, wnd, property, 0, /* long_offset */ |
93 |
max_length, /* long_length */ |
94 |
False, /* delete */ |
95 |
AnyPropertyType, /* req_type */ |
96 |
&actual_type_return, |
97 |
&actual_format_return, |
98 |
nitems_return, &bytes_after_return, prop_return); |
99 |
|
100 |
if (result != Success) |
101 |
{ |
102 |
fprintf(stderr, "XGetWindowProperty failed\n"); |
103 |
return (-1); |
104 |
} |
105 |
|
106 |
if (actual_type_return == None || actual_format_return == 0) |
107 |
{ |
108 |
if (!nowarn) |
109 |
fprintf(stderr, "Window is missing property %s\n", propname); |
110 |
return (-1); |
111 |
} |
112 |
|
113 |
if (bytes_after_return) |
114 |
{ |
115 |
fprintf(stderr, "%s is too big for me\n", propname); |
116 |
return (-1); |
117 |
} |
118 |
|
119 |
if (actual_format_return != 32) |
120 |
{ |
121 |
fprintf(stderr, "%s has bad format\n", propname); |
122 |
return (-1); |
123 |
} |
124 |
|
125 |
return (0); |
126 |
} |
127 |
|
128 |
/* |
129 |
Get current desktop number |
130 |
Returns -1 on error |
131 |
*/ |
132 |
static int |
133 |
get_current_desktop(void) |
134 |
{ |
135 |
unsigned long nitems_return; |
136 |
unsigned char *prop_return; |
137 |
int current_desktop; |
138 |
|
139 |
if (get_property_value |
140 |
(DefaultRootWindow(g_display), "_NET_CURRENT_DESKTOP", 1, &nitems_return, |
141 |
&prop_return, 0) < 0) |
142 |
return (-1); |
143 |
|
144 |
if (nitems_return != 1) |
145 |
{ |
146 |
fprintf(stderr, "_NET_CURRENT_DESKTOP has bad length\n"); |
147 |
return (-1); |
148 |
} |
149 |
|
150 |
current_desktop = *prop_return; |
151 |
XFree(prop_return); |
152 |
return current_desktop; |
153 |
} |
154 |
|
155 |
/* |
156 |
Get workarea geometry |
157 |
Returns zero on success, -1 on error |
158 |
*/ |
159 |
|
160 |
int |
161 |
get_current_workarea(uint32 * x, uint32 * y, uint32 * width, uint32 * height) |
162 |
{ |
163 |
int current_desktop; |
164 |
unsigned long nitems_return; |
165 |
unsigned char *prop_return; |
166 |
long *return_words; |
167 |
const uint32 net_workarea_x_offset = 0; |
168 |
const uint32 net_workarea_y_offset = 1; |
169 |
const uint32 net_workarea_width_offset = 2; |
170 |
const uint32 net_workarea_height_offset = 3; |
171 |
const uint32 max_prop_length = 32 * 4; /* Max 32 desktops */ |
172 |
|
173 |
if (get_property_value |
174 |
(DefaultRootWindow(g_display), "_NET_WORKAREA", max_prop_length, &nitems_return, |
175 |
&prop_return, 0) < 0) |
176 |
return (-1); |
177 |
|
178 |
if (nitems_return % 4) |
179 |
{ |
180 |
fprintf(stderr, "_NET_WORKAREA has odd length\n"); |
181 |
return (-1); |
182 |
} |
183 |
|
184 |
current_desktop = get_current_desktop(); |
185 |
|
186 |
if (current_desktop < 0) |
187 |
return -1; |
188 |
|
189 |
return_words = (long *) prop_return; |
190 |
|
191 |
*x = return_words[current_desktop * 4 + net_workarea_x_offset]; |
192 |
*y = return_words[current_desktop * 4 + net_workarea_y_offset]; |
193 |
*width = return_words[current_desktop * 4 + net_workarea_width_offset]; |
194 |
*height = return_words[current_desktop * 4 + net_workarea_height_offset]; |
195 |
|
196 |
XFree(prop_return); |
197 |
|
198 |
return (0); |
199 |
|
200 |
} |
201 |
|
202 |
|
203 |
|
204 |
void |
205 |
ewmh_init(Display *display) |
206 |
{ |
207 |
g_display = display; |
208 |
/* FIXME: Use XInternAtoms */ |
209 |
g_net_wm_state_maximized_vert_atom = |
210 |
XInternAtom(g_display, "_NET_WM_STATE_MAXIMIZED_VERT", False); |
211 |
g_net_wm_state_maximized_horz_atom = |
212 |
XInternAtom(g_display, "_NET_WM_STATE_MAXIMIZED_HORZ", False); |
213 |
g_net_wm_state_hidden_atom = XInternAtom(g_display, "_NET_WM_STATE_HIDDEN", False); |
214 |
g_net_wm_state_skip_taskbar_atom = |
215 |
XInternAtom(g_display, "_NET_WM_STATE_SKIP_TASKBAR", False); |
216 |
g_net_wm_state_skip_pager_atom = XInternAtom(g_display, "_NET_WM_STATE_SKIP_PAGER", False); |
217 |
g_net_wm_state_modal_atom = XInternAtom(g_display, "_NET_WM_STATE_MODAL", False); |
218 |
g_net_wm_state_above_atom = XInternAtom(g_display, "_NET_WM_STATE_ABOVE", False); |
219 |
g_net_wm_state_atom = XInternAtom(g_display, "_NET_WM_STATE", False); |
220 |
g_net_wm_state_fullscreen_atom = XInternAtom(g_display, "_NET_WM_STATE_FULLSCREEN", False); |
221 |
g_net_wm_desktop_atom = XInternAtom(g_display, "_NET_WM_DESKTOP", False); |
222 |
g_net_wm_name_atom = XInternAtom(g_display, "_NET_WM_NAME", False); |
223 |
g_net_wm_icon_atom = XInternAtom(g_display, "_NET_WM_ICON", False); |
224 |
g_utf8_string_atom = XInternAtom(g_display, "UTF8_STRING", False); |
225 |
} |
226 |
|
227 |
|
228 |
/* |
229 |
Get the window state: normal/minimized/maximized. |
230 |
*/ |
231 |
#ifndef MAKE_PROTO |
232 |
int |
233 |
ewmh_get_window_state(Window w) |
234 |
{ |
235 |
unsigned long nitems_return; |
236 |
unsigned char *prop_return; |
237 |
uint32 *return_words; |
238 |
unsigned long item; |
239 |
Bool maximized_vert, maximized_horz, hidden; |
240 |
|
241 |
maximized_vert = maximized_horz = hidden = False; |
242 |
|
243 |
if (get_property_value(w, "_NET_WM_STATE", 64, &nitems_return, &prop_return, 0) < 0) |
244 |
return SEAMLESSRDP_NORMAL; |
245 |
|
246 |
return_words = (uint32 *) prop_return; |
247 |
|
248 |
for (item = 0; item < nitems_return; item++) |
249 |
{ |
250 |
if (return_words[item] == g_net_wm_state_maximized_vert_atom) |
251 |
maximized_vert = True; |
252 |
if (return_words[item] == g_net_wm_state_maximized_horz_atom) |
253 |
maximized_horz = True; |
254 |
if (return_words[item] == g_net_wm_state_hidden_atom) |
255 |
hidden = True; |
256 |
} |
257 |
|
258 |
XFree(prop_return); |
259 |
|
260 |
if (maximized_vert && maximized_horz) |
261 |
return SEAMLESSRDP_MAXIMIZED; |
262 |
else if (hidden) |
263 |
return SEAMLESSRDP_MINIMIZED; |
264 |
else |
265 |
return SEAMLESSRDP_NORMAL; |
266 |
} |
267 |
|
268 |
static int |
269 |
ewmh_modify_state(Window wnd, Bool add, Atom atom1, Atom atom2) |
270 |
{ |
271 |
Status status; |
272 |
XEvent xevent; |
273 |
|
274 |
int result; |
275 |
unsigned long nitems; |
276 |
unsigned char *props; |
277 |
uint32 state = WithdrawnState; |
278 |
|
279 |
/* The spec states that the window manager must respect any |
280 |
_NET_WM_STATE attributes on a withdrawn window. In order words, we |
281 |
modify the attributes directly for withdrawn windows and ask the WM |
282 |
to do it for active windows. */ |
283 |
result = get_property_value(wnd, "WM_STATE", 64, &nitems, &props, 1); |
284 |
if ((result >= 0) && nitems) |
285 |
{ |
286 |
state = *(uint32 *) props; |
287 |
XFree(props); |
288 |
} |
289 |
|
290 |
if (state == WithdrawnState) |
291 |
{ |
292 |
if (add) |
293 |
{ |
294 |
Atom atoms[2]; |
295 |
|
296 |
atoms[0] = atom1; |
297 |
nitems = 1; |
298 |
if (atom2) |
299 |
{ |
300 |
atoms[1] = atom2; |
301 |
nitems = 2; |
302 |
} |
303 |
|
304 |
XChangeProperty(g_display, wnd, g_net_wm_state_atom, XA_ATOM, |
305 |
32, PropModeAppend, (unsigned char *) atoms, nitems); |
306 |
} |
307 |
else |
308 |
{ |
309 |
Atom *atoms; |
310 |
int i; |
311 |
|
312 |
if (get_property_value(wnd, "_NET_WM_STATE", 64, &nitems, &props, 1) < 0) |
313 |
return 0; |
314 |
|
315 |
atoms = (Atom *) props; |
316 |
|
317 |
for (i = 0; i < nitems; i++) |
318 |
{ |
319 |
if ((atoms[i] == atom1) || (atom2 && (atoms[i] == atom2))) |
320 |
{ |
321 |
if (i != (nitems - 1)) |
322 |
memmove(&atoms[i], &atoms[i + 1], |
323 |
sizeof(Atom) * (nitems - i - 1)); |
324 |
nitems--; |
325 |
i--; |
326 |
} |
327 |
} |
328 |
|
329 |
XChangeProperty(g_display, wnd, g_net_wm_state_atom, XA_ATOM, |
330 |
32, PropModeReplace, (unsigned char *) atoms, nitems); |
331 |
|
332 |
XFree(props); |
333 |
} |
334 |
|
335 |
return 0; |
336 |
} |
337 |
|
338 |
xevent.type = ClientMessage; |
339 |
xevent.xclient.window = wnd; |
340 |
xevent.xclient.message_type = g_net_wm_state_atom; |
341 |
xevent.xclient.format = 32; |
342 |
if (add) |
343 |
xevent.xclient.data.l[0] = _NET_WM_STATE_ADD; |
344 |
else |
345 |
xevent.xclient.data.l[0] = _NET_WM_STATE_REMOVE; |
346 |
xevent.xclient.data.l[1] = atom1; |
347 |
xevent.xclient.data.l[2] = atom2; |
348 |
xevent.xclient.data.l[3] = 0; |
349 |
xevent.xclient.data.l[4] = 0; |
350 |
status = XSendEvent(g_display, DefaultRootWindow(g_display), False, |
351 |
SubstructureNotifyMask | SubstructureRedirectMask, &xevent); |
352 |
if (!status) |
353 |
return -1; |
354 |
|
355 |
return 0; |
356 |
} |
357 |
|
358 |
|
359 |
int ewmh_state_fullscreen(Window wnd, Bool fullscreen) |
360 |
{ |
361 |
if (ewmh_modify_state(wnd, fullscreen, g_net_wm_state_fullscreen_atom, 0) < 0) |
362 |
return -1; |
363 |
return 0; |
364 |
} |
365 |
|
366 |
/* |
367 |
Set the window state: normal/minimized/maximized. |
368 |
Returns -1 on failure. |
369 |
*/ |
370 |
int |
371 |
ewmh_change_state(Window wnd, int state) |
372 |
{ |
373 |
/* |
374 |
* Deal with the max atoms |
375 |
*/ |
376 |
if (state == SEAMLESSRDP_MAXIMIZED) |
377 |
{ |
378 |
if (ewmh_modify_state |
379 |
(wnd, 1, g_net_wm_state_maximized_vert_atom, |
380 |
g_net_wm_state_maximized_horz_atom) < 0) |
381 |
return -1; |
382 |
} |
383 |
else |
384 |
{ |
385 |
if (ewmh_modify_state |
386 |
(wnd, 0, g_net_wm_state_maximized_vert_atom, |
387 |
g_net_wm_state_maximized_horz_atom) < 0) |
388 |
return -1; |
389 |
} |
390 |
|
391 |
return 0; |
392 |
} |
393 |
|
394 |
|
395 |
int |
396 |
ewmh_get_window_desktop(Window wnd) |
397 |
{ |
398 |
unsigned long nitems_return; |
399 |
unsigned char *prop_return; |
400 |
int desktop; |
401 |
|
402 |
if (get_property_value(wnd, "_NET_WM_DESKTOP", 1, &nitems_return, &prop_return, 0) < 0) |
403 |
return (-1); |
404 |
|
405 |
if (nitems_return != 1) |
406 |
{ |
407 |
fprintf(stderr, "_NET_WM_DESKTOP has bad length\n"); |
408 |
return (-1); |
409 |
} |
410 |
|
411 |
desktop = *prop_return; |
412 |
XFree(prop_return); |
413 |
return desktop; |
414 |
} |
415 |
|
416 |
|
417 |
int |
418 |
ewmh_move_to_desktop(Window wnd, unsigned int desktop) |
419 |
{ |
420 |
Status status; |
421 |
XEvent xevent; |
422 |
|
423 |
xevent.type = ClientMessage; |
424 |
xevent.xclient.window = wnd; |
425 |
xevent.xclient.message_type = g_net_wm_desktop_atom; |
426 |
xevent.xclient.format = 32; |
427 |
xevent.xclient.data.l[0] = desktop; |
428 |
xevent.xclient.data.l[1] = 0; |
429 |
xevent.xclient.data.l[2] = 0; |
430 |
xevent.xclient.data.l[3] = 0; |
431 |
xevent.xclient.data.l[4] = 0; |
432 |
status = XSendEvent(g_display, DefaultRootWindow(g_display), False, |
433 |
SubstructureNotifyMask | SubstructureRedirectMask, &xevent); |
434 |
if (!status) |
435 |
return -1; |
436 |
|
437 |
return 0; |
438 |
} |
439 |
|
440 |
void |
441 |
ewmh_set_wm_name(Window wnd, const char *title) |
442 |
{ |
443 |
int len; |
444 |
|
445 |
len = strlen(title); |
446 |
XChangeProperty(g_display, wnd, g_net_wm_name_atom, g_utf8_string_atom, |
447 |
8, PropModeReplace, (unsigned char *) title, len); |
448 |
} |
449 |
|
450 |
|
451 |
int |
452 |
ewmh_set_window_popup(Window wnd) |
453 |
{ |
454 |
if (ewmh_modify_state |
455 |
(wnd, 1, g_net_wm_state_skip_taskbar_atom, g_net_wm_state_skip_pager_atom) < 0) |
456 |
return -1; |
457 |
return 0; |
458 |
} |
459 |
|
460 |
int |
461 |
ewmh_set_window_modal(Window wnd) |
462 |
{ |
463 |
if (ewmh_modify_state(wnd, 1, g_net_wm_state_modal_atom, 0) < 0) |
464 |
return -1; |
465 |
return 0; |
466 |
} |
467 |
|
468 |
void |
469 |
ewmh_set_icon(Window wnd, int width, int height, const char *rgba_data) |
470 |
{ |
471 |
unsigned long nitems, i; |
472 |
unsigned char *props; |
473 |
unsigned long *cur_set, *new_set; |
474 |
unsigned long *icon; |
475 |
|
476 |
cur_set = NULL; |
477 |
new_set = NULL; |
478 |
|
479 |
if (get_property_value(wnd, "_NET_WM_ICON", 10000, &nitems, &props, 1) >= 0) |
480 |
{ |
481 |
cur_set = (unsigned long *) props; |
482 |
|
483 |
for (i = 0; i < nitems;) |
484 |
{ |
485 |
if (cur_set[i] == width && cur_set[i + 1] == height) |
486 |
break; |
487 |
|
488 |
i += 2 + cur_set[i] * cur_set[i + 1]; |
489 |
} |
490 |
|
491 |
if (i != nitems) |
492 |
icon = cur_set + i; |
493 |
else |
494 |
{ |
495 |
new_set = xmalloc((nitems + width * height + 2) * sizeof(unsigned long)); |
496 |
memcpy(new_set, cur_set, nitems * sizeof(unsigned long)); |
497 |
icon = new_set + nitems; |
498 |
nitems += width * height + 2; |
499 |
} |
500 |
} |
501 |
else |
502 |
{ |
503 |
new_set = xmalloc((width * height + 2) * sizeof(unsigned long)); |
504 |
icon = new_set; |
505 |
nitems = width * height + 2; |
506 |
} |
507 |
|
508 |
icon[0] = width; |
509 |
icon[1] = height; |
510 |
|
511 |
/* Convert RGBA -> ARGB */ |
512 |
for (i = 0; i < width * height; i++) |
513 |
{ |
514 |
icon[i + 2] = |
515 |
rgba_data[i * 4 + 3] << 24 | |
516 |
((rgba_data[i * 4 + 0] << 16) & 0x00FF0000) | |
517 |
((rgba_data[i * 4 + 1] << 8) & 0x0000FF00) | |
518 |
((rgba_data[i * 4 + 2] << 0) & 0x000000FF); |
519 |
} |
520 |
|
521 |
XChangeProperty(g_display, wnd, g_net_wm_icon_atom, XA_CARDINAL, 32, |
522 |
PropModeReplace, (unsigned char *) (new_set ? new_set : cur_set), nitems); |
523 |
|
524 |
if (cur_set) |
525 |
XFree(cur_set); |
526 |
if (new_set) |
527 |
free(new_set); |
528 |
} |
529 |
|
530 |
void |
531 |
ewmh_del_icon(Window wnd, int width, int height) |
532 |
{ |
533 |
unsigned long nitems, i, icon_size; |
534 |
unsigned char *props; |
535 |
unsigned long *cur_set, *new_set; |
536 |
|
537 |
cur_set = NULL; |
538 |
new_set = NULL; |
539 |
|
540 |
if (get_property_value(wnd, "_NET_WM_ICON", 10000, &nitems, &props, 1) < 0) |
541 |
return; |
542 |
|
543 |
cur_set = (unsigned long *) props; |
544 |
|
545 |
for (i = 0; i < nitems;) |
546 |
{ |
547 |
if (cur_set[i] == width && cur_set[i + 1] == height) |
548 |
break; |
549 |
|
550 |
i += 2 + cur_set[i] * cur_set[i + 1]; |
551 |
} |
552 |
|
553 |
if (i == nitems) |
554 |
goto out; |
555 |
|
556 |
icon_size = width * height + 2; |
557 |
new_set = xmalloc((nitems - icon_size) * sizeof(unsigned long)); |
558 |
|
559 |
if (i != 0) |
560 |
memcpy(new_set, cur_set, i * sizeof(unsigned long)); |
561 |
if (i != nitems - icon_size) |
562 |
memcpy(new_set + i, cur_set + i + icon_size, |
563 |
(nitems - (i + icon_size)) * sizeof(unsigned long)); |
564 |
|
565 |
nitems -= icon_size; |
566 |
|
567 |
XChangeProperty(g_display, wnd, g_net_wm_icon_atom, XA_CARDINAL, 32, |
568 |
PropModeReplace, (unsigned char *) new_set, nitems); |
569 |
|
570 |
free(new_set); |
571 |
|
572 |
out: |
573 |
XFree(cur_set); |
574 |
} |
575 |
|
576 |
int |
577 |
ewmh_set_window_above(Window wnd) |
578 |
{ |
579 |
if (ewmh_modify_state(wnd, 1, g_net_wm_state_above_atom, 0) < 0) |
580 |
return -1; |
581 |
return 0; |
582 |
} |
583 |
|
584 |
#endif /* MAKE_PROTO */ |
585 |
|
586 |
|
587 |
#if 0 |
588 |
|
589 |
/* FIXME: _NET_MOVERESIZE_WINDOW is for pagers, not for |
590 |
applications. We should implement _NET_WM_MOVERESIZE instead */ |
591 |
|
592 |
int |
593 |
ewmh_net_moveresize_window(Window wnd, int x, int y, int width, int height) |
594 |
{ |
595 |
Status status; |
596 |
XEvent xevent; |
597 |
Atom moveresize; |
598 |
|
599 |
moveresize = XInternAtom(g_display, "_NET_MOVERESIZE_WINDOW", False); |
600 |
if (!moveresize) |
601 |
{ |
602 |
return -1; |
603 |
} |
604 |
|
605 |
xevent.type = ClientMessage; |
606 |
xevent.xclient.window = wnd; |
607 |
xevent.xclient.message_type = moveresize; |
608 |
xevent.xclient.format = 32; |
609 |
xevent.xclient.data.l[0] = StaticGravity | (1 << 8) | (1 << 9) | (1 << 10) | (1 << 11); |
610 |
xevent.xclient.data.l[1] = x; |
611 |
xevent.xclient.data.l[2] = y; |
612 |
xevent.xclient.data.l[3] = width; |
613 |
xevent.xclient.data.l[4] = height; |
614 |
|
615 |
status = XSendEvent(g_display, DefaultRootWindow(g_display), False, |
616 |
SubstructureNotifyMask | SubstructureRedirectMask, &xevent); |
617 |
if (!status) |
618 |
return -1; |
619 |
return 0; |
620 |
} |
621 |
|
622 |
#endif |
623 |
/* -*- c-basic-offset: 8 -*- |
624 |
rdesktop: A Remote Desktop Protocol client. |
625 |
|
626 |
Support functions for Extended Window Manager Hints, |
627 |
http://www.freedesktop.org/wiki/Standards_2fwm_2dspec |
628 |
|
629 |
Copyright 2005 Peter Astrand <astrand@cendio.se> for Cendio AB |
630 |
Copyright 2007 Pierre Ossman <ossman@cendio.se> for Cendio AB |
631 |
|
632 |
This program is free software: you can redistribute it and/or modify |
633 |
it under the terms of the GNU General Public License as published by |
634 |
the Free Software Foundation, either version 3 of the License, or |
635 |
(at your option) any later version. |
636 |
|
637 |
This program is distributed in the hope that it will be useful, |
638 |
but WITHOUT ANY WARRANTY; without even the implied warranty of |
639 |
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
640 |
GNU General Public License for more details. |
641 |
|
642 |
You should have received a copy of the GNU General Public License |
643 |
along with this program. If not, see <http://www.gnu.org/licenses/>. |
644 |
*/ |
645 |
|
646 |
#include <stdlib.h> |
647 |
#include <stdio.h> |
648 |
#include <string.h> |
649 |
#include <X11/Xlib.h> |
650 |
#include <X11/Xatom.h> |
651 |
#include <X11/Xutil.h> |
652 |
|
653 |
#define _NET_WM_STATE_REMOVE 0 /* remove/unset property */ |
654 |
#define _NET_WM_STATE_ADD 1 /* add/set property */ |
655 |
#define _NET_WM_STATE_TOGGLE 2 /* toggle property */ |
656 |
|
657 |
typedef unsigned int uint32; |
658 |
|
659 |
// FIXME: Remove, this file shouldn't depend on seamlessrdp! |
660 |
#define SEAMLESSRDP_NORMAL 0 |
661 |
#define SEAMLESSRDP_MINIMIZED 1 |
662 |
#define SEAMLESSRDP_MAXIMIZED 2 |
663 |
|
664 |
#ifndef EX_UNAVAILABLE |
665 |
#define EX_UNAVAILABLE 69 |
666 |
#endif |
667 |
|
668 |
// FIXME: Need to think about this one... |
669 |
/* malloc; exit if out of memory */ |
670 |
static void * |
671 |
xmalloc(int size) |
672 |
{ |
673 |
void *mem = malloc(size); |
674 |
if (mem == NULL) |
675 |
{ |
676 |
fprintf(stderr, "ERROR: xmalloc %d\n", size); |
677 |
exit(EX_UNAVAILABLE); |
678 |
} |
679 |
return mem; |
680 |
} |
681 |
|
682 |
|
683 |
static Display *g_display; |
684 |
|
685 |
static Atom g_net_wm_state_maximized_vert_atom, g_net_wm_state_maximized_horz_atom, |
686 |
g_net_wm_state_hidden_atom, g_net_wm_name_atom, g_utf8_string_atom, |
687 |
g_net_wm_state_skip_taskbar_atom, g_net_wm_state_skip_pager_atom, |
688 |
g_net_wm_state_modal_atom, g_net_wm_icon_atom, g_net_wm_state_above_atom, |
689 |
g_net_wm_state_fullscreen_atom; |
690 |
|
691 |
Atom g_net_wm_state_atom, g_net_wm_desktop_atom; |
692 |
|
693 |
/* |
694 |
Get window property value (32 bit format) |
695 |
Returns zero on success, -1 on error |
696 |
*/ |
697 |
static int |
698 |
get_property_value(Window wnd, char *propname, long max_length, |
699 |
unsigned long *nitems_return, unsigned char **prop_return, int nowarn) |
700 |
{ |
701 |
int result; |
702 |
Atom property; |
703 |
Atom actual_type_return; |
704 |
int actual_format_return; |
705 |
unsigned long bytes_after_return; |
706 |
|
707 |
property = XInternAtom(g_display, propname, True); |
708 |
if (property == None) |
709 |
{ |
710 |
fprintf(stderr, "Atom %s does not exist\n", propname); |
711 |
return (-1); |
712 |
} |
713 |
|
714 |
result = XGetWindowProperty(g_display, wnd, property, 0, /* long_offset */ |
715 |
max_length, /* long_length */ |
716 |
False, /* delete */ |
717 |
AnyPropertyType, /* req_type */ |
718 |
&actual_type_return, |
719 |
&actual_format_return, |
720 |
nitems_return, &bytes_after_return, prop_return); |
721 |
|
722 |
if (result != Success) |
723 |
{ |
724 |
fprintf(stderr, "XGetWindowProperty failed\n"); |
725 |
return (-1); |
726 |
} |
727 |
|
728 |
if (actual_type_return == None || actual_format_return == 0) |
729 |
{ |
730 |
if (!nowarn) |
731 |
fprintf(stderr, "Window is missing property %s\n", propname); |
732 |
return (-1); |
733 |
} |
734 |
|
735 |
if (bytes_after_return) |
736 |
{ |
737 |
fprintf(stderr, "%s is too big for me\n", propname); |
738 |
return (-1); |
739 |
} |
740 |
|
741 |
if (actual_format_return != 32) |
742 |
{ |
743 |
fprintf(stderr, "%s has bad format\n", propname); |
744 |
return (-1); |
745 |
} |
746 |
|
747 |
return (0); |
748 |
} |
749 |
|
750 |
/* |
751 |
Get current desktop number |
752 |
Returns -1 on error |
753 |
*/ |
754 |
static int |
755 |
get_current_desktop(void) |
756 |
{ |
757 |
unsigned long nitems_return; |
758 |
unsigned char *prop_return; |
759 |
int current_desktop; |
760 |
|
761 |
if (get_property_value |
762 |
(DefaultRootWindow(g_display), "_NET_CURRENT_DESKTOP", 1, &nitems_return, |
763 |
&prop_return, 0) < 0) |
764 |
return (-1); |
765 |
|
766 |
if (nitems_return != 1) |
767 |
{ |
768 |
fprintf(stderr, "_NET_CURRENT_DESKTOP has bad length\n"); |
769 |
return (-1); |
770 |
} |
771 |
|
772 |
current_desktop = *prop_return; |
773 |
XFree(prop_return); |
774 |
return current_desktop; |
775 |
} |
776 |
|
777 |
/* |
778 |
Get workarea geometry |
779 |
Returns zero on success, -1 on error |
780 |
*/ |
781 |
|
782 |
int |
783 |
get_current_workarea(uint32 * x, uint32 * y, uint32 * width, uint32 * height) |
784 |
{ |
785 |
int current_desktop; |
786 |
unsigned long nitems_return; |
787 |
unsigned char *prop_return; |
788 |
long *return_words; |
789 |
const uint32 net_workarea_x_offset = 0; |
790 |
const uint32 net_workarea_y_offset = 1; |
791 |
const uint32 net_workarea_width_offset = 2; |
792 |
const uint32 net_workarea_height_offset = 3; |
793 |
const uint32 max_prop_length = 32 * 4; /* Max 32 desktops */ |
794 |
|
795 |
if (get_property_value |
796 |
(DefaultRootWindow(g_display), "_NET_WORKAREA", max_prop_length, &nitems_return, |
797 |
&prop_return, 0) < 0) |
798 |
return (-1); |
799 |
|
800 |
if (nitems_return % 4) |
801 |
{ |
802 |
fprintf(stderr, "_NET_WORKAREA has odd length\n"); |
803 |
return (-1); |
804 |
} |
805 |
|
806 |
current_desktop = get_current_desktop(); |
807 |
|
808 |
if (current_desktop < 0) |
809 |
return -1; |
810 |
|
811 |
return_words = (long *) prop_return; |
812 |
|
813 |
*x = return_words[current_desktop * 4 + net_workarea_x_offset]; |
814 |
*y = return_words[current_desktop * 4 + net_workarea_y_offset]; |
815 |
*width = return_words[current_desktop * 4 + net_workarea_width_offset]; |
816 |
*height = return_words[current_desktop * 4 + net_workarea_height_offset]; |
817 |
|
818 |
XFree(prop_return); |
819 |
|
820 |
return (0); |
821 |
|
822 |
} |
823 |
|
824 |
|
825 |
|
826 |
void |
827 |
ewmh_init(Display *display) |
828 |
{ |
829 |
g_display = display; |
830 |
/* FIXME: Use XInternAtoms */ |
831 |
g_net_wm_state_maximized_vert_atom = |
832 |
XInternAtom(g_display, "_NET_WM_STATE_MAXIMIZED_VERT", False); |
833 |
g_net_wm_state_maximized_horz_atom = |
834 |
XInternAtom(g_display, "_NET_WM_STATE_MAXIMIZED_HORZ", False); |
835 |
g_net_wm_state_hidden_atom = XInternAtom(g_display, "_NET_WM_STATE_HIDDEN", False); |
836 |
g_net_wm_state_skip_taskbar_atom = |
837 |
XInternAtom(g_display, "_NET_WM_STATE_SKIP_TASKBAR", False); |
838 |
g_net_wm_state_skip_pager_atom = XInternAtom(g_display, "_NET_WM_STATE_SKIP_PAGER", False); |
839 |
g_net_wm_state_modal_atom = XInternAtom(g_display, "_NET_WM_STATE_MODAL", False); |
840 |
g_net_wm_state_above_atom = XInternAtom(g_display, "_NET_WM_STATE_ABOVE", False); |
841 |
g_net_wm_state_atom = XInternAtom(g_display, "_NET_WM_STATE", False); |
842 |
g_net_wm_state_fullscreen_atom = XInternAtom(g_display, "_NET_WM_STATE_FULLSCREEN", False); |
843 |
g_net_wm_desktop_atom = XInternAtom(g_display, "_NET_WM_DESKTOP", False); |
844 |
g_net_wm_name_atom = XInternAtom(g_display, "_NET_WM_NAME", False); |
845 |
g_net_wm_icon_atom = XInternAtom(g_display, "_NET_WM_ICON", False); |
846 |
g_utf8_string_atom = XInternAtom(g_display, "UTF8_STRING", False); |
847 |
} |
848 |
|
849 |
|
850 |
/* |
851 |
Get the window state: normal/minimized/maximized. |
852 |
*/ |
853 |
#ifndef MAKE_PROTO |
854 |
int |
855 |
ewmh_get_window_state(Window w) |
856 |
{ |
857 |
unsigned long nitems_return; |
858 |
unsigned char *prop_return; |
859 |
uint32 *return_words; |
860 |
unsigned long item; |
861 |
Bool maximized_vert, maximized_horz, hidden; |
862 |
|
863 |
maximized_vert = maximized_horz = hidden = False; |
864 |
|
865 |
if (get_property_value(w, "_NET_WM_STATE", 64, &nitems_return, &prop_return, 0) < 0) |
866 |
return SEAMLESSRDP_NORMAL; |
867 |
|
868 |
return_words = (uint32 *) prop_return; |
869 |
|
870 |
for (item = 0; item < nitems_return; item++) |
871 |
{ |
872 |
if (return_words[item] == g_net_wm_state_maximized_vert_atom) |
873 |
maximized_vert = True; |
874 |
if (return_words[item] == g_net_wm_state_maximized_horz_atom) |
875 |
maximized_horz = True; |
876 |
if (return_words[item] == g_net_wm_state_hidden_atom) |
877 |
hidden = True; |
878 |
} |
879 |
|
880 |
XFree(prop_return); |
881 |
|
882 |
if (maximized_vert && maximized_horz) |
883 |
return SEAMLESSRDP_MAXIMIZED; |
884 |
else if (hidden) |
885 |
return SEAMLESSRDP_MINIMIZED; |
886 |
else |
887 |
return SEAMLESSRDP_NORMAL; |
888 |
} |
889 |
|
890 |
static int |
891 |
ewmh_modify_state(Window wnd, Bool add, Atom atom1, Atom atom2) |
892 |
{ |
893 |
Status status; |
894 |
XEvent xevent; |
895 |
|
896 |
int result; |
897 |
unsigned long nitems; |
898 |
unsigned char *props; |
899 |
uint32 state = WithdrawnState; |
900 |
|
901 |
/* The spec states that the window manager must respect any |
902 |
_NET_WM_STATE attributes on a withdrawn window. In order words, we |
903 |
modify the attributes directly for withdrawn windows and ask the WM |
904 |
to do it for active windows. */ |
905 |
result = get_property_value(wnd, "WM_STATE", 64, &nitems, &props, 1); |
906 |
if ((result >= 0) && nitems) |
907 |
{ |
908 |
state = *(uint32 *) props; |
909 |
XFree(props); |
910 |
} |
911 |
|
912 |
if (state == WithdrawnState) |
913 |
{ |
914 |
if (add) |
915 |
{ |
916 |
Atom atoms[2]; |
917 |
|
918 |
atoms[0] = atom1; |
919 |
nitems = 1; |
920 |
if (atom2) |
921 |
{ |
922 |
atoms[1] = atom2; |
923 |
nitems = 2; |
924 |
} |
925 |
|
926 |
XChangeProperty(g_display, wnd, g_net_wm_state_atom, XA_ATOM, |
927 |
32, PropModeAppend, (unsigned char *) atoms, nitems); |
928 |
} |
929 |
else |
930 |
{ |
931 |
Atom *atoms; |
932 |
int i; |
933 |
|
934 |
if (get_property_value(wnd, "_NET_WM_STATE", 64, &nitems, &props, 1) < 0) |
935 |
return 0; |
936 |
|
937 |
atoms = (Atom *) props; |
938 |
|
939 |
for (i = 0; i < nitems; i++) |
940 |
{ |
941 |
if ((atoms[i] == atom1) || (atom2 && (atoms[i] == atom2))) |
942 |
{ |
943 |
if (i != (nitems - 1)) |
944 |
memmove(&atoms[i], &atoms[i + 1], |
945 |
sizeof(Atom) * (nitems - i - 1)); |
946 |
nitems--; |
947 |
i--; |
948 |
} |
949 |
} |
950 |
|
951 |
XChangeProperty(g_display, wnd, g_net_wm_state_atom, XA_ATOM, |
952 |
32, PropModeReplace, (unsigned char *) atoms, nitems); |
953 |
|
954 |
XFree(props); |
955 |
} |
956 |
|
957 |
return 0; |
958 |
} |
959 |
|
960 |
xevent.type = ClientMessage; |
961 |
xevent.xclient.window = wnd; |
962 |
xevent.xclient.message_type = g_net_wm_state_atom; |
963 |
xevent.xclient.format = 32; |
964 |
if (add) |
965 |
xevent.xclient.data.l[0] = _NET_WM_STATE_ADD; |
966 |
else |
967 |
xevent.xclient.data.l[0] = _NET_WM_STATE_REMOVE; |
968 |
xevent.xclient.data.l[1] = atom1; |
969 |
xevent.xclient.data.l[2] = atom2; |
970 |
xevent.xclient.data.l[3] = 0; |
971 |
xevent.xclient.data.l[4] = 0; |
972 |
status = XSendEvent(g_display, DefaultRootWindow(g_display), False, |
973 |
SubstructureNotifyMask | SubstructureRedirectMask, &xevent); |
974 |
if (!status) |
975 |
return -1; |
976 |
|
977 |
return 0; |
978 |
} |
979 |
|
980 |
|
981 |
int ewmh_state_fullscreen(Window wnd, Bool fullscreen) |
982 |
{ |
983 |
if (ewmh_modify_state(wnd, fullscreen, g_net_wm_state_fullscreen_atom, 0) < 0) |
984 |
return -1; |
985 |
return 0; |
986 |
} |
987 |
|
988 |
/* |
989 |
Set the window state: normal/minimized/maximized. |
990 |
Returns -1 on failure. |
991 |
*/ |
992 |
int |
993 |
ewmh_change_state(Window wnd, int state) |
994 |
{ |
995 |
/* |
996 |
* Deal with the max atoms |
997 |
*/ |
998 |
if (state == SEAMLESSRDP_MAXIMIZED) |
999 |
{ |
1000 |
if (ewmh_modify_state |
1001 |
(wnd, 1, g_net_wm_state_maximized_vert_atom, |
1002 |
g_net_wm_state_maximized_horz_atom) < 0) |
1003 |
return -1; |
1004 |
} |
1005 |
else |
1006 |
{ |
1007 |
if (ewmh_modify_state |
1008 |
(wnd, 0, g_net_wm_state_maximized_vert_atom, |
1009 |
g_net_wm_state_maximized_horz_atom) < 0) |
1010 |
return -1; |
1011 |
} |
1012 |
|
1013 |
return 0; |
1014 |
} |
1015 |
|
1016 |
|
1017 |
int |
1018 |
ewmh_get_window_desktop(Window wnd) |
1019 |
{ |
1020 |
unsigned long nitems_return; |
1021 |
unsigned char *prop_return; |
1022 |
int desktop; |
1023 |
|
1024 |
if (get_property_value(wnd, "_NET_WM_DESKTOP", 1, &nitems_return, &prop_return, 0) < 0) |
1025 |
return (-1); |
1026 |
|
1027 |
if (nitems_return != 1) |
1028 |
{ |
1029 |
fprintf(stderr, "_NET_WM_DESKTOP has bad length\n"); |
1030 |
return (-1); |
1031 |
} |
1032 |
|
1033 |
desktop = *prop_return; |
1034 |
XFree(prop_return); |
1035 |
return desktop; |
1036 |
} |
1037 |
|
1038 |
|
1039 |
int |
1040 |
ewmh_move_to_desktop(Window wnd, unsigned int desktop) |
1041 |
{ |
1042 |
Status status; |
1043 |
XEvent xevent; |
1044 |
|
1045 |
xevent.type = ClientMessage; |
1046 |
xevent.xclient.window = wnd; |
1047 |
xevent.xclient.message_type = g_net_wm_desktop_atom; |
1048 |
xevent.xclient.format = 32; |
1049 |
xevent.xclient.data.l[0] = desktop; |
1050 |
xevent.xclient.data.l[1] = 0; |
1051 |
xevent.xclient.data.l[2] = 0; |
1052 |
xevent.xclient.data.l[3] = 0; |
1053 |
xevent.xclient.data.l[4] = 0; |
1054 |
status = XSendEvent(g_display, DefaultRootWindow(g_display), False, |
1055 |
SubstructureNotifyMask | SubstructureRedirectMask, &xevent); |
1056 |
if (!status) |
1057 |
return -1; |
1058 |
|
1059 |
return 0; |
1060 |
} |
1061 |
|
1062 |
void |
1063 |
ewmh_set_wm_name(Window wnd, const char *title) |
1064 |
{ |
1065 |
int len; |
1066 |
|
1067 |
len = strlen(title); |
1068 |
XChangeProperty(g_display, wnd, g_net_wm_name_atom, g_utf8_string_atom, |
1069 |
8, PropModeReplace, (unsigned char *) title, len); |
1070 |
} |
1071 |
|
1072 |
|
1073 |
int |
1074 |
ewmh_set_window_popup(Window wnd) |
1075 |
{ |
1076 |
if (ewmh_modify_state |
1077 |
(wnd, 1, g_net_wm_state_skip_taskbar_atom, g_net_wm_state_skip_pager_atom) < 0) |
1078 |
return -1; |
1079 |
return 0; |
1080 |
} |
1081 |
|
1082 |
int |
1083 |
ewmh_set_window_modal(Window wnd) |
1084 |
{ |
1085 |
if (ewmh_modify_state(wnd, 1, g_net_wm_state_modal_atom, 0) < 0) |
1086 |
return -1; |
1087 |
return 0; |
1088 |
} |
1089 |
|
1090 |
void |
1091 |
ewmh_set_icon(Window wnd, int width, int height, const char *rgba_data) |
1092 |
{ |
1093 |
unsigned long nitems, i; |
1094 |
unsigned char *props; |
1095 |
unsigned long *cur_set, *new_set; |
1096 |
unsigned long *icon; |
1097 |
|
1098 |
cur_set = NULL; |
1099 |
new_set = NULL; |
1100 |
|
1101 |
if (get_property_value(wnd, "_NET_WM_ICON", 10000, &nitems, &props, 1) >= 0) |
1102 |
{ |
1103 |
cur_set = (unsigned long *) props; |
1104 |
|
1105 |
for (i = 0; i < nitems;) |
1106 |
{ |
1107 |
if (cur_set[i] == width && cur_set[i + 1] == height) |
1108 |
break; |
1109 |
|
1110 |
i += 2 + cur_set[i] * cur_set[i + 1]; |
1111 |
} |
1112 |
|
1113 |
if (i != nitems) |
1114 |
icon = cur_set + i; |
1115 |
else |
1116 |
{ |
1117 |
new_set = xmalloc((nitems + width * height + 2) * sizeof(unsigned long)); |
1118 |
memcpy(new_set, cur_set, nitems * sizeof(unsigned long)); |
1119 |
icon = new_set + nitems; |
1120 |
nitems += width * height + 2; |
1121 |
} |
1122 |
} |
1123 |
else |
1124 |
{ |
1125 |
new_set = xmalloc((width * height + 2) * sizeof(unsigned long)); |
1126 |
icon = new_set; |
1127 |
nitems = width * height + 2; |
1128 |
} |
1129 |
|
1130 |
icon[0] = width; |
1131 |
icon[1] = height; |
1132 |
|
1133 |
/* Convert RGBA -> ARGB */ |
1134 |
for (i = 0; i < width * height; i++) |
1135 |
{ |
1136 |
icon[i + 2] = |
1137 |
rgba_data[i * 4 + 3] << 24 | |
1138 |
((rgba_data[i * 4 + 0] << 16) & 0x00FF0000) | |
1139 |
((rgba_data[i * 4 + 1] << 8) & 0x0000FF00) | |
1140 |
((rgba_data[i * 4 + 2] << 0) & 0x000000FF); |
1141 |
} |
1142 |
|
1143 |
XChangeProperty(g_display, wnd, g_net_wm_icon_atom, XA_CARDINAL, 32, |
1144 |
PropModeReplace, (unsigned char *) (new_set ? new_set : cur_set), nitems); |
1145 |
|
1146 |
if (cur_set) |
1147 |
XFree(cur_set); |
1148 |
if (new_set) |
1149 |
free(new_set); |
1150 |
} |
1151 |
|
1152 |
void |
1153 |
ewmh_del_icon(Window wnd, int width, int height) |
1154 |
{ |
1155 |
unsigned long nitems, i, icon_size; |
1156 |
unsigned char *props; |
1157 |
unsigned long *cur_set, *new_set; |
1158 |
|
1159 |
cur_set = NULL; |
1160 |
new_set = NULL; |
1161 |
|
1162 |
if (get_property_value(wnd, "_NET_WM_ICON", 10000, &nitems, &props, 1) < 0) |
1163 |
return; |
1164 |
|
1165 |
cur_set = (unsigned long *) props; |
1166 |
|
1167 |
for (i = 0; i < nitems;) |
1168 |
{ |
1169 |
if (cur_set[i] == width && cur_set[i + 1] == height) |
1170 |
break; |
1171 |
|
1172 |
i += 2 + cur_set[i] * cur_set[i + 1]; |
1173 |
} |
1174 |
|
1175 |
if (i == nitems) |
1176 |
goto out; |
1177 |
|
1178 |
icon_size = width * height + 2; |
1179 |
new_set = xmalloc((nitems - icon_size) * sizeof(unsigned long)); |
1180 |
|
1181 |
if (i != 0) |
1182 |
memcpy(new_set, cur_set, i * sizeof(unsigned long)); |
1183 |
if (i != nitems - icon_size) |
1184 |
memcpy(new_set + i, cur_set + i + icon_size, |
1185 |
(nitems - (i + icon_size)) * sizeof(unsigned long)); |
1186 |
|
1187 |
nitems -= icon_size; |
1188 |
|
1189 |
XChangeProperty(g_display, wnd, g_net_wm_icon_atom, XA_CARDINAL, 32, |
1190 |
PropModeReplace, (unsigned char *) new_set, nitems); |
1191 |
|
1192 |
free(new_set); |
1193 |
|
1194 |
out: |
1195 |
XFree(cur_set); |
1196 |
} |
1197 |
|
1198 |
int |
1199 |
ewmh_set_window_above(Window wnd) |
1200 |
{ |
1201 |
if (ewmh_modify_state(wnd, 1, g_net_wm_state_above_atom, 0) < 0) |
1202 |
return -1; |
1203 |
return 0; |
1204 |
} |
1205 |
|
1206 |
#endif /* MAKE_PROTO */ |
1207 |
|
1208 |
|
1209 |
#if 0 |
1210 |
|
1211 |
/* FIXME: _NET_MOVERESIZE_WINDOW is for pagers, not for |
1212 |
applications. We should implement _NET_WM_MOVERESIZE instead */ |
1213 |
|
1214 |
int |
1215 |
ewmh_net_moveresize_window(Window wnd, int x, int y, int width, int height) |
1216 |
{ |
1217 |
Status status; |
1218 |
XEvent xevent; |
1219 |
Atom moveresize; |
1220 |
|
1221 |
moveresize = XInternAtom(g_display, "_NET_MOVERESIZE_WINDOW", False); |
1222 |
if (!moveresize) |
1223 |
{ |
1224 |
return -1; |
1225 |
} |
1226 |
|
1227 |
xevent.type = ClientMessage; |
1228 |
xevent.xclient.window = wnd; |
1229 |
xevent.xclient.message_type = moveresize; |
1230 |
xevent.xclient.format = 32; |
1231 |
xevent.xclient.data.l[0] = StaticGravity | (1 << 8) | (1 << 9) | (1 << 10) | (1 << 11); |
1232 |
xevent.xclient.data.l[1] = x; |
1233 |
xevent.xclient.data.l[2] = y; |
1234 |
xevent.xclient.data.l[3] = width; |
1235 |
xevent.xclient.data.l[4] = height; |
1236 |
|
1237 |
status = XSendEvent(g_display, DefaultRootWindow(g_display), False, |
1238 |
SubstructureNotifyMask | SubstructureRedirectMask, &xevent); |
1239 |
if (!status) |
1240 |
return -1; |
1241 |
return 0; |
1242 |
} |
1243 |
|
1244 |
#endif |