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 along
18 * with this program; if not, write to the Free Software Foundation, Inc.,
19 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
26 * This file needs to be checked for all calls to XGetWindowProperty() and
27 * proper checks need to be made on the returned values. Only checking for
28 * return to be Success is not enough. -Dan
34 #include <X11/Xatom.h>
35 #include <X11/Xarch.h>
38 #include <WINGs/WUtil.h>
39 #include "WindowMaker.h"
42 #include "workspace.h"
51 #include "properties.h"
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_supporting_wm_check
;
65 static Atom net_virtual_roots
; /* N/A */
66 static Atom net_desktop_layout
; /* XXX */
67 static Atom net_showing_desktop
;
69 /* Other Root Window Messages */
70 static Atom net_close_window
;
71 static Atom net_moveresize_window
; /* TODO */
72 static Atom net_wm_moveresize
; /* TODO */
74 /* Application Window Properties */
75 static Atom net_wm_name
;
76 static Atom net_wm_visible_name
; /* TODO (unnecessary?) */
77 static Atom net_wm_icon_name
;
78 static Atom net_wm_visible_icon_name
; /* TODO (unnecessary?) */
79 static Atom net_wm_desktop
;
80 static Atom net_wm_window_type
;
81 static Atom net_wm_window_type_desktop
;
82 static Atom net_wm_window_type_dock
;
83 static Atom net_wm_window_type_toolbar
;
84 static Atom net_wm_window_type_menu
;
85 static Atom net_wm_window_type_utility
;
86 static Atom net_wm_window_type_splash
;
87 static Atom net_wm_window_type_dialog
;
88 static Atom net_wm_window_type_dropdown_menu
;
89 static Atom net_wm_window_type_popup_menu
;
90 static Atom net_wm_window_type_tooltip
;
91 static Atom net_wm_window_type_notification
;
92 static Atom net_wm_window_type_combo
;
93 static Atom net_wm_window_type_dnd
;
94 static Atom net_wm_window_type_normal
;
95 static Atom net_wm_state
;
96 static Atom net_wm_state_modal
; /* XXX: what is this?!? */
97 static Atom net_wm_state_sticky
;
98 static Atom net_wm_state_maximized_vert
;
99 static Atom net_wm_state_maximized_horz
;
100 static Atom net_wm_state_shaded
;
101 static Atom net_wm_state_skip_taskbar
;
102 static Atom net_wm_state_skip_pager
;
103 static Atom net_wm_state_hidden
;
104 static Atom net_wm_state_fullscreen
;
105 static Atom net_wm_state_above
;
106 static Atom net_wm_state_below
;
107 static Atom net_wm_allowed_actions
;
108 static Atom net_wm_action_move
;
109 static Atom net_wm_action_resize
;
110 static Atom net_wm_action_minimize
;
111 static Atom net_wm_action_shade
;
112 static Atom net_wm_action_stick
;
113 static Atom net_wm_action_maximize_horz
;
114 static Atom net_wm_action_maximize_vert
;
115 static Atom net_wm_action_fullscreen
;
116 static Atom net_wm_action_change_desktop
;
117 static Atom net_wm_action_close
;
118 static Atom net_wm_strut
; /* XXX: see net_workarea */
119 static Atom net_wm_strut_partial
; /* TODO: doesn't really fit into the current strut scheme */
120 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. */
121 static Atom net_wm_icon
;
122 static Atom net_wm_pid
; /* TODO */
123 static Atom net_wm_handled_icons
; /* FIXME: see net_wm_icon_geometry */
124 static Atom net_wm_window_opacity
;
126 static Atom net_frame_extents
;
128 /* Window Manager Protocols */
129 static Atom net_wm_ping
; /* TODO */
131 static Atom utf8_string
;
138 static atomitem_t atomNames
[] = {
139 {"_NET_SUPPORTED", &net_supported
},
140 {"_NET_CLIENT_LIST", &net_client_list
},
141 {"_NET_CLIENT_LIST_STACKING", &net_client_list_stacking
},
142 {"_NET_NUMBER_OF_DESKTOPS", &net_number_of_desktops
},
143 {"_NET_DESKTOP_GEOMETRY", &net_desktop_geometry
},
144 {"_NET_DESKTOP_VIEWPORT", &net_desktop_viewport
},
145 {"_NET_CURRENT_DESKTOP", &net_current_desktop
},
146 {"_NET_DESKTOP_NAMES", &net_desktop_names
},
147 {"_NET_ACTIVE_WINDOW", &net_active_window
},
148 {"_NET_SUPPORTING_WM_CHECK", &net_supporting_wm_check
},
149 {"_NET_VIRTUAL_ROOTS", &net_virtual_roots
},
150 {"_NET_DESKTOP_LAYOUT", &net_desktop_layout
},
151 {"_NET_SHOWING_DESKTOP", &net_showing_desktop
},
153 {"_NET_CLOSE_WINDOW", &net_close_window
},
154 {"_NET_MOVERESIZE_WINDOW", &net_moveresize_window
},
155 {"_NET_WM_MOVERESIZE", &net_wm_moveresize
},
157 {"_NET_WM_NAME", &net_wm_name
},
158 {"_NET_WM_VISIBLE_NAME", &net_wm_visible_name
},
159 {"_NET_WM_ICON_NAME", &net_wm_icon_name
},
160 {"_NET_WM_VISIBLE_ICON_NAME", &net_wm_visible_icon_name
},
161 {"_NET_WM_DESKTOP", &net_wm_desktop
},
162 {"_NET_WM_WINDOW_TYPE", &net_wm_window_type
},
163 {"_NET_WM_WINDOW_TYPE_DESKTOP", &net_wm_window_type_desktop
},
164 {"_NET_WM_WINDOW_TYPE_DOCK", &net_wm_window_type_dock
},
165 {"_NET_WM_WINDOW_TYPE_TOOLBAR", &net_wm_window_type_toolbar
},
166 {"_NET_WM_WINDOW_TYPE_MENU", &net_wm_window_type_menu
},
167 {"_NET_WM_WINDOW_TYPE_UTILITY", &net_wm_window_type_utility
},
168 {"_NET_WM_WINDOW_TYPE_SPLASH", &net_wm_window_type_splash
},
169 {"_NET_WM_WINDOW_TYPE_DIALOG", &net_wm_window_type_dialog
},
170 {"_NET_WM_WINDOW_TYPE_DROPDOWN_MENU", &net_wm_window_type_dropdown_menu
},
171 {"_NET_WM_WINDOW_TYPE_POPUP_MENU", &net_wm_window_type_popup_menu
},
172 {"_NET_WM_WINDOW_TYPE_TOOLTIP", &net_wm_window_type_tooltip
},
173 {"_NET_WM_WINDOW_TYPE_NOTIFICATION", &net_wm_window_type_notification
},
174 {"_NET_WM_WINDOW_TYPE_COMBO", &net_wm_window_type_combo
},
175 {"_NET_WM_WINDOW_TYPE_DND", &net_wm_window_type_dnd
},
176 {"_NET_WM_WINDOW_TYPE_NORMAL", &net_wm_window_type_normal
},
177 {"_NET_WM_STATE", &net_wm_state
},
178 {"_NET_WM_STATE_MODAL", &net_wm_state_modal
},
179 {"_NET_WM_STATE_STICKY", &net_wm_state_sticky
},
180 {"_NET_WM_STATE_MAXIMIZED_VERT", &net_wm_state_maximized_vert
},
181 {"_NET_WM_STATE_MAXIMIZED_HORZ", &net_wm_state_maximized_horz
},
182 {"_NET_WM_STATE_SHADED", &net_wm_state_shaded
},
183 {"_NET_WM_STATE_SKIP_TASKBAR", &net_wm_state_skip_taskbar
},
184 {"_NET_WM_STATE_SKIP_PAGER", &net_wm_state_skip_pager
},
185 {"_NET_WM_STATE_HIDDEN", &net_wm_state_hidden
},
186 {"_NET_WM_STATE_FULLSCREEN", &net_wm_state_fullscreen
},
187 {"_NET_WM_STATE_ABOVE", &net_wm_state_above
},
188 {"_NET_WM_STATE_BELOW", &net_wm_state_below
},
189 {"_NET_WM_ALLOWED_ACTIONS", &net_wm_allowed_actions
},
190 {"_NET_WM_ACTION_MOVE", &net_wm_action_move
},
191 {"_NET_WM_ACTION_RESIZE", &net_wm_action_resize
},
192 {"_NET_WM_ACTION_MINIMIZE", &net_wm_action_minimize
},
193 {"_NET_WM_ACTION_SHADE", &net_wm_action_shade
},
194 {"_NET_WM_ACTION_STICK", &net_wm_action_stick
},
195 {"_NET_WM_ACTION_MAXIMIZE_HORZ", &net_wm_action_maximize_horz
},
196 {"_NET_WM_ACTION_MAXIMIZE_VERT", &net_wm_action_maximize_vert
},
197 {"_NET_WM_ACTION_FULLSCREEN", &net_wm_action_fullscreen
},
198 {"_NET_WM_ACTION_CHANGE_DESKTOP", &net_wm_action_change_desktop
},
199 {"_NET_WM_ACTION_CLOSE", &net_wm_action_close
},
200 {"_NET_WM_STRUT", &net_wm_strut
},
201 {"_NET_WM_STRUT_PARTIAL", &net_wm_strut_partial
},
202 {"_NET_WM_ICON_GEOMETRY", &net_wm_icon_geometry
},
203 {"_NET_WM_ICON", &net_wm_icon
},
204 {"_NET_WM_PID", &net_wm_pid
},
205 {"_NET_WM_HANDLED_ICONS", &net_wm_handled_icons
},
206 {"_NET_WM_WINDOW_OPACITY", &net_wm_window_opacity
},
208 {"_NET_FRAME_EXTENTS", &net_frame_extents
},
210 {"_NET_WM_PING", &net_wm_ping
},
212 {"UTF8_STRING", &utf8_string
},
215 #define _NET_WM_STATE_REMOVE 0
216 #define _NET_WM_STATE_ADD 1
217 #define _NET_WM_STATE_TOGGLE 2
219 #define _NET_WM_MOVERESIZE_SIZE_TOPLEFT 0
220 #define _NET_WM_MOVERESIZE_SIZE_TOP 1
221 #define _NET_WM_MOVERESIZE_SIZE_TOPRIGHT 2
222 #define _NET_WM_MOVERESIZE_SIZE_RIGHT 3
223 #define _NET_WM_MOVERESIZE_SIZE_BOTTOMRIGHT 4
224 #define _NET_WM_MOVERESIZE_SIZE_BOTTOM 5
225 #define _NET_WM_MOVERESIZE_SIZE_BOTTOMLEFT 6
226 #define _NET_WM_MOVERESIZE_SIZE_LEFT 7
227 #define _NET_WM_MOVERESIZE_MOVE 8 /* movement only */
228 #define _NET_WM_MOVERESIZE_SIZE_KEYBOARD 9 /* size via keyboard */
229 #define _NET_WM_MOVERESIZE_MOVE_KEYBOARD 10 /* move via keyboard */
231 static void observer(void *self
, WMNotification
*notif
);
232 static void wsobserver(void *self
, WMNotification
*notif
);
234 static void updateClientList(WScreen
*scr
);
235 static void updateClientListStacking(WScreen
*scr
, WWindow
*);
237 static void updateWorkspaceNames(WScreen
*scr
);
238 static void updateCurrentWorkspace(WScreen
*scr
);
239 static void updateWorkspaceCount(WScreen
*scr
);
240 static void wNETWMShowingDesktop(WScreen
*scr
, Bool show
);
242 typedef struct NetData
{
244 WReservedArea
*strut
;
245 WWindow
**show_desktop
;
248 static void setSupportedHints(WScreen
*scr
)
250 Atom atom
[wlengthof(atomNames
)];
253 /* set supported hints list */
254 /* XXX: extend this !!! */
256 atom
[i
++] = net_client_list
;
257 atom
[i
++] = net_client_list_stacking
;
258 atom
[i
++] = net_number_of_desktops
;
259 atom
[i
++] = net_desktop_geometry
;
260 atom
[i
++] = net_desktop_viewport
;
261 atom
[i
++] = net_current_desktop
;
262 atom
[i
++] = net_desktop_names
;
263 atom
[i
++] = net_active_window
;
264 atom
[i
++] = net_supporting_wm_check
;
265 atom
[i
++] = net_showing_desktop
;
267 atom
[i
++] = net_wm_moveresize
;
269 atom
[i
++] = net_wm_desktop
;
270 atom
[i
++] = net_wm_window_type
;
271 atom
[i
++] = net_wm_window_type_desktop
;
272 atom
[i
++] = net_wm_window_type_dock
;
273 atom
[i
++] = net_wm_window_type_toolbar
;
274 atom
[i
++] = net_wm_window_type_menu
;
275 atom
[i
++] = net_wm_window_type_utility
;
276 atom
[i
++] = net_wm_window_type_splash
;
277 atom
[i
++] = net_wm_window_type_dialog
;
278 atom
[i
++] = net_wm_window_type_dropdown_menu
;
279 atom
[i
++] = net_wm_window_type_popup_menu
;
280 atom
[i
++] = net_wm_window_type_tooltip
;
281 atom
[i
++] = net_wm_window_type_notification
;
282 atom
[i
++] = net_wm_window_type_combo
;
283 atom
[i
++] = net_wm_window_type_dnd
;
284 atom
[i
++] = net_wm_window_type_normal
;
286 atom
[i
++] = net_wm_state
;
287 /* atom[i++] = net_wm_state_modal; *//* XXX: not sure where/when to use it. */
288 atom
[i
++] = net_wm_state_sticky
;
289 atom
[i
++] = net_wm_state_shaded
;
290 atom
[i
++] = net_wm_state_maximized_horz
;
291 atom
[i
++] = net_wm_state_maximized_vert
;
292 atom
[i
++] = net_wm_state_skip_taskbar
;
293 atom
[i
++] = net_wm_state_skip_pager
;
294 atom
[i
++] = net_wm_state_hidden
;
295 atom
[i
++] = net_wm_state_fullscreen
;
296 atom
[i
++] = net_wm_state_above
;
297 atom
[i
++] = net_wm_state_below
;
299 atom
[i
++] = net_wm_allowed_actions
;
300 atom
[i
++] = net_wm_action_move
;
301 atom
[i
++] = net_wm_action_resize
;
302 atom
[i
++] = net_wm_action_minimize
;
303 atom
[i
++] = net_wm_action_shade
;
304 atom
[i
++] = net_wm_action_stick
;
305 atom
[i
++] = net_wm_action_maximize_horz
;
306 atom
[i
++] = net_wm_action_maximize_vert
;
307 atom
[i
++] = net_wm_action_fullscreen
;
308 atom
[i
++] = net_wm_action_change_desktop
;
309 atom
[i
++] = net_wm_action_close
;
311 atom
[i
++] = net_wm_strut
;
312 atom
[i
++] = net_wm_icon_geometry
;
313 atom
[i
++] = net_wm_icon
;
314 atom
[i
++] = net_wm_handled_icons
;
315 atom
[i
++] = net_wm_window_opacity
;
317 atom
[i
++] = net_frame_extents
;
319 atom
[i
++] = net_wm_name
;
320 atom
[i
++] = net_wm_icon_name
;
322 XChangeProperty(dpy
, scr
->root_win
, net_supported
, XA_ATOM
, 32, PropModeReplace
, (unsigned char *)atom
, i
);
324 /* set supporting wm hint */
325 XChangeProperty(dpy
, scr
->root_win
, net_supporting_wm_check
, XA_WINDOW
, 32,
326 PropModeReplace
, (unsigned char *)&scr
->info_window
, 1);
328 XChangeProperty(dpy
, scr
->info_window
, net_supporting_wm_check
, XA_WINDOW
,
329 32, PropModeReplace
, (unsigned char *)&scr
->info_window
, 1);
332 void wNETWMUpdateDesktop(WScreen
*scr
)
334 long *views
, sizes
[2];
337 if (w_global
.workspace
.count
== 0)
340 count
= w_global
.workspace
.count
* 2;
341 views
= wmalloc(sizeof(long) * count
);
342 /*memset(views, 0, sizeof(long) * count); */
343 sizes
[0] = scr
->scr_width
;
344 sizes
[1] = scr
->scr_height
;
346 for (i
= 0; i
< w_global
.workspace
.count
; i
++) {
347 views
[2 * i
+ 0] = 0;
348 views
[2 * i
+ 1] = 0;
351 XChangeProperty(dpy
, scr
->root_win
, net_desktop_geometry
, XA_CARDINAL
, 32,
352 PropModeReplace
, (unsigned char *)sizes
, 2);
354 XChangeProperty(dpy
, scr
->root_win
, net_desktop_viewport
, XA_CARDINAL
, 32,
355 PropModeReplace
, (unsigned char *)views
, count
);
360 int wNETWMGetCurrentDesktopFromHint(WScreen
*scr
)
365 prop
= PropGetCheckProperty(scr
->root_win
, net_current_desktop
, XA_CARDINAL
, 0, 1, &count
);
367 int desktop
= *(long *)prop
;
375 * Find the best icon to be used by Window Maker for appicon/miniwindows.
376 * Currently the algorithm is to take the image with the size closest
377 * to icon_size x icon_size, but never bigger than that.
379 * This algorithm is very poorly implemented and needs to be redone (it can
380 * easily select images with very large widths and very small heights over
381 * square images, if the area of the former is closer to the desired one).
383 * The logic can also be changed to accept bigger images and scale them down.
385 static unsigned long *findBestIcon(unsigned long *data
, unsigned long items
)
388 unsigned long i
, distance
;
391 /* better use only 75% of icon_size. For 64x64 this means 48x48
392 * This leaves room around the icon for the miniwindow title and
393 * results in better overall aesthetics -Dan */
394 wanted
= wPreferences
.icon_size
* wPreferences
.icon_size
;
396 for (icon
= NULL
, distance
= wanted
, i
= 0L; i
< items
- 1;) {
397 size
= data
[i
] * data
[i
+ 1];
401 if (d
>= 0 && d
<= distance
&& (i
+ size
+ 2) <= items
) {
411 static RImage
*makeRImageFromARGBData(unsigned long *data
)
413 int size
, width
, height
, i
;
415 unsigned char *imgdata
;
420 size
= width
* height
;
425 image
= RCreateImage(width
, height
, True
);
427 for (imgdata
= image
->data
, i
= 2; i
< size
+ 2; i
++, imgdata
+= 4) {
429 imgdata
[3] = (pixel
>> 24) & 0xff; /* A */
430 imgdata
[0] = (pixel
>> 16) & 0xff; /* R */
431 imgdata
[1] = (pixel
>> 8) & 0xff; /* G */
432 imgdata
[2] = (pixel
>> 0) & 0xff; /* B */
438 RImage
*get_window_image_from_x11(Window window
)
443 unsigned long items
, rest
;
444 unsigned long *property
, *data
;
446 /* Get the icon from X11 Window */
447 if (XGetWindowProperty(dpy
, window
, net_wm_icon
, 0L, LONG_MAX
,
448 False
, XA_CARDINAL
, &type
, &format
, &items
, &rest
,
449 (unsigned char **)&property
) != Success
|| !property
)
452 if (type
!= XA_CARDINAL
|| format
!= 32 || items
< 2) {
457 /* Find the best icon */
458 data
= findBestIcon(property
, items
);
464 /* Save the best icon in the X11 icon */
465 image
= makeRImageFromARGBData(data
);
469 /* Resize the image to the correct value */
470 image
= wIconValidateIconSize(image
, wPreferences
.icon_size
);
475 static void updateIconImage(WWindow
*wwin
)
477 /* Remove the icon image from X11 */
478 if (wwin
->net_icon_image
)
479 RReleaseImage(wwin
->net_icon_image
);
481 /* Save the icon in the X11 icon */
482 wwin
->net_icon_image
= get_window_image_from_x11(wwin
->client_win
);
484 /* Refresh the Window Icon */
486 wIconUpdate(wwin
->icon
);
488 /* Refresh the application icon */
489 WApplication
*app
= wApplicationOf(wwin
->main_window
);
490 if (app
&& app
->app_icon
) {
491 wIconUpdate(app
->app_icon
->icon
);
492 wAppIconPaint(app
->app_icon
);
496 static void updateWindowOpacity(WWindow
*wwin
)
500 unsigned long items
, rest
;
501 unsigned long *property
;
506 /* We don't care about this ourselves, but other programs need us to copy
507 * this to the frame window. */
508 if (XGetWindowProperty(dpy
, wwin
->client_win
, net_wm_window_opacity
, 0L, 1L,
509 False
, XA_CARDINAL
, &type
, &format
, &items
, &rest
,
510 (unsigned char **)&property
) != Success
)
514 XDeleteProperty(dpy
, wwin
->frame
->core
->window
, net_wm_window_opacity
);
515 } else if (type
== XA_CARDINAL
&& format
== 32 && items
== 1 && property
) {
516 XChangeProperty(dpy
, wwin
->frame
->core
->window
, net_wm_window_opacity
,
517 XA_CARDINAL
, 32, PropModeReplace
, (unsigned char *)property
, 1L);
524 static void updateShowDesktop(WScreen
*scr
, Bool show
)
528 foo
= (show
== True
);
529 XChangeProperty(dpy
, scr
->root_win
, net_showing_desktop
, XA_CARDINAL
, 32,
530 PropModeReplace
, (unsigned char *)&foo
, 1);
533 static void wNETWMShowingDesktop(WScreen
*scr
, Bool show
)
535 if (show
&& scr
->netdata
->show_desktop
== NULL
) {
536 WWindow
*tmp
, **wins
;
539 wins
= (WWindow
**) wmalloc(sizeof(WWindow
*) * (scr
->window_count
+ 1));
541 tmp
= scr
->focused_window
;
543 if (!tmp
->flags
.hidden
&& !tmp
->flags
.miniaturized
&& !WFLAGP(tmp
, skip_window_list
)) {
546 tmp
->flags
.skip_next_animation
= 1;
547 tmp
->flags
.net_show_desktop
= 1;
555 scr
->netdata
->show_desktop
= wins
;
556 updateShowDesktop(scr
, True
);
557 } else if (scr
->netdata
->show_desktop
!= NULL
) {
558 /* FIXME: get rid of workspace flashing ! */
559 int ws
= w_global
.workspace
.current
;
561 for (tmp
= scr
->netdata
->show_desktop
; *tmp
; ++tmp
) {
562 wDeiconifyWindow(*tmp
);
563 (*tmp
)->flags
.net_show_desktop
= 0;
565 if (ws
!= w_global
.workspace
.current
)
566 wWorkspaceChange(scr
, ws
);
567 wfree(scr
->netdata
->show_desktop
);
568 scr
->netdata
->show_desktop
= NULL
;
569 updateShowDesktop(scr
, False
);
573 void wNETWMInitStuff(WScreen
*scr
)
579 wmessage("wNETWMInitStuff");
582 #ifdef HAVE_XINTERNATOMS
584 Atom atoms
[wlengthof(atomNames
)];
585 char *names
[wlengthof(atomNames
)];
587 for (i
= 0; i
< wlengthof(atomNames
); ++i
)
588 names
[i
] = atomNames
[i
].name
;
590 XInternAtoms(dpy
, &names
[0], wlengthof(atomNames
), False
, atoms
);
591 for (i
= 0; i
< wlengthof(atomNames
); ++i
)
592 *atomNames
[i
].atom
= atoms
[i
];
596 for (i
= 0; i
< wlengthof(atomNames
); i
++)
597 *atomNames
[i
].atom
= XInternAtom(dpy
, atomNames
[i
].name
, False
);
600 data
= wmalloc(sizeof(NetData
));
603 data
->show_desktop
= NULL
;
607 setSupportedHints(scr
);
609 WMAddNotificationObserver(observer
, data
, WMNManaged
, NULL
);
610 WMAddNotificationObserver(observer
, data
, WMNUnmanaged
, NULL
);
611 WMAddNotificationObserver(observer
, data
, WMNChangedWorkspace
, NULL
);
612 WMAddNotificationObserver(observer
, data
, WMNChangedState
, NULL
);
613 WMAddNotificationObserver(observer
, data
, WMNChangedFocus
, NULL
);
614 WMAddNotificationObserver(observer
, data
, WMNChangedStacking
, NULL
);
615 WMAddNotificationObserver(observer
, data
, WMNChangedName
, NULL
);
617 WMAddNotificationObserver(wsobserver
, data
, WMNWorkspaceCreated
, NULL
);
618 WMAddNotificationObserver(wsobserver
, data
, WMNWorkspaceDestroyed
, NULL
);
619 WMAddNotificationObserver(wsobserver
, data
, WMNWorkspaceChanged
, NULL
);
620 WMAddNotificationObserver(wsobserver
, data
, WMNWorkspaceNameChanged
, NULL
);
622 updateClientList(scr
);
623 updateClientListStacking(scr
, NULL
);
624 updateWorkspaceCount(scr
);
625 updateWorkspaceNames(scr
);
626 updateShowDesktop(scr
, False
);
628 wScreenUpdateUsableArea(scr
);
631 void wNETWMCleanup(WScreen
*scr
)
635 for (i
= 0; i
< wlengthof(atomNames
); i
++)
636 XDeleteProperty(dpy
, scr
->root_win
, *atomNames
[i
].atom
);
639 void wNETWMUpdateActions(WWindow
*wwin
, Bool del
)
641 Atom action
[10]; /* nr of actions atoms defined */
645 XDeleteProperty(dpy
, wwin
->client_win
, net_wm_allowed_actions
);
649 if (IS_MOVABLE(wwin
))
650 action
[i
++] = net_wm_action_move
;
652 if (IS_RESIZABLE(wwin
))
653 action
[i
++] = net_wm_action_resize
;
655 if (!WFLAGP(wwin
, no_miniaturizable
))
656 action
[i
++] = net_wm_action_minimize
;
658 if (!WFLAGP(wwin
, no_shadeable
))
659 action
[i
++] = net_wm_action_shade
;
661 /* if (!WFLAGP(wwin, no_stickable)) */
662 action
[i
++] = net_wm_action_stick
;
664 /* if (!(WFLAGP(wwin, no_maximizeable) & MAX_HORIZONTAL)) */
665 if (IS_RESIZABLE(wwin
))
666 action
[i
++] = net_wm_action_maximize_horz
;
668 /* if (!(WFLAGP(wwin, no_maximizeable) & MAX_VERTICAL)) */
669 if (IS_RESIZABLE(wwin
))
670 action
[i
++] = net_wm_action_maximize_vert
;
672 /* if (!WFLAGP(wwin, no_fullscreen)) */
673 action
[i
++] = net_wm_action_fullscreen
;
675 /* if (!WFLAGP(wwin, no_change_desktop)) */
676 action
[i
++] = net_wm_action_change_desktop
;
678 if (!WFLAGP(wwin
, no_closable
))
679 action
[i
++] = net_wm_action_close
;
681 XChangeProperty(dpy
, wwin
->client_win
, net_wm_allowed_actions
,
682 XA_ATOM
, 32, PropModeReplace
, (unsigned char *)action
, i
);
685 Bool
wNETWMGetUsableArea(WScreen
*scr
, int head
, WArea
*area
)
690 if (!scr
->netdata
|| !scr
->netdata
->strut
)
693 area
->x1
= area
->y1
= area
->x2
= area
->y2
= 0;
695 for (cur
= scr
->netdata
->strut
; cur
; cur
= cur
->next
) {
696 WWindow
*wwin
= wWindowFor(cur
->window
);
697 if (wWindowTouchesHead(wwin
, head
)) {
698 if (cur
->area
.x1
> area
->x1
)
699 area
->x1
= cur
->area
.x1
;
700 if (cur
->area
.y1
> area
->y1
)
701 area
->y1
= cur
->area
.y1
;
702 if (cur
->area
.x2
> area
->x2
)
703 area
->x2
= cur
->area
.x2
;
704 if (cur
->area
.y2
> area
->y2
)
705 area
->y2
= cur
->area
.y2
;
709 if (area
->x1
== 0 && area
->x2
== 0 && area
->y1
== 0 && area
->y2
== 0)
712 rect
= wGetRectForHead(scr
, head
);
714 area
->x1
= rect
.pos
.x
+ area
->x1
;
715 area
->x2
= rect
.pos
.x
+ rect
.size
.width
- area
->x2
;
716 area
->y1
= rect
.pos
.y
+ area
->y1
;
717 area
->y2
= rect
.pos
.y
+ rect
.size
.height
- area
->y2
;
722 static void updateClientList(WScreen
*scr
)
728 windows
= (Window
*) wmalloc(sizeof(Window
) * (scr
->window_count
+ 1));
731 wwin
= scr
->focused_window
;
733 windows
[count
++] = wwin
->client_win
;
736 XChangeProperty(dpy
, scr
->root_win
, net_client_list
, XA_WINDOW
, 32,
737 PropModeReplace
, (unsigned char *)windows
, count
);
743 static void updateClientListStacking(WScreen
*scr
, WWindow
*wwin_excl
)
746 Window
*client_list
, *client_list_reverse
;
751 /* update client list */
752 i
= scr
->window_count
+ 1;
753 client_list
= (Window
*) wmalloc(sizeof(Window
) * i
);
754 client_list_reverse
= (Window
*) wmalloc(sizeof(Window
) * i
);
757 WM_ETARETI_BAG(scr
->stacking_list
, tmp
, iter
) {
759 wwin
= wWindowFor(tmp
->window
);
760 /* wwin_excl is a window to exclude from the list
761 (e.g. it's now unmanaged) */
762 if (wwin
&& (wwin
!= wwin_excl
))
763 client_list
[client_count
++] = wwin
->client_win
;
764 tmp
= tmp
->stacking
->under
;
768 for (i
= 0; i
< client_count
; i
++) {
769 Window w
= client_list
[client_count
- i
- 1];
770 client_list_reverse
[i
] = w
;
773 XChangeProperty(dpy
, scr
->root_win
, net_client_list_stacking
, XA_WINDOW
, 32,
774 PropModeReplace
, (unsigned char *)client_list_reverse
, client_count
);
777 wfree(client_list_reverse
);
782 static void updateWorkspaceCount(WScreen
*scr
)
786 count
= w_global
.workspace
.count
;
788 XChangeProperty(dpy
, scr
->root_win
, net_number_of_desktops
, XA_CARDINAL
,
789 32, PropModeReplace
, (unsigned char *)&count
, 1);
792 static void updateCurrentWorkspace(WScreen
*scr
)
796 count
= w_global
.workspace
.current
;
798 XChangeProperty(dpy
, scr
->root_win
, net_current_desktop
, XA_CARDINAL
, 32,
799 PropModeReplace
, (unsigned char *)&count
, 1);
802 static void updateWorkspaceNames(WScreen
*scr
)
804 char buf
[MAX_WORKSPACES
* (MAX_WORKSPACENAME_WIDTH
+ 1)], *pos
;
805 unsigned int i
, len
, curr_size
;
809 for (i
= 0; i
< w_global
.workspace
.count
; i
++) {
810 curr_size
= strlen(w_global
.workspace
.array
[i
]->name
);
811 strcpy(pos
, w_global
.workspace
.array
[i
]->name
);
812 pos
+= (curr_size
+ 1);
813 len
+= (curr_size
+ 1);
816 XChangeProperty(dpy
, scr
->root_win
, net_desktop_names
, utf8_string
, 8,
817 PropModeReplace
, (unsigned char *)buf
, len
);
820 static void updateFocusHint(WScreen
*scr
)
824 if (!scr
->focused_window
|| !scr
->focused_window
->flags
.focused
)
827 window
= scr
->focused_window
->client_win
;
829 XChangeProperty(dpy
, scr
->root_win
, net_active_window
, XA_WINDOW
, 32,
830 PropModeReplace
, (unsigned char *)&window
, 1);
833 static void updateWorkspaceHint(WWindow
*wwin
, Bool fake
, Bool del
)
838 XDeleteProperty(dpy
, wwin
->client_win
, net_wm_desktop
);
840 l
= ((fake
|| IS_OMNIPRESENT(wwin
)) ? -1 : wwin
->frame
->workspace
);
841 XChangeProperty(dpy
, wwin
->client_win
, net_wm_desktop
, XA_CARDINAL
,
842 32, PropModeReplace
, (unsigned char *)&l
, 1);
846 static void updateStateHint(WWindow
*wwin
, Bool changedWorkspace
, Bool del
)
849 XDeleteProperty(dpy
, wwin
->client_win
, net_wm_state
);
851 Atom state
[15]; /* nr of defined state atoms */
854 if (changedWorkspace
|| (wPreferences
.sticky_icons
&& !IS_OMNIPRESENT(wwin
)))
855 updateWorkspaceHint(wwin
, False
, False
);
857 if (IS_OMNIPRESENT(wwin
))
858 state
[i
++] = net_wm_state_sticky
;
859 if (wwin
->flags
.shaded
)
860 state
[i
++] = net_wm_state_shaded
;
861 if (wwin
->flags
.maximized
& MAX_HORIZONTAL
)
862 state
[i
++] = net_wm_state_maximized_horz
;
863 if (wwin
->flags
.maximized
& MAX_VERTICAL
)
864 state
[i
++] = net_wm_state_maximized_vert
;
865 if (WFLAGP(wwin
, skip_window_list
))
866 state
[i
++] = net_wm_state_skip_taskbar
;
867 if (wwin
->flags
.net_skip_pager
)
868 state
[i
++] = net_wm_state_skip_pager
;
869 if ((wwin
->flags
.hidden
|| wwin
->flags
.miniaturized
) && !wwin
->flags
.net_show_desktop
) {
870 state
[i
++] = net_wm_state_hidden
;
871 state
[i
++] = net_wm_state_skip_pager
;
873 if (wwin
->flags
.miniaturized
&& wPreferences
.sticky_icons
) {
874 if (!IS_OMNIPRESENT(wwin
))
875 updateWorkspaceHint(wwin
, True
, False
);
876 state
[i
++] = net_wm_state_sticky
;
879 if (WFLAGP(wwin
, sunken
))
880 state
[i
++] = net_wm_state_below
;
881 if (WFLAGP(wwin
, floating
))
882 state
[i
++] = net_wm_state_above
;
883 if (wwin
->flags
.fullscreen
)
884 state
[i
++] = net_wm_state_fullscreen
;
886 XChangeProperty(dpy
, wwin
->client_win
, net_wm_state
, XA_ATOM
, 32,
887 PropModeReplace
, (unsigned char *)state
, i
);
891 static Bool
updateStrut(WScreen
*scr
, Window w
, Bool adding
)
894 Bool hasState
= False
;
899 unsigned long nitems_ret
, bytes_after_ret
;
902 if ((XGetWindowProperty(dpy
, w
, net_wm_strut
, 0, 4, False
,
903 XA_CARDINAL
, &type_ret
, &fmt_ret
, &nitems_ret
,
904 &bytes_after_ret
, (unsigned char **)&data
) == Success
&& data
) ||
905 ((XGetWindowProperty(dpy
, w
, net_wm_strut_partial
, 0, 12, False
,
906 XA_CARDINAL
, &type_ret
, &fmt_ret
, &nitems_ret
,
907 &bytes_after_ret
, (unsigned char **)&data
) == Success
&& data
))) {
909 /* XXX: This is strictly incorrect in the case of net_wm_strut_partial...
910 * Discard the start and end properties from the partial strut and treat it as
911 * a (deprecated) strut.
912 * This means we are marking the whole width or height of the screen as
913 * reserved, which is not necessarily what the strut defines. However for the
914 * purposes of determining placement or maximization it's probably good enough.
916 area
= (WReservedArea
*) wmalloc(sizeof(WReservedArea
));
917 area
->area
.x1
= data
[0];
918 area
->area
.x2
= data
[1];
919 area
->area
.y1
= data
[2];
920 area
->area
.y2
= data
[3];
924 area
->next
= scr
->netdata
->strut
;
925 scr
->netdata
->strut
= area
;
932 area
= scr
->netdata
->strut
;
935 if (area
->window
== w
) {
936 scr
->netdata
->strut
= area
->next
;
940 while (area
->next
&& area
->next
->window
!= w
)
946 next
= area
->next
->next
;
959 static int getWindowLayer(WWindow
*wwin
)
961 int layer
= WMNormalLevel
;
963 if (wwin
->type
== net_wm_window_type_desktop
) {
964 layer
= WMDesktopLevel
;
965 } else if (wwin
->type
== net_wm_window_type_dock
) {
967 } else if (wwin
->type
== net_wm_window_type_toolbar
) {
968 layer
= WMMainMenuLevel
;
969 } else if (wwin
->type
== net_wm_window_type_menu
) {
970 layer
= WMSubmenuLevel
;
971 } else if (wwin
->type
== net_wm_window_type_utility
) {
972 } else if (wwin
->type
== net_wm_window_type_splash
) {
973 } else if (wwin
->type
== net_wm_window_type_dialog
) {
974 if (wwin
->transient_for
) {
975 WWindow
*parent
= wWindowFor(wwin
->transient_for
);
976 if (parent
&& parent
->flags
.fullscreen
)
977 layer
= WMNormalLevel
;
979 /* //layer = WMPopUpLevel; // this seems a bad idea -Dan */
980 } else if (wwin
->type
== net_wm_window_type_dropdown_menu
) {
981 layer
= WMSubmenuLevel
;
982 } else if (wwin
->type
== net_wm_window_type_popup_menu
) {
983 layer
= WMSubmenuLevel
;
984 } else if (wwin
->type
== net_wm_window_type_tooltip
) {
985 } else if (wwin
->type
== net_wm_window_type_notification
) {
986 layer
= WMPopUpLevel
;
987 } else if (wwin
->type
== net_wm_window_type_combo
) {
988 layer
= WMSubmenuLevel
;
989 } else if (wwin
->type
== net_wm_window_type_dnd
) {
990 } else if (wwin
->type
== net_wm_window_type_normal
) {
993 if (wwin
->client_flags
.sunken
&& WMSunkenLevel
< layer
)
994 layer
= WMSunkenLevel
;
995 if (wwin
->client_flags
.floating
&& WMFloatingLevel
> layer
)
996 layer
= WMFloatingLevel
;
1001 static void doStateAtom(WWindow
*wwin
, Atom state
, int set
, Bool init
)
1003 if (state
== net_wm_state_sticky
) {
1004 if (set
== _NET_WM_STATE_TOGGLE
)
1005 set
= !IS_OMNIPRESENT(wwin
);
1007 if (set
!= wwin
->flags
.omnipresent
)
1008 wWindowSetOmnipresent(wwin
, set
);
1010 } else if (state
== net_wm_state_shaded
) {
1011 if (set
== _NET_WM_STATE_TOGGLE
)
1012 set
= !wwin
->flags
.shaded
;
1015 wwin
->flags
.shaded
= set
;
1020 wUnshadeWindow(wwin
);
1022 } else if (state
== net_wm_state_skip_taskbar
) {
1023 if (set
== _NET_WM_STATE_TOGGLE
)
1024 set
= !wwin
->client_flags
.skip_window_list
;
1026 wwin
->client_flags
.skip_window_list
= set
;
1027 } else if (state
== net_wm_state_skip_pager
) {
1028 if (set
== _NET_WM_STATE_TOGGLE
)
1029 set
= !wwin
->flags
.net_skip_pager
;
1031 wwin
->flags
.net_skip_pager
= set
;
1032 } else if (state
== net_wm_state_maximized_vert
) {
1033 if (set
== _NET_WM_STATE_TOGGLE
)
1034 set
= !(wwin
->flags
.maximized
& MAX_VERTICAL
);
1037 wwin
->flags
.maximized
|= (set
? MAX_VERTICAL
: 0);
1040 wMaximizeWindow(wwin
, wwin
->flags
.maximized
| MAX_VERTICAL
);
1042 wMaximizeWindow(wwin
, wwin
->flags
.maximized
& ~MAX_VERTICAL
);
1044 } else if (state
== net_wm_state_maximized_horz
) {
1045 if (set
== _NET_WM_STATE_TOGGLE
)
1046 set
= !(wwin
->flags
.maximized
& MAX_HORIZONTAL
);
1049 wwin
->flags
.maximized
|= (set
? MAX_HORIZONTAL
: 0);
1052 wMaximizeWindow(wwin
, wwin
->flags
.maximized
| MAX_HORIZONTAL
);
1054 wMaximizeWindow(wwin
, wwin
->flags
.maximized
& ~MAX_HORIZONTAL
);
1056 } else if (state
== net_wm_state_hidden
) {
1057 if (set
== _NET_WM_STATE_TOGGLE
)
1058 set
= !(wwin
->flags
.miniaturized
);
1061 wwin
->flags
.miniaturized
= set
;
1064 wIconifyWindow(wwin
);
1066 wDeiconifyWindow(wwin
);
1068 } else if (state
== net_wm_state_fullscreen
) {
1069 if (set
== _NET_WM_STATE_TOGGLE
)
1070 set
= !(wwin
->flags
.fullscreen
);
1073 wwin
->flags
.fullscreen
= set
;
1076 wFullscreenWindow(wwin
);
1078 wUnfullscreenWindow(wwin
);
1080 } else if (state
== net_wm_state_above
) {
1081 if (set
== _NET_WM_STATE_TOGGLE
)
1082 set
= !(wwin
->client_flags
.floating
);
1085 wwin
->client_flags
.floating
= set
;
1087 wwin
->client_flags
.floating
= set
;
1088 ChangeStackingLevel(wwin
->frame
->core
, getWindowLayer(wwin
));
1091 } else if (state
== net_wm_state_below
) {
1092 if (set
== _NET_WM_STATE_TOGGLE
)
1093 set
= !(wwin
->client_flags
.sunken
);
1096 wwin
->client_flags
.sunken
= set
;
1098 wwin
->client_flags
.sunken
= set
;
1099 ChangeStackingLevel(wwin
->frame
->core
, getWindowLayer(wwin
));
1104 wmessage("doStateAtom unknown atom %s set %d\n", XGetAtomName(dpy
, state
), set
);
1109 static void removeIcon(WWindow
*wwin
)
1111 if (wwin
->icon
== NULL
)
1113 if (wwin
->flags
.miniaturized
&& wwin
->icon
->mapped
) {
1114 XUnmapWindow(dpy
, wwin
->icon
->core
->window
);
1115 RemoveFromStackList(wwin
->icon
->core
);
1116 wIconDestroy(wwin
->icon
);
1121 static Bool
handleWindowType(WWindow
*wwin
, Atom type
, int *layer
)
1125 if (type
== net_wm_window_type_desktop
) {
1126 wwin
->client_flags
.no_titlebar
= 1;
1127 wwin
->client_flags
.no_resizable
= 1;
1128 wwin
->client_flags
.no_miniaturizable
= 1;
1129 wwin
->client_flags
.no_border
= 1;
1130 wwin
->client_flags
.no_resizebar
= 1;
1131 wwin
->client_flags
.no_shadeable
= 1;
1132 wwin
->client_flags
.no_movable
= 1;
1133 wwin
->client_flags
.omnipresent
= 1;
1134 wwin
->client_flags
.skip_window_list
= 1;
1135 wwin
->client_flags
.skip_switchpanel
= 1;
1136 wwin
->client_flags
.dont_move_off
= 1;
1137 wwin
->client_flags
.no_appicon
= 1;
1138 wwin
->flags
.net_skip_pager
= 1;
1141 } else if (type
== net_wm_window_type_dock
) {
1142 wwin
->client_flags
.no_titlebar
= 1;
1143 wwin
->client_flags
.no_resizable
= 1;
1144 wwin
->client_flags
.no_miniaturizable
= 1;
1145 wwin
->client_flags
.no_border
= 1; /* XXX: really not a single decoration. */
1146 wwin
->client_flags
.no_resizebar
= 1;
1147 wwin
->client_flags
.no_shadeable
= 1;
1148 wwin
->client_flags
.no_movable
= 1;
1149 wwin
->client_flags
.omnipresent
= 1;
1150 wwin
->client_flags
.skip_window_list
= 1;
1151 wwin
->client_flags
.skip_switchpanel
= 1;
1152 wwin
->client_flags
.dont_move_off
= 1;
1153 wwin
->flags
.net_skip_pager
= 1;
1154 } else if (type
== net_wm_window_type_toolbar
) {
1155 wwin
->client_flags
.no_titlebar
= 1;
1156 wwin
->client_flags
.no_resizable
= 1;
1157 wwin
->client_flags
.no_miniaturizable
= 1;
1158 wwin
->client_flags
.no_resizebar
= 1;
1159 wwin
->client_flags
.no_shadeable
= 1;
1160 wwin
->client_flags
.skip_window_list
= 1;
1161 wwin
->client_flags
.skip_switchpanel
= 1;
1162 wwin
->client_flags
.dont_move_off
= 1;
1163 wwin
->client_flags
.no_appicon
= 1;
1164 } else if (type
== net_wm_window_type_menu
||
1165 type
== net_wm_window_type_dropdown_menu
||
1166 type
== net_wm_window_type_popup_menu
||
1167 type
== net_wm_window_type_combo
) {
1168 wwin
->client_flags
.no_titlebar
= 1;
1169 wwin
->client_flags
.no_resizable
= 1;
1170 wwin
->client_flags
.no_miniaturizable
= 1;
1171 wwin
->client_flags
.no_resizebar
= 1;
1172 wwin
->client_flags
.no_shadeable
= 1;
1173 wwin
->client_flags
.skip_window_list
= 1;
1174 wwin
->client_flags
.skip_switchpanel
= 1;
1175 wwin
->client_flags
.dont_move_off
= 1;
1176 wwin
->client_flags
.no_appicon
= 1;
1177 } else if (type
== net_wm_window_type_utility
) {
1178 wwin
->client_flags
.no_appicon
= 1;
1179 } else if (type
== net_wm_window_type_splash
) {
1180 wwin
->client_flags
.no_titlebar
= 1;
1181 wwin
->client_flags
.no_resizable
= 1;
1182 wwin
->client_flags
.no_miniaturizable
= 1;
1183 wwin
->client_flags
.no_resizebar
= 1;
1184 wwin
->client_flags
.no_shadeable
= 1;
1185 wwin
->client_flags
.no_movable
= 1;
1186 wwin
->client_flags
.skip_window_list
= 1;
1187 wwin
->client_flags
.skip_switchpanel
= 1;
1188 wwin
->client_flags
.dont_move_off
= 1;
1189 wwin
->client_flags
.no_appicon
= 1;
1190 wwin
->flags
.net_skip_pager
= 1;
1191 } else if (type
== net_wm_window_type_dialog
) {
1192 /* These also seem a bad idea in our context -Dan
1193 // wwin->client_flags.skip_window_list = 1;
1194 // wwin->client_flags.no_appicon = 1;
1196 } else if (wwin
->type
== net_wm_window_type_tooltip
) {
1197 wwin
->client_flags
.no_titlebar
= 1;
1198 wwin
->client_flags
.no_resizable
= 1;
1199 wwin
->client_flags
.no_miniaturizable
= 1;
1200 wwin
->client_flags
.no_resizebar
= 1;
1201 wwin
->client_flags
.no_shadeable
= 1;
1202 wwin
->client_flags
.no_movable
= 1;
1203 wwin
->client_flags
.skip_window_list
= 1;
1204 wwin
->client_flags
.skip_switchpanel
= 1;
1205 wwin
->client_flags
.dont_move_off
= 1;
1206 wwin
->client_flags
.no_appicon
= 1;
1207 wwin
->client_flags
.no_focusable
= 1;
1208 wwin
->flags
.net_skip_pager
= 1;
1209 } else if (wwin
->type
== net_wm_window_type_notification
) {
1210 wwin
->client_flags
.no_titlebar
= 1;
1211 wwin
->client_flags
.no_resizable
= 1;
1212 wwin
->client_flags
.no_miniaturizable
= 1;
1213 wwin
->client_flags
.no_border
= 1;
1214 wwin
->client_flags
.no_resizebar
= 1;
1215 wwin
->client_flags
.no_shadeable
= 1;
1216 wwin
->client_flags
.no_movable
= 1;
1217 wwin
->client_flags
.omnipresent
= 1;
1218 wwin
->client_flags
.skip_window_list
= 1;
1219 wwin
->client_flags
.skip_switchpanel
= 1;
1220 wwin
->client_flags
.dont_move_off
= 1;
1221 wwin
->client_flags
.no_hide_others
= 1;
1222 wwin
->client_flags
.no_appicon
= 1;
1223 wwin
->client_flags
.no_focusable
= 1;
1224 wwin
->flags
.net_skip_pager
= 1;
1225 } else if (wwin
->type
== net_wm_window_type_dnd
) {
1226 wwin
->client_flags
.no_titlebar
= 1;
1227 wwin
->client_flags
.no_resizable
= 1;
1228 wwin
->client_flags
.no_miniaturizable
= 1;
1229 wwin
->client_flags
.no_border
= 1;
1230 wwin
->client_flags
.no_resizebar
= 1;
1231 wwin
->client_flags
.no_shadeable
= 1;
1232 wwin
->client_flags
.no_movable
= 1;
1233 wwin
->client_flags
.skip_window_list
= 1;
1234 wwin
->client_flags
.skip_switchpanel
= 1;
1235 wwin
->client_flags
.dont_move_off
= 1;
1236 wwin
->client_flags
.no_appicon
= 1;
1237 wwin
->flags
.net_skip_pager
= 1;
1238 } else if (type
== net_wm_window_type_normal
) {
1244 *layer
= getWindowLayer(wwin
);
1249 void wNETWMPositionSplash(WWindow
*wwin
, int *x
, int *y
, int width
, int height
)
1251 if (wwin
->type
== net_wm_window_type_splash
) {
1252 WScreen
*scr
= wwin
->screen_ptr
;
1253 WMRect rect
= wGetRectForHead(scr
, wGetHeadForPointerLocation(scr
));
1254 *x
= rect
.pos
.x
+ (rect
.size
.width
- width
) / 2;
1255 *y
= rect
.pos
.y
+ (rect
.size
.height
- height
) / 2;
1259 static void updateWindowType(WWindow
*wwin
)
1263 unsigned long nitems_ret
, bytes_after_ret
;
1266 if (XGetWindowProperty(dpy
, wwin
->client_win
, net_wm_window_type
, 0, 1,
1267 False
, XA_ATOM
, &type_ret
, &fmt_ret
, &nitems_ret
,
1268 &bytes_after_ret
, (unsigned char **)&data
) == Success
&& data
) {
1271 Atom
*type
= (Atom
*) data
;
1272 for (i
= 0; i
< nitems_ret
; ++i
) {
1273 if (handleWindowType(wwin
, type
[i
], &layer
))
1279 if (wwin
->frame
!= NULL
) {
1280 ChangeStackingLevel(wwin
->frame
->core
, layer
);
1281 wwin
->frame
->flags
.need_texture_change
= 1;
1282 wWindowConfigureBorders(wwin
);
1283 wFrameWindowPaint(wwin
->frame
);
1284 wNETWMUpdateActions(wwin
, False
);
1288 void wNETWMCheckClientHints(WWindow
*wwin
, int *layer
, int *workspace
)
1292 unsigned long nitems_ret
, bytes_after_ret
;
1295 if (XGetWindowProperty(dpy
, wwin
->client_win
, net_wm_desktop
, 0, 1, False
,
1296 XA_CARDINAL
, &type_ret
, &fmt_ret
, &nitems_ret
,
1297 &bytes_after_ret
, (unsigned char **)&data
) == Success
&& data
) {
1299 long desktop
= *data
;
1303 wwin
->client_flags
.omnipresent
= 1;
1305 *workspace
= desktop
;
1308 if (XGetWindowProperty(dpy
, wwin
->client_win
, net_wm_state
, 0, 1, False
,
1309 XA_ATOM
, &type_ret
, &fmt_ret
, &nitems_ret
,
1310 &bytes_after_ret
, (unsigned char **)&data
) == Success
&& data
) {
1312 Atom
*state
= (Atom
*) data
;
1313 for (i
= 0; i
< nitems_ret
; ++i
)
1314 doStateAtom(wwin
, state
[i
], _NET_WM_STATE_ADD
, True
);
1319 if (XGetWindowProperty(dpy
, wwin
->client_win
, net_wm_window_type
, 0, 1, False
,
1320 XA_ATOM
, &type_ret
, &fmt_ret
, &nitems_ret
,
1321 &bytes_after_ret
, (unsigned char **)&data
) == Success
&& data
) {
1323 Atom
*type
= (Atom
*) data
;
1324 for (i
= 0; i
< nitems_ret
; ++i
) {
1325 if (handleWindowType(wwin
, type
[i
], layer
))
1331 wNETWMUpdateActions(wwin
, False
);
1332 updateStrut(wwin
->screen_ptr
, wwin
->client_win
, False
);
1333 updateStrut(wwin
->screen_ptr
, wwin
->client_win
, True
);
1335 wScreenUpdateUsableArea(wwin
->screen_ptr
);
1338 static Bool
updateNetIconInfo(WWindow
*wwin
)
1342 unsigned long nitems_ret
, bytes_after_ret
;
1344 Bool hasState
= False
;
1345 Bool old_state
= wwin
->flags
.net_handle_icon
;
1347 if (XGetWindowProperty(dpy
, wwin
->client_win
, net_wm_handled_icons
, 0, 1, False
,
1348 XA_CARDINAL
, &type_ret
, &fmt_ret
, &nitems_ret
,
1349 &bytes_after_ret
, (unsigned char **)&data
) == Success
&& data
) {
1350 long handled
= *data
;
1351 wwin
->flags
.net_handle_icon
= (handled
!= 0);
1356 wwin
->flags
.net_handle_icon
= False
;
1359 if (XGetWindowProperty(dpy
, wwin
->client_win
, net_wm_icon_geometry
, 0, 4, False
,
1360 XA_CARDINAL
, &type_ret
, &fmt_ret
, &nitems_ret
,
1361 &bytes_after_ret
, (unsigned char **)&data
) == Success
&& data
) {
1364 if (wwin
->flags
.net_handle_icon
)
1366 wwin
->flags
.net_handle_icon
= True
;
1369 wwin
->icon_x
= data
[0];
1370 wwin
->icon_y
= data
[1];
1371 wwin
->icon_w
= data
[2];
1372 wwin
->icon_h
= data
[3];
1379 wwin
->flags
.net_handle_icon
= False
;
1382 if (wwin
->flags
.miniaturized
&& old_state
!= wwin
->flags
.net_handle_icon
) {
1383 if (wwin
->flags
.net_handle_icon
) {
1386 wwin
->flags
.miniaturized
= False
;
1387 wwin
->flags
.skip_next_animation
= True
;
1388 wIconifyWindow(wwin
);
1395 void wNETWMCheckInitialClientState(WWindow
*wwin
)
1398 wmessage("wNETWMCheckInitialClientState");
1401 wNETWMShowingDesktop(wwin
->screen_ptr
, False
);
1403 updateWindowType(wwin
);
1404 updateNetIconInfo(wwin
);
1405 updateIconImage(wwin
);
1408 void wNETWMCheckInitialFrameState(WWindow
*wwin
)
1411 wmessage("wNETWMCheckInitialFrameState");
1414 updateWindowOpacity(wwin
);
1417 static void handleDesktopNames(WScreen
*scr
)
1419 unsigned long nitems_ret
, bytes_after_ret
;
1420 char *data
, *names
[32];
1424 if (XGetWindowProperty(dpy
, scr
->root_win
, net_desktop_names
, 0, 1, False
,
1425 utf8_string
, &type_ret
, &fmt_ret
, &nitems_ret
,
1426 &bytes_after_ret
, (unsigned char **)&data
) != Success
)
1432 if (type_ret
!= utf8_string
|| fmt_ret
!= 8)
1437 for (i
= 0; i
< nitems_ret
; i
++) {
1440 names
[n
] = &data
[i
];
1441 } else if (*names
[n
] == 0) {
1442 names
[n
] = &data
[i
];
1443 wWorkspaceRename(scr
, n
, names
[n
]);
1448 Bool
wNETWMProcessClientMessage(XClientMessageEvent
*event
)
1455 wmessage("processClientMessage type %s\n", XGetAtomName(dpy
, event
->message_type
));
1458 scr
= wScreenForWindow(event
->window
);
1460 /* generic client messages */
1461 if (event
->message_type
== net_current_desktop
) {
1462 wWorkspaceChange(scr
, event
->data
.l
[0]);
1463 } else if (event
->message_type
== net_number_of_desktops
) {
1466 value
= event
->data
.l
[0];
1467 if (value
> w_global
.workspace
.count
) {
1468 wWorkspaceMake(scr
, value
- w_global
.workspace
.count
);
1469 } else if (value
< w_global
.workspace
.count
) {
1471 Bool rebuild
= False
;
1473 for (i
= w_global
.workspace
.count
- 1; i
>= value
; i
--) {
1474 if (!wWorkspaceDelete(scr
, i
)) {
1481 updateWorkspaceCount(scr
);
1483 } else if (event
->message_type
== net_showing_desktop
) {
1484 wNETWMShowingDesktop(scr
, event
->data
.l
[0]);
1485 } else if (event
->message_type
== net_desktop_names
) {
1486 handleDesktopNames(scr
);
1495 /* window specific client messages */
1497 wwin
= wWindowFor(event
->window
);
1501 if (event
->message_type
== net_active_window
) {
1503 * Satisfy a client's focus request only if
1504 * - request comes from a pager, or
1505 * - it's explicitly allowed in Advanced Options, or
1506 * - giving the client the focus does not cause a change in
1507 * the active workspace (XXX: or the active head if Xinerama)
1509 if (wwin
->frame
->workspace
== w_global
.workspace
.current
/* No workspace change */
1510 || event
->data
.l
[0] == 2 /* Requested by pager */
1511 || WFLAGP(wwin
, focus_across_wksp
) /* Explicitly allowed */) {
1512 wNETWMShowingDesktop(scr
, False
);
1513 wMakeWindowVisible(wwin
);
1515 } else if (event
->message_type
== net_close_window
) {
1516 if (!WFLAGP(wwin
, no_closable
)) {
1517 if (wwin
->protocols
.DELETE_WINDOW
)
1518 wClientSendProtocol(wwin
, w_global
.atom
.wm
.delete_window
,
1519 w_global
.timestamp
.last_event
);
1521 } else if (event
->message_type
== net_wm_state
) {
1522 int maximized
= wwin
->flags
.maximized
;
1523 long set
= event
->data
.l
[0];
1526 wmessage("net_wm_state set %ld a1 %s a2 %s\n", set
,
1527 XGetAtomName(dpy
, event
->data
.l
[1]), XGetAtomName(dpy
, event
->data
.l
[2]));
1530 doStateAtom(wwin
, (Atom
) event
->data
.l
[1], set
, False
);
1531 if (event
->data
.l
[2])
1532 doStateAtom(wwin
, (Atom
) event
->data
.l
[2], set
, False
);
1534 if (wwin
->flags
.maximized
!= maximized
) {
1535 if (!wwin
->flags
.maximized
) {
1536 wwin
->flags
.maximized
= maximized
;
1537 wUnmaximizeWindow(wwin
);
1539 wMaximizeWindow(wwin
, wwin
->flags
.maximized
);
1542 updateStateHint(wwin
, False
, False
);
1543 } else if (event
->message_type
== net_wm_handled_icons
|| event
->message_type
== net_wm_icon_geometry
) {
1544 updateNetIconInfo(wwin
);
1545 } else if (event
->message_type
== net_wm_desktop
) {
1546 long desktop
= event
->data
.l
[0];
1547 if (desktop
== -1) {
1548 wWindowSetOmnipresent(wwin
, True
);
1550 if (IS_OMNIPRESENT(wwin
))
1551 wWindowSetOmnipresent(wwin
, False
);
1552 wWindowChangeWorkspace(wwin
, desktop
);
1561 void wNETWMCheckClientHintChange(WWindow
*wwin
, XPropertyEvent
*event
)
1564 wmessage("clientHintChange type %s\n", XGetAtomName(dpy
, event
->atom
));
1567 if (event
->atom
== net_wm_strut
|| event
->atom
== net_wm_strut_partial
) {
1568 updateStrut(wwin
->screen_ptr
, wwin
->client_win
, False
);
1569 updateStrut(wwin
->screen_ptr
, wwin
->client_win
, True
);
1570 wScreenUpdateUsableArea(wwin
->screen_ptr
);
1571 } else if (event
->atom
== net_wm_handled_icons
|| event
->atom
== net_wm_icon_geometry
) {
1572 updateNetIconInfo(wwin
);
1573 } else if (event
->atom
== net_wm_window_type
) {
1574 updateWindowType(wwin
);
1575 } else if (event
->atom
== net_wm_name
) {
1576 char *name
= wNETWMGetWindowName(wwin
->client_win
);
1577 wWindowUpdateName(wwin
, name
);
1580 } else if (event
->atom
== net_wm_icon_name
) {
1582 wIconChangeTitle(wwin
->icon
, wwin
);
1583 wIconPaint(wwin
->icon
);
1585 } else if (event
->atom
== net_wm_icon
) {
1586 updateIconImage(wwin
);
1587 } else if (event
->atom
== net_wm_window_opacity
) {
1588 updateWindowOpacity(wwin
);
1592 int wNETWMGetPidForWindow(Window window
)
1596 unsigned long nitems_ret
, bytes_after_ret
;
1600 if (XGetWindowProperty(dpy
, window
, net_wm_pid
, 0, 1, False
,
1601 XA_CARDINAL
, &type_ret
, &fmt_ret
, &nitems_ret
,
1602 &bytes_after_ret
, (unsigned char **)&data
) == Success
&& data
) {
1612 char *wNETWMGetWindowName(Window window
)
1618 name
= (char *)PropGetCheckProperty(window
, net_wm_name
, utf8_string
, 0, 0, &size
);
1620 ret
= wstrndup(name
, size
);
1629 char *wNETWMGetIconName(Window window
)
1635 name
= (char *)PropGetCheckProperty(window
, net_wm_icon_name
, utf8_string
, 0, 0, &size
);
1637 ret
= wstrndup(name
, size
);
1646 static void observer(void *self
, WMNotification
*notif
)
1648 WWindow
*wwin
= (WWindow
*) WMGetNotificationObject(notif
);
1649 const char *name
= WMGetNotificationName(notif
);
1650 void *data
= WMGetNotificationClientData(notif
);
1651 NetData
*ndata
= (NetData
*) self
;
1653 if (strcmp(name
, WMNManaged
) == 0 && wwin
) {
1654 updateClientList(wwin
->screen_ptr
);
1655 updateClientListStacking(wwin
->screen_ptr
, NULL
);
1656 updateStateHint(wwin
, True
, False
);
1658 updateStrut(wwin
->screen_ptr
, wwin
->client_win
, False
);
1659 updateStrut(wwin
->screen_ptr
, wwin
->client_win
, True
);
1660 wScreenUpdateUsableArea(wwin
->screen_ptr
);
1661 } else if (strcmp(name
, WMNUnmanaged
) == 0 && wwin
) {
1662 updateClientList(wwin
->screen_ptr
);
1663 updateClientListStacking(wwin
->screen_ptr
, wwin
);
1664 updateWorkspaceHint(wwin
, False
, True
);
1665 updateStateHint(wwin
, False
, True
);
1666 wNETWMUpdateActions(wwin
, True
);
1668 updateStrut(wwin
->screen_ptr
, wwin
->client_win
, False
);
1669 wScreenUpdateUsableArea(wwin
->screen_ptr
);
1670 } else if (strcmp(name
, WMNResetStacking
) == 0 && wwin
) {
1671 updateClientListStacking(wwin
->screen_ptr
, NULL
);
1672 updateStateHint(wwin
, False
, False
);
1673 } else if (strcmp(name
, WMNChangedStacking
) == 0 && wwin
) {
1674 updateClientListStacking(wwin
->screen_ptr
, NULL
);
1675 updateStateHint(wwin
, False
, False
);
1676 } else if (strcmp(name
, WMNChangedFocus
) == 0) {
1677 updateFocusHint(ndata
->scr
);
1678 } else if (strcmp(name
, WMNChangedWorkspace
) == 0 && wwin
) {
1679 updateWorkspaceHint(wwin
, False
, False
);
1680 updateStateHint(wwin
, True
, False
);
1681 } else if (strcmp(name
, WMNChangedState
) == 0 && wwin
) {
1682 updateStateHint(wwin
, !strcmp(data
, "omnipresent"), False
);
1686 static void wsobserver(void *self
, WMNotification
*notif
)
1688 WScreen
*scr
= (WScreen
*) WMGetNotificationObject(notif
);
1689 const char *name
= WMGetNotificationName(notif
);
1691 /* Parameter not used, but tell the compiler that it is ok */
1694 if (strcmp(name
, WMNWorkspaceCreated
) == 0) {
1695 updateWorkspaceCount(scr
);
1696 updateWorkspaceNames(scr
);
1697 } else if (strcmp(name
, WMNWorkspaceDestroyed
) == 0) {
1698 updateWorkspaceCount(scr
);
1699 updateWorkspaceNames(scr
);
1700 } else if (strcmp(name
, WMNWorkspaceChanged
) == 0) {
1701 updateCurrentWorkspace(scr
);
1702 } else if (strcmp(name
, WMNWorkspaceNameChanged
) == 0) {
1703 updateWorkspaceNames(scr
);
1707 void wNETFrameExtents(WWindow
*wwin
)
1709 long extents
[4] = { 0, 0, 0, 0 };
1711 /* The extents array describes dimensions which are not
1712 * part of the client window. In our case that means
1713 * widths of the border and heights of the titlebar and resizebar.
1720 if (wwin
->frame
->titlebar
)
1721 extents
[2] = wwin
->frame
->titlebar
->height
;
1722 if (wwin
->frame
->resizebar
)
1723 extents
[3] = wwin
->frame
->resizebar
->height
;
1724 if (HAS_BORDER(wwin
)) {
1725 extents
[0] += wwin
->screen_ptr
->frame_border_width
;
1726 extents
[1] += wwin
->screen_ptr
->frame_border_width
;
1727 extents
[2] += wwin
->screen_ptr
->frame_border_width
;
1728 extents
[3] += wwin
->screen_ptr
->frame_border_width
;
1731 XChangeProperty(dpy
, wwin
->client_win
, net_frame_extents
, XA_CARDINAL
, 32, PropModeReplace
, (unsigned char *) extents
, 4);
1734 void wNETCleanupFrameExtents(WWindow
*wwin
)
1736 XDeleteProperty(dpy
, wwin
->client_win
, net_frame_extents
);