- Check whether libXft is at least version 2.1.2 else refuse to compile.
[wmaker-crm.git] / src / wmspec.c
bloba96231ae8cd3003faeabfe1abcdb8e8eb6a34883
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"
45 #ifdef DEBUG_WMSPEC
46 #include <stdio.h>
47 #endif
49 /* Global variables */
50 extern Atom _XA_WM_DELETE_WINDOW;
51 extern Time LastTimestamp;
52 extern WPreferences wPreferences;
54 /* Root Window Properties */
55 static Atom net_supported;
56 static Atom net_client_list;
57 static Atom net_client_list_stacking;
58 static Atom net_number_of_desktops;
59 static Atom net_desktop_geometry;
60 static Atom net_desktop_viewport;
61 static Atom net_current_desktop;
62 static Atom net_desktop_names;
63 static Atom net_active_window;
64 static Atom net_workarea; /* XXX: not xinerama compatible */
65 static Atom net_supporting_wm_check;
66 static Atom net_virtual_roots; /* N/A */
67 static Atom net_desktop_layout; /* XXX */
68 static Atom net_showing_desktop;
70 /* Other Root Window Messages */
71 static Atom net_close_window;
72 static Atom net_moveresize_window; /* TODO */
73 static Atom net_wm_moveresize; /* TODO */
75 /* Application Window Properties */
76 static Atom net_wm_name; /* TODO */
77 static Atom net_wm_visible_name; /* TODO */
78 static Atom net_wm_icon_name; /* TODO */
79 static Atom net_wm_visible_icon_name; /* TODO */
80 static Atom net_wm_desktop;
81 static Atom net_wm_window_type;
82 static Atom net_wm_window_type_desktop;
83 static Atom net_wm_window_type_dock;
84 static Atom net_wm_window_type_toolbar;
85 static Atom net_wm_window_type_menu;
86 static Atom net_wm_window_type_utility;
87 static Atom net_wm_window_type_splash;
88 static Atom net_wm_window_type_dialog;
89 static Atom net_wm_window_type_normal;
90 static Atom net_wm_state;
91 static Atom net_wm_state_modal; /* XXX: what is this?!? */
92 static Atom net_wm_state_sticky;
93 static Atom net_wm_state_maximized_vert;
94 static Atom net_wm_state_maximized_horz;
95 static Atom net_wm_state_shaded;
96 static Atom net_wm_state_skip_taskbar;
97 static Atom net_wm_state_skip_pager;
98 static Atom net_wm_state_hidden;
99 static Atom net_wm_state_fullscreen;
100 static Atom net_wm_state_above;
101 static Atom net_wm_state_below;
102 static Atom net_wm_allowed_actions;
103 static Atom net_wm_action_move;
104 static Atom net_wm_action_resize;
105 static Atom net_wm_action_minimize;
106 static Atom net_wm_action_shade;
107 static Atom net_wm_action_stick;
108 static Atom net_wm_action_maximize_horz;
109 static Atom net_wm_action_maximize_vert;
110 static Atom net_wm_action_fullscreen;
111 static Atom net_wm_action_change_desktop;
112 static Atom net_wm_action_close;
113 static Atom net_wm_strut; /* XXX: see net_workarea */
114 static Atom net_wm_strut_partial; /* TODO: doesn't really fit into the current strut scheme */
115 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. */
116 static Atom net_wm_icon;
117 static Atom net_wm_pid; /* TODO */
118 static Atom net_wm_handled_icons; /* FIXME: see net_wm_icon_geometry */
120 /* Window Manager Protocols */
121 static Atom net_wm_ping; /* TODO */
123 static Atom utf8_string;
125 typedef struct {
126 char * name;
127 Atom * atom;
128 } atomitem_t;
130 static atomitem_t atomNames[] = {
131 { "_NET_SUPPORTED", &net_supported },
132 { "_NET_CLIENT_LIST", &net_client_list },
133 { "_NET_CLIENT_LIST_STACKING", &net_client_list_stacking },
134 { "_NET_NUMBER_OF_DESKTOPS", &net_number_of_desktops },
135 { "_NET_DESKTOP_GEOMETRY", &net_desktop_geometry },
136 { "_NET_DESKTOP_VIEWPORT", &net_desktop_viewport },
137 { "_NET_CURRENT_DESKTOP", &net_current_desktop },
138 { "_NET_DESKTOP_NAMES", &net_desktop_names },
139 { "_NET_ACTIVE_WINDOW", &net_active_window },
140 { "_NET_WORKAREA", &net_workarea },
141 { "_NET_SUPPORTING_WM_CHECK", &net_supporting_wm_check },
142 { "_NET_VIRTUAL_ROOTS", &net_virtual_roots },
143 { "_NET_DESKTOP_LAYOUT", &net_desktop_layout },
144 { "_NET_SHOWING_DESKTOP", &net_showing_desktop },
146 { "_NET_CLOSE_WINDOW", &net_close_window },
147 { "_NET_MOVERESIZE_WINDOW", &net_moveresize_window },
148 { "_NET_WM_MOVERESIZE", &net_wm_moveresize },
150 { "_NET_WM_NAME", &net_wm_name },
151 { "_NET_WM_VISIBLE_NAME", &net_wm_visible_name },
152 { "_NET_WM_ICON_NAME", &net_wm_icon_name },
153 { "_NET_WM_VISIBLE_ICON_NAME", &net_wm_visible_icon_name },
154 { "_NET_WM_DESKTOP", &net_wm_desktop },
155 { "_NET_WM_WINDOW_TYPE", &net_wm_window_type },
156 { "_NET_WM_WINDOW_TYPE_DESKTOP", &net_wm_window_type_desktop },
157 { "_NET_WM_WINDOW_TYPE_DOCK", &net_wm_window_type_dock },
158 { "_NET_WM_WINDOW_TYPE_TOOLBAR", &net_wm_window_type_toolbar },
159 { "_NET_WM_WINDOW_TYPE_MENU", &net_wm_window_type_menu },
160 { "_NET_WM_WINDOW_TYPE_UTILITY", &net_wm_window_type_utility },
161 { "_NET_WM_WINDOW_TYPE_SPLASH", &net_wm_window_type_splash },
162 { "_NET_WM_WINDOW_TYPE_DIALOG", &net_wm_window_type_dialog },
163 { "_NET_WM_WINDOW_TYPE_NORMAL", &net_wm_window_type_normal },
164 { "_NET_WM_STATE", &net_wm_state },
165 { "_NET_WM_STATE_MODAL", &net_wm_state_modal },
166 { "_NET_WM_STATE_STICKY", &net_wm_state_sticky },
167 { "_NET_WM_STATE_MAXIMIZED_VERT", &net_wm_state_maximized_vert },
168 { "_NET_WM_STATE_MAXIMIZED_HORZ", &net_wm_state_maximized_horz },
169 { "_NET_WM_STATE_SHADED", &net_wm_state_shaded },
170 { "_NET_WM_STATE_SKIP_TASKBAR", &net_wm_state_skip_taskbar },
171 { "_NET_WM_STATE_SKIP_PAGER", &net_wm_state_skip_pager },
172 { "_NET_WM_STATE_HIDDEN", &net_wm_state_hidden },
173 { "_NET_WM_STATE_FULLSCREEN", &net_wm_state_fullscreen },
174 { "_NET_WM_STATE_ABOVE", &net_wm_state_above },
175 { "_NET_WM_STATE_BELOW", &net_wm_state_below },
176 { "_NET_WM_ALLOWED_ACTIONS", &net_wm_allowed_actions },
177 { "_NET_WM_ACTION_MOVE", &net_wm_action_move },
178 { "_NET_WM_ACTION_RESIZE", &net_wm_action_resize },
179 { "_NET_WM_ACTION_MINIMIZE", &net_wm_action_minimize },
180 { "_NET_WM_ACTION_SHADE", &net_wm_action_shade },
181 { "_NET_WM_ACTION_STICK", &net_wm_action_stick },
182 { "_NET_WM_ACTION_MAXIMIZE_HORZ", &net_wm_action_maximize_horz },
183 { "_NET_WM_ACTION_MAXIMIZE_VERT", &net_wm_action_maximize_vert },
184 { "_NET_WM_ACTION_FULLSCREEN", &net_wm_action_fullscreen },
185 { "_NET_WM_ACTION_CHANGE_DESKTOP", &net_wm_action_change_desktop },
186 { "_NET_WM_ACTION_CLOSE", &net_wm_action_close },
187 { "_NET_WM_STRUT", &net_wm_strut },
188 { "_NET_WM_STRUT_PARTIAL", &net_wm_strut_partial },
189 { "_NET_WM_ICON_GEOMETRY", &net_wm_icon_geometry },
190 { "_NET_WM_ICON", &net_wm_icon },
191 { "_NET_WM_PID", &net_wm_pid },
192 { "_NET_WM_HANDLED_ICONS", &net_wm_handled_icons },
194 { "_NET_WM_PING", &net_wm_ping },
196 { "UTF8_STRING", &utf8_string },
199 #define atomNr (sizeof(atomNames)/sizeof(atomitem_t))
201 #define _NET_WM_STATE_REMOVE 0
202 #define _NET_WM_STATE_ADD 1
203 #define _NET_WM_STATE_TOGGLE 2
205 #define _NET_WM_MOVERESIZE_SIZE_TOPLEFT 0
206 #define _NET_WM_MOVERESIZE_SIZE_TOP 1
207 #define _NET_WM_MOVERESIZE_SIZE_TOPRIGHT 2
208 #define _NET_WM_MOVERESIZE_SIZE_RIGHT 3
209 #define _NET_WM_MOVERESIZE_SIZE_BOTTOMRIGHT 4
210 #define _NET_WM_MOVERESIZE_SIZE_BOTTOM 5
211 #define _NET_WM_MOVERESIZE_SIZE_BOTTOMLEFT 6
212 #define _NET_WM_MOVERESIZE_SIZE_LEFT 7
213 #define _NET_WM_MOVERESIZE_MOVE 8 /* movement only */
214 #define _NET_WM_MOVERESIZE_SIZE_KEYBOARD 9 /* size via keyboard */
215 #define _NET_WM_MOVERESIZE_MOVE_KEYBOARD 10 /* move via keyboard */
217 static void observer(void *self, WMNotification *notif);
218 static void wsobserver(void *self, WMNotification *notif);
220 static void updateClientList(WScreen *scr);
221 static void updateClientListStacking(WScreen *scr, WWindow *);
223 static void updateWorkspaceNames(WScreen *scr);
224 static void updateCurrentWorkspace(WScreen *scr);
225 static void updateWorkspaceCount(WScreen *scr);
227 typedef struct NetData {
228 WScreen *scr;
229 WReservedArea *strut;
230 WWindow **show_desktop;
231 } NetData;
234 static void
235 setSupportedHints(WScreen *scr)
237 Atom atom[atomNr];
238 int i = 0;
240 /* set supported hints list */
241 /* XXX: extend this !!! */
243 atom[i++] = net_client_list;
244 atom[i++] = net_client_list_stacking;
245 atom[i++] = net_number_of_desktops;
246 atom[i++] = net_desktop_geometry;
247 atom[i++] = net_desktop_viewport;
248 atom[i++] = net_current_desktop;
249 atom[i++] = net_desktop_names;
250 atom[i++] = net_active_window;
251 atom[i++] = net_workarea;
252 atom[i++] = net_supporting_wm_check;
253 atom[i++] = net_showing_desktop;
254 #if 0
255 atom[i++] = net_wm_moveresize;
256 #endif
257 atom[i++] = net_wm_desktop;
258 atom[i++] = net_wm_window_type;
259 atom[i++] = net_wm_window_type_desktop;
260 atom[i++] = net_wm_window_type_dock;
261 atom[i++] = net_wm_window_type_toolbar;
262 atom[i++] = net_wm_window_type_menu;
263 atom[i++] = net_wm_window_type_utility;
264 atom[i++] = net_wm_window_type_splash;
265 atom[i++] = net_wm_window_type_dialog;
266 atom[i++] = net_wm_window_type_normal;
268 atom[i++] = net_wm_state;
269 /* atom[i++] = net_wm_state_modal; */ /* XXX: not sure where/when to use it. */
270 atom[i++] = net_wm_state_sticky;
271 atom[i++] = net_wm_state_shaded;
272 atom[i++] = net_wm_state_maximized_horz;
273 atom[i++] = net_wm_state_maximized_vert;
274 atom[i++] = net_wm_state_skip_taskbar;
275 atom[i++] = net_wm_state_skip_pager;
276 atom[i++] = net_wm_state_hidden;
277 atom[i++] = net_wm_state_fullscreen;
278 atom[i++] = net_wm_state_above;
279 atom[i++] = net_wm_state_below;
281 atom[i++] = net_wm_allowed_actions;
282 atom[i++] = net_wm_action_move;
283 atom[i++] = net_wm_action_resize;
284 atom[i++] = net_wm_action_minimize;
285 atom[i++] = net_wm_action_shade;
286 atom[i++] = net_wm_action_stick;
287 atom[i++] = net_wm_action_maximize_horz;
288 atom[i++] = net_wm_action_maximize_vert;
289 atom[i++] = net_wm_action_fullscreen;
290 atom[i++] = net_wm_action_change_desktop;
291 atom[i++] = net_wm_action_close;
293 atom[i++] = net_wm_strut;
294 atom[i++] = net_wm_icon_geometry;
295 atom[i++] = net_wm_icon;
296 atom[i++] = net_wm_handled_icons;
298 XChangeProperty(dpy, scr->root_win, net_supported, XA_ATOM, 32,
299 PropModeReplace, (unsigned char*)atom, i);
301 /* set supporting wm hint */
302 XChangeProperty(dpy, scr->root_win, net_supporting_wm_check, XA_WINDOW, 32,
303 PropModeReplace, (unsigned char*)&scr->info_window, 1);
305 XChangeProperty(dpy, scr->info_window, net_supporting_wm_check, XA_WINDOW,
306 32, PropModeReplace, (unsigned char*)&scr->info_window, 1);
310 void
311 wNETWMUpdateDesktop(WScreen *scr)
313 CARD32 *views, sizes[2];
314 int count, i;
316 if (scr->workspace_count==0)
317 return;
319 count = scr->workspace_count * 2;
320 views = wmalloc(sizeof(CARD32) * count);
321 /*memset(views, 0, sizeof(CARD32) * count);*/
323 #ifdef VIRTUAL_DESKTOP
324 sizes[0] = scr->workspaces[scr->current_workspace]->width;
325 sizes[1] = scr->workspaces[scr->current_workspace]->height;
326 #else
327 sizes[0] = scr->scr_width;
328 sizes[1] = scr->scr_height;
329 #endif
331 for (i=0; i<scr->workspace_count; i++) {
332 #ifdef VIRTUAL_DESKTOP
333 views[2*i + 0] = scr->workspaces[i]->view_x;
334 views[2*i + 1] = scr->workspaces[i]->view_y;
335 #else
336 views[2*i + 0] = 0;
337 views[2*i + 1] = 0;
338 #endif
341 XChangeProperty(dpy, scr->root_win, net_desktop_geometry, XA_CARDINAL, 32,
342 PropModeReplace, (unsigned char*)sizes, 2);
344 XChangeProperty(dpy, scr->root_win, net_desktop_viewport, XA_CARDINAL, 32,
345 PropModeReplace, (unsigned char*)views, count);
347 wfree(views);
351 static void
352 updateIconImage(WScreen *scr, WWindow *wwin)
354 Atom actual_type_return;
355 int actual_format_return;
356 unsigned long nitems_return, bytes_after_return;
357 unsigned char *prop_return;
358 int rc = XGetWindowProperty(dpy, wwin->client_win, net_wm_icon, 0, ~0, False,
359 XA_CARDINAL, &actual_type_return, &actual_format_return,
360 &nitems_return, &bytes_after_return, &prop_return);
362 if (rc==Success && prop_return) {
363 unsigned int *data = (unsigned int *)prop_return;
364 unsigned int pos = 0, len = 0;
365 unsigned int best_pos = 0, best_tmp = ~0;
366 extern WPreferences wPreferences;
367 unsigned int pref_size = wPreferences.icon_size;
368 unsigned int pref_sq = pref_size*pref_size;
369 char *src, *dst;
370 RImage *new_rimage;
372 do {
373 len = data[pos+0]*data[pos+1];
374 unsigned int tmp = pref_sq-len;
375 if (tmp < best_tmp && tmp > 0) {
376 best_tmp = tmp;
377 best_pos = pos;
379 pos += 2+len;
380 } while (pos < nitems_return && len != 0);
382 new_rimage = RCreateImage(data[best_pos+0], data[best_pos+1], True);
383 len = data[best_pos+0] * data[best_pos+1];
384 src = (char*)&data[best_pos+2];
385 dst = new_rimage->data;
386 for (pos=0; pos<len; ++pos, src+=4, dst+=4) {
387 dst[0] = src[2]; /* R */
388 dst[1] = src[1]; /* G */
389 dst[2] = src[0]; /* B */
390 dst[3] = src[3]; /* A */
393 if (new_rimage) {
394 if (wwin->net_icon_image)
395 RReleaseImage(wwin->net_icon_image);
396 wwin->net_icon_image = new_rimage;
399 XFree(prop_return);
404 static void
405 updateShowDesktop(WScreen * scr, Bool show)
407 CARD32 foo;
409 foo = (show == True);
410 XChangeProperty(dpy, scr->root_win, net_showing_desktop, XA_CARDINAL, 32,
411 PropModeReplace, (unsigned char *)&foo, 1);
415 void
416 wNETWMShowingDesktop(WScreen *scr, Bool show)
418 if (show && scr->netdata->show_desktop == NULL) {
419 WWindow *tmp, **wins;
420 int i=0;
422 wins = (WWindow **)wmalloc(sizeof(WWindow *)*(scr->window_count+1));
424 tmp = scr->focused_window;
425 while (tmp) {
426 if (!tmp->flags.hidden && !tmp->flags.miniaturized &&
427 !WFLAGP(tmp, skip_window_list)) {
429 wins[i++] = tmp;
430 tmp->flags.skip_next_animation = 1;
431 tmp->flags.net_show_desktop = 1;
432 wIconifyWindow(tmp);
435 tmp = tmp->prev;
437 wins[i++] = NULL;
439 scr->netdata->show_desktop = wins;
440 updateShowDesktop(scr, True);
441 } else if (scr->netdata->show_desktop != NULL) {
442 /* FIXME: get rid of workspace flashing ! */
443 int ws = scr->current_workspace;
444 WWindow **tmp;
445 for (tmp = scr->netdata->show_desktop; *tmp; ++tmp) {
446 wDeiconifyWindow(*tmp);
447 (*tmp)->flags.net_show_desktop = 0;
449 if (ws != scr->current_workspace)
450 wWorkspaceChange(scr, ws);
451 wfree(scr->netdata->show_desktop);
452 scr->netdata->show_desktop = NULL;
453 updateShowDesktop(scr, False);
458 void
459 wNETWMInitStuff(WScreen *scr)
461 NetData *data;
462 int i;
464 #ifdef DEBUG_WMSPEC
465 printf( "wNETWMInitStuff\n");
466 #endif
468 #ifdef HAVE_XINTERNATOMS
470 Atom atoms[atomNr];
471 char * names[atomNr];
473 for (i = 0; i < atomNr; ++i) {
474 names[i] = atomNames[i].name;
476 XInternAtoms(dpy, &names[0], atomNr, False, atoms);
477 for (i = 0; i < atomNr; ++i) {
478 *atomNames[i].atom = atoms[i];
481 #else
482 for (i = 0; i < atomNr; i++) {
483 *atomNames[i].atom = XInternAtom(dpy, atomNames[i].name, False);
485 #endif
487 data = wmalloc(sizeof(NetData));
488 data->scr = scr;
489 data->strut = NULL;
490 data->show_desktop = NULL;
492 scr->netdata = data;
494 setSupportedHints(scr);
496 WMAddNotificationObserver(observer, data, WMNManaged, NULL);
497 WMAddNotificationObserver(observer, data, WMNUnmanaged, NULL);
498 WMAddNotificationObserver(observer, data, WMNChangedWorkspace, NULL);
499 WMAddNotificationObserver(observer, data, WMNChangedState, NULL);
500 WMAddNotificationObserver(observer, data, WMNChangedFocus, NULL);
501 WMAddNotificationObserver(observer, data, WMNChangedStacking, NULL);
502 WMAddNotificationObserver(observer, data, WMNChangedName, NULL);
504 WMAddNotificationObserver(wsobserver, data, WMNWorkspaceCreated, NULL);
505 WMAddNotificationObserver(wsobserver, data, WMNWorkspaceDestroyed, NULL);
506 WMAddNotificationObserver(wsobserver, data, WMNWorkspaceChanged, NULL);
507 WMAddNotificationObserver(wsobserver, data, WMNWorkspaceNameChanged, NULL);
509 updateClientList(scr);
510 updateClientListStacking(scr, NULL);
511 updateWorkspaceCount(scr);
512 updateCurrentWorkspace(scr);
513 updateWorkspaceNames(scr);
514 updateShowDesktop(scr, False);
516 wScreenUpdateUsableArea(scr);
520 void
521 wNETWMUpdateActions(WWindow *wwin, Bool del)
523 Atom action[10]; /* nr of actions atoms defined */
524 int i = 0;
526 if (del) {
527 XDeleteProperty(dpy, wwin->client_win, net_wm_allowed_actions);
528 return;
531 if (IS_MOVABLE(wwin))
532 action[i++] = net_wm_action_move;
534 if (IS_RESIZABLE(wwin))
535 action[i++] = net_wm_action_resize;
537 if (!WFLAGP(wwin, no_miniaturizable))
538 action[i++] = net_wm_action_minimize;
540 if (!WFLAGP(wwin, no_shadeable))
541 action[i++] = net_wm_action_shade;
543 /* if (!WFLAGP(wwin, no_stickable)) */
544 action[i++] = net_wm_action_stick;
546 /* if (!(WFLAGP(wwin, no_maximizeable) & MAX_HORIZONTAL)) */
547 if (IS_RESIZABLE(wwin))
548 action[i++] = net_wm_action_maximize_horz;
550 /* if (!(WFLAGP(wwin, no_maximizeable) & MAX_VERTICAL)) */
551 if (IS_RESIZABLE(wwin))
552 action[i++] = net_wm_action_maximize_vert;
554 /* if (!WFLAGP(wwin, no_fullscreen)) */
555 action[i++] = net_wm_action_fullscreen;
557 /* if (!WFLAGP(wwin, no_change_desktop)) */
558 action[i++] = net_wm_action_change_desktop;
560 if (!WFLAGP(wwin, no_closable))
561 action[i++] = net_wm_action_close;
563 XChangeProperty(dpy, wwin->client_win, net_wm_allowed_actions,
564 XA_ATOM, 32, PropModeReplace, (unsigned char *)action, i);
568 void
569 wNETWMUpdateWorkarea(WScreen *scr, WArea usableArea)
571 CARD32 *area;
572 int count, i;
574 /* XXX: not Xinerama compatible,
575 xinerama gets the largest available */
577 if(!scr->netdata || scr->workspace_count==0)
578 return;
580 count = scr->workspace_count * 4;
581 area = wmalloc(sizeof(CARD32) * count);
582 for (i=0; i<scr->workspace_count; i++) {
583 area[4*i + 0] = usableArea.x1;
584 area[4*i + 1] = usableArea.y1;
585 area[4*i + 2] = usableArea.x2 - usableArea.x1;
586 area[4*i + 3] = usableArea.y2 - usableArea.y1;
589 XChangeProperty(dpy, scr->root_win, net_workarea, XA_CARDINAL, 32,
590 PropModeReplace, (unsigned char*)area, count);
592 wfree(area);
596 Bool
597 wNETWMGetUsableArea(WScreen *scr, int head, WArea *area)
599 WReservedArea *cur;
600 WMRect rect;
602 if(!scr->netdata || !scr->netdata->strut)
603 return False;
605 area->x1 = area->y1 = area->x2 = area->y2 = 0;
607 for(cur = scr->netdata->strut ; cur ; cur = cur->next) {
608 WWindow * wwin = wWindowFor(cur->window);
609 if (wWindowTouchesHead(wwin, head)) {
610 if(cur->area.x1 > area->x1)
611 area->x1 = cur->area.x1;
612 if(cur->area.y1 > area->y1)
613 area->y1 = cur->area.y1;
614 if(cur->area.x2 > area->x2)
615 area->x2 = cur->area.x2;
616 if(cur->area.y2 > area->y2)
617 area->y2 = cur->area.y2;
621 if (area->x1==0 && area->x2==0 &&
622 area->y1==0 && area->y2==0) return False;
624 rect = wGetRectForHead(scr, head);
626 area->x1 = rect.pos.x + area->x1;
627 area->x2 = rect.pos.x + rect.size.width - area->x2;
628 area->y1 = rect.pos.y + area->y1;
629 area->y2 = rect.pos.y + rect.size.height - area->y2;
631 return True;
635 static void
636 updateClientList(WScreen *scr)
638 WWindow *wwin;
639 Window *windows;
640 int count;
642 windows = (Window *)wmalloc(sizeof(Window)*(scr->window_count+1));
644 count = 0;
645 wwin = scr->focused_window;
646 while (wwin) {
647 windows[count++] = wwin->client_win;
648 wwin = wwin->prev;
650 XChangeProperty(dpy, scr->root_win, net_client_list, XA_WINDOW, 32,
651 PropModeReplace, (unsigned char*)windows, count);
653 wfree(windows);
654 XFlush(dpy);
658 static void
659 updateClientListStacking(WScreen *scr, WWindow *wwin_excl)
661 WWindow *wwin;
662 Window *client_list;
663 Window *client_list_reverse;
664 int client_count;
665 WCoreWindow *tmp;
666 WMBagIterator iter;
667 int i;
669 /* update client list */
670 i = scr->window_count + 1;
671 client_list = (Window*)wmalloc(sizeof(Window) * i);
672 client_list_reverse = (Window*)wmalloc(sizeof(Window) * i);
674 client_count = 0;
675 WM_ETARETI_BAG(scr->stacking_list, tmp, iter) {
676 while (tmp) {
677 wwin = wWindowFor(tmp->window);
678 /* wwin_excl is a window to exclude from the list
679 (e.g. it's now unmanaged) */
680 if(wwin && (wwin != wwin_excl))
681 client_list[client_count++] = wwin->client_win;
682 tmp = tmp->stacking->under;
686 for(i = 0; i < client_count; i++) {
687 Window w = client_list[client_count - i - 1];
688 client_list_reverse[i] = w;
691 XChangeProperty(dpy, scr->root_win, net_client_list_stacking, XA_WINDOW, 32,
692 PropModeReplace, (unsigned char *)client_list_reverse, client_count);
694 wfree(client_list);
695 wfree(client_list_reverse);
697 XFlush(dpy);
701 static void
702 updateWorkspaceCount(WScreen *scr) /* changeable */
704 CARD32 count;
706 count = scr->workspace_count;
708 XChangeProperty(dpy, scr->root_win, net_number_of_desktops, XA_CARDINAL,
709 32, PropModeReplace, (unsigned char*)&count, 1);
713 static void
714 updateCurrentWorkspace(WScreen *scr) /* changeable */
716 CARD32 count;
718 count = scr->current_workspace;
720 XChangeProperty(dpy, scr->root_win, net_current_desktop, XA_CARDINAL, 32,
721 PropModeReplace, (unsigned char*)&count, 1);
725 static void
726 updateWorkspaceNames(WScreen *scr)
728 char buf[1024], *pos;
729 unsigned int i, len, curr_size;
731 pos = buf;
732 len = 0;
733 for(i = 0; i < scr->workspace_count; i++) {
734 curr_size = strlen(scr->workspaces[i]->name);
735 strcpy(pos, scr->workspaces[i]->name);
736 pos += (curr_size+1);
737 len += (curr_size+1);
740 XChangeProperty(dpy, scr->root_win, net_desktop_names, utf8_string, 8,
741 PropModeReplace, (unsigned char *)buf, len);
745 static void
746 updateFocusHint(WScreen *scr, WWindow *wwin) /* changeable */
748 Window window;
750 if (!scr->focused_window || !scr->focused_window->flags.focused)
751 window = None;
752 else
753 window = scr->focused_window->client_win;
755 XChangeProperty(dpy, scr->root_win, net_active_window, XA_WINDOW, 32,
756 PropModeReplace, (unsigned char*)&window, 1);
760 static void
761 updateWorkspaceHint(WWindow *wwin, Bool fake, Bool del)
763 CARD32 l;
765 if (del) {
766 XDeleteProperty(dpy, wwin->client_win, net_wm_desktop);
767 } else {
768 l = ((fake || IS_OMNIPRESENT(wwin)) ? -1 : wwin->frame->workspace);
769 XChangeProperty(dpy, wwin->client_win, net_wm_desktop, XA_CARDINAL,
770 32, PropModeReplace, (unsigned char*)&l, 1);
775 static void
776 updateStateHint(WWindow *wwin, Bool changedWorkspace, Bool del) /* changeable */
778 if (del) {
779 if (!wwin->flags.net_state_from_client) {
780 XDeleteProperty(dpy, wwin->client_win, net_wm_state);
782 } else {
783 Atom state[11]; /* nr of defined state atoms */
784 int i = 0;
786 if(changedWorkspace || (wPreferences.sticky_icons && !IS_OMNIPRESENT(wwin)))
787 updateWorkspaceHint(wwin, False, False);
789 if (IS_OMNIPRESENT(wwin))
790 state[i++] = net_wm_state_sticky;
791 if (wwin->flags.shaded)
792 state[i++] = net_wm_state_shaded;
793 if (wwin->flags.maximized & MAX_HORIZONTAL)
794 state[i++] = net_wm_state_maximized_horz;
795 if (wwin->flags.maximized & MAX_VERTICAL)
796 state[i++] = net_wm_state_maximized_vert;
797 if (WFLAGP(wwin, skip_window_list))
798 state[i++] = net_wm_state_skip_taskbar;
799 if (wwin->flags.net_skip_pager)
800 state[i++] = net_wm_state_skip_pager;
801 if ((wwin->flags.hidden || wwin->flags.miniaturized) && !wwin->flags.net_show_desktop){
802 state[i++] = net_wm_state_hidden;
803 state[i++] = net_wm_state_skip_pager;
805 if (wwin->flags.miniaturized && wPreferences.sticky_icons) {
806 if( !IS_OMNIPRESENT(wwin))
807 updateWorkspaceHint(wwin, True, False);
808 state[i++] = net_wm_state_sticky;
811 if (WFLAGP(wwin, sunken))
812 state[i++] = net_wm_state_below;
813 if (WFLAGP(wwin, floating))
814 state[i++] = net_wm_state_above;
815 if (wwin->flags.fullscreen)
816 state[i++] = net_wm_state_fullscreen;
818 XChangeProperty(dpy, wwin->client_win, net_wm_state, XA_ATOM, 32,
819 PropModeReplace, (unsigned char *)state, i);
824 static Bool
825 updateStrut(WWindow *wwin, Bool adding)
827 WScreen *scr;
828 WReservedArea *area;
829 Bool hasState = False;
831 scr = wwin->screen_ptr;
833 if (adding) {
834 Atom type_ret;
835 int fmt_ret;
836 unsigned long nitems_ret;
837 unsigned long bytes_after_ret;
838 long *data = 0;
840 if (XGetWindowProperty(dpy, wwin->client_win, net_wm_strut, 0, 4, False,
841 XA_CARDINAL, &type_ret, &fmt_ret, &nitems_ret,
842 &bytes_after_ret,
843 (unsigned char**)&data)==Success && data) {
845 area = (WReservedArea *)wmalloc(sizeof(WReservedArea));
846 area->area.x1 = data[0];
847 area->area.x2 = data[1];
848 area->area.y1 = data[2];
849 area->area.y2 = data[3];
851 area->window = wwin->client_win;
853 area->next = scr->netdata->strut;
854 scr->netdata->strut = area;
856 XFree(data);
857 hasState = True;
858 #ifdef VIRTUAL_DESKTOP
859 /* just in case wm_window_type didn't set it already */
860 wwin->client_flags.virtual_stick = 1;
861 #endif
864 } else {
865 /* deleting */
866 area = scr->netdata->strut;
868 if(area) {
869 if(area->window == wwin->client_win) {
870 scr->netdata->strut = area->next;
871 wfree(area);
872 hasState = True;
873 } else {
874 while(area->next && area->next->window != wwin->client_win)
875 area = area->next;
877 if(area->next) {
878 WReservedArea *next;
880 next = area->next->next;
881 wfree(area->next);
882 area->next = next;
884 hasState = True;
890 return hasState;
894 static int
895 getWindowLayer(WWindow * wwin)
897 int layer = WMNormalLevel;
899 if (wwin->type == net_wm_window_type_desktop) {
900 layer = WMDesktopLevel;
901 } else if (wwin->type == net_wm_window_type_dock) {
902 layer = WMDockLevel;
903 } else if (wwin->type == net_wm_window_type_toolbar) {
904 layer = WMMainMenuLevel;
905 } else if (wwin->type == net_wm_window_type_menu) {
906 layer = WMSubmenuLevel;
907 } else if (wwin->type == net_wm_window_type_utility) {
908 } else if (wwin->type == net_wm_window_type_splash) {
909 } else if (wwin->type == net_wm_window_type_dialog) {
910 if (wwin->transient_for) {
911 WWindow *parent = wWindowFor(wwin->transient_for);
912 if (parent && parent->flags.fullscreen) {
913 layer = WMFullscreenLevel;
916 //layer = WMPopUpLevel;
917 } else if (wwin->type == net_wm_window_type_normal) {
920 if (wwin->client_flags.sunken && WMSunkenLevel < layer)
921 layer = WMSunkenLevel;
922 if (wwin->client_flags.floating && WMFloatingLevel > layer)
923 layer = WMFloatingLevel;
925 return layer;
929 static void
930 doStateAtom(WWindow *wwin, Atom state, int set, Bool init)
933 if (state == net_wm_state_sticky) {
934 if (set == _NET_WM_STATE_TOGGLE) {
935 set = !IS_OMNIPRESENT(wwin);
937 if (set != wwin->flags.omnipresent) {
938 wWindowSetOmnipresent(wwin, set);
940 } else if (state == net_wm_state_shaded) {
941 if (set == _NET_WM_STATE_TOGGLE) {
942 set = !wwin->flags.shaded;
944 if (init) {
945 wwin->flags.shaded = set;
946 } else {
947 if (set) {
948 wShadeWindow(wwin);
949 } else {
950 wUnshadeWindow(wwin);
953 } else if (state == net_wm_state_skip_taskbar) {
954 if (set == _NET_WM_STATE_TOGGLE) {
955 set = !wwin->client_flags.skip_window_list;
957 wwin->client_flags.skip_window_list = set;
958 } else if (state == net_wm_state_skip_pager) {
959 if (set == _NET_WM_STATE_TOGGLE) {
960 set = !wwin->flags.net_skip_pager;
962 wwin->flags.net_skip_pager = set;
963 } else if (state == net_wm_state_maximized_vert) {
964 if (set == _NET_WM_STATE_TOGGLE) {
965 set = !(wwin->flags.maximized & MAX_VERTICAL);
967 if (init) {
968 wwin->flags.maximized = set;
969 } else {
970 if (set) {
971 wMaximizeWindow(wwin, wwin->flags.maximized | MAX_VERTICAL);
972 } else {
973 wMaximizeWindow(wwin, wwin->flags.maximized & ~MAX_VERTICAL);
976 } else if (state == net_wm_state_maximized_horz) {
977 if (set == _NET_WM_STATE_TOGGLE) {
978 set = !(wwin->flags.maximized & MAX_HORIZONTAL);
980 if (init) {
981 wwin->flags.maximized = set;
982 } else {
983 if (set) {
984 wMaximizeWindow(wwin, wwin->flags.maximized | MAX_HORIZONTAL);
985 } else {
986 wMaximizeWindow(wwin, wwin->flags.maximized & ~MAX_HORIZONTAL);
989 } else if (state == net_wm_state_hidden) {
990 if (set == _NET_WM_STATE_TOGGLE) {
991 set = !(wwin->flags.miniaturized);
993 if (init) {
994 wwin->flags.miniaturized = set;
995 } else {
996 if (set) {
997 wIconifyWindow(wwin);
998 } else {
999 wDeiconifyWindow(wwin);
1002 } else if (state == net_wm_state_fullscreen) {
1003 if (set == _NET_WM_STATE_TOGGLE) {
1004 set = !(wwin->flags.fullscreen);
1006 if (init) {
1007 wwin->flags.fullscreen = set;
1008 } else {
1009 if (set) {
1010 wFullscreenWindow(wwin);
1011 } else {
1012 wUnfullscreenWindow(wwin);
1015 } else if (state == net_wm_state_above) {
1016 if (set == _NET_WM_STATE_TOGGLE) {
1017 set = !(wwin->client_flags.floating);
1019 if (init) {
1020 wwin->client_flags.floating = set;
1021 } else {
1022 wwin->client_flags.floating = set;
1023 ChangeStackingLevel(wwin->frame->core, getWindowLayer(wwin));
1026 } else if (state == net_wm_state_below) {
1027 if (set == _NET_WM_STATE_TOGGLE) {
1028 set = !(wwin->client_flags.sunken);
1030 if (init) {
1031 wwin->client_flags.sunken = set;
1032 } else {
1033 wwin->client_flags.sunken = set;
1034 ChangeStackingLevel(wwin->frame->core, getWindowLayer(wwin));
1037 } else {
1038 #ifdef DEBUG_WMSPEC
1039 printf("doStateAtom unknown atom %s set %d\n", XGetAtomName(dpy, state), set);
1040 #endif
1045 static void
1046 removeIcon( WWindow * wwin)
1048 if (wwin->icon == NULL)
1049 return;
1050 if (wwin->flags.miniaturized && wwin->icon->mapped) {
1051 XUnmapWindow(dpy, wwin->icon->core->window);
1052 RemoveFromStackList(wwin->icon->core);
1053 wIconDestroy(wwin->icon);
1054 wwin->icon = NULL;
1059 static Bool
1060 handleWindowType(WWindow * wwin, Atom type, int *layer)
1062 Bool ret = True;
1064 if (type == net_wm_window_type_desktop) {
1065 wwin->client_flags.no_titlebar = 1;
1066 wwin->client_flags.no_resizable = 1;
1067 wwin->client_flags.no_miniaturizable = 1;
1068 wwin->client_flags.no_border = 1;
1069 wwin->client_flags.no_resizebar = 1;
1070 wwin->client_flags.no_shadeable = 1;
1071 wwin->client_flags.no_movable = 1;
1072 wwin->client_flags.omnipresent = 1;
1073 wwin->client_flags.skip_window_list = 1;
1074 wwin->client_flags.dont_move_off = 1;
1075 wwin->client_flags.no_appicon = 1;
1076 wwin->flags.net_skip_pager = 1;
1077 wwin->frame_x = 0;
1078 wwin->frame_y = 0;
1079 #ifdef VIRTUAL_DESKTOP
1080 wwin->client_flags.virtual_stick = 1;
1081 #endif
1082 } else if (type == net_wm_window_type_dock) {
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; /* XXX: really not a single decoration. */
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->flags.net_skip_pager = 1;
1094 #ifdef VIRTUAL_DESKTOP
1095 wwin->client_flags.virtual_stick = 1;
1096 #endif
1097 } else if (type == net_wm_window_type_toolbar) {
1098 wwin->client_flags.no_titlebar = 1;
1099 wwin->client_flags.no_resizable = 1;
1100 wwin->client_flags.no_miniaturizable = 1;
1101 wwin->client_flags.no_resizebar = 1;
1102 wwin->client_flags.no_shadeable = 1;
1103 wwin->client_flags.skip_window_list = 1;
1104 wwin->client_flags.dont_move_off = 1;
1105 wwin->client_flags.no_appicon = 1;
1106 } else if (type == net_wm_window_type_menu) {
1107 wwin->client_flags.no_titlebar = 1;
1108 wwin->client_flags.no_resizable = 1;
1109 wwin->client_flags.no_miniaturizable = 1;
1110 wwin->client_flags.no_resizebar = 1;
1111 wwin->client_flags.no_shadeable = 1;
1112 wwin->client_flags.skip_window_list = 1;
1113 wwin->client_flags.dont_move_off = 1;
1114 wwin->client_flags.no_appicon = 1;
1115 } else if (type == net_wm_window_type_utility) {
1116 wwin->client_flags.no_appicon = 1;
1117 } else if (type == net_wm_window_type_splash) {
1118 wwin->client_flags.no_titlebar = 1;
1119 wwin->client_flags.no_resizable = 1;
1120 wwin->client_flags.no_miniaturizable = 1;
1121 wwin->client_flags.no_resizebar = 1;
1122 wwin->client_flags.no_shadeable = 1;
1123 wwin->client_flags.no_movable = 1;
1124 wwin->client_flags.skip_window_list = 1;
1125 wwin->client_flags.dont_move_off = 1;
1126 wwin->client_flags.no_appicon = 1;
1127 wwin->flags.net_skip_pager = 1;
1128 } else if (type == net_wm_window_type_dialog) {
1129 // wwin->client_flags.skip_window_list = 1;
1130 // wwin->client_flags.no_appicon = 1;
1131 } else if (type == net_wm_window_type_normal) {
1132 } else {
1133 ret = False;
1136 wwin->type = type;
1137 *layer = getWindowLayer(wwin);
1139 return ret;
1143 void
1144 wNETWMPositionSplash(WWindow *wwin, int *x, int *y, int width, int height)
1146 if (wwin->type == net_wm_window_type_splash) {
1147 WScreen * scr = wwin->screen_ptr;
1148 WMRect rect = wGetRectForHead(scr, wGetHeadForPointerLocation(scr));
1149 *x = rect.pos.x + (rect.size.width - width)/2;
1150 *y = rect.pos.y + (rect.size.height - height)/2;
1155 static void
1156 updateWindowType(WWindow * wwin)
1158 Atom type_ret;
1159 int fmt_ret;
1160 unsigned long nitems_ret;
1161 unsigned long bytes_after_ret;
1162 long *data = 0;
1163 int layer;
1164 if (XGetWindowProperty(dpy, wwin->client_win, net_wm_window_type, 0, 1,
1165 False, XA_ATOM, &type_ret, &fmt_ret, &nitems_ret,
1166 &bytes_after_ret, (unsigned char **)&data)==Success
1167 && data) {
1169 int i;
1170 Atom * type = (Atom *)data;
1171 for (i=0; i<nitems_ret; ++i) {
1172 if (handleWindowType(wwin, type[i], &layer)) break;
1174 XFree(data);
1177 ChangeStackingLevel(wwin->frame->core, layer);
1178 wwin->frame->flags.need_texture_change = 1;
1179 wWindowConfigureBorders(wwin);
1180 wFrameWindowPaint(wwin->frame);
1181 wNETWMUpdateActions(wwin, False);
1185 Bool
1186 wNETWMCheckClientHints(WWindow *wwin, int *layer, int *workspace)
1188 Atom type_ret;
1189 int fmt_ret;
1190 unsigned long nitems_ret;
1191 unsigned long bytes_after_ret;
1192 long *data = 0;
1193 Bool hasState = False;
1194 int i;
1196 if (XGetWindowProperty(dpy, wwin->client_win, net_wm_desktop, 0, 1, False,
1197 XA_CARDINAL, &type_ret, &fmt_ret, &nitems_ret,
1198 &bytes_after_ret,
1199 (unsigned char**)&data)==Success && data) {
1201 long desktop = *data;
1202 XFree(data);
1204 if(desktop == -1)
1205 wwin->client_flags.omnipresent = 1;
1206 else
1207 *workspace = desktop;
1209 hasState = True;
1212 if (XGetWindowProperty(dpy, wwin->client_win, net_wm_state, 0, 1, False,
1213 XA_ATOM, &type_ret, &fmt_ret, &nitems_ret,
1214 &bytes_after_ret,
1215 (unsigned char**)&data)==Success && data) {
1217 Atom * state = (Atom *)data;
1218 for(i=0; i<nitems_ret; ++i) {
1219 doStateAtom(wwin, state[i], _NET_WM_STATE_ADD, True);
1221 XFree(data);
1222 hasState = True;
1225 if (XGetWindowProperty(dpy, wwin->client_win, net_wm_window_type, 0, 1, False,
1226 XA_ATOM, &type_ret, &fmt_ret, &nitems_ret,
1227 &bytes_after_ret,
1228 (unsigned char **)&data) == Success && data) {
1230 Atom * type = (Atom *)data;
1231 for (i=0; i<nitems_ret; ++i) {
1232 if (handleWindowType(wwin, type[i], layer)) break;
1234 XFree(data);
1235 hasState = True;
1238 wNETWMUpdateActions(wwin, False);
1239 updateStrut(wwin, False);
1240 if (updateStrut(wwin, True)) {
1241 hasState = True;
1243 wScreenUpdateUsableArea(wwin->screen_ptr);
1245 return hasState;
1249 static Bool
1250 updateNetIconInfo(WWindow *wwin) {
1252 Atom type_ret;
1253 int fmt_ret;
1254 unsigned long nitems_ret;
1255 unsigned long bytes_after_ret;
1256 long *data = 0;
1257 Bool hasState = False;
1258 Bool old_state = wwin->flags.net_handle_icon;
1260 if (XGetWindowProperty(dpy, wwin->client_win, net_wm_handled_icons, 0, 1, False,
1261 XA_CARDINAL, &type_ret, &fmt_ret, &nitems_ret,
1262 &bytes_after_ret, (unsigned char **)&data) == Success && data) {
1263 long handled = *data;
1264 wwin->flags.net_handle_icon = (handled != 0);
1265 XFree(data);
1266 hasState = True;
1268 } else wwin->flags.net_handle_icon = False;
1270 if ( XGetWindowProperty(dpy, wwin->client_win, net_wm_icon_geometry, 0, 4, False,
1271 XA_CARDINAL, &type_ret, &fmt_ret, &nitems_ret,
1272 &bytes_after_ret, (unsigned char **)&data) == Success && data) {
1274 #ifdef NETWM_PROPER
1275 if (wwin->flags.net_handle_icon)
1276 #else
1277 wwin->flags.net_handle_icon = True;
1278 #endif
1280 wwin->icon_x = data[0];
1281 wwin->icon_y = data[1];
1282 wwin->icon_w = data[2];
1283 wwin->icon_h = data[3];
1286 XFree(data);
1287 hasState = True;
1289 } else wwin->flags.net_handle_icon = False;
1291 if (wwin->flags.miniaturized &&
1292 old_state != wwin->flags.net_handle_icon) {
1293 if (wwin->flags.net_handle_icon) {
1294 removeIcon(wwin);
1295 } else {
1296 wwin->flags.miniaturized = False;
1297 wwin->flags.skip_next_animation = True;
1298 wIconifyWindow(wwin);
1302 return hasState;
1306 Bool
1307 wNETWMCheckInitialClientState(WWindow *wwin)
1309 Bool hasState = False;
1311 #ifdef DEBUG_WMSPEC
1312 printf("CheckInitialClientState\n");
1313 #endif
1315 wNETWMShowingDesktop(wwin->screen_ptr, False);
1317 hasState |= updateNetIconInfo(wwin);
1319 updateIconImage(wwin->screen_ptr, wwin);
1321 return hasState;
1325 static void
1326 handleDesktopNames(XClientMessageEvent *event, WScreen *scr)
1328 unsigned long nitems_ret, bytes_after_ret;
1329 char *data, *names[32];
1330 int fmt_ret, i, n;
1331 Atom type_ret;
1333 if (XGetWindowProperty(dpy, scr->root_win, net_desktop_names, 0, 1, False,
1334 utf8_string, &type_ret, &fmt_ret, &nitems_ret,
1335 &bytes_after_ret,
1336 (unsigned char**)&data)!=Success) {
1337 return;
1340 if (data == 0)
1341 return;
1343 if (type_ret != utf8_string || fmt_ret != 8)
1344 return;
1346 n = 0;
1347 names[n] = data;
1348 for (i = 0; i < nitems_ret; i++) {
1349 if (data[i] == 0) {
1350 n++;
1351 names[n] = &data[i];
1352 } else if (*names[n] == 0) {
1353 names[n] = &data[i];
1354 wWorkspaceRename(scr, n, names[n]);
1360 Bool
1361 wNETWMProcessClientMessage(XClientMessageEvent *event)
1363 WScreen *scr;
1364 WWindow *wwin;
1365 Bool done = True;
1367 #ifdef DEBUG_WMSPEC
1368 printf("processClientMessage type %s\n", XGetAtomName(dpy, event->message_type));
1369 #endif
1371 scr = wScreenForWindow(event->window);
1372 if (scr) {
1373 /* generic client messages */
1374 if (event->message_type == net_current_desktop) {
1375 wWorkspaceChange(scr, event->data.l[0]);
1376 } else if(event->message_type == net_number_of_desktops) {
1377 long value;
1379 value = event->data.l[0];
1380 if(value > scr->workspace_count) {
1381 wWorkspaceMake(scr, value - scr->workspace_count);
1382 } else if(value < scr->workspace_count) {
1383 int i;
1384 Bool rebuild = False;
1386 for (i = scr->workspace_count-1; i >= value; i--) {
1387 if (!wWorkspaceDelete(scr, i)) {
1388 rebuild = True;
1389 break;
1393 if(rebuild) {
1394 updateWorkspaceCount(scr);
1397 } else if (event->message_type == net_showing_desktop) {
1398 wNETWMShowingDesktop(scr, event->data.l[0]);
1399 #ifdef VIRTUAL_DESKTOP
1400 } else if (event->message_type == net_desktop_viewport) {
1401 wWorkspaceSetViewPort(scr, scr->current_workspace,
1402 event->data.l[0], event->data.l[1]);
1403 #endif
1404 } else if (event->message_type == net_desktop_names) {
1405 handleDesktopNames(event, scr);
1406 } else {
1407 done = False;
1410 if (done)
1411 return True;
1414 /* window specific client messages */
1416 wwin = wWindowFor(event->window);
1417 if (!wwin)
1418 return False;
1420 if (event->message_type == net_active_window) {
1421 wNETWMShowingDesktop(scr, False);
1422 wMakeWindowVisible(wwin);
1423 } else if (event->message_type == net_close_window) {
1424 if (!WFLAGP(wwin, no_closable)) {
1425 if (wwin->protocols.DELETE_WINDOW)
1426 wClientSendProtocol(wwin, _XA_WM_DELETE_WINDOW, LastTimestamp);
1428 } else if (event->message_type == net_wm_state) {
1429 int maximized = wwin->flags.maximized;
1430 long set = event->data.l[0];
1432 #ifdef DEBUG_WMSPEC
1433 printf("net_wm_state set %d a1 %s a2 %s\n", set,
1434 XGetAtomName(dpy, event->data.l[1]),
1435 XGetAtomName(dpy, event->data.l[2]));
1436 #endif
1438 doStateAtom(wwin, (Atom)event->data.l[1], set, False);
1439 if(event->data.l[2])
1440 doStateAtom(wwin, (Atom)event->data.l[2], set, False);
1442 if(wwin->flags.maximized != maximized) {
1443 if(!wwin->flags.maximized) {
1444 wwin->flags.maximized = maximized;
1445 wUnmaximizeWindow(wwin);
1446 } else {
1447 wMaximizeWindow(wwin, wwin->flags.maximized);
1450 updateStateHint(wwin, False, False);
1451 } else if (event->message_type == net_wm_handled_icons ||
1452 event->message_type == net_wm_icon_geometry) {
1453 updateNetIconInfo(wwin);
1454 } else if (event->message_type == net_wm_desktop) {
1455 long desktop = event->data.l[0];
1456 if (desktop == -1) {
1457 wWindowSetOmnipresent(wwin, True);
1458 } else {
1459 if (IS_OMNIPRESENT(wwin))
1460 wWindowSetOmnipresent(wwin, False);
1461 wWindowChangeWorkspace(wwin, desktop);
1463 } else if (event->message_type == net_wm_icon) {
1464 updateIconImage(scr, wwin);
1465 } else {
1466 done = False;
1469 return done;
1473 Bool
1474 wNETWMCheckClientHintChange(WWindow *wwin, XPropertyEvent *event)
1476 Bool ret = True;
1478 if(event->atom == net_wm_strut) {
1479 updateStrut(wwin, False);
1480 updateStrut(wwin, True);
1481 wScreenUpdateUsableArea(wwin->screen_ptr);
1482 } else if (event->atom == net_wm_handled_icons ||
1483 event->atom == net_wm_icon_geometry) {
1484 updateNetIconInfo(wwin);
1485 } else if (event->atom == net_wm_window_type) {
1486 updateWindowType(wwin);
1487 } else {
1488 ret = False;
1491 return ret;
1496 wNETWMGetPidForWindow(Window window)
1498 Atom type_ret;
1499 int fmt_ret;
1500 unsigned long nitems_ret;
1501 unsigned long bytes_after_ret;
1502 long *data = 0;
1503 int pid;
1505 if (XGetWindowProperty(dpy, window, net_wm_pid, 0, 1, False,
1506 XA_CARDINAL, &type_ret, &fmt_ret, &nitems_ret,
1507 &bytes_after_ret,
1508 (unsigned char**)&data)==Success && data) {
1510 pid = *data;
1511 XFree(data);
1512 } else {
1513 pid = 0;
1516 return pid;
1520 static void
1521 observer(void *self, WMNotification *notif)
1523 WWindow *wwin = (WWindow*)WMGetNotificationObject(notif);
1524 const char *name = WMGetNotificationName(notif);
1525 void *data = WMGetNotificationClientData(notif);
1526 NetData *ndata = (NetData*)self;
1529 if (strcmp(name, WMNManaged) == 0 && wwin) {
1530 updateClientList(wwin->screen_ptr);
1531 updateClientListStacking(wwin->screen_ptr, NULL);
1532 updateStateHint(wwin, True, False);
1534 updateStrut(wwin, False);
1535 updateStrut(wwin, True);
1536 wScreenUpdateUsableArea(wwin->screen_ptr);
1537 } else if (strcmp(name, WMNUnmanaged) == 0 && wwin) {
1538 updateClientList(wwin->screen_ptr);
1539 updateClientListStacking(wwin->screen_ptr, wwin);
1540 updateWorkspaceHint(wwin, False, True);
1541 updateStateHint(wwin, False, True);
1542 wNETWMUpdateActions(wwin, True);
1544 updateStrut(wwin, False);
1545 wScreenUpdateUsableArea(wwin->screen_ptr);
1546 } else if (strcmp(name, WMNResetStacking) == 0 && wwin) {
1547 updateClientListStacking(wwin->screen_ptr, NULL);
1548 updateStateHint(wwin, False, False);
1549 } else if (strcmp(name, WMNChangedStacking) == 0 && wwin) {
1550 updateClientListStacking(wwin->screen_ptr, NULL);
1551 updateStateHint(wwin, False, False);
1552 } else if (strcmp(name, WMNChangedFocus) == 0) {
1553 updateFocusHint(ndata->scr, wwin);
1554 } else if (strcmp(name, WMNChangedWorkspace) == 0 && wwin) {
1555 updateWorkspaceHint(wwin, False, False);
1556 updateStateHint(wwin, True, False);
1557 } else if (strcmp(name, WMNChangedState) == 0 && wwin) {
1558 updateStateHint(wwin, !strcmp(data, "omnipresent"), False);
1563 static void
1564 wsobserver(void *self, WMNotification *notif)
1566 WScreen *scr = (WScreen*)WMGetNotificationObject(notif);
1567 const char *name = WMGetNotificationName(notif);
1568 //void *data = WMGetNotificationClientData(notif);
1570 if (strcmp(name, WMNWorkspaceCreated) == 0) {
1571 updateWorkspaceCount(scr);
1572 updateWorkspaceNames(scr);
1573 } else if (strcmp(name, WMNWorkspaceDestroyed) == 0) {
1574 updateWorkspaceCount(scr);
1575 updateWorkspaceNames(scr);
1576 } else if (strcmp(name, WMNWorkspaceChanged) == 0) {
1577 updateCurrentWorkspace(scr);
1578 } else if (strcmp(name, WMNWorkspaceNameChanged) == 0) {
1579 updateWorkspaceNames(scr);
1583 #endif /* NETWM_HINTS */