- Removed legacy OFFIX_DND support code
[wmaker-crm.git] / src / wmspec.c
blob602b5f98dc2bf67a510b1f5d3e89bf160e75a0fe
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; /* TODO */
78 static Atom net_wm_visible_name; /* TODO */
79 static Atom net_wm_icon_name; /* TODO */
80 static Atom net_wm_visible_icon_name; /* TODO */
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 XChangeProperty(dpy, scr->root_win, net_supported, XA_ATOM, 32,
300 PropModeReplace, (unsigned char*)atom, i);
302 /* set supporting wm hint */
303 XChangeProperty(dpy, scr->root_win, net_supporting_wm_check, XA_WINDOW, 32,
304 PropModeReplace, (unsigned char*)&scr->info_window, 1);
306 XChangeProperty(dpy, scr->info_window, net_supporting_wm_check, XA_WINDOW,
307 32, PropModeReplace, (unsigned char*)&scr->info_window, 1);
311 void
312 wNETWMUpdateDesktop(WScreen *scr)
314 CARD32 *views, sizes[2];
315 int count, i;
317 if (scr->workspace_count==0)
318 return;
320 count = scr->workspace_count * 2;
321 views = wmalloc(sizeof(CARD32) * count);
322 /*memset(views, 0, sizeof(CARD32) * count);*/
324 #ifdef VIRTUAL_DESKTOP
325 sizes[0] = scr->workspaces[scr->current_workspace]->width;
326 sizes[1] = scr->workspaces[scr->current_workspace]->height;
327 #else
328 sizes[0] = scr->scr_width;
329 sizes[1] = scr->scr_height;
330 #endif
332 for (i=0; i<scr->workspace_count; i++) {
333 #ifdef VIRTUAL_DESKTOP
334 views[2*i + 0] = scr->workspaces[i]->view_x;
335 views[2*i + 1] = scr->workspaces[i]->view_y;
336 #else
337 views[2*i + 0] = 0;
338 views[2*i + 1] = 0;
339 #endif
342 XChangeProperty(dpy, scr->root_win, net_desktop_geometry, XA_CARDINAL, 32,
343 PropModeReplace, (unsigned char*)sizes, 2);
345 XChangeProperty(dpy, scr->root_win, net_desktop_viewport, XA_CARDINAL, 32,
346 PropModeReplace, (unsigned char*)views, count);
348 wfree(views);
353 wNETWMGetCurrentDesktopFromHint(WScreen *scr)
355 int count;
356 unsigned char *prop;
358 prop= PropGetCheckProperty(scr->root_win, net_current_desktop, XA_CARDINAL,
359 0, 1, &count);
360 if (prop)
362 int desktop= *(CARD32*)prop;
363 XFree(prop);
364 return desktop;
366 return -1;
370 static void
371 updateIconImage(WScreen *scr, WWindow *wwin)
373 Atom actual_type_return;
374 int actual_format_return;
375 unsigned long nitems_return, bytes_after_return;
376 unsigned char *prop_return;
377 int rc = XGetWindowProperty(dpy, wwin->client_win, net_wm_icon, 0, ~0, False,
378 XA_CARDINAL, &actual_type_return, &actual_format_return,
379 &nitems_return, &bytes_after_return, &prop_return);
381 if (rc==Success && prop_return) {
382 unsigned int *data = (unsigned int *)prop_return;
383 unsigned int pos = 0, len = 0;
384 unsigned int best_pos = 0, best_tmp = ~0;
385 extern WPreferences wPreferences;
386 unsigned int pref_size = wPreferences.icon_size;
387 unsigned int pref_sq = pref_size*pref_size;
388 char *src, *dst;
389 RImage *new_rimage;
391 do {
392 len = data[pos+0]*data[pos+1];
393 unsigned int tmp = pref_sq-len;
394 if (tmp < best_tmp && tmp > 0) {
395 best_tmp = tmp;
396 best_pos = pos;
398 pos += 2+len;
399 } while (pos < nitems_return && len != 0);
401 new_rimage = RCreateImage(data[best_pos+0], data[best_pos+1], True);
402 len = data[best_pos+0] * data[best_pos+1];
403 src = (char*)&data[best_pos+2];
404 dst = new_rimage->data;
405 for (pos=0; pos<len; ++pos, src+=4, dst+=4) {
406 dst[0] = src[2]; /* R */
407 dst[1] = src[1]; /* G */
408 dst[2] = src[0]; /* B */
409 dst[3] = src[3]; /* A */
412 if (new_rimage) {
413 if (wwin->net_icon_image)
414 RReleaseImage(wwin->net_icon_image);
415 wwin->net_icon_image = new_rimage;
418 XFree(prop_return);
423 static void
424 updateShowDesktop(WScreen * scr, Bool show)
426 CARD32 foo;
428 foo = (show == True);
429 XChangeProperty(dpy, scr->root_win, net_showing_desktop, XA_CARDINAL, 32,
430 PropModeReplace, (unsigned char *)&foo, 1);
434 void
435 wNETWMShowingDesktop(WScreen *scr, Bool show)
437 if (show && scr->netdata->show_desktop == NULL) {
438 WWindow *tmp, **wins;
439 int i=0;
441 wins = (WWindow **)wmalloc(sizeof(WWindow *)*(scr->window_count+1));
443 tmp = scr->focused_window;
444 while (tmp) {
445 if (!tmp->flags.hidden && !tmp->flags.miniaturized &&
446 !WFLAGP(tmp, skip_window_list)) {
448 wins[i++] = tmp;
449 tmp->flags.skip_next_animation = 1;
450 tmp->flags.net_show_desktop = 1;
451 wIconifyWindow(tmp);
454 tmp = tmp->prev;
456 wins[i++] = NULL;
458 scr->netdata->show_desktop = wins;
459 updateShowDesktop(scr, True);
460 } else if (scr->netdata->show_desktop != NULL) {
461 /* FIXME: get rid of workspace flashing ! */
462 int ws = scr->current_workspace;
463 WWindow **tmp;
464 for (tmp = scr->netdata->show_desktop; *tmp; ++tmp) {
465 wDeiconifyWindow(*tmp);
466 (*tmp)->flags.net_show_desktop = 0;
468 if (ws != scr->current_workspace)
469 wWorkspaceChange(scr, ws);
470 wfree(scr->netdata->show_desktop);
471 scr->netdata->show_desktop = NULL;
472 updateShowDesktop(scr, False);
477 void
478 wNETWMInitStuff(WScreen *scr)
480 NetData *data;
481 int i;
483 #ifdef DEBUG_WMSPEC
484 printf( "wNETWMInitStuff\n");
485 #endif
487 #ifdef HAVE_XINTERNATOMS
489 Atom atoms[atomNr];
490 char * names[atomNr];
492 for (i = 0; i < atomNr; ++i) {
493 names[i] = atomNames[i].name;
495 XInternAtoms(dpy, &names[0], atomNr, False, atoms);
496 for (i = 0; i < atomNr; ++i) {
497 *atomNames[i].atom = atoms[i];
500 #else
501 for (i = 0; i < atomNr; i++) {
502 *atomNames[i].atom = XInternAtom(dpy, atomNames[i].name, False);
504 #endif
506 data = wmalloc(sizeof(NetData));
507 data->scr = scr;
508 data->strut = NULL;
509 data->show_desktop = NULL;
511 scr->netdata = data;
513 setSupportedHints(scr);
515 WMAddNotificationObserver(observer, data, WMNManaged, NULL);
516 WMAddNotificationObserver(observer, data, WMNUnmanaged, NULL);
517 WMAddNotificationObserver(observer, data, WMNChangedWorkspace, NULL);
518 WMAddNotificationObserver(observer, data, WMNChangedState, NULL);
519 WMAddNotificationObserver(observer, data, WMNChangedFocus, NULL);
520 WMAddNotificationObserver(observer, data, WMNChangedStacking, NULL);
521 WMAddNotificationObserver(observer, data, WMNChangedName, NULL);
523 WMAddNotificationObserver(wsobserver, data, WMNWorkspaceCreated, NULL);
524 WMAddNotificationObserver(wsobserver, data, WMNWorkspaceDestroyed, NULL);
525 WMAddNotificationObserver(wsobserver, data, WMNWorkspaceChanged, NULL);
526 WMAddNotificationObserver(wsobserver, data, WMNWorkspaceNameChanged, NULL);
528 updateClientList(scr);
529 updateClientListStacking(scr, NULL);
530 updateWorkspaceCount(scr);
531 updateWorkspaceNames(scr);
532 updateShowDesktop(scr, False);
534 wScreenUpdateUsableArea(scr);
538 void
539 wNETWMUpdateActions(WWindow *wwin, Bool del)
541 Atom action[10]; /* nr of actions atoms defined */
542 int i = 0;
544 if (del) {
545 XDeleteProperty(dpy, wwin->client_win, net_wm_allowed_actions);
546 return;
549 if (IS_MOVABLE(wwin))
550 action[i++] = net_wm_action_move;
552 if (IS_RESIZABLE(wwin))
553 action[i++] = net_wm_action_resize;
555 if (!WFLAGP(wwin, no_miniaturizable))
556 action[i++] = net_wm_action_minimize;
558 if (!WFLAGP(wwin, no_shadeable))
559 action[i++] = net_wm_action_shade;
561 /* if (!WFLAGP(wwin, no_stickable)) */
562 action[i++] = net_wm_action_stick;
564 /* if (!(WFLAGP(wwin, no_maximizeable) & MAX_HORIZONTAL)) */
565 if (IS_RESIZABLE(wwin))
566 action[i++] = net_wm_action_maximize_horz;
568 /* if (!(WFLAGP(wwin, no_maximizeable) & MAX_VERTICAL)) */
569 if (IS_RESIZABLE(wwin))
570 action[i++] = net_wm_action_maximize_vert;
572 /* if (!WFLAGP(wwin, no_fullscreen)) */
573 action[i++] = net_wm_action_fullscreen;
575 /* if (!WFLAGP(wwin, no_change_desktop)) */
576 action[i++] = net_wm_action_change_desktop;
578 if (!WFLAGP(wwin, no_closable))
579 action[i++] = net_wm_action_close;
581 XChangeProperty(dpy, wwin->client_win, net_wm_allowed_actions,
582 XA_ATOM, 32, PropModeReplace, (unsigned char *)action, i);
586 void
587 wNETWMUpdateWorkarea(WScreen *scr, WArea usableArea)
589 CARD32 *area;
590 int count, i;
592 /* XXX: not Xinerama compatible,
593 xinerama gets the largest available */
595 if(!scr->netdata || scr->workspace_count==0)
596 return;
598 count = scr->workspace_count * 4;
599 area = wmalloc(sizeof(CARD32) * count);
600 for (i=0; i<scr->workspace_count; i++) {
601 area[4*i + 0] = usableArea.x1;
602 area[4*i + 1] = usableArea.y1;
603 area[4*i + 2] = usableArea.x2 - usableArea.x1;
604 area[4*i + 3] = usableArea.y2 - usableArea.y1;
607 XChangeProperty(dpy, scr->root_win, net_workarea, XA_CARDINAL, 32,
608 PropModeReplace, (unsigned char*)area, count);
610 wfree(area);
614 Bool
615 wNETWMGetUsableArea(WScreen *scr, int head, WArea *area)
617 WReservedArea *cur;
618 WMRect rect;
620 if(!scr->netdata || !scr->netdata->strut)
621 return False;
623 area->x1 = area->y1 = area->x2 = area->y2 = 0;
625 for(cur = scr->netdata->strut ; cur ; cur = cur->next) {
626 WWindow * wwin = wWindowFor(cur->window);
627 if (wWindowTouchesHead(wwin, head)) {
628 if(cur->area.x1 > area->x1)
629 area->x1 = cur->area.x1;
630 if(cur->area.y1 > area->y1)
631 area->y1 = cur->area.y1;
632 if(cur->area.x2 > area->x2)
633 area->x2 = cur->area.x2;
634 if(cur->area.y2 > area->y2)
635 area->y2 = cur->area.y2;
639 if (area->x1==0 && area->x2==0 &&
640 area->y1==0 && area->y2==0) return False;
642 rect = wGetRectForHead(scr, head);
644 area->x1 = rect.pos.x + area->x1;
645 area->x2 = rect.pos.x + rect.size.width - area->x2;
646 area->y1 = rect.pos.y + area->y1;
647 area->y2 = rect.pos.y + rect.size.height - area->y2;
649 return True;
653 static void
654 updateClientList(WScreen *scr)
656 WWindow *wwin;
657 Window *windows;
658 int count;
660 windows = (Window *)wmalloc(sizeof(Window)*(scr->window_count+1));
662 count = 0;
663 wwin = scr->focused_window;
664 while (wwin) {
665 windows[count++] = wwin->client_win;
666 wwin = wwin->prev;
668 XChangeProperty(dpy, scr->root_win, net_client_list, XA_WINDOW, 32,
669 PropModeReplace, (unsigned char*)windows, count);
671 wfree(windows);
672 XFlush(dpy);
676 static void
677 updateClientListStacking(WScreen *scr, WWindow *wwin_excl)
679 WWindow *wwin;
680 Window *client_list;
681 Window *client_list_reverse;
682 int client_count;
683 WCoreWindow *tmp;
684 WMBagIterator iter;
685 int i;
687 /* update client list */
688 i = scr->window_count + 1;
689 client_list = (Window*)wmalloc(sizeof(Window) * i);
690 client_list_reverse = (Window*)wmalloc(sizeof(Window) * i);
692 client_count = 0;
693 WM_ETARETI_BAG(scr->stacking_list, tmp, iter) {
694 while (tmp) {
695 wwin = wWindowFor(tmp->window);
696 /* wwin_excl is a window to exclude from the list
697 (e.g. it's now unmanaged) */
698 if(wwin && (wwin != wwin_excl))
699 client_list[client_count++] = wwin->client_win;
700 tmp = tmp->stacking->under;
704 for(i = 0; i < client_count; i++) {
705 Window w = client_list[client_count - i - 1];
706 client_list_reverse[i] = w;
709 XChangeProperty(dpy, scr->root_win, net_client_list_stacking, XA_WINDOW, 32,
710 PropModeReplace, (unsigned char *)client_list_reverse, client_count);
712 wfree(client_list);
713 wfree(client_list_reverse);
715 XFlush(dpy);
719 static void
720 updateWorkspaceCount(WScreen *scr) /* changeable */
722 CARD32 count;
724 count = scr->workspace_count;
726 XChangeProperty(dpy, scr->root_win, net_number_of_desktops, XA_CARDINAL,
727 32, PropModeReplace, (unsigned char*)&count, 1);
731 static void
732 updateCurrentWorkspace(WScreen *scr) /* changeable */
734 CARD32 count;
736 count = scr->current_workspace;
738 XChangeProperty(dpy, scr->root_win, net_current_desktop, XA_CARDINAL, 32,
739 PropModeReplace, (unsigned char*)&count, 1);
743 static void
744 updateWorkspaceNames(WScreen *scr)
746 char buf[1024], *pos;
747 unsigned int i, len, curr_size;
749 pos = buf;
750 len = 0;
751 for(i = 0; i < scr->workspace_count; i++) {
752 curr_size = strlen(scr->workspaces[i]->name);
753 strcpy(pos, scr->workspaces[i]->name);
754 pos += (curr_size+1);
755 len += (curr_size+1);
758 XChangeProperty(dpy, scr->root_win, net_desktop_names, utf8_string, 8,
759 PropModeReplace, (unsigned char *)buf, len);
763 static void
764 updateFocusHint(WScreen *scr, WWindow *wwin) /* changeable */
766 Window window;
768 if (!scr->focused_window || !scr->focused_window->flags.focused)
769 window = None;
770 else
771 window = scr->focused_window->client_win;
773 XChangeProperty(dpy, scr->root_win, net_active_window, XA_WINDOW, 32,
774 PropModeReplace, (unsigned char*)&window, 1);
778 static void
779 updateWorkspaceHint(WWindow *wwin, Bool fake, Bool del)
781 CARD32 l;
783 if (del) {
784 XDeleteProperty(dpy, wwin->client_win, net_wm_desktop);
785 } else {
786 l = ((fake || IS_OMNIPRESENT(wwin)) ? -1 : wwin->frame->workspace);
787 XChangeProperty(dpy, wwin->client_win, net_wm_desktop, XA_CARDINAL,
788 32, PropModeReplace, (unsigned char*)&l, 1);
793 static void
794 updateStateHint(WWindow *wwin, Bool changedWorkspace, Bool del) /* changeable */
796 if (del) {
797 if (!wwin->flags.net_state_from_client) {
798 XDeleteProperty(dpy, wwin->client_win, net_wm_state);
800 } else {
801 Atom state[11]; /* nr of defined state atoms */
802 int i = 0;
804 if(changedWorkspace || (wPreferences.sticky_icons && !IS_OMNIPRESENT(wwin)))
805 updateWorkspaceHint(wwin, False, False);
807 if (IS_OMNIPRESENT(wwin))
808 state[i++] = net_wm_state_sticky;
809 if (wwin->flags.shaded)
810 state[i++] = net_wm_state_shaded;
811 if (wwin->flags.maximized & MAX_HORIZONTAL)
812 state[i++] = net_wm_state_maximized_horz;
813 if (wwin->flags.maximized & MAX_VERTICAL)
814 state[i++] = net_wm_state_maximized_vert;
815 if (WFLAGP(wwin, skip_window_list))
816 state[i++] = net_wm_state_skip_taskbar;
817 if (wwin->flags.net_skip_pager)
818 state[i++] = net_wm_state_skip_pager;
819 if ((wwin->flags.hidden || wwin->flags.miniaturized) && !wwin->flags.net_show_desktop){
820 state[i++] = net_wm_state_hidden;
821 state[i++] = net_wm_state_skip_pager;
823 if (wwin->flags.miniaturized && wPreferences.sticky_icons) {
824 if( !IS_OMNIPRESENT(wwin))
825 updateWorkspaceHint(wwin, True, False);
826 state[i++] = net_wm_state_sticky;
829 if (WFLAGP(wwin, sunken))
830 state[i++] = net_wm_state_below;
831 if (WFLAGP(wwin, floating))
832 state[i++] = net_wm_state_above;
833 if (wwin->flags.fullscreen)
834 state[i++] = net_wm_state_fullscreen;
836 XChangeProperty(dpy, wwin->client_win, net_wm_state, XA_ATOM, 32,
837 PropModeReplace, (unsigned char *)state, i);
842 static Bool
843 updateStrut(WWindow *wwin, Bool adding)
845 WScreen *scr;
846 WReservedArea *area;
847 Bool hasState = False;
849 scr = wwin->screen_ptr;
851 if (adding) {
852 Atom type_ret;
853 int fmt_ret;
854 unsigned long nitems_ret;
855 unsigned long bytes_after_ret;
856 long *data = 0;
858 if (XGetWindowProperty(dpy, wwin->client_win, net_wm_strut, 0, 4, False,
859 XA_CARDINAL, &type_ret, &fmt_ret, &nitems_ret,
860 &bytes_after_ret,
861 (unsigned char**)&data)==Success && data) {
863 area = (WReservedArea *)wmalloc(sizeof(WReservedArea));
864 area->area.x1 = data[0];
865 area->area.x2 = data[1];
866 area->area.y1 = data[2];
867 area->area.y2 = data[3];
869 area->window = wwin->client_win;
871 area->next = scr->netdata->strut;
872 scr->netdata->strut = area;
874 XFree(data);
875 hasState = True;
876 #ifdef VIRTUAL_DESKTOP
877 /* just in case wm_window_type didn't set it already */
878 wwin->client_flags.virtual_stick = 1;
879 #endif
882 } else {
883 /* deleting */
884 area = scr->netdata->strut;
886 if(area) {
887 if(area->window == wwin->client_win) {
888 scr->netdata->strut = area->next;
889 wfree(area);
890 hasState = True;
891 } else {
892 while(area->next && area->next->window != wwin->client_win)
893 area = area->next;
895 if(area->next) {
896 WReservedArea *next;
898 next = area->next->next;
899 wfree(area->next);
900 area->next = next;
902 hasState = True;
908 return hasState;
912 static int
913 getWindowLayer(WWindow * wwin)
915 int layer = WMNormalLevel;
917 if (wwin->type == net_wm_window_type_desktop) {
918 layer = WMDesktopLevel;
919 } else if (wwin->type == net_wm_window_type_dock) {
920 layer = WMDockLevel;
921 } else if (wwin->type == net_wm_window_type_toolbar) {
922 layer = WMMainMenuLevel;
923 } else if (wwin->type == net_wm_window_type_menu) {
924 layer = WMSubmenuLevel;
925 } else if (wwin->type == net_wm_window_type_utility) {
926 } else if (wwin->type == net_wm_window_type_splash) {
927 } else if (wwin->type == net_wm_window_type_dialog) {
928 if (wwin->transient_for) {
929 WWindow *parent = wWindowFor(wwin->transient_for);
930 if (parent && parent->flags.fullscreen) {
931 layer = WMFullscreenLevel;
934 //layer = WMPopUpLevel;
935 } else if (wwin->type == net_wm_window_type_normal) {
938 if (wwin->client_flags.sunken && WMSunkenLevel < layer)
939 layer = WMSunkenLevel;
940 if (wwin->client_flags.floating && WMFloatingLevel > layer)
941 layer = WMFloatingLevel;
943 return layer;
947 static void
948 doStateAtom(WWindow *wwin, Atom state, int set, Bool init)
951 if (state == net_wm_state_sticky) {
952 if (set == _NET_WM_STATE_TOGGLE) {
953 set = !IS_OMNIPRESENT(wwin);
955 if (set != wwin->flags.omnipresent) {
956 wWindowSetOmnipresent(wwin, set);
958 } else if (state == net_wm_state_shaded) {
959 if (set == _NET_WM_STATE_TOGGLE) {
960 set = !wwin->flags.shaded;
962 if (init) {
963 wwin->flags.shaded = set;
964 } else {
965 if (set) {
966 wShadeWindow(wwin);
967 } else {
968 wUnshadeWindow(wwin);
971 } else if (state == net_wm_state_skip_taskbar) {
972 if (set == _NET_WM_STATE_TOGGLE) {
973 set = !wwin->client_flags.skip_window_list;
975 wwin->client_flags.skip_window_list = set;
976 } else if (state == net_wm_state_skip_pager) {
977 if (set == _NET_WM_STATE_TOGGLE) {
978 set = !wwin->flags.net_skip_pager;
980 wwin->flags.net_skip_pager = set;
981 } else if (state == net_wm_state_maximized_vert) {
982 if (set == _NET_WM_STATE_TOGGLE) {
983 set = !(wwin->flags.maximized & MAX_VERTICAL);
985 if (init) {
986 wwin->flags.maximized = set;
987 } else {
988 if (set) {
989 wMaximizeWindow(wwin, wwin->flags.maximized | MAX_VERTICAL);
990 } else {
991 wMaximizeWindow(wwin, wwin->flags.maximized & ~MAX_VERTICAL);
994 } else if (state == net_wm_state_maximized_horz) {
995 if (set == _NET_WM_STATE_TOGGLE) {
996 set = !(wwin->flags.maximized & MAX_HORIZONTAL);
998 if (init) {
999 wwin->flags.maximized = set;
1000 } else {
1001 if (set) {
1002 wMaximizeWindow(wwin, wwin->flags.maximized | MAX_HORIZONTAL);
1003 } else {
1004 wMaximizeWindow(wwin, wwin->flags.maximized & ~MAX_HORIZONTAL);
1007 } else if (state == net_wm_state_hidden) {
1008 if (set == _NET_WM_STATE_TOGGLE) {
1009 set = !(wwin->flags.miniaturized);
1011 if (init) {
1012 wwin->flags.miniaturized = set;
1013 } else {
1014 if (set) {
1015 wIconifyWindow(wwin);
1016 } else {
1017 wDeiconifyWindow(wwin);
1020 } else if (state == net_wm_state_fullscreen) {
1021 if (set == _NET_WM_STATE_TOGGLE) {
1022 set = !(wwin->flags.fullscreen);
1024 if (init) {
1025 wwin->flags.fullscreen = set;
1026 } else {
1027 if (set) {
1028 wFullscreenWindow(wwin);
1029 } else {
1030 wUnfullscreenWindow(wwin);
1033 } else if (state == net_wm_state_above) {
1034 if (set == _NET_WM_STATE_TOGGLE) {
1035 set = !(wwin->client_flags.floating);
1037 if (init) {
1038 wwin->client_flags.floating = set;
1039 } else {
1040 wwin->client_flags.floating = set;
1041 ChangeStackingLevel(wwin->frame->core, getWindowLayer(wwin));
1044 } else if (state == net_wm_state_below) {
1045 if (set == _NET_WM_STATE_TOGGLE) {
1046 set = !(wwin->client_flags.sunken);
1048 if (init) {
1049 wwin->client_flags.sunken = set;
1050 } else {
1051 wwin->client_flags.sunken = set;
1052 ChangeStackingLevel(wwin->frame->core, getWindowLayer(wwin));
1055 } else {
1056 #ifdef DEBUG_WMSPEC
1057 printf("doStateAtom unknown atom %s set %d\n", XGetAtomName(dpy, state), set);
1058 #endif
1063 static void
1064 removeIcon( WWindow * wwin)
1066 if (wwin->icon == NULL)
1067 return;
1068 if (wwin->flags.miniaturized && wwin->icon->mapped) {
1069 XUnmapWindow(dpy, wwin->icon->core->window);
1070 RemoveFromStackList(wwin->icon->core);
1071 wIconDestroy(wwin->icon);
1072 wwin->icon = NULL;
1077 static Bool
1078 handleWindowType(WWindow * wwin, Atom type, int *layer)
1080 Bool ret = True;
1082 if (type == net_wm_window_type_desktop) {
1083 wwin->client_flags.no_titlebar = 1;
1084 wwin->client_flags.no_resizable = 1;
1085 wwin->client_flags.no_miniaturizable = 1;
1086 wwin->client_flags.no_border = 1;
1087 wwin->client_flags.no_resizebar = 1;
1088 wwin->client_flags.no_shadeable = 1;
1089 wwin->client_flags.no_movable = 1;
1090 wwin->client_flags.omnipresent = 1;
1091 wwin->client_flags.skip_window_list = 1;
1092 wwin->client_flags.dont_move_off = 1;
1093 wwin->client_flags.no_appicon = 1;
1094 wwin->flags.net_skip_pager = 1;
1095 wwin->frame_x = 0;
1096 wwin->frame_y = 0;
1097 #ifdef VIRTUAL_DESKTOP
1098 wwin->client_flags.virtual_stick = 1;
1099 #endif
1100 } else if (type == net_wm_window_type_dock) {
1101 wwin->client_flags.no_titlebar = 1;
1102 wwin->client_flags.no_resizable = 1;
1103 wwin->client_flags.no_miniaturizable = 1;
1104 wwin->client_flags.no_border = 1; /* XXX: really not a single decoration. */
1105 wwin->client_flags.no_resizebar = 1;
1106 wwin->client_flags.no_shadeable = 1;
1107 wwin->client_flags.no_movable = 1;
1108 wwin->client_flags.omnipresent = 1;
1109 wwin->client_flags.skip_window_list = 1;
1110 wwin->client_flags.dont_move_off = 1;
1111 wwin->flags.net_skip_pager = 1;
1112 #ifdef VIRTUAL_DESKTOP
1113 wwin->client_flags.virtual_stick = 1;
1114 #endif
1115 } else if (type == net_wm_window_type_toolbar) {
1116 wwin->client_flags.no_titlebar = 1;
1117 wwin->client_flags.no_resizable = 1;
1118 wwin->client_flags.no_miniaturizable = 1;
1119 wwin->client_flags.no_resizebar = 1;
1120 wwin->client_flags.no_shadeable = 1;
1121 wwin->client_flags.skip_window_list = 1;
1122 wwin->client_flags.dont_move_off = 1;
1123 wwin->client_flags.no_appicon = 1;
1124 } else if (type == net_wm_window_type_menu) {
1125 wwin->client_flags.no_titlebar = 1;
1126 wwin->client_flags.no_resizable = 1;
1127 wwin->client_flags.no_miniaturizable = 1;
1128 wwin->client_flags.no_resizebar = 1;
1129 wwin->client_flags.no_shadeable = 1;
1130 wwin->client_flags.skip_window_list = 1;
1131 wwin->client_flags.dont_move_off = 1;
1132 wwin->client_flags.no_appicon = 1;
1133 } else if (type == net_wm_window_type_utility) {
1134 wwin->client_flags.no_appicon = 1;
1135 } else if (type == net_wm_window_type_splash) {
1136 wwin->client_flags.no_titlebar = 1;
1137 wwin->client_flags.no_resizable = 1;
1138 wwin->client_flags.no_miniaturizable = 1;
1139 wwin->client_flags.no_resizebar = 1;
1140 wwin->client_flags.no_shadeable = 1;
1141 wwin->client_flags.no_movable = 1;
1142 wwin->client_flags.skip_window_list = 1;
1143 wwin->client_flags.dont_move_off = 1;
1144 wwin->client_flags.no_appicon = 1;
1145 wwin->flags.net_skip_pager = 1;
1146 } else if (type == net_wm_window_type_dialog) {
1147 // wwin->client_flags.skip_window_list = 1;
1148 // wwin->client_flags.no_appicon = 1;
1149 } else if (type == net_wm_window_type_normal) {
1150 } else {
1151 ret = False;
1154 wwin->type = type;
1155 *layer = getWindowLayer(wwin);
1157 return ret;
1161 void
1162 wNETWMPositionSplash(WWindow *wwin, int *x, int *y, int width, int height)
1164 if (wwin->type == net_wm_window_type_splash) {
1165 WScreen * scr = wwin->screen_ptr;
1166 WMRect rect = wGetRectForHead(scr, wGetHeadForPointerLocation(scr));
1167 *x = rect.pos.x + (rect.size.width - width)/2;
1168 *y = rect.pos.y + (rect.size.height - height)/2;
1173 static void
1174 updateWindowType(WWindow * wwin)
1176 Atom type_ret;
1177 int fmt_ret;
1178 unsigned long nitems_ret;
1179 unsigned long bytes_after_ret;
1180 long *data = 0;
1181 int layer;
1182 if (XGetWindowProperty(dpy, wwin->client_win, net_wm_window_type, 0, 1,
1183 False, XA_ATOM, &type_ret, &fmt_ret, &nitems_ret,
1184 &bytes_after_ret, (unsigned char **)&data)==Success
1185 && data) {
1187 int i;
1188 Atom * type = (Atom *)data;
1189 for (i=0; i<nitems_ret; ++i) {
1190 if (handleWindowType(wwin, type[i], &layer)) break;
1192 XFree(data);
1195 ChangeStackingLevel(wwin->frame->core, layer);
1196 wwin->frame->flags.need_texture_change = 1;
1197 wWindowConfigureBorders(wwin);
1198 wFrameWindowPaint(wwin->frame);
1199 wNETWMUpdateActions(wwin, False);
1203 Bool
1204 wNETWMCheckClientHints(WWindow *wwin, int *layer, int *workspace)
1206 Atom type_ret;
1207 int fmt_ret;
1208 unsigned long nitems_ret;
1209 unsigned long bytes_after_ret;
1210 long *data = 0;
1211 Bool hasState = False;
1212 int i;
1214 if (XGetWindowProperty(dpy, wwin->client_win, net_wm_desktop, 0, 1, False,
1215 XA_CARDINAL, &type_ret, &fmt_ret, &nitems_ret,
1216 &bytes_after_ret,
1217 (unsigned char**)&data)==Success && data) {
1219 long desktop = *data;
1220 XFree(data);
1222 if(desktop == -1)
1223 wwin->client_flags.omnipresent = 1;
1224 else
1225 *workspace = desktop;
1227 hasState = True;
1230 if (XGetWindowProperty(dpy, wwin->client_win, net_wm_state, 0, 1, False,
1231 XA_ATOM, &type_ret, &fmt_ret, &nitems_ret,
1232 &bytes_after_ret,
1233 (unsigned char**)&data)==Success && data) {
1235 Atom * state = (Atom *)data;
1236 for(i=0; i<nitems_ret; ++i) {
1237 doStateAtom(wwin, state[i], _NET_WM_STATE_ADD, True);
1239 XFree(data);
1240 hasState = True;
1243 if (XGetWindowProperty(dpy, wwin->client_win, net_wm_window_type, 0, 1, False,
1244 XA_ATOM, &type_ret, &fmt_ret, &nitems_ret,
1245 &bytes_after_ret,
1246 (unsigned char **)&data) == Success && data) {
1248 Atom * type = (Atom *)data;
1249 for (i=0; i<nitems_ret; ++i) {
1250 if (handleWindowType(wwin, type[i], layer)) break;
1252 XFree(data);
1253 hasState = True;
1256 wNETWMUpdateActions(wwin, False);
1257 updateStrut(wwin, False);
1258 if (updateStrut(wwin, True)) {
1259 hasState = True;
1261 wScreenUpdateUsableArea(wwin->screen_ptr);
1263 return hasState;
1267 static Bool
1268 updateNetIconInfo(WWindow *wwin) {
1270 Atom type_ret;
1271 int fmt_ret;
1272 unsigned long nitems_ret;
1273 unsigned long bytes_after_ret;
1274 long *data = 0;
1275 Bool hasState = False;
1276 Bool old_state = wwin->flags.net_handle_icon;
1278 if (XGetWindowProperty(dpy, wwin->client_win, net_wm_handled_icons, 0, 1, False,
1279 XA_CARDINAL, &type_ret, &fmt_ret, &nitems_ret,
1280 &bytes_after_ret, (unsigned char **)&data) == Success && data) {
1281 long handled = *data;
1282 wwin->flags.net_handle_icon = (handled != 0);
1283 XFree(data);
1284 hasState = True;
1286 } else wwin->flags.net_handle_icon = False;
1288 if ( XGetWindowProperty(dpy, wwin->client_win, net_wm_icon_geometry, 0, 4, False,
1289 XA_CARDINAL, &type_ret, &fmt_ret, &nitems_ret,
1290 &bytes_after_ret, (unsigned char **)&data) == Success && data) {
1292 #ifdef NETWM_PROPER
1293 if (wwin->flags.net_handle_icon)
1294 #else
1295 wwin->flags.net_handle_icon = True;
1296 #endif
1298 wwin->icon_x = data[0];
1299 wwin->icon_y = data[1];
1300 wwin->icon_w = data[2];
1301 wwin->icon_h = data[3];
1304 XFree(data);
1305 hasState = True;
1307 } else wwin->flags.net_handle_icon = False;
1309 if (wwin->flags.miniaturized &&
1310 old_state != wwin->flags.net_handle_icon) {
1311 if (wwin->flags.net_handle_icon) {
1312 removeIcon(wwin);
1313 } else {
1314 wwin->flags.miniaturized = False;
1315 wwin->flags.skip_next_animation = True;
1316 wIconifyWindow(wwin);
1320 return hasState;
1324 Bool
1325 wNETWMCheckInitialClientState(WWindow *wwin)
1327 Bool hasState = False;
1329 #ifdef DEBUG_WMSPEC
1330 printf("CheckInitialClientState\n");
1331 #endif
1333 wNETWMShowingDesktop(wwin->screen_ptr, False);
1335 hasState |= updateNetIconInfo(wwin);
1337 updateIconImage(wwin->screen_ptr, wwin);
1339 return hasState;
1343 static void
1344 handleDesktopNames(XClientMessageEvent *event, WScreen *scr)
1346 unsigned long nitems_ret, bytes_after_ret;
1347 char *data, *names[32];
1348 int fmt_ret, i, n;
1349 Atom type_ret;
1351 if (XGetWindowProperty(dpy, scr->root_win, net_desktop_names, 0, 1, False,
1352 utf8_string, &type_ret, &fmt_ret, &nitems_ret,
1353 &bytes_after_ret,
1354 (unsigned char**)&data)!=Success) {
1355 return;
1358 if (data == 0)
1359 return;
1361 if (type_ret != utf8_string || fmt_ret != 8)
1362 return;
1364 n = 0;
1365 names[n] = data;
1366 for (i = 0; i < nitems_ret; i++) {
1367 if (data[i] == 0) {
1368 n++;
1369 names[n] = &data[i];
1370 } else if (*names[n] == 0) {
1371 names[n] = &data[i];
1372 wWorkspaceRename(scr, n, names[n]);
1378 Bool
1379 wNETWMProcessClientMessage(XClientMessageEvent *event)
1381 WScreen *scr;
1382 WWindow *wwin;
1383 Bool done = True;
1385 #ifdef DEBUG_WMSPEC
1386 printf("processClientMessage type %s\n", XGetAtomName(dpy, event->message_type));
1387 #endif
1389 scr = wScreenForWindow(event->window);
1390 if (scr) {
1391 /* generic client messages */
1392 if (event->message_type == net_current_desktop) {
1393 wWorkspaceChange(scr, event->data.l[0]);
1394 } else if(event->message_type == net_number_of_desktops) {
1395 long value;
1397 value = event->data.l[0];
1398 if(value > scr->workspace_count) {
1399 wWorkspaceMake(scr, value - scr->workspace_count);
1400 } else if(value < scr->workspace_count) {
1401 int i;
1402 Bool rebuild = False;
1404 for (i = scr->workspace_count-1; i >= value; i--) {
1405 if (!wWorkspaceDelete(scr, i)) {
1406 rebuild = True;
1407 break;
1411 if(rebuild) {
1412 updateWorkspaceCount(scr);
1415 } else if (event->message_type == net_showing_desktop) {
1416 wNETWMShowingDesktop(scr, event->data.l[0]);
1417 #ifdef VIRTUAL_DESKTOP
1418 } else if (event->message_type == net_desktop_viewport) {
1419 wWorkspaceSetViewPort(scr, scr->current_workspace,
1420 event->data.l[0], event->data.l[1]);
1421 #endif
1422 } else if (event->message_type == net_desktop_names) {
1423 handleDesktopNames(event, scr);
1424 } else {
1425 done = False;
1428 if (done)
1429 return True;
1432 /* window specific client messages */
1434 wwin = wWindowFor(event->window);
1435 if (!wwin)
1436 return False;
1438 if (event->message_type == net_active_window) {
1439 wNETWMShowingDesktop(scr, False);
1440 wMakeWindowVisible(wwin);
1441 } else if (event->message_type == net_close_window) {
1442 if (!WFLAGP(wwin, no_closable)) {
1443 if (wwin->protocols.DELETE_WINDOW)
1444 wClientSendProtocol(wwin, _XA_WM_DELETE_WINDOW, LastTimestamp);
1446 } else if (event->message_type == net_wm_state) {
1447 int maximized = wwin->flags.maximized;
1448 long set = event->data.l[0];
1450 #ifdef DEBUG_WMSPEC
1451 printf("net_wm_state set %d a1 %s a2 %s\n", set,
1452 XGetAtomName(dpy, event->data.l[1]),
1453 XGetAtomName(dpy, event->data.l[2]));
1454 #endif
1456 doStateAtom(wwin, (Atom)event->data.l[1], set, False);
1457 if(event->data.l[2])
1458 doStateAtom(wwin, (Atom)event->data.l[2], set, False);
1460 if(wwin->flags.maximized != maximized) {
1461 if(!wwin->flags.maximized) {
1462 wwin->flags.maximized = maximized;
1463 wUnmaximizeWindow(wwin);
1464 } else {
1465 wMaximizeWindow(wwin, wwin->flags.maximized);
1468 updateStateHint(wwin, False, False);
1469 } else if (event->message_type == net_wm_handled_icons ||
1470 event->message_type == net_wm_icon_geometry) {
1471 updateNetIconInfo(wwin);
1472 } else if (event->message_type == net_wm_desktop) {
1473 long desktop = event->data.l[0];
1474 if (desktop == -1) {
1475 wWindowSetOmnipresent(wwin, True);
1476 } else {
1477 if (IS_OMNIPRESENT(wwin))
1478 wWindowSetOmnipresent(wwin, False);
1479 wWindowChangeWorkspace(wwin, desktop);
1481 } else if (event->message_type == net_wm_icon) {
1482 updateIconImage(scr, wwin);
1483 } else {
1484 done = False;
1487 return done;
1491 Bool
1492 wNETWMCheckClientHintChange(WWindow *wwin, XPropertyEvent *event)
1494 Bool ret = True;
1496 if(event->atom == net_wm_strut) {
1497 updateStrut(wwin, False);
1498 updateStrut(wwin, True);
1499 wScreenUpdateUsableArea(wwin->screen_ptr);
1500 } else if (event->atom == net_wm_handled_icons ||
1501 event->atom == net_wm_icon_geometry) {
1502 updateNetIconInfo(wwin);
1503 } else if (event->atom == net_wm_window_type) {
1504 updateWindowType(wwin);
1505 } else {
1506 ret = False;
1509 return ret;
1514 wNETWMGetPidForWindow(Window window)
1516 Atom type_ret;
1517 int fmt_ret;
1518 unsigned long nitems_ret;
1519 unsigned long bytes_after_ret;
1520 long *data = 0;
1521 int pid;
1523 if (XGetWindowProperty(dpy, window, net_wm_pid, 0, 1, False,
1524 XA_CARDINAL, &type_ret, &fmt_ret, &nitems_ret,
1525 &bytes_after_ret,
1526 (unsigned char**)&data)==Success && data) {
1528 pid = *data;
1529 XFree(data);
1530 } else {
1531 pid = 0;
1534 return pid;
1538 static void
1539 observer(void *self, WMNotification *notif)
1541 WWindow *wwin = (WWindow*)WMGetNotificationObject(notif);
1542 const char *name = WMGetNotificationName(notif);
1543 void *data = WMGetNotificationClientData(notif);
1544 NetData *ndata = (NetData*)self;
1547 if (strcmp(name, WMNManaged) == 0 && wwin) {
1548 updateClientList(wwin->screen_ptr);
1549 updateClientListStacking(wwin->screen_ptr, NULL);
1550 updateStateHint(wwin, True, False);
1552 updateStrut(wwin, False);
1553 updateStrut(wwin, True);
1554 wScreenUpdateUsableArea(wwin->screen_ptr);
1555 } else if (strcmp(name, WMNUnmanaged) == 0 && wwin) {
1556 updateClientList(wwin->screen_ptr);
1557 updateClientListStacking(wwin->screen_ptr, wwin);
1558 updateWorkspaceHint(wwin, False, True);
1559 updateStateHint(wwin, False, True);
1560 wNETWMUpdateActions(wwin, True);
1562 updateStrut(wwin, False);
1563 wScreenUpdateUsableArea(wwin->screen_ptr);
1564 } else if (strcmp(name, WMNResetStacking) == 0 && wwin) {
1565 updateClientListStacking(wwin->screen_ptr, NULL);
1566 updateStateHint(wwin, False, False);
1567 } else if (strcmp(name, WMNChangedStacking) == 0 && wwin) {
1568 updateClientListStacking(wwin->screen_ptr, NULL);
1569 updateStateHint(wwin, False, False);
1570 } else if (strcmp(name, WMNChangedFocus) == 0) {
1571 updateFocusHint(ndata->scr, wwin);
1572 } else if (strcmp(name, WMNChangedWorkspace) == 0 && wwin) {
1573 updateWorkspaceHint(wwin, False, False);
1574 updateStateHint(wwin, True, False);
1575 } else if (strcmp(name, WMNChangedState) == 0 && wwin) {
1576 updateStateHint(wwin, !strcmp(data, "omnipresent"), False);
1581 static void
1582 wsobserver(void *self, WMNotification *notif)
1584 WScreen *scr = (WScreen*)WMGetNotificationObject(notif);
1585 const char *name = WMGetNotificationName(notif);
1586 //void *data = WMGetNotificationClientData(notif);
1588 if (strcmp(name, WMNWorkspaceCreated) == 0) {
1589 updateWorkspaceCount(scr);
1590 updateWorkspaceNames(scr);
1591 } else if (strcmp(name, WMNWorkspaceDestroyed) == 0) {
1592 updateWorkspaceCount(scr);
1593 updateWorkspaceNames(scr);
1594 } else if (strcmp(name, WMNWorkspaceChanged) == 0) {
1595 updateCurrentWorkspace(scr);
1596 } else if (strcmp(name, WMNWorkspaceNameChanged) == 0) {
1597 updateWorkspaceNames(scr);
1601 #endif /* NETWM_HINTS */