- Fixed all // comments
[wmaker-crm.git] / src / wmspec.c
blobf6c52109d77d495bf9f2a0c0e378da0aca0cf685
1 /* wmspec.c-- support for the wm-spec Hints
3 * Window Maker window manager
5 * Copyright (c) 1998-2003 Alfredo K. Kojima
7 * This program is free software; you can redistribute it and/or modify
8 * it under the terms of the GNU General Public License as published by
9 * the Free Software Foundation; either version 2 of the License, or
10 * (at your option) any later version.
12 * This program is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 * GNU General Public License for more details.
17 * You should have received a copy of the GNU General Public License
18 * along with this program; if not, write to the Free Software
19 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307,
20 * USA.
24 #include "wconfig.h"
26 #ifdef NETWM_HINTS
28 #include <X11/Xlib.h>
29 #include <X11/Xatom.h>
30 #include <string.h>
32 #include "WindowMaker.h"
33 #include "window.h"
34 #include "screen.h"
35 #include "workspace.h"
36 #include "framewin.h"
37 #include "actions.h"
38 #include "client.h"
39 #include "wmspec.h"
40 #include "icon.h"
41 #include "stacking.h"
42 #include "xinerama.h"
43 #include "properties.h"
46 #ifdef DEBUG_WMSPEC
47 #include <stdio.h>
48 #endif
50 /* Global variables */
51 extern Atom _XA_WM_DELETE_WINDOW;
52 extern Time LastTimestamp;
53 extern WPreferences wPreferences;
55 /* Root Window Properties */
56 static Atom net_supported;
57 static Atom net_client_list;
58 static Atom net_client_list_stacking;
59 static Atom net_number_of_desktops;
60 static Atom net_desktop_geometry;
61 static Atom net_desktop_viewport;
62 static Atom net_current_desktop;
63 static Atom net_desktop_names;
64 static Atom net_active_window;
65 static Atom net_workarea; /* XXX: not xinerama compatible */
66 static Atom net_supporting_wm_check;
67 static Atom net_virtual_roots; /* N/A */
68 static Atom net_desktop_layout; /* XXX */
69 static Atom net_showing_desktop;
71 /* Other Root Window Messages */
72 static Atom net_close_window;
73 static Atom net_moveresize_window; /* TODO */
74 static Atom net_wm_moveresize; /* TODO */
76 /* Application Window Properties */
77 static Atom net_wm_name;
78 static Atom net_wm_visible_name; /* TODO (unnecessary?) */
79 static Atom net_wm_icon_name;
80 static Atom net_wm_visible_icon_name; /* TODO (unnecessary?) */
81 static Atom net_wm_desktop;
82 static Atom net_wm_window_type;
83 static Atom net_wm_window_type_desktop;
84 static Atom net_wm_window_type_dock;
85 static Atom net_wm_window_type_toolbar;
86 static Atom net_wm_window_type_menu;
87 static Atom net_wm_window_type_utility;
88 static Atom net_wm_window_type_splash;
89 static Atom net_wm_window_type_dialog;
90 static Atom net_wm_window_type_normal;
91 static Atom net_wm_state;
92 static Atom net_wm_state_modal; /* XXX: what is this?!? */
93 static Atom net_wm_state_sticky;
94 static Atom net_wm_state_maximized_vert;
95 static Atom net_wm_state_maximized_horz;
96 static Atom net_wm_state_shaded;
97 static Atom net_wm_state_skip_taskbar;
98 static Atom net_wm_state_skip_pager;
99 static Atom net_wm_state_hidden;
100 static Atom net_wm_state_fullscreen;
101 static Atom net_wm_state_above;
102 static Atom net_wm_state_below;
103 static Atom net_wm_allowed_actions;
104 static Atom net_wm_action_move;
105 static Atom net_wm_action_resize;
106 static Atom net_wm_action_minimize;
107 static Atom net_wm_action_shade;
108 static Atom net_wm_action_stick;
109 static Atom net_wm_action_maximize_horz;
110 static Atom net_wm_action_maximize_vert;
111 static Atom net_wm_action_fullscreen;
112 static Atom net_wm_action_change_desktop;
113 static Atom net_wm_action_close;
114 static Atom net_wm_strut; /* XXX: see net_workarea */
115 static Atom net_wm_strut_partial; /* TODO: doesn't really fit into the current strut scheme */
116 static Atom net_wm_icon_geometry; /* FIXME: should work together with net_wm_handled_icons, gnome-panel-2.2.0.1 doesn't use _NET_WM_HANDLED_ICONS, thus present situation. */
117 static Atom net_wm_icon;
118 static Atom net_wm_pid; /* TODO */
119 static Atom net_wm_handled_icons; /* FIXME: see net_wm_icon_geometry */
121 /* Window Manager Protocols */
122 static Atom net_wm_ping; /* TODO */
124 static Atom utf8_string;
126 typedef struct {
127 char * name;
128 Atom * atom;
129 } atomitem_t;
131 static atomitem_t atomNames[] = {
132 { "_NET_SUPPORTED", &net_supported },
133 { "_NET_CLIENT_LIST", &net_client_list },
134 { "_NET_CLIENT_LIST_STACKING", &net_client_list_stacking },
135 { "_NET_NUMBER_OF_DESKTOPS", &net_number_of_desktops },
136 { "_NET_DESKTOP_GEOMETRY", &net_desktop_geometry },
137 { "_NET_DESKTOP_VIEWPORT", &net_desktop_viewport },
138 { "_NET_CURRENT_DESKTOP", &net_current_desktop },
139 { "_NET_DESKTOP_NAMES", &net_desktop_names },
140 { "_NET_ACTIVE_WINDOW", &net_active_window },
141 { "_NET_WORKAREA", &net_workarea },
142 { "_NET_SUPPORTING_WM_CHECK", &net_supporting_wm_check },
143 { "_NET_VIRTUAL_ROOTS", &net_virtual_roots },
144 { "_NET_DESKTOP_LAYOUT", &net_desktop_layout },
145 { "_NET_SHOWING_DESKTOP", &net_showing_desktop },
147 { "_NET_CLOSE_WINDOW", &net_close_window },
148 { "_NET_MOVERESIZE_WINDOW", &net_moveresize_window },
149 { "_NET_WM_MOVERESIZE", &net_wm_moveresize },
151 { "_NET_WM_NAME", &net_wm_name },
152 { "_NET_WM_VISIBLE_NAME", &net_wm_visible_name },
153 { "_NET_WM_ICON_NAME", &net_wm_icon_name },
154 { "_NET_WM_VISIBLE_ICON_NAME", &net_wm_visible_icon_name },
155 { "_NET_WM_DESKTOP", &net_wm_desktop },
156 { "_NET_WM_WINDOW_TYPE", &net_wm_window_type },
157 { "_NET_WM_WINDOW_TYPE_DESKTOP", &net_wm_window_type_desktop },
158 { "_NET_WM_WINDOW_TYPE_DOCK", &net_wm_window_type_dock },
159 { "_NET_WM_WINDOW_TYPE_TOOLBAR", &net_wm_window_type_toolbar },
160 { "_NET_WM_WINDOW_TYPE_MENU", &net_wm_window_type_menu },
161 { "_NET_WM_WINDOW_TYPE_UTILITY", &net_wm_window_type_utility },
162 { "_NET_WM_WINDOW_TYPE_SPLASH", &net_wm_window_type_splash },
163 { "_NET_WM_WINDOW_TYPE_DIALOG", &net_wm_window_type_dialog },
164 { "_NET_WM_WINDOW_TYPE_NORMAL", &net_wm_window_type_normal },
165 { "_NET_WM_STATE", &net_wm_state },
166 { "_NET_WM_STATE_MODAL", &net_wm_state_modal },
167 { "_NET_WM_STATE_STICKY", &net_wm_state_sticky },
168 { "_NET_WM_STATE_MAXIMIZED_VERT", &net_wm_state_maximized_vert },
169 { "_NET_WM_STATE_MAXIMIZED_HORZ", &net_wm_state_maximized_horz },
170 { "_NET_WM_STATE_SHADED", &net_wm_state_shaded },
171 { "_NET_WM_STATE_SKIP_TASKBAR", &net_wm_state_skip_taskbar },
172 { "_NET_WM_STATE_SKIP_PAGER", &net_wm_state_skip_pager },
173 { "_NET_WM_STATE_HIDDEN", &net_wm_state_hidden },
174 { "_NET_WM_STATE_FULLSCREEN", &net_wm_state_fullscreen },
175 { "_NET_WM_STATE_ABOVE", &net_wm_state_above },
176 { "_NET_WM_STATE_BELOW", &net_wm_state_below },
177 { "_NET_WM_ALLOWED_ACTIONS", &net_wm_allowed_actions },
178 { "_NET_WM_ACTION_MOVE", &net_wm_action_move },
179 { "_NET_WM_ACTION_RESIZE", &net_wm_action_resize },
180 { "_NET_WM_ACTION_MINIMIZE", &net_wm_action_minimize },
181 { "_NET_WM_ACTION_SHADE", &net_wm_action_shade },
182 { "_NET_WM_ACTION_STICK", &net_wm_action_stick },
183 { "_NET_WM_ACTION_MAXIMIZE_HORZ", &net_wm_action_maximize_horz },
184 { "_NET_WM_ACTION_MAXIMIZE_VERT", &net_wm_action_maximize_vert },
185 { "_NET_WM_ACTION_FULLSCREEN", &net_wm_action_fullscreen },
186 { "_NET_WM_ACTION_CHANGE_DESKTOP", &net_wm_action_change_desktop },
187 { "_NET_WM_ACTION_CLOSE", &net_wm_action_close },
188 { "_NET_WM_STRUT", &net_wm_strut },
189 { "_NET_WM_STRUT_PARTIAL", &net_wm_strut_partial },
190 { "_NET_WM_ICON_GEOMETRY", &net_wm_icon_geometry },
191 { "_NET_WM_ICON", &net_wm_icon },
192 { "_NET_WM_PID", &net_wm_pid },
193 { "_NET_WM_HANDLED_ICONS", &net_wm_handled_icons },
195 { "_NET_WM_PING", &net_wm_ping },
197 { "UTF8_STRING", &utf8_string },
200 #define atomNr (sizeof(atomNames)/sizeof(atomitem_t))
202 #define _NET_WM_STATE_REMOVE 0
203 #define _NET_WM_STATE_ADD 1
204 #define _NET_WM_STATE_TOGGLE 2
206 #define _NET_WM_MOVERESIZE_SIZE_TOPLEFT 0
207 #define _NET_WM_MOVERESIZE_SIZE_TOP 1
208 #define _NET_WM_MOVERESIZE_SIZE_TOPRIGHT 2
209 #define _NET_WM_MOVERESIZE_SIZE_RIGHT 3
210 #define _NET_WM_MOVERESIZE_SIZE_BOTTOMRIGHT 4
211 #define _NET_WM_MOVERESIZE_SIZE_BOTTOM 5
212 #define _NET_WM_MOVERESIZE_SIZE_BOTTOMLEFT 6
213 #define _NET_WM_MOVERESIZE_SIZE_LEFT 7
214 #define _NET_WM_MOVERESIZE_MOVE 8 /* movement only */
215 #define _NET_WM_MOVERESIZE_SIZE_KEYBOARD 9 /* size via keyboard */
216 #define _NET_WM_MOVERESIZE_MOVE_KEYBOARD 10 /* move via keyboard */
218 static void observer(void *self, WMNotification *notif);
219 static void wsobserver(void *self, WMNotification *notif);
221 static void updateClientList(WScreen *scr);
222 static void updateClientListStacking(WScreen *scr, WWindow *);
224 static void updateWorkspaceNames(WScreen *scr);
225 static void updateCurrentWorkspace(WScreen *scr);
226 static void updateWorkspaceCount(WScreen *scr);
228 typedef struct NetData {
229 WScreen *scr;
230 WReservedArea *strut;
231 WWindow **show_desktop;
232 } NetData;
235 static void
236 setSupportedHints(WScreen *scr)
238 Atom atom[atomNr];
239 int i = 0;
241 /* set supported hints list */
242 /* XXX: extend this !!! */
244 atom[i++] = net_client_list;
245 atom[i++] = net_client_list_stacking;
246 atom[i++] = net_number_of_desktops;
247 atom[i++] = net_desktop_geometry;
248 atom[i++] = net_desktop_viewport;
249 atom[i++] = net_current_desktop;
250 atom[i++] = net_desktop_names;
251 atom[i++] = net_active_window;
252 atom[i++] = net_workarea;
253 atom[i++] = net_supporting_wm_check;
254 atom[i++] = net_showing_desktop;
255 #if 0
256 atom[i++] = net_wm_moveresize;
257 #endif
258 atom[i++] = net_wm_desktop;
259 atom[i++] = net_wm_window_type;
260 atom[i++] = net_wm_window_type_desktop;
261 atom[i++] = net_wm_window_type_dock;
262 atom[i++] = net_wm_window_type_toolbar;
263 atom[i++] = net_wm_window_type_menu;
264 atom[i++] = net_wm_window_type_utility;
265 atom[i++] = net_wm_window_type_splash;
266 atom[i++] = net_wm_window_type_dialog;
267 atom[i++] = net_wm_window_type_normal;
269 atom[i++] = net_wm_state;
270 /* atom[i++] = net_wm_state_modal; */ /* XXX: not sure where/when to use it. */
271 atom[i++] = net_wm_state_sticky;
272 atom[i++] = net_wm_state_shaded;
273 atom[i++] = net_wm_state_maximized_horz;
274 atom[i++] = net_wm_state_maximized_vert;
275 atom[i++] = net_wm_state_skip_taskbar;
276 atom[i++] = net_wm_state_skip_pager;
277 atom[i++] = net_wm_state_hidden;
278 atom[i++] = net_wm_state_fullscreen;
279 atom[i++] = net_wm_state_above;
280 atom[i++] = net_wm_state_below;
282 atom[i++] = net_wm_allowed_actions;
283 atom[i++] = net_wm_action_move;
284 atom[i++] = net_wm_action_resize;
285 atom[i++] = net_wm_action_minimize;
286 atom[i++] = net_wm_action_shade;
287 atom[i++] = net_wm_action_stick;
288 atom[i++] = net_wm_action_maximize_horz;
289 atom[i++] = net_wm_action_maximize_vert;
290 atom[i++] = net_wm_action_fullscreen;
291 atom[i++] = net_wm_action_change_desktop;
292 atom[i++] = net_wm_action_close;
294 atom[i++] = net_wm_strut;
295 atom[i++] = net_wm_icon_geometry;
296 atom[i++] = net_wm_icon;
297 atom[i++] = net_wm_handled_icons;
299 atom[i++] = net_wm_name;
300 atom[i++] = net_wm_icon_name;
302 XChangeProperty(dpy, scr->root_win, net_supported, XA_ATOM, 32,
303 PropModeReplace, (unsigned char*)atom, i);
305 /* set supporting wm hint */
306 XChangeProperty(dpy, scr->root_win, net_supporting_wm_check, XA_WINDOW, 32,
307 PropModeReplace, (unsigned char*)&scr->info_window, 1);
309 XChangeProperty(dpy, scr->info_window, net_supporting_wm_check, XA_WINDOW,
310 32, PropModeReplace, (unsigned char*)&scr->info_window, 1);
314 void
315 wNETWMUpdateDesktop(WScreen *scr)
317 CARD32 *views, sizes[2];
318 int count, i;
320 if (scr->workspace_count==0)
321 return;
323 count = scr->workspace_count * 2;
324 views = wmalloc(sizeof(CARD32) * count);
325 /*memset(views, 0, sizeof(CARD32) * count);*/
327 #ifdef VIRTUAL_DESKTOP
328 sizes[0] = scr->workspaces[scr->current_workspace]->width;
329 sizes[1] = scr->workspaces[scr->current_workspace]->height;
330 #else
331 sizes[0] = scr->scr_width;
332 sizes[1] = scr->scr_height;
333 #endif
335 for (i=0; i<scr->workspace_count; i++) {
336 #ifdef VIRTUAL_DESKTOP
337 views[2*i + 0] = scr->workspaces[i]->view_x;
338 views[2*i + 1] = scr->workspaces[i]->view_y;
339 #else
340 views[2*i + 0] = 0;
341 views[2*i + 1] = 0;
342 #endif
345 XChangeProperty(dpy, scr->root_win, net_desktop_geometry, XA_CARDINAL, 32,
346 PropModeReplace, (unsigned char*)sizes, 2);
348 XChangeProperty(dpy, scr->root_win, net_desktop_viewport, XA_CARDINAL, 32,
349 PropModeReplace, (unsigned char*)views, count);
351 wfree(views);
356 wNETWMGetCurrentDesktopFromHint(WScreen *scr)
358 int count;
359 unsigned char *prop;
361 prop= PropGetCheckProperty(scr->root_win, net_current_desktop, XA_CARDINAL,
362 0, 1, &count);
363 if (prop)
365 int desktop= *(CARD32*)prop;
366 XFree(prop);
367 return desktop;
369 return -1;
373 static void
374 updateIconImage(WScreen *scr, WWindow *wwin)
376 Atom actual_type_return;
377 int actual_format_return;
378 unsigned long nitems_return, bytes_after_return;
379 unsigned char *prop_return;
380 int rc = XGetWindowProperty(dpy, wwin->client_win, net_wm_icon, 0, ~0, False,
381 XA_CARDINAL, &actual_type_return, &actual_format_return,
382 &nitems_return, &bytes_after_return, &prop_return);
384 if (rc==Success && prop_return) {
385 unsigned int *data = (unsigned int *)prop_return;
386 unsigned int pos = 0, len = 0;
387 unsigned int best_pos = 0, best_tmp = ~0;
388 extern WPreferences wPreferences;
389 unsigned int pref_size = wPreferences.icon_size;
390 unsigned int pref_sq = pref_size*pref_size;
391 char *src, *dst;
392 RImage *new_rimage;
394 do {
395 len = data[pos+0]*data[pos+1];
396 unsigned int tmp = pref_sq-len;
397 if (tmp < best_tmp && tmp > 0) {
398 best_tmp = tmp;
399 best_pos = pos;
401 pos += 2+len;
402 } while (pos < nitems_return && len != 0);
404 new_rimage = RCreateImage(data[best_pos+0], data[best_pos+1], True);
405 len = data[best_pos+0] * data[best_pos+1];
406 src = (char*)&data[best_pos+2];
407 dst = new_rimage->data;
408 for (pos=0; pos<len; ++pos, src+=4, dst+=4) {
409 dst[0] = src[2]; /* R */
410 dst[1] = src[1]; /* G */
411 dst[2] = src[0]; /* B */
412 dst[3] = src[3]; /* A */
415 if (new_rimage) {
416 if (wwin->net_icon_image)
417 RReleaseImage(wwin->net_icon_image);
418 wwin->net_icon_image = new_rimage;
421 XFree(prop_return);
426 static void
427 updateShowDesktop(WScreen * scr, Bool show)
429 CARD32 foo;
431 foo = (show == True);
432 XChangeProperty(dpy, scr->root_win, net_showing_desktop, XA_CARDINAL, 32,
433 PropModeReplace, (unsigned char *)&foo, 1);
437 void
438 wNETWMShowingDesktop(WScreen *scr, Bool show)
440 if (show && scr->netdata->show_desktop == NULL) {
441 WWindow *tmp, **wins;
442 int i=0;
444 wins = (WWindow **)wmalloc(sizeof(WWindow *)*(scr->window_count+1));
446 tmp = scr->focused_window;
447 while (tmp) {
448 if (!tmp->flags.hidden && !tmp->flags.miniaturized &&
449 !WFLAGP(tmp, skip_window_list)) {
451 wins[i++] = tmp;
452 tmp->flags.skip_next_animation = 1;
453 tmp->flags.net_show_desktop = 1;
454 wIconifyWindow(tmp);
457 tmp = tmp->prev;
459 wins[i++] = NULL;
461 scr->netdata->show_desktop = wins;
462 updateShowDesktop(scr, True);
463 } else if (scr->netdata->show_desktop != NULL) {
464 /* FIXME: get rid of workspace flashing ! */
465 int ws = scr->current_workspace;
466 WWindow **tmp;
467 for (tmp = scr->netdata->show_desktop; *tmp; ++tmp) {
468 wDeiconifyWindow(*tmp);
469 (*tmp)->flags.net_show_desktop = 0;
471 if (ws != scr->current_workspace)
472 wWorkspaceChange(scr, ws);
473 wfree(scr->netdata->show_desktop);
474 scr->netdata->show_desktop = NULL;
475 updateShowDesktop(scr, False);
480 void
481 wNETWMInitStuff(WScreen *scr)
483 NetData *data;
484 int i;
486 #ifdef DEBUG_WMSPEC
487 printf( "wNETWMInitStuff\n");
488 #endif
490 #ifdef HAVE_XINTERNATOMS
492 Atom atoms[atomNr];
493 char * names[atomNr];
495 for (i = 0; i < atomNr; ++i) {
496 names[i] = atomNames[i].name;
498 XInternAtoms(dpy, &names[0], atomNr, False, atoms);
499 for (i = 0; i < atomNr; ++i) {
500 *atomNames[i].atom = atoms[i];
503 #else
504 for (i = 0; i < atomNr; i++) {
505 *atomNames[i].atom = XInternAtom(dpy, atomNames[i].name, False);
507 #endif
509 data = wmalloc(sizeof(NetData));
510 data->scr = scr;
511 data->strut = NULL;
512 data->show_desktop = NULL;
514 scr->netdata = data;
516 setSupportedHints(scr);
518 WMAddNotificationObserver(observer, data, WMNManaged, NULL);
519 WMAddNotificationObserver(observer, data, WMNUnmanaged, NULL);
520 WMAddNotificationObserver(observer, data, WMNChangedWorkspace, NULL);
521 WMAddNotificationObserver(observer, data, WMNChangedState, NULL);
522 WMAddNotificationObserver(observer, data, WMNChangedFocus, NULL);
523 WMAddNotificationObserver(observer, data, WMNChangedStacking, NULL);
524 WMAddNotificationObserver(observer, data, WMNChangedName, NULL);
526 WMAddNotificationObserver(wsobserver, data, WMNWorkspaceCreated, NULL);
527 WMAddNotificationObserver(wsobserver, data, WMNWorkspaceDestroyed, NULL);
528 WMAddNotificationObserver(wsobserver, data, WMNWorkspaceChanged, NULL);
529 WMAddNotificationObserver(wsobserver, data, WMNWorkspaceNameChanged, NULL);
531 updateClientList(scr);
532 updateClientListStacking(scr, NULL);
533 updateWorkspaceCount(scr);
534 updateWorkspaceNames(scr);
535 updateShowDesktop(scr, False);
537 wScreenUpdateUsableArea(scr);
541 void
542 wNETWMCleanup(WScreen *scr)
544 int i;
546 for (i= 0; i < atomNr; i++)
547 XDeleteProperty(dpy, scr->root_win, *atomNames[i].atom);
551 void
552 wNETWMUpdateActions(WWindow *wwin, Bool del)
554 Atom action[10]; /* nr of actions atoms defined */
555 int i = 0;
557 if (del) {
558 XDeleteProperty(dpy, wwin->client_win, net_wm_allowed_actions);
559 return;
562 if (IS_MOVABLE(wwin))
563 action[i++] = net_wm_action_move;
565 if (IS_RESIZABLE(wwin))
566 action[i++] = net_wm_action_resize;
568 if (!WFLAGP(wwin, no_miniaturizable))
569 action[i++] = net_wm_action_minimize;
571 if (!WFLAGP(wwin, no_shadeable))
572 action[i++] = net_wm_action_shade;
574 /* if (!WFLAGP(wwin, no_stickable)) */
575 action[i++] = net_wm_action_stick;
577 /* if (!(WFLAGP(wwin, no_maximizeable) & MAX_HORIZONTAL)) */
578 if (IS_RESIZABLE(wwin))
579 action[i++] = net_wm_action_maximize_horz;
581 /* if (!(WFLAGP(wwin, no_maximizeable) & MAX_VERTICAL)) */
582 if (IS_RESIZABLE(wwin))
583 action[i++] = net_wm_action_maximize_vert;
585 /* if (!WFLAGP(wwin, no_fullscreen)) */
586 action[i++] = net_wm_action_fullscreen;
588 /* if (!WFLAGP(wwin, no_change_desktop)) */
589 action[i++] = net_wm_action_change_desktop;
591 if (!WFLAGP(wwin, no_closable))
592 action[i++] = net_wm_action_close;
594 XChangeProperty(dpy, wwin->client_win, net_wm_allowed_actions,
595 XA_ATOM, 32, PropModeReplace, (unsigned char *)action, i);
599 void
600 wNETWMUpdateWorkarea(WScreen *scr, WArea usableArea)
602 CARD32 *area;
603 int count, i;
605 /* XXX: not Xinerama compatible,
606 xinerama gets the largest available */
608 if(!scr->netdata || scr->workspace_count==0)
609 return;
611 count = scr->workspace_count * 4;
612 area = wmalloc(sizeof(CARD32) * count);
613 for (i=0; i<scr->workspace_count; i++) {
614 area[4*i + 0] = usableArea.x1;
615 area[4*i + 1] = usableArea.y1;
616 area[4*i + 2] = usableArea.x2 - usableArea.x1;
617 area[4*i + 3] = usableArea.y2 - usableArea.y1;
620 XChangeProperty(dpy, scr->root_win, net_workarea, XA_CARDINAL, 32,
621 PropModeReplace, (unsigned char*)area, count);
623 wfree(area);
627 Bool
628 wNETWMGetUsableArea(WScreen *scr, int head, WArea *area)
630 WReservedArea *cur;
631 WMRect rect;
633 if(!scr->netdata || !scr->netdata->strut)
634 return False;
636 area->x1 = area->y1 = area->x2 = area->y2 = 0;
638 for(cur = scr->netdata->strut ; cur ; cur = cur->next) {
639 WWindow * wwin = wWindowFor(cur->window);
640 if (wWindowTouchesHead(wwin, head)) {
641 if(cur->area.x1 > area->x1)
642 area->x1 = cur->area.x1;
643 if(cur->area.y1 > area->y1)
644 area->y1 = cur->area.y1;
645 if(cur->area.x2 > area->x2)
646 area->x2 = cur->area.x2;
647 if(cur->area.y2 > area->y2)
648 area->y2 = cur->area.y2;
652 if (area->x1==0 && area->x2==0 &&
653 area->y1==0 && area->y2==0) return False;
655 rect = wGetRectForHead(scr, head);
657 area->x1 = rect.pos.x + area->x1;
658 area->x2 = rect.pos.x + rect.size.width - area->x2;
659 area->y1 = rect.pos.y + area->y1;
660 area->y2 = rect.pos.y + rect.size.height - area->y2;
662 return True;
666 static void
667 updateClientList(WScreen *scr)
669 WWindow *wwin;
670 Window *windows;
671 int count;
673 windows = (Window *)wmalloc(sizeof(Window)*(scr->window_count+1));
675 count = 0;
676 wwin = scr->focused_window;
677 while (wwin) {
678 windows[count++] = wwin->client_win;
679 wwin = wwin->prev;
681 XChangeProperty(dpy, scr->root_win, net_client_list, XA_WINDOW, 32,
682 PropModeReplace, (unsigned char*)windows, count);
684 wfree(windows);
685 XFlush(dpy);
689 static void
690 updateClientListStacking(WScreen *scr, WWindow *wwin_excl)
692 WWindow *wwin;
693 Window *client_list;
694 Window *client_list_reverse;
695 int client_count;
696 WCoreWindow *tmp;
697 WMBagIterator iter;
698 int i;
700 /* update client list */
701 i = scr->window_count + 1;
702 client_list = (Window*)wmalloc(sizeof(Window) * i);
703 client_list_reverse = (Window*)wmalloc(sizeof(Window) * i);
705 client_count = 0;
706 WM_ETARETI_BAG(scr->stacking_list, tmp, iter) {
707 while (tmp) {
708 wwin = wWindowFor(tmp->window);
709 /* wwin_excl is a window to exclude from the list
710 (e.g. it's now unmanaged) */
711 if(wwin && (wwin != wwin_excl))
712 client_list[client_count++] = wwin->client_win;
713 tmp = tmp->stacking->under;
717 for(i = 0; i < client_count; i++) {
718 Window w = client_list[client_count - i - 1];
719 client_list_reverse[i] = w;
722 XChangeProperty(dpy, scr->root_win, net_client_list_stacking, XA_WINDOW, 32,
723 PropModeReplace, (unsigned char *)client_list_reverse, client_count);
725 wfree(client_list);
726 wfree(client_list_reverse);
728 XFlush(dpy);
732 static void
733 updateWorkspaceCount(WScreen *scr) /* changeable */
735 CARD32 count;
737 count = scr->workspace_count;
739 XChangeProperty(dpy, scr->root_win, net_number_of_desktops, XA_CARDINAL,
740 32, PropModeReplace, (unsigned char*)&count, 1);
744 static void
745 updateCurrentWorkspace(WScreen *scr) /* changeable */
747 CARD32 count;
749 count = scr->current_workspace;
751 XChangeProperty(dpy, scr->root_win, net_current_desktop, XA_CARDINAL, 32,
752 PropModeReplace, (unsigned char*)&count, 1);
756 static void
757 updateWorkspaceNames(WScreen *scr)
759 char buf[1024], *pos;
760 unsigned int i, len, curr_size;
762 pos = buf;
763 len = 0;
764 for(i = 0; i < scr->workspace_count; i++) {
765 curr_size = strlen(scr->workspaces[i]->name);
766 strcpy(pos, scr->workspaces[i]->name);
767 pos += (curr_size+1);
768 len += (curr_size+1);
771 XChangeProperty(dpy, scr->root_win, net_desktop_names, utf8_string, 8,
772 PropModeReplace, (unsigned char *)buf, len);
776 static void
777 updateFocusHint(WScreen *scr, WWindow *wwin) /* changeable */
779 Window window;
781 if (!scr->focused_window || !scr->focused_window->flags.focused)
782 window = None;
783 else
784 window = scr->focused_window->client_win;
786 XChangeProperty(dpy, scr->root_win, net_active_window, XA_WINDOW, 32,
787 PropModeReplace, (unsigned char*)&window, 1);
791 static void
792 updateWorkspaceHint(WWindow *wwin, Bool fake, Bool del)
794 CARD32 l;
796 if (del) {
797 XDeleteProperty(dpy, wwin->client_win, net_wm_desktop);
798 } else {
799 l = ((fake || IS_OMNIPRESENT(wwin)) ? -1 : wwin->frame->workspace);
800 XChangeProperty(dpy, wwin->client_win, net_wm_desktop, XA_CARDINAL,
801 32, PropModeReplace, (unsigned char*)&l, 1);
806 static void
807 updateStateHint(WWindow *wwin, Bool changedWorkspace, Bool del) /* changeable */
809 if (del) {
810 if (!wwin->flags.net_state_from_client) {
811 XDeleteProperty(dpy, wwin->client_win, net_wm_state);
813 } else {
814 Atom state[11]; /* nr of defined state atoms */
815 int i = 0;
817 if(changedWorkspace || (wPreferences.sticky_icons && !IS_OMNIPRESENT(wwin)))
818 updateWorkspaceHint(wwin, False, False);
820 if (IS_OMNIPRESENT(wwin))
821 state[i++] = net_wm_state_sticky;
822 if (wwin->flags.shaded)
823 state[i++] = net_wm_state_shaded;
824 if (wwin->flags.maximized & MAX_HORIZONTAL)
825 state[i++] = net_wm_state_maximized_horz;
826 if (wwin->flags.maximized & MAX_VERTICAL)
827 state[i++] = net_wm_state_maximized_vert;
828 if (WFLAGP(wwin, skip_window_list))
829 state[i++] = net_wm_state_skip_taskbar;
830 if (wwin->flags.net_skip_pager)
831 state[i++] = net_wm_state_skip_pager;
832 if ((wwin->flags.hidden || wwin->flags.miniaturized) && !wwin->flags.net_show_desktop){
833 state[i++] = net_wm_state_hidden;
834 state[i++] = net_wm_state_skip_pager;
836 if (wwin->flags.miniaturized && wPreferences.sticky_icons) {
837 if( !IS_OMNIPRESENT(wwin))
838 updateWorkspaceHint(wwin, True, False);
839 state[i++] = net_wm_state_sticky;
842 if (WFLAGP(wwin, sunken))
843 state[i++] = net_wm_state_below;
844 if (WFLAGP(wwin, floating))
845 state[i++] = net_wm_state_above;
846 if (wwin->flags.fullscreen)
847 state[i++] = net_wm_state_fullscreen;
849 XChangeProperty(dpy, wwin->client_win, net_wm_state, XA_ATOM, 32,
850 PropModeReplace, (unsigned char *)state, i);
855 static Bool
856 updateStrut(WWindow *wwin, Bool adding)
858 WScreen *scr;
859 WReservedArea *area;
860 Bool hasState = False;
862 scr = wwin->screen_ptr;
864 if (adding) {
865 Atom type_ret;
866 int fmt_ret;
867 unsigned long nitems_ret;
868 unsigned long bytes_after_ret;
869 long *data = 0;
871 if (XGetWindowProperty(dpy, wwin->client_win, net_wm_strut, 0, 4, False,
872 XA_CARDINAL, &type_ret, &fmt_ret, &nitems_ret,
873 &bytes_after_ret,
874 (unsigned char**)&data)==Success && data) {
876 area = (WReservedArea *)wmalloc(sizeof(WReservedArea));
877 area->area.x1 = data[0];
878 area->area.x2 = data[1];
879 area->area.y1 = data[2];
880 area->area.y2 = data[3];
882 area->window = wwin->client_win;
884 area->next = scr->netdata->strut;
885 scr->netdata->strut = area;
887 XFree(data);
888 hasState = True;
889 #ifdef VIRTUAL_DESKTOP
890 /* just in case wm_window_type didn't set it already */
891 wwin->client_flags.virtual_stick = 1;
892 #endif
895 } else {
896 /* deleting */
897 area = scr->netdata->strut;
899 if(area) {
900 if(area->window == wwin->client_win) {
901 scr->netdata->strut = area->next;
902 wfree(area);
903 hasState = True;
904 } else {
905 while(area->next && area->next->window != wwin->client_win)
906 area = area->next;
908 if(area->next) {
909 WReservedArea *next;
911 next = area->next->next;
912 wfree(area->next);
913 area->next = next;
915 hasState = True;
921 return hasState;
925 static int
926 getWindowLayer(WWindow * wwin)
928 int layer = WMNormalLevel;
930 if (wwin->type == net_wm_window_type_desktop) {
931 layer = WMDesktopLevel;
932 } else if (wwin->type == net_wm_window_type_dock) {
933 layer = WMDockLevel;
934 } else if (wwin->type == net_wm_window_type_toolbar) {
935 layer = WMMainMenuLevel;
936 } else if (wwin->type == net_wm_window_type_menu) {
937 layer = WMSubmenuLevel;
938 } else if (wwin->type == net_wm_window_type_utility) {
939 } else if (wwin->type == net_wm_window_type_splash) {
940 } else if (wwin->type == net_wm_window_type_dialog) {
941 if (wwin->transient_for) {
942 WWindow *parent = wWindowFor(wwin->transient_for);
943 if (parent && parent->flags.fullscreen) {
944 layer = WMFullscreenLevel;
947 /* //layer = WMPopUpLevel; // this seems a bad idea -Dan */
948 } else if (wwin->type == net_wm_window_type_normal) {
951 if (wwin->client_flags.sunken && WMSunkenLevel < layer)
952 layer = WMSunkenLevel;
953 if (wwin->client_flags.floating && WMFloatingLevel > layer)
954 layer = WMFloatingLevel;
956 return layer;
960 static void
961 doStateAtom(WWindow *wwin, Atom state, int set, Bool init)
964 if (state == net_wm_state_sticky) {
965 if (set == _NET_WM_STATE_TOGGLE) {
966 set = !IS_OMNIPRESENT(wwin);
968 if (set != wwin->flags.omnipresent) {
969 wWindowSetOmnipresent(wwin, set);
971 } else if (state == net_wm_state_shaded) {
972 if (set == _NET_WM_STATE_TOGGLE) {
973 set = !wwin->flags.shaded;
975 if (init) {
976 wwin->flags.shaded = set;
977 } else {
978 if (set) {
979 wShadeWindow(wwin);
980 } else {
981 wUnshadeWindow(wwin);
984 } else if (state == net_wm_state_skip_taskbar) {
985 if (set == _NET_WM_STATE_TOGGLE) {
986 set = !wwin->client_flags.skip_window_list;
988 wwin->client_flags.skip_window_list = set;
989 } else if (state == net_wm_state_skip_pager) {
990 if (set == _NET_WM_STATE_TOGGLE) {
991 set = !wwin->flags.net_skip_pager;
993 wwin->flags.net_skip_pager = set;
994 } else if (state == net_wm_state_maximized_vert) {
995 if (set == _NET_WM_STATE_TOGGLE) {
996 set = !(wwin->flags.maximized & MAX_VERTICAL);
998 if (init) {
999 wwin->flags.maximized = set;
1000 } else {
1001 if (set) {
1002 wMaximizeWindow(wwin, wwin->flags.maximized | MAX_VERTICAL);
1003 } else {
1004 wMaximizeWindow(wwin, wwin->flags.maximized & ~MAX_VERTICAL);
1007 } else if (state == net_wm_state_maximized_horz) {
1008 if (set == _NET_WM_STATE_TOGGLE) {
1009 set = !(wwin->flags.maximized & MAX_HORIZONTAL);
1011 if (init) {
1012 wwin->flags.maximized = set;
1013 } else {
1014 if (set) {
1015 wMaximizeWindow(wwin, wwin->flags.maximized | MAX_HORIZONTAL);
1016 } else {
1017 wMaximizeWindow(wwin, wwin->flags.maximized & ~MAX_HORIZONTAL);
1020 } else if (state == net_wm_state_hidden) {
1021 if (set == _NET_WM_STATE_TOGGLE) {
1022 set = !(wwin->flags.miniaturized);
1024 if (init) {
1025 wwin->flags.miniaturized = set;
1026 } else {
1027 if (set) {
1028 wIconifyWindow(wwin);
1029 } else {
1030 wDeiconifyWindow(wwin);
1033 } else if (state == net_wm_state_fullscreen) {
1034 if (set == _NET_WM_STATE_TOGGLE) {
1035 set = !(wwin->flags.fullscreen);
1037 if (init) {
1038 wwin->flags.fullscreen = set;
1039 } else {
1040 if (set) {
1041 wFullscreenWindow(wwin);
1042 } else {
1043 wUnfullscreenWindow(wwin);
1046 } else if (state == net_wm_state_above) {
1047 if (set == _NET_WM_STATE_TOGGLE) {
1048 set = !(wwin->client_flags.floating);
1050 if (init) {
1051 wwin->client_flags.floating = set;
1052 } else {
1053 wwin->client_flags.floating = set;
1054 ChangeStackingLevel(wwin->frame->core, getWindowLayer(wwin));
1057 } else if (state == net_wm_state_below) {
1058 if (set == _NET_WM_STATE_TOGGLE) {
1059 set = !(wwin->client_flags.sunken);
1061 if (init) {
1062 wwin->client_flags.sunken = set;
1063 } else {
1064 wwin->client_flags.sunken = set;
1065 ChangeStackingLevel(wwin->frame->core, getWindowLayer(wwin));
1068 } else {
1069 #ifdef DEBUG_WMSPEC
1070 printf("doStateAtom unknown atom %s set %d\n", XGetAtomName(dpy, state), set);
1071 #endif
1076 static void
1077 removeIcon( WWindow * wwin)
1079 if (wwin->icon == NULL)
1080 return;
1081 if (wwin->flags.miniaturized && wwin->icon->mapped) {
1082 XUnmapWindow(dpy, wwin->icon->core->window);
1083 RemoveFromStackList(wwin->icon->core);
1084 wIconDestroy(wwin->icon);
1085 wwin->icon = NULL;
1090 static Bool
1091 handleWindowType(WWindow * wwin, Atom type, int *layer)
1093 Bool ret = True;
1095 if (type == net_wm_window_type_desktop) {
1096 wwin->client_flags.no_titlebar = 1;
1097 wwin->client_flags.no_resizable = 1;
1098 wwin->client_flags.no_miniaturizable = 1;
1099 wwin->client_flags.no_border = 1;
1100 wwin->client_flags.no_resizebar = 1;
1101 wwin->client_flags.no_shadeable = 1;
1102 wwin->client_flags.no_movable = 1;
1103 wwin->client_flags.omnipresent = 1;
1104 wwin->client_flags.skip_window_list = 1;
1105 wwin->client_flags.dont_move_off = 1;
1106 wwin->client_flags.no_appicon = 1;
1107 wwin->flags.net_skip_pager = 1;
1108 wwin->frame_x = 0;
1109 wwin->frame_y = 0;
1110 #ifdef VIRTUAL_DESKTOP
1111 wwin->client_flags.virtual_stick = 1;
1112 #endif
1113 } else if (type == net_wm_window_type_dock) {
1114 wwin->client_flags.no_titlebar = 1;
1115 wwin->client_flags.no_resizable = 1;
1116 wwin->client_flags.no_miniaturizable = 1;
1117 wwin->client_flags.no_border = 1; /* XXX: really not a single decoration. */
1118 wwin->client_flags.no_resizebar = 1;
1119 wwin->client_flags.no_shadeable = 1;
1120 wwin->client_flags.no_movable = 1;
1121 wwin->client_flags.omnipresent = 1;
1122 wwin->client_flags.skip_window_list = 1;
1123 wwin->client_flags.dont_move_off = 1;
1124 wwin->flags.net_skip_pager = 1;
1125 #ifdef VIRTUAL_DESKTOP
1126 wwin->client_flags.virtual_stick = 1;
1127 #endif
1128 } else if (type == net_wm_window_type_toolbar) {
1129 wwin->client_flags.no_titlebar = 1;
1130 wwin->client_flags.no_resizable = 1;
1131 wwin->client_flags.no_miniaturizable = 1;
1132 wwin->client_flags.no_resizebar = 1;
1133 wwin->client_flags.no_shadeable = 1;
1134 wwin->client_flags.skip_window_list = 1;
1135 wwin->client_flags.dont_move_off = 1;
1136 wwin->client_flags.no_appicon = 1;
1137 } else if (type == net_wm_window_type_menu) {
1138 wwin->client_flags.no_titlebar = 1;
1139 wwin->client_flags.no_resizable = 1;
1140 wwin->client_flags.no_miniaturizable = 1;
1141 wwin->client_flags.no_resizebar = 1;
1142 wwin->client_flags.no_shadeable = 1;
1143 wwin->client_flags.skip_window_list = 1;
1144 wwin->client_flags.dont_move_off = 1;
1145 wwin->client_flags.no_appicon = 1;
1146 } else if (type == net_wm_window_type_utility) {
1147 wwin->client_flags.no_appicon = 1;
1148 } else if (type == net_wm_window_type_splash) {
1149 wwin->client_flags.no_titlebar = 1;
1150 wwin->client_flags.no_resizable = 1;
1151 wwin->client_flags.no_miniaturizable = 1;
1152 wwin->client_flags.no_resizebar = 1;
1153 wwin->client_flags.no_shadeable = 1;
1154 wwin->client_flags.no_movable = 1;
1155 wwin->client_flags.skip_window_list = 1;
1156 wwin->client_flags.dont_move_off = 1;
1157 wwin->client_flags.no_appicon = 1;
1158 wwin->flags.net_skip_pager = 1;
1159 } else if (type == net_wm_window_type_dialog) {
1160 /* These also seem a bad idea in our context -Dan
1161 // wwin->client_flags.skip_window_list = 1;
1162 // wwin->client_flags.no_appicon = 1;
1164 } else if (type == net_wm_window_type_normal) {
1165 } else {
1166 ret = False;
1169 wwin->type = type;
1170 *layer = getWindowLayer(wwin);
1172 return ret;
1176 void
1177 wNETWMPositionSplash(WWindow *wwin, int *x, int *y, int width, int height)
1179 if (wwin->type == net_wm_window_type_splash) {
1180 WScreen * scr = wwin->screen_ptr;
1181 WMRect rect = wGetRectForHead(scr, wGetHeadForPointerLocation(scr));
1182 *x = rect.pos.x + (rect.size.width - width)/2;
1183 *y = rect.pos.y + (rect.size.height - height)/2;
1188 static void
1189 updateWindowType(WWindow * wwin)
1191 Atom type_ret;
1192 int fmt_ret;
1193 unsigned long nitems_ret;
1194 unsigned long bytes_after_ret;
1195 long *data = 0;
1196 int layer;
1197 if (XGetWindowProperty(dpy, wwin->client_win, net_wm_window_type, 0, 1,
1198 False, XA_ATOM, &type_ret, &fmt_ret, &nitems_ret,
1199 &bytes_after_ret, (unsigned char **)&data)==Success
1200 && data) {
1202 int i;
1203 Atom * type = (Atom *)data;
1204 for (i=0; i<nitems_ret; ++i) {
1205 if (handleWindowType(wwin, type[i], &layer)) break;
1207 XFree(data);
1210 ChangeStackingLevel(wwin->frame->core, layer);
1211 wwin->frame->flags.need_texture_change = 1;
1212 wWindowConfigureBorders(wwin);
1213 wFrameWindowPaint(wwin->frame);
1214 wNETWMUpdateActions(wwin, False);
1218 Bool
1219 wNETWMCheckClientHints(WWindow *wwin, int *layer, int *workspace)
1221 Atom type_ret;
1222 int fmt_ret;
1223 unsigned long nitems_ret;
1224 unsigned long bytes_after_ret;
1225 long *data = 0;
1226 Bool hasState = False;
1227 int i;
1229 if (XGetWindowProperty(dpy, wwin->client_win, net_wm_desktop, 0, 1, False,
1230 XA_CARDINAL, &type_ret, &fmt_ret, &nitems_ret,
1231 &bytes_after_ret,
1232 (unsigned char**)&data)==Success && data) {
1234 long desktop = *data;
1235 XFree(data);
1237 if(desktop == -1)
1238 wwin->client_flags.omnipresent = 1;
1239 else
1240 *workspace = desktop;
1242 hasState = True;
1245 if (XGetWindowProperty(dpy, wwin->client_win, net_wm_state, 0, 1, False,
1246 XA_ATOM, &type_ret, &fmt_ret, &nitems_ret,
1247 &bytes_after_ret,
1248 (unsigned char**)&data)==Success && data) {
1250 Atom * state = (Atom *)data;
1251 for(i=0; i<nitems_ret; ++i) {
1252 doStateAtom(wwin, state[i], _NET_WM_STATE_ADD, True);
1254 XFree(data);
1255 hasState = True;
1258 if (XGetWindowProperty(dpy, wwin->client_win, net_wm_window_type, 0, 1, False,
1259 XA_ATOM, &type_ret, &fmt_ret, &nitems_ret,
1260 &bytes_after_ret,
1261 (unsigned char **)&data) == Success && data) {
1263 Atom * type = (Atom *)data;
1264 for (i=0; i<nitems_ret; ++i) {
1265 if (handleWindowType(wwin, type[i], layer)) break;
1267 XFree(data);
1268 hasState = True;
1271 wNETWMUpdateActions(wwin, False);
1272 updateStrut(wwin, False);
1273 if (updateStrut(wwin, True)) {
1274 hasState = True;
1276 wScreenUpdateUsableArea(wwin->screen_ptr);
1278 return hasState;
1282 static Bool
1283 updateNetIconInfo(WWindow *wwin) {
1285 Atom type_ret;
1286 int fmt_ret;
1287 unsigned long nitems_ret;
1288 unsigned long bytes_after_ret;
1289 long *data = 0;
1290 Bool hasState = False;
1291 Bool old_state = wwin->flags.net_handle_icon;
1293 if (XGetWindowProperty(dpy, wwin->client_win, net_wm_handled_icons, 0, 1, False,
1294 XA_CARDINAL, &type_ret, &fmt_ret, &nitems_ret,
1295 &bytes_after_ret, (unsigned char **)&data) == Success && data) {
1296 long handled = *data;
1297 wwin->flags.net_handle_icon = (handled != 0);
1298 XFree(data);
1299 hasState = True;
1301 } else wwin->flags.net_handle_icon = False;
1303 if ( XGetWindowProperty(dpy, wwin->client_win, net_wm_icon_geometry, 0, 4, False,
1304 XA_CARDINAL, &type_ret, &fmt_ret, &nitems_ret,
1305 &bytes_after_ret, (unsigned char **)&data) == Success && data) {
1307 #ifdef NETWM_PROPER
1308 if (wwin->flags.net_handle_icon)
1309 #else
1310 wwin->flags.net_handle_icon = True;
1311 #endif
1313 wwin->icon_x = data[0];
1314 wwin->icon_y = data[1];
1315 wwin->icon_w = data[2];
1316 wwin->icon_h = data[3];
1319 XFree(data);
1320 hasState = True;
1322 } else wwin->flags.net_handle_icon = False;
1324 if (wwin->flags.miniaturized &&
1325 old_state != wwin->flags.net_handle_icon) {
1326 if (wwin->flags.net_handle_icon) {
1327 removeIcon(wwin);
1328 } else {
1329 wwin->flags.miniaturized = False;
1330 wwin->flags.skip_next_animation = True;
1331 wIconifyWindow(wwin);
1335 return hasState;
1339 Bool
1340 wNETWMCheckInitialClientState(WWindow *wwin)
1342 Bool hasState = False;
1344 #ifdef DEBUG_WMSPEC
1345 printf("CheckInitialClientState\n");
1346 #endif
1348 wNETWMShowingDesktop(wwin->screen_ptr, False);
1350 hasState |= updateNetIconInfo(wwin);
1352 updateIconImage(wwin->screen_ptr, wwin);
1354 return hasState;
1358 static void
1359 handleDesktopNames(XClientMessageEvent *event, WScreen *scr)
1361 unsigned long nitems_ret, bytes_after_ret;
1362 char *data, *names[32];
1363 int fmt_ret, i, n;
1364 Atom type_ret;
1366 if (XGetWindowProperty(dpy, scr->root_win, net_desktop_names, 0, 1, False,
1367 utf8_string, &type_ret, &fmt_ret, &nitems_ret,
1368 &bytes_after_ret,
1369 (unsigned char**)&data)!=Success) {
1370 return;
1373 if (data == 0)
1374 return;
1376 if (type_ret != utf8_string || fmt_ret != 8)
1377 return;
1379 n = 0;
1380 names[n] = data;
1381 for (i = 0; i < nitems_ret; i++) {
1382 if (data[i] == 0) {
1383 n++;
1384 names[n] = &data[i];
1385 } else if (*names[n] == 0) {
1386 names[n] = &data[i];
1387 wWorkspaceRename(scr, n, names[n]);
1393 Bool
1394 wNETWMProcessClientMessage(XClientMessageEvent *event)
1396 WScreen *scr;
1397 WWindow *wwin;
1398 Bool done = True;
1400 #ifdef DEBUG_WMSPEC
1401 printf("processClientMessage type %s\n", XGetAtomName(dpy, event->message_type));
1402 #endif
1404 scr = wScreenForWindow(event->window);
1405 if (scr) {
1406 /* generic client messages */
1407 if (event->message_type == net_current_desktop) {
1408 wWorkspaceChange(scr, event->data.l[0]);
1409 } else if(event->message_type == net_number_of_desktops) {
1410 long value;
1412 value = event->data.l[0];
1413 if(value > scr->workspace_count) {
1414 wWorkspaceMake(scr, value - scr->workspace_count);
1415 } else if(value < scr->workspace_count) {
1416 int i;
1417 Bool rebuild = False;
1419 for (i = scr->workspace_count-1; i >= value; i--) {
1420 if (!wWorkspaceDelete(scr, i)) {
1421 rebuild = True;
1422 break;
1426 if(rebuild) {
1427 updateWorkspaceCount(scr);
1430 } else if (event->message_type == net_showing_desktop) {
1431 wNETWMShowingDesktop(scr, event->data.l[0]);
1432 #ifdef VIRTUAL_DESKTOP
1433 } else if (event->message_type == net_desktop_viewport) {
1434 wWorkspaceSetViewPort(scr, scr->current_workspace,
1435 event->data.l[0], event->data.l[1]);
1436 #endif
1437 } else if (event->message_type == net_desktop_names) {
1438 handleDesktopNames(event, scr);
1439 } else {
1440 done = False;
1443 if (done)
1444 return True;
1447 /* window specific client messages */
1449 wwin = wWindowFor(event->window);
1450 if (!wwin)
1451 return False;
1453 if (event->message_type == net_active_window) {
1454 wNETWMShowingDesktop(scr, False);
1455 wMakeWindowVisible(wwin);
1456 } else if (event->message_type == net_close_window) {
1457 if (!WFLAGP(wwin, no_closable)) {
1458 if (wwin->protocols.DELETE_WINDOW)
1459 wClientSendProtocol(wwin, _XA_WM_DELETE_WINDOW, LastTimestamp);
1461 } else if (event->message_type == net_wm_state) {
1462 int maximized = wwin->flags.maximized;
1463 long set = event->data.l[0];
1465 #ifdef DEBUG_WMSPEC
1466 printf("net_wm_state set %d a1 %s a2 %s\n", set,
1467 XGetAtomName(dpy, event->data.l[1]),
1468 XGetAtomName(dpy, event->data.l[2]));
1469 #endif
1471 doStateAtom(wwin, (Atom)event->data.l[1], set, False);
1472 if(event->data.l[2])
1473 doStateAtom(wwin, (Atom)event->data.l[2], set, False);
1475 if(wwin->flags.maximized != maximized) {
1476 if(!wwin->flags.maximized) {
1477 wwin->flags.maximized = maximized;
1478 wUnmaximizeWindow(wwin);
1479 } else {
1480 wMaximizeWindow(wwin, wwin->flags.maximized);
1483 updateStateHint(wwin, False, False);
1484 } else if (event->message_type == net_wm_handled_icons ||
1485 event->message_type == net_wm_icon_geometry) {
1486 updateNetIconInfo(wwin);
1487 } else if (event->message_type == net_wm_desktop) {
1488 long desktop = event->data.l[0];
1489 if (desktop == -1) {
1490 wWindowSetOmnipresent(wwin, True);
1491 } else {
1492 if (IS_OMNIPRESENT(wwin))
1493 wWindowSetOmnipresent(wwin, False);
1494 wWindowChangeWorkspace(wwin, desktop);
1496 } else if (event->message_type == net_wm_icon) {
1497 updateIconImage(scr, wwin);
1498 } else {
1499 done = False;
1502 return done;
1506 Bool
1507 wNETWMCheckClientHintChange(WWindow *wwin, XPropertyEvent *event)
1509 Bool ret = True;
1511 if(event->atom == net_wm_strut) {
1512 updateStrut(wwin, False);
1513 updateStrut(wwin, True);
1514 wScreenUpdateUsableArea(wwin->screen_ptr);
1515 } else if (event->atom == net_wm_handled_icons ||
1516 event->atom == net_wm_icon_geometry) {
1517 updateNetIconInfo(wwin);
1518 } else if (event->atom == net_wm_window_type) {
1519 updateWindowType(wwin);
1520 } else if (event->atom == net_wm_name) {
1521 char *name= wNETWMGetWindowName(wwin->client_win);
1522 wWindowUpdateName(wwin, name);
1523 if (name) wfree(name);
1524 } else if (event->atom == net_wm_icon_name) {
1525 if (wwin->icon) {
1526 char *name= wNETWMGetIconName(wwin->client_win);
1527 wIconChangeTitle(wwin->icon, name);
1529 } else {
1530 ret = False;
1533 return ret;
1538 wNETWMGetPidForWindow(Window window)
1540 Atom type_ret;
1541 int fmt_ret;
1542 unsigned long nitems_ret;
1543 unsigned long bytes_after_ret;
1544 long *data = 0;
1545 int pid;
1547 if (XGetWindowProperty(dpy, window, net_wm_pid, 0, 1, False,
1548 XA_CARDINAL, &type_ret, &fmt_ret, &nitems_ret,
1549 &bytes_after_ret,
1550 (unsigned char**)&data)==Success && data) {
1552 pid = *data;
1553 XFree(data);
1554 } else {
1555 pid = 0;
1558 return pid;
1562 char*
1563 wNETWMGetWindowName(Window window)
1565 char *name;
1566 char *ret;
1567 int size;
1569 name= (char*)PropGetCheckProperty(window,
1570 net_wm_name, utf8_string, 0,
1571 0, &size);
1572 if (name) {
1573 ret= wstrndup(name, size);
1574 XFree(name);
1576 else
1577 ret= NULL;
1578 return ret;
1582 char*
1583 wNETWMGetIconName(Window window)
1585 char *name;
1586 char *ret;
1587 int size;
1589 name= (char*)PropGetCheckProperty(window,
1590 net_wm_icon_name, utf8_string, 0,
1591 0, &size);
1592 if (name) {
1593 ret= wstrndup(name, size);
1594 XFree(name);
1596 else
1597 ret= NULL;
1598 return ret;
1602 static void
1603 observer(void *self, WMNotification *notif)
1605 WWindow *wwin = (WWindow*)WMGetNotificationObject(notif);
1606 const char *name = WMGetNotificationName(notif);
1607 void *data = WMGetNotificationClientData(notif);
1608 NetData *ndata = (NetData*)self;
1611 if (strcmp(name, WMNManaged) == 0 && wwin) {
1612 updateClientList(wwin->screen_ptr);
1613 updateClientListStacking(wwin->screen_ptr, NULL);
1614 updateStateHint(wwin, True, False);
1616 updateStrut(wwin, False);
1617 updateStrut(wwin, True);
1618 wScreenUpdateUsableArea(wwin->screen_ptr);
1619 } else if (strcmp(name, WMNUnmanaged) == 0 && wwin) {
1620 updateClientList(wwin->screen_ptr);
1621 updateClientListStacking(wwin->screen_ptr, wwin);
1622 updateWorkspaceHint(wwin, False, True);
1623 updateStateHint(wwin, False, True);
1624 wNETWMUpdateActions(wwin, True);
1626 updateStrut(wwin, False);
1627 wScreenUpdateUsableArea(wwin->screen_ptr);
1628 } else if (strcmp(name, WMNResetStacking) == 0 && wwin) {
1629 updateClientListStacking(wwin->screen_ptr, NULL);
1630 updateStateHint(wwin, False, False);
1631 } else if (strcmp(name, WMNChangedStacking) == 0 && wwin) {
1632 updateClientListStacking(wwin->screen_ptr, NULL);
1633 updateStateHint(wwin, False, False);
1634 } else if (strcmp(name, WMNChangedFocus) == 0) {
1635 updateFocusHint(ndata->scr, wwin);
1636 } else if (strcmp(name, WMNChangedWorkspace) == 0 && wwin) {
1637 updateWorkspaceHint(wwin, False, False);
1638 updateStateHint(wwin, True, False);
1639 } else if (strcmp(name, WMNChangedState) == 0 && wwin) {
1640 updateStateHint(wwin, !strcmp(data, "omnipresent"), False);
1645 static void
1646 wsobserver(void *self, WMNotification *notif)
1648 WScreen *scr = (WScreen*)WMGetNotificationObject(notif);
1649 const char *name = WMGetNotificationName(notif);
1651 if (strcmp(name, WMNWorkspaceCreated) == 0) {
1652 updateWorkspaceCount(scr);
1653 updateWorkspaceNames(scr);
1654 } else if (strcmp(name, WMNWorkspaceDestroyed) == 0) {
1655 updateWorkspaceCount(scr);
1656 updateWorkspaceNames(scr);
1657 } else if (strcmp(name, WMNWorkspaceChanged) == 0) {
1658 updateCurrentWorkspace(scr);
1659 } else if (strcmp(name, WMNWorkspaceNameChanged) == 0) {
1660 updateWorkspaceNames(scr);
1664 #endif /* NETWM_HINTS */