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>
37 #include <WINGs/WUtil.h>
38 #include "WindowMaker.h"
41 #include "workspace.h"
50 #include "properties.h"
53 /* Root Window Properties */
54 static Atom net_supported
;
55 static Atom net_client_list
;
56 static Atom net_client_list_stacking
;
57 static Atom net_number_of_desktops
;
58 static Atom net_desktop_geometry
;
59 static Atom net_desktop_viewport
;
60 static Atom net_current_desktop
;
61 static Atom net_desktop_names
;
62 static Atom net_active_window
;
63 static Atom net_workarea
;
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
;
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_WORKAREA", &net_workarea
},
149 {"_NET_SUPPORTING_WM_CHECK", &net_supporting_wm_check
},
150 {"_NET_VIRTUAL_ROOTS", &net_virtual_roots
},
151 {"_NET_DESKTOP_LAYOUT", &net_desktop_layout
},
152 {"_NET_SHOWING_DESKTOP", &net_showing_desktop
},
154 {"_NET_CLOSE_WINDOW", &net_close_window
},
155 {"_NET_MOVERESIZE_WINDOW", &net_moveresize_window
},
156 {"_NET_WM_MOVERESIZE", &net_wm_moveresize
},
158 {"_NET_WM_NAME", &net_wm_name
},
159 {"_NET_WM_VISIBLE_NAME", &net_wm_visible_name
},
160 {"_NET_WM_ICON_NAME", &net_wm_icon_name
},
161 {"_NET_WM_VISIBLE_ICON_NAME", &net_wm_visible_icon_name
},
162 {"_NET_WM_DESKTOP", &net_wm_desktop
},
163 {"_NET_WM_WINDOW_TYPE", &net_wm_window_type
},
164 {"_NET_WM_WINDOW_TYPE_DESKTOP", &net_wm_window_type_desktop
},
165 {"_NET_WM_WINDOW_TYPE_DOCK", &net_wm_window_type_dock
},
166 {"_NET_WM_WINDOW_TYPE_TOOLBAR", &net_wm_window_type_toolbar
},
167 {"_NET_WM_WINDOW_TYPE_MENU", &net_wm_window_type_menu
},
168 {"_NET_WM_WINDOW_TYPE_UTILITY", &net_wm_window_type_utility
},
169 {"_NET_WM_WINDOW_TYPE_SPLASH", &net_wm_window_type_splash
},
170 {"_NET_WM_WINDOW_TYPE_DIALOG", &net_wm_window_type_dialog
},
171 {"_NET_WM_WINDOW_TYPE_DROPDOWN_MENU", &net_wm_window_type_dropdown_menu
},
172 {"_NET_WM_WINDOW_TYPE_POPUP_MENU", &net_wm_window_type_popup_menu
},
173 {"_NET_WM_WINDOW_TYPE_TOOLTIP", &net_wm_window_type_tooltip
},
174 {"_NET_WM_WINDOW_TYPE_NOTIFICATION", &net_wm_window_type_notification
},
175 {"_NET_WM_WINDOW_TYPE_COMBO", &net_wm_window_type_combo
},
176 {"_NET_WM_WINDOW_TYPE_DND", &net_wm_window_type_dnd
},
177 {"_NET_WM_WINDOW_TYPE_NORMAL", &net_wm_window_type_normal
},
178 {"_NET_WM_STATE", &net_wm_state
},
179 {"_NET_WM_STATE_MODAL", &net_wm_state_modal
},
180 {"_NET_WM_STATE_STICKY", &net_wm_state_sticky
},
181 {"_NET_WM_STATE_MAXIMIZED_VERT", &net_wm_state_maximized_vert
},
182 {"_NET_WM_STATE_MAXIMIZED_HORZ", &net_wm_state_maximized_horz
},
183 {"_NET_WM_STATE_SHADED", &net_wm_state_shaded
},
184 {"_NET_WM_STATE_SKIP_TASKBAR", &net_wm_state_skip_taskbar
},
185 {"_NET_WM_STATE_SKIP_PAGER", &net_wm_state_skip_pager
},
186 {"_NET_WM_STATE_HIDDEN", &net_wm_state_hidden
},
187 {"_NET_WM_STATE_FULLSCREEN", &net_wm_state_fullscreen
},
188 {"_NET_WM_STATE_ABOVE", &net_wm_state_above
},
189 {"_NET_WM_STATE_BELOW", &net_wm_state_below
},
190 {"_NET_WM_ALLOWED_ACTIONS", &net_wm_allowed_actions
},
191 {"_NET_WM_ACTION_MOVE", &net_wm_action_move
},
192 {"_NET_WM_ACTION_RESIZE", &net_wm_action_resize
},
193 {"_NET_WM_ACTION_MINIMIZE", &net_wm_action_minimize
},
194 {"_NET_WM_ACTION_SHADE", &net_wm_action_shade
},
195 {"_NET_WM_ACTION_STICK", &net_wm_action_stick
},
196 {"_NET_WM_ACTION_MAXIMIZE_HORZ", &net_wm_action_maximize_horz
},
197 {"_NET_WM_ACTION_MAXIMIZE_VERT", &net_wm_action_maximize_vert
},
198 {"_NET_WM_ACTION_FULLSCREEN", &net_wm_action_fullscreen
},
199 {"_NET_WM_ACTION_CHANGE_DESKTOP", &net_wm_action_change_desktop
},
200 {"_NET_WM_ACTION_CLOSE", &net_wm_action_close
},
201 {"_NET_WM_STRUT", &net_wm_strut
},
202 {"_NET_WM_STRUT_PARTIAL", &net_wm_strut_partial
},
203 {"_NET_WM_ICON_GEOMETRY", &net_wm_icon_geometry
},
204 {"_NET_WM_ICON", &net_wm_icon
},
205 {"_NET_WM_PID", &net_wm_pid
},
206 {"_NET_WM_HANDLED_ICONS", &net_wm_handled_icons
},
207 {"_NET_WM_WINDOW_OPACITY", &net_wm_window_opacity
},
209 {"_NET_FRAME_EXTENTS", &net_frame_extents
},
211 {"_NET_WM_PING", &net_wm_ping
},
213 {"UTF8_STRING", &utf8_string
},
216 #define _NET_WM_STATE_ADD 1
217 #define _NET_WM_STATE_TOGGLE 2
221 * These constant provide information on the kind of window move/resize when
222 * it is initiated by the application instead of by WindowMaker. They are
223 * parameter for the client message _NET_WM_MOVERESIZE, as defined by the
224 * FreeDesktop wm-spec standard:
225 * http://standards.freedesktop.org/wm-spec/1.5/ar01s04.html
227 * Today, WindowMaker does not support this at all (the corresponding Atom
228 * is not added to the list in setSupportedHints), probably because there is
229 * nothing it needs to do about it, the application is assumed to know what
230 * it is doing, and WindowMaker won't get in the way.
232 * The definition of the constants (taken from the standard) are disabled to
233 * avoid a spurious warning (-Wunused-macros).
235 #define _NET_WM_MOVERESIZE_SIZE_TOPLEFT 0
236 #define _NET_WM_MOVERESIZE_SIZE_TOP 1
237 #define _NET_WM_MOVERESIZE_SIZE_TOPRIGHT 2
238 #define _NET_WM_MOVERESIZE_SIZE_RIGHT 3
239 #define _NET_WM_MOVERESIZE_SIZE_BOTTOMRIGHT 4
240 #define _NET_WM_MOVERESIZE_SIZE_BOTTOM 5
241 #define _NET_WM_MOVERESIZE_SIZE_BOTTOMLEFT 6
242 #define _NET_WM_MOVERESIZE_SIZE_LEFT 7
243 #define _NET_WM_MOVERESIZE_MOVE 8 /* movement only */
244 #define _NET_WM_MOVERESIZE_SIZE_KEYBOARD 9 /* size via keyboard */
245 #define _NET_WM_MOVERESIZE_MOVE_KEYBOARD 10 /* move via keyboard */
248 static void observer(void *self
, WMNotification
*notif
);
249 static void wsobserver(void *self
, WMNotification
*notif
);
251 static void updateClientList(WScreen
*scr
);
252 static void updateClientListStacking(WScreen
*scr
, WWindow
*);
254 static void updateWorkspaceNames(WScreen
*scr
);
255 static void updateCurrentWorkspace(WScreen
*scr
);
256 static void updateWorkspaceCount(WScreen
*scr
);
257 static void wNETWMShowingDesktop(WScreen
*scr
, Bool show
);
259 typedef struct NetData
{
261 WReservedArea
*strut
;
262 WWindow
**show_desktop
;
265 static void setSupportedHints(WScreen
*scr
)
267 Atom atom
[wlengthof(atomNames
)];
270 /* set supported hints list */
271 /* XXX: extend this !!! */
273 atom
[i
++] = net_client_list
;
274 atom
[i
++] = net_client_list_stacking
;
275 atom
[i
++] = net_number_of_desktops
;
276 atom
[i
++] = net_desktop_geometry
;
277 atom
[i
++] = net_desktop_viewport
;
278 atom
[i
++] = net_current_desktop
;
279 atom
[i
++] = net_desktop_names
;
280 atom
[i
++] = net_active_window
;
281 atom
[i
++] = net_workarea
;
282 atom
[i
++] = net_supporting_wm_check
;
283 atom
[i
++] = net_showing_desktop
;
285 atom
[i
++] = net_wm_moveresize
;
287 atom
[i
++] = net_wm_desktop
;
288 atom
[i
++] = net_wm_window_type
;
289 atom
[i
++] = net_wm_window_type_desktop
;
290 atom
[i
++] = net_wm_window_type_dock
;
291 atom
[i
++] = net_wm_window_type_toolbar
;
292 atom
[i
++] = net_wm_window_type_menu
;
293 atom
[i
++] = net_wm_window_type_utility
;
294 atom
[i
++] = net_wm_window_type_splash
;
295 atom
[i
++] = net_wm_window_type_dialog
;
296 atom
[i
++] = net_wm_window_type_dropdown_menu
;
297 atom
[i
++] = net_wm_window_type_popup_menu
;
298 atom
[i
++] = net_wm_window_type_tooltip
;
299 atom
[i
++] = net_wm_window_type_notification
;
300 atom
[i
++] = net_wm_window_type_combo
;
301 atom
[i
++] = net_wm_window_type_dnd
;
302 atom
[i
++] = net_wm_window_type_normal
;
304 atom
[i
++] = net_wm_state
;
305 /* atom[i++] = net_wm_state_modal; *//* XXX: not sure where/when to use it. */
306 atom
[i
++] = net_wm_state_sticky
;
307 atom
[i
++] = net_wm_state_shaded
;
308 atom
[i
++] = net_wm_state_maximized_horz
;
309 atom
[i
++] = net_wm_state_maximized_vert
;
310 atom
[i
++] = net_wm_state_skip_taskbar
;
311 atom
[i
++] = net_wm_state_skip_pager
;
312 atom
[i
++] = net_wm_state_hidden
;
313 atom
[i
++] = net_wm_state_fullscreen
;
314 atom
[i
++] = net_wm_state_above
;
315 atom
[i
++] = net_wm_state_below
;
317 atom
[i
++] = net_wm_allowed_actions
;
318 atom
[i
++] = net_wm_action_move
;
319 atom
[i
++] = net_wm_action_resize
;
320 atom
[i
++] = net_wm_action_minimize
;
321 atom
[i
++] = net_wm_action_shade
;
322 atom
[i
++] = net_wm_action_stick
;
323 atom
[i
++] = net_wm_action_maximize_horz
;
324 atom
[i
++] = net_wm_action_maximize_vert
;
325 atom
[i
++] = net_wm_action_fullscreen
;
326 atom
[i
++] = net_wm_action_change_desktop
;
327 atom
[i
++] = net_wm_action_close
;
329 atom
[i
++] = net_wm_strut
;
330 atom
[i
++] = net_wm_icon_geometry
;
331 atom
[i
++] = net_wm_icon
;
332 atom
[i
++] = net_wm_handled_icons
;
333 atom
[i
++] = net_wm_window_opacity
;
335 atom
[i
++] = net_frame_extents
;
337 atom
[i
++] = net_wm_name
;
338 atom
[i
++] = net_wm_icon_name
;
340 XChangeProperty(dpy
, scr
->root_win
, net_supported
, XA_ATOM
, 32, PropModeReplace
, (unsigned char *)atom
, i
);
342 /* set supporting wm hint */
343 XChangeProperty(dpy
, scr
->root_win
, net_supporting_wm_check
, XA_WINDOW
, 32,
344 PropModeReplace
, (unsigned char *)&scr
->info_window
, 1);
346 XChangeProperty(dpy
, scr
->info_window
, net_supporting_wm_check
, XA_WINDOW
,
347 32, PropModeReplace
, (unsigned char *)&scr
->info_window
, 1);
350 void wNETWMUpdateDesktop(WScreen
*scr
)
352 long *views
, sizes
[2];
355 if (scr
->workspace_count
== 0)
358 count
= scr
->workspace_count
* 2;
359 views
= wmalloc(sizeof(long) * count
);
360 sizes
[0] = scr
->scr_width
;
361 sizes
[1] = scr
->scr_height
;
363 for (i
= 0; i
< scr
->workspace_count
; i
++) {
364 views
[2 * i
+ 0] = 0;
365 views
[2 * i
+ 1] = 0;
368 XChangeProperty(dpy
, scr
->root_win
, net_desktop_geometry
, XA_CARDINAL
, 32,
369 PropModeReplace
, (unsigned char *)sizes
, 2);
371 XChangeProperty(dpy
, scr
->root_win
, net_desktop_viewport
, XA_CARDINAL
, 32,
372 PropModeReplace
, (unsigned char *)views
, count
);
377 int wNETWMGetCurrentDesktopFromHint(WScreen
*scr
)
382 prop
= PropGetCheckProperty(scr
->root_win
, net_current_desktop
, XA_CARDINAL
, 0, 1, &count
);
384 int desktop
= *(long *)prop
;
392 * Find the best icon to be used by Window Maker for appicon/miniwindows.
393 * Currently the algorithm is to take the image with the size closest
394 * to icon_size x icon_size, but never bigger than that.
396 * This algorithm is very poorly implemented and needs to be redone (it can
397 * easily select images with very large widths and very small heights over
398 * square images, if the area of the former is closer to the desired one).
400 * The logic can also be changed to accept bigger images and scale them down.
402 static unsigned long *findBestIcon(unsigned long *data
, unsigned long items
)
405 unsigned long i
, distance
;
408 /* better use only 75% of icon_size. For 64x64 this means 48x48
409 * This leaves room around the icon for the miniwindow title and
410 * results in better overall aesthetics -Dan */
411 wanted
= wPreferences
.icon_size
* wPreferences
.icon_size
;
413 for (icon
= NULL
, distance
= wanted
, i
= 0L; i
< items
- 1;) {
414 size
= data
[i
] * data
[i
+ 1];
418 if (d
>= 0 && d
<= distance
&& (i
+ size
+ 2) <= items
) {
428 static RImage
*makeRImageFromARGBData(unsigned long *data
)
430 int size
, width
, height
, i
;
432 unsigned char *imgdata
;
437 size
= width
* height
;
442 image
= RCreateImage(width
, height
, True
);
444 for (imgdata
= image
->data
, i
= 2; i
< size
+ 2; i
++, imgdata
+= 4) {
446 imgdata
[3] = (pixel
>> 24) & 0xff; /* A */
447 imgdata
[0] = (pixel
>> 16) & 0xff; /* R */
448 imgdata
[1] = (pixel
>> 8) & 0xff; /* G */
449 imgdata
[2] = (pixel
>> 0) & 0xff; /* B */
455 RImage
*get_window_image_from_x11(Window window
)
460 unsigned long items
, rest
;
461 unsigned long *property
, *data
;
463 /* Get the icon from X11 Window */
464 if (XGetWindowProperty(dpy
, window
, net_wm_icon
, 0L, LONG_MAX
,
465 False
, XA_CARDINAL
, &type
, &format
, &items
, &rest
,
466 (unsigned char **)&property
) != Success
|| !property
)
469 if (type
!= XA_CARDINAL
|| format
!= 32 || items
< 2) {
474 /* Find the best icon */
475 data
= findBestIcon(property
, items
);
481 /* Save the best icon in the X11 icon */
482 image
= makeRImageFromARGBData(data
);
486 /* Resize the image to the correct value */
487 image
= wIconValidateIconSize(image
, wPreferences
.icon_size
);
492 static void updateIconImage(WWindow
*wwin
)
494 /* Remove the icon image from X11 */
495 if (wwin
->net_icon_image
)
496 RReleaseImage(wwin
->net_icon_image
);
498 /* Save the icon in the X11 icon */
499 wwin
->net_icon_image
= get_window_image_from_x11(wwin
->client_win
);
501 /* Refresh the Window Icon */
503 wIconUpdate(wwin
->icon
);
505 /* Refresh the application icon */
506 WApplication
*app
= wApplicationOf(wwin
->main_window
);
507 if (app
&& app
->app_icon
) {
508 wIconUpdate(app
->app_icon
->icon
);
509 wAppIconPaint(app
->app_icon
);
513 static void updateWindowOpacity(WWindow
*wwin
)
517 unsigned long items
, rest
;
518 unsigned long *property
;
523 /* We don't care about this ourselves, but other programs need us to copy
524 * this to the frame window. */
525 if (XGetWindowProperty(dpy
, wwin
->client_win
, net_wm_window_opacity
, 0L, 1L,
526 False
, XA_CARDINAL
, &type
, &format
, &items
, &rest
,
527 (unsigned char **)&property
) != Success
)
531 XDeleteProperty(dpy
, wwin
->frame
->core
->window
, net_wm_window_opacity
);
532 } else if (type
== XA_CARDINAL
&& format
== 32 && items
== 1 && property
) {
533 XChangeProperty(dpy
, wwin
->frame
->core
->window
, net_wm_window_opacity
,
534 XA_CARDINAL
, 32, PropModeReplace
, (unsigned char *)property
, 1L);
541 static void updateShowDesktop(WScreen
*scr
, Bool show
)
545 foo
= (show
== True
);
546 XChangeProperty(dpy
, scr
->root_win
, net_showing_desktop
, XA_CARDINAL
, 32,
547 PropModeReplace
, (unsigned char *)&foo
, 1);
550 static void wNETWMShowingDesktop(WScreen
*scr
, Bool show
)
552 if (show
&& scr
->netdata
->show_desktop
== NULL
) {
553 WWindow
*tmp
, **wins
;
556 wins
= (WWindow
**) wmalloc(sizeof(WWindow
*) * (scr
->window_count
+ 1));
558 tmp
= scr
->focused_window
;
560 if (!tmp
->flags
.hidden
&& !tmp
->flags
.miniaturized
&& !WFLAGP(tmp
, skip_window_list
)) {
563 tmp
->flags
.skip_next_animation
= 1;
564 tmp
->flags
.net_show_desktop
= 1;
572 scr
->netdata
->show_desktop
= wins
;
573 updateShowDesktop(scr
, True
);
574 } else if (scr
->netdata
->show_desktop
!= NULL
) {
575 /* FIXME: get rid of workspace flashing ! */
576 int ws
= scr
->current_workspace
;
578 for (tmp
= scr
->netdata
->show_desktop
; *tmp
; ++tmp
) {
579 wDeiconifyWindow(*tmp
);
580 (*tmp
)->flags
.net_show_desktop
= 0;
582 if (ws
!= scr
->current_workspace
)
583 wWorkspaceChange(scr
, ws
);
584 wfree(scr
->netdata
->show_desktop
);
585 scr
->netdata
->show_desktop
= NULL
;
586 updateShowDesktop(scr
, False
);
590 void wNETWMInitStuff(WScreen
*scr
)
596 wmessage("wNETWMInitStuff");
599 #ifdef HAVE_XINTERNATOMS
601 Atom atoms
[wlengthof(atomNames
)];
602 char *names
[wlengthof(atomNames
)];
604 for (i
= 0; i
< wlengthof(atomNames
); ++i
)
605 names
[i
] = atomNames
[i
].name
;
607 XInternAtoms(dpy
, &names
[0], wlengthof(atomNames
), False
, atoms
);
608 for (i
= 0; i
< wlengthof(atomNames
); ++i
)
609 *atomNames
[i
].atom
= atoms
[i
];
613 for (i
= 0; i
< wlengthof(atomNames
); i
++)
614 *atomNames
[i
].atom
= XInternAtom(dpy
, atomNames
[i
].name
, False
);
617 data
= wmalloc(sizeof(NetData
));
620 data
->show_desktop
= NULL
;
624 setSupportedHints(scr
);
626 WMAddNotificationObserver(observer
, data
, WMNManaged
, NULL
);
627 WMAddNotificationObserver(observer
, data
, WMNUnmanaged
, NULL
);
628 WMAddNotificationObserver(observer
, data
, WMNChangedWorkspace
, NULL
);
629 WMAddNotificationObserver(observer
, data
, WMNChangedState
, NULL
);
630 WMAddNotificationObserver(observer
, data
, WMNChangedFocus
, NULL
);
631 WMAddNotificationObserver(observer
, data
, WMNChangedStacking
, NULL
);
632 WMAddNotificationObserver(observer
, data
, WMNChangedName
, NULL
);
634 WMAddNotificationObserver(wsobserver
, data
, WMNWorkspaceCreated
, NULL
);
635 WMAddNotificationObserver(wsobserver
, data
, WMNWorkspaceDestroyed
, NULL
);
636 WMAddNotificationObserver(wsobserver
, data
, WMNWorkspaceChanged
, NULL
);
637 WMAddNotificationObserver(wsobserver
, data
, WMNWorkspaceNameChanged
, NULL
);
639 updateClientList(scr
);
640 updateClientListStacking(scr
, NULL
);
641 updateWorkspaceCount(scr
);
642 updateWorkspaceNames(scr
);
643 updateShowDesktop(scr
, False
);
645 wScreenUpdateUsableArea(scr
);
648 void wNETWMCleanup(WScreen
*scr
)
652 for (i
= 0; i
< wlengthof(atomNames
); i
++)
653 XDeleteProperty(dpy
, scr
->root_win
, *atomNames
[i
].atom
);
656 void wNETWMUpdateActions(WWindow
*wwin
, Bool del
)
658 Atom action
[10]; /* nr of actions atoms defined */
662 XDeleteProperty(dpy
, wwin
->client_win
, net_wm_allowed_actions
);
666 if (IS_MOVABLE(wwin
))
667 action
[i
++] = net_wm_action_move
;
669 if (IS_RESIZABLE(wwin
))
670 action
[i
++] = net_wm_action_resize
;
672 if (!WFLAGP(wwin
, no_miniaturizable
))
673 action
[i
++] = net_wm_action_minimize
;
675 if (!WFLAGP(wwin
, no_shadeable
))
676 action
[i
++] = net_wm_action_shade
;
678 /* if (!WFLAGP(wwin, no_stickable)) */
679 action
[i
++] = net_wm_action_stick
;
681 /* if (!(WFLAGP(wwin, no_maximizeable) & MAX_HORIZONTAL)) */
682 if (IS_RESIZABLE(wwin
))
683 action
[i
++] = net_wm_action_maximize_horz
;
685 /* if (!(WFLAGP(wwin, no_maximizeable) & MAX_VERTICAL)) */
686 if (IS_RESIZABLE(wwin
))
687 action
[i
++] = net_wm_action_maximize_vert
;
689 /* if (!WFLAGP(wwin, no_fullscreen)) */
690 action
[i
++] = net_wm_action_fullscreen
;
692 /* if (!WFLAGP(wwin, no_change_desktop)) */
693 action
[i
++] = net_wm_action_change_desktop
;
695 if (!WFLAGP(wwin
, no_closable
))
696 action
[i
++] = net_wm_action_close
;
698 XChangeProperty(dpy
, wwin
->client_win
, net_wm_allowed_actions
,
699 XA_ATOM
, 32, PropModeReplace
, (unsigned char *)action
, i
);
702 void wNETWMUpdateWorkarea(WScreen
*scr
)
708 /* If the _NET_xxx were not initialised, it not necessary to do anything */
712 if (!scr
->usableArea
) {
713 /* If we don't have any info, we fall back on using the complete screen area */
716 total_usable
.x2
= scr
->scr_width
;
717 total_usable
.y2
= scr
->scr_height
;
723 * the _NET_WORKAREA is supposed to contain the total area of the screen that
724 * is usable, so we merge the areas from all xrandr sub-screens
726 total_usable
= scr
->usableArea
[0];
728 for (i
= 1; i
< wXineramaHeads(scr
); i
++) {
729 /* The merge is not subtle because _NET_WORKAREA does not need more */
730 if (scr
->usableArea
[i
].x1
< total_usable
.x1
)
731 total_usable
.x1
= scr
->usableArea
[i
].x1
;
733 if (scr
->usableArea
[i
].y1
< total_usable
.y1
)
734 total_usable
.y1
= scr
->usableArea
[i
].y1
;
736 if (scr
->usableArea
[i
].x2
> total_usable
.x2
)
737 total_usable
.x2
= scr
->usableArea
[i
].x2
;
739 if (scr
->usableArea
[i
].y2
> total_usable
.y2
)
740 total_usable
.y2
= scr
->usableArea
[i
].y2
;
745 /* We are expected to repeat the information for each workspace */
746 if (scr
->workspace_count
== 0)
749 nb_workspace
= scr
->workspace_count
;
752 long property_value
[nb_workspace
* 4];
755 for (i
= 0; i
< nb_workspace
; i
++) {
756 property_value
[4 * i
+ 0] = total_usable
.x1
;
757 property_value
[4 * i
+ 1] = total_usable
.y1
;
758 property_value
[4 * i
+ 2] = total_usable
.x2
- total_usable
.x1
;
759 property_value
[4 * i
+ 3] = total_usable
.y2
- total_usable
.y1
;
762 XChangeProperty(dpy
, scr
->root_win
, net_workarea
, XA_CARDINAL
, 32, PropModeReplace
,
763 (unsigned char *) property_value
, nb_workspace
* 4);
767 Bool
wNETWMGetUsableArea(WScreen
*scr
, int head
, WArea
*area
)
772 if (!scr
->netdata
|| !scr
->netdata
->strut
)
775 area
->x1
= area
->y1
= area
->x2
= area
->y2
= 0;
777 for (cur
= scr
->netdata
->strut
; cur
; cur
= cur
->next
) {
778 WWindow
*wwin
= wWindowFor(cur
->window
);
779 if (wWindowTouchesHead(wwin
, head
)) {
780 if (cur
->area
.x1
> area
->x1
)
781 area
->x1
= cur
->area
.x1
;
782 if (cur
->area
.y1
> area
->y1
)
783 area
->y1
= cur
->area
.y1
;
784 if (cur
->area
.x2
> area
->x2
)
785 area
->x2
= cur
->area
.x2
;
786 if (cur
->area
.y2
> area
->y2
)
787 area
->y2
= cur
->area
.y2
;
791 if (area
->x1
== 0 && area
->x2
== 0 && area
->y1
== 0 && area
->y2
== 0)
794 rect
= wGetRectForHead(scr
, head
);
796 area
->x1
= rect
.pos
.x
+ area
->x1
;
797 area
->x2
= rect
.pos
.x
+ rect
.size
.width
- area
->x2
;
798 area
->y1
= rect
.pos
.y
+ area
->y1
;
799 area
->y2
= rect
.pos
.y
+ rect
.size
.height
- area
->y2
;
804 static void updateClientList(WScreen
*scr
)
810 windows
= (Window
*) wmalloc(sizeof(Window
) * (scr
->window_count
+ 1));
813 wwin
= scr
->focused_window
;
815 windows
[count
++] = wwin
->client_win
;
818 XChangeProperty(dpy
, scr
->root_win
, net_client_list
, XA_WINDOW
, 32,
819 PropModeReplace
, (unsigned char *)windows
, count
);
825 static void updateClientListStacking(WScreen
*scr
, WWindow
*wwin_excl
)
828 Window
*client_list
, *client_list_reverse
;
833 /* update client list */
834 i
= scr
->window_count
+ 1;
835 client_list
= (Window
*) wmalloc(sizeof(Window
) * i
);
836 client_list_reverse
= (Window
*) wmalloc(sizeof(Window
) * i
);
839 WM_ETARETI_BAG(scr
->stacking_list
, tmp
, iter
) {
841 wwin
= wWindowFor(tmp
->window
);
842 /* wwin_excl is a window to exclude from the list
843 (e.g. it's now unmanaged) */
844 if (wwin
&& (wwin
!= wwin_excl
))
845 client_list
[client_count
++] = wwin
->client_win
;
846 tmp
= tmp
->stacking
->under
;
850 for (i
= 0; i
< client_count
; i
++) {
851 Window w
= client_list
[client_count
- i
- 1];
852 client_list_reverse
[i
] = w
;
855 XChangeProperty(dpy
, scr
->root_win
, net_client_list_stacking
, XA_WINDOW
, 32,
856 PropModeReplace
, (unsigned char *)client_list_reverse
, client_count
);
859 wfree(client_list_reverse
);
864 static void updateWorkspaceCount(WScreen
*scr
)
868 count
= scr
->workspace_count
;
870 XChangeProperty(dpy
, scr
->root_win
, net_number_of_desktops
, XA_CARDINAL
,
871 32, PropModeReplace
, (unsigned char *)&count
, 1);
874 static void updateCurrentWorkspace(WScreen
*scr
)
878 count
= scr
->current_workspace
;
880 XChangeProperty(dpy
, scr
->root_win
, net_current_desktop
, XA_CARDINAL
, 32,
881 PropModeReplace
, (unsigned char *)&count
, 1);
884 static void updateWorkspaceNames(WScreen
*scr
)
886 char buf
[MAX_WORKSPACES
* (MAX_WORKSPACENAME_WIDTH
+ 1)], *pos
;
887 unsigned int i
, len
, curr_size
;
891 for (i
= 0; i
< scr
->workspace_count
; i
++) {
892 curr_size
= strlen(scr
->workspaces
[i
]->name
);
893 strcpy(pos
, scr
->workspaces
[i
]->name
);
894 pos
+= (curr_size
+ 1);
895 len
+= (curr_size
+ 1);
898 XChangeProperty(dpy
, scr
->root_win
, net_desktop_names
, utf8_string
, 8,
899 PropModeReplace
, (unsigned char *)buf
, len
);
902 static void updateFocusHint(WScreen
*scr
)
906 if (!scr
->focused_window
|| !scr
->focused_window
->flags
.focused
)
909 window
= scr
->focused_window
->client_win
;
911 XChangeProperty(dpy
, scr
->root_win
, net_active_window
, XA_WINDOW
, 32,
912 PropModeReplace
, (unsigned char *)&window
, 1);
915 static void updateWorkspaceHint(WWindow
*wwin
, Bool fake
, Bool del
)
920 XDeleteProperty(dpy
, wwin
->client_win
, net_wm_desktop
);
922 l
= ((fake
|| IS_OMNIPRESENT(wwin
)) ? -1 : wwin
->frame
->workspace
);
923 XChangeProperty(dpy
, wwin
->client_win
, net_wm_desktop
, XA_CARDINAL
,
924 32, PropModeReplace
, (unsigned char *)&l
, 1);
928 static void updateStateHint(WWindow
*wwin
, Bool changedWorkspace
, Bool del
)
931 XDeleteProperty(dpy
, wwin
->client_win
, net_wm_state
);
933 Atom state
[15]; /* nr of defined state atoms */
936 if (changedWorkspace
|| (wPreferences
.sticky_icons
&& !IS_OMNIPRESENT(wwin
)))
937 updateWorkspaceHint(wwin
, False
, False
);
939 if (IS_OMNIPRESENT(wwin
))
940 state
[i
++] = net_wm_state_sticky
;
941 if (wwin
->flags
.shaded
)
942 state
[i
++] = net_wm_state_shaded
;
943 if (wwin
->flags
.maximized
& MAX_HORIZONTAL
)
944 state
[i
++] = net_wm_state_maximized_horz
;
945 if (wwin
->flags
.maximized
& MAX_VERTICAL
)
946 state
[i
++] = net_wm_state_maximized_vert
;
947 if (WFLAGP(wwin
, skip_window_list
))
948 state
[i
++] = net_wm_state_skip_taskbar
;
949 if (wwin
->flags
.net_skip_pager
)
950 state
[i
++] = net_wm_state_skip_pager
;
951 if ((wwin
->flags
.hidden
|| wwin
->flags
.miniaturized
) && !wwin
->flags
.net_show_desktop
) {
952 state
[i
++] = net_wm_state_hidden
;
953 state
[i
++] = net_wm_state_skip_pager
;
955 if (wwin
->flags
.miniaturized
&& wPreferences
.sticky_icons
) {
956 if (!IS_OMNIPRESENT(wwin
))
957 updateWorkspaceHint(wwin
, True
, False
);
958 state
[i
++] = net_wm_state_sticky
;
961 if (WFLAGP(wwin
, sunken
))
962 state
[i
++] = net_wm_state_below
;
963 if (WFLAGP(wwin
, floating
))
964 state
[i
++] = net_wm_state_above
;
965 if (wwin
->flags
.fullscreen
)
966 state
[i
++] = net_wm_state_fullscreen
;
968 XChangeProperty(dpy
, wwin
->client_win
, net_wm_state
, XA_ATOM
, 32,
969 PropModeReplace
, (unsigned char *)state
, i
);
973 static Bool
updateStrut(WScreen
*scr
, Window w
, Bool adding
)
976 Bool hasState
= False
;
981 unsigned long nitems_ret
, bytes_after_ret
;
984 if ((XGetWindowProperty(dpy
, w
, net_wm_strut
, 0, 4, False
,
985 XA_CARDINAL
, &type_ret
, &fmt_ret
, &nitems_ret
,
986 &bytes_after_ret
, (unsigned char **)&data
) == Success
&& data
) ||
987 ((XGetWindowProperty(dpy
, w
, net_wm_strut_partial
, 0, 12, False
,
988 XA_CARDINAL
, &type_ret
, &fmt_ret
, &nitems_ret
,
989 &bytes_after_ret
, (unsigned char **)&data
) == Success
&& data
))) {
991 /* XXX: This is strictly incorrect in the case of net_wm_strut_partial...
992 * Discard the start and end properties from the partial strut and treat it as
993 * a (deprecated) strut.
994 * This means we are marking the whole width or height of the screen as
995 * reserved, which is not necessarily what the strut defines. However for the
996 * purposes of determining placement or maximization it's probably good enough.
998 area
= (WReservedArea
*) wmalloc(sizeof(WReservedArea
));
999 area
->area
.x1
= data
[0];
1000 area
->area
.x2
= data
[1];
1001 area
->area
.y1
= data
[2];
1002 area
->area
.y2
= data
[3];
1006 area
->next
= scr
->netdata
->strut
;
1007 scr
->netdata
->strut
= area
;
1014 area
= scr
->netdata
->strut
;
1017 if (area
->window
== w
) {
1018 scr
->netdata
->strut
= area
->next
;
1022 while (area
->next
&& area
->next
->window
!= w
)
1026 WReservedArea
*next
;
1028 next
= area
->next
->next
;
1041 static int getWindowLayer(WWindow
*wwin
)
1043 int layer
= WMNormalLevel
;
1045 if (wwin
->type
== net_wm_window_type_desktop
) {
1046 layer
= WMDesktopLevel
;
1047 } else if (wwin
->type
== net_wm_window_type_dock
) {
1048 layer
= WMDockLevel
;
1049 } else if (wwin
->type
== net_wm_window_type_toolbar
) {
1050 layer
= WMMainMenuLevel
;
1051 } else if (wwin
->type
== net_wm_window_type_menu
) {
1052 layer
= WMSubmenuLevel
;
1053 } else if (wwin
->type
== net_wm_window_type_utility
) {
1054 } else if (wwin
->type
== net_wm_window_type_splash
) {
1055 } else if (wwin
->type
== net_wm_window_type_dialog
) {
1056 if (wwin
->transient_for
) {
1057 WWindow
*parent
= wWindowFor(wwin
->transient_for
);
1058 if (parent
&& parent
->flags
.fullscreen
)
1059 layer
= WMFullscreenLevel
;
1061 /* //layer = WMPopUpLevel; // this seems a bad idea -Dan */
1062 } else if (wwin
->type
== net_wm_window_type_dropdown_menu
) {
1063 layer
= WMSubmenuLevel
;
1064 } else if (wwin
->type
== net_wm_window_type_popup_menu
) {
1065 layer
= WMSubmenuLevel
;
1066 } else if (wwin
->type
== net_wm_window_type_tooltip
) {
1067 } else if (wwin
->type
== net_wm_window_type_notification
) {
1068 layer
= WMPopUpLevel
;
1069 } else if (wwin
->type
== net_wm_window_type_combo
) {
1070 layer
= WMSubmenuLevel
;
1071 } else if (wwin
->type
== net_wm_window_type_dnd
) {
1072 } else if (wwin
->type
== net_wm_window_type_normal
) {
1075 if (wwin
->client_flags
.sunken
&& WMSunkenLevel
< layer
)
1076 layer
= WMSunkenLevel
;
1077 if (wwin
->client_flags
.floating
&& WMFloatingLevel
> layer
)
1078 layer
= WMFloatingLevel
;
1083 static void doStateAtom(WWindow
*wwin
, Atom state
, int set
, Bool init
)
1085 if (state
== net_wm_state_sticky
) {
1086 if (set
== _NET_WM_STATE_TOGGLE
)
1087 set
= !IS_OMNIPRESENT(wwin
);
1089 if (set
!= wwin
->flags
.omnipresent
)
1090 wWindowSetOmnipresent(wwin
, set
);
1092 } else if (state
== net_wm_state_shaded
) {
1093 if (set
== _NET_WM_STATE_TOGGLE
)
1094 set
= !wwin
->flags
.shaded
;
1097 wwin
->flags
.shaded
= set
;
1102 wUnshadeWindow(wwin
);
1104 } else if (state
== net_wm_state_skip_taskbar
) {
1105 if (set
== _NET_WM_STATE_TOGGLE
)
1106 set
= !wwin
->client_flags
.skip_window_list
;
1108 wwin
->client_flags
.skip_window_list
= set
;
1109 } else if (state
== net_wm_state_skip_pager
) {
1110 if (set
== _NET_WM_STATE_TOGGLE
)
1111 set
= !wwin
->flags
.net_skip_pager
;
1113 wwin
->flags
.net_skip_pager
= set
;
1114 } else if (state
== net_wm_state_maximized_vert
) {
1115 if (set
== _NET_WM_STATE_TOGGLE
)
1116 set
= !(wwin
->flags
.maximized
& MAX_VERTICAL
);
1119 wwin
->flags
.maximized
|= (set
? MAX_VERTICAL
: 0);
1122 wMaximizeWindow(wwin
, wwin
->flags
.maximized
| MAX_VERTICAL
,
1123 wGetHeadForWindow(wwin
));
1125 wMaximizeWindow(wwin
, wwin
->flags
.maximized
& ~MAX_VERTICAL
,
1126 wGetHeadForWindow(wwin
));
1128 } else if (state
== net_wm_state_maximized_horz
) {
1129 if (set
== _NET_WM_STATE_TOGGLE
)
1130 set
= !(wwin
->flags
.maximized
& MAX_HORIZONTAL
);
1133 wwin
->flags
.maximized
|= (set
? MAX_HORIZONTAL
: 0);
1136 wMaximizeWindow(wwin
, wwin
->flags
.maximized
| MAX_HORIZONTAL
,
1137 wGetHeadForWindow(wwin
));
1139 wMaximizeWindow(wwin
, wwin
->flags
.maximized
& ~MAX_HORIZONTAL
,
1140 wGetHeadForWindow(wwin
));
1142 } else if (state
== net_wm_state_hidden
) {
1143 if (set
== _NET_WM_STATE_TOGGLE
)
1144 set
= !(wwin
->flags
.miniaturized
);
1147 wwin
->flags
.miniaturized
= set
;
1150 wIconifyWindow(wwin
);
1152 wDeiconifyWindow(wwin
);
1154 } else if (state
== net_wm_state_fullscreen
) {
1155 if (set
== _NET_WM_STATE_TOGGLE
)
1156 set
= !(wwin
->flags
.fullscreen
);
1159 wwin
->flags
.fullscreen
= set
;
1162 wFullscreenWindow(wwin
);
1164 wUnfullscreenWindow(wwin
);
1166 } else if (state
== net_wm_state_above
) {
1167 if (set
== _NET_WM_STATE_TOGGLE
)
1168 set
= !(wwin
->client_flags
.floating
);
1171 wwin
->client_flags
.floating
= set
;
1173 wwin
->client_flags
.floating
= set
;
1174 ChangeStackingLevel(wwin
->frame
->core
, getWindowLayer(wwin
));
1177 } else if (state
== net_wm_state_below
) {
1178 if (set
== _NET_WM_STATE_TOGGLE
)
1179 set
= !(wwin
->client_flags
.sunken
);
1182 wwin
->client_flags
.sunken
= set
;
1184 wwin
->client_flags
.sunken
= set
;
1185 ChangeStackingLevel(wwin
->frame
->core
, getWindowLayer(wwin
));
1190 wmessage("doStateAtom unknown atom %s set %d", XGetAtomName(dpy
, state
), set
);
1195 static void removeIcon(WWindow
*wwin
)
1197 if (wwin
->icon
== NULL
)
1199 if (wwin
->flags
.miniaturized
&& wwin
->icon
->mapped
) {
1200 XUnmapWindow(dpy
, wwin
->icon
->core
->window
);
1201 RemoveFromStackList(wwin
->icon
->core
);
1202 wIconDestroy(wwin
->icon
);
1207 static Bool
handleWindowType(WWindow
*wwin
, Atom type
, int *layer
)
1211 if (type
== net_wm_window_type_desktop
) {
1212 wwin
->client_flags
.no_titlebar
= 1;
1213 wwin
->client_flags
.no_resizable
= 1;
1214 wwin
->client_flags
.no_miniaturizable
= 1;
1215 wwin
->client_flags
.no_border
= 1;
1216 wwin
->client_flags
.no_resizebar
= 1;
1217 wwin
->client_flags
.no_shadeable
= 1;
1218 wwin
->client_flags
.no_movable
= 1;
1219 wwin
->client_flags
.omnipresent
= 1;
1220 wwin
->client_flags
.skip_window_list
= 1;
1221 wwin
->client_flags
.skip_switchpanel
= 1;
1222 wwin
->client_flags
.dont_move_off
= 1;
1223 wwin
->client_flags
.no_appicon
= 1;
1224 wwin
->flags
.net_skip_pager
= 1;
1227 } else if (type
== net_wm_window_type_dock
) {
1228 wwin
->client_flags
.no_titlebar
= 1;
1229 wwin
->client_flags
.no_resizable
= 1;
1230 wwin
->client_flags
.no_miniaturizable
= 1;
1231 wwin
->client_flags
.no_border
= 1; /* XXX: really not a single decoration. */
1232 wwin
->client_flags
.no_resizebar
= 1;
1233 wwin
->client_flags
.no_shadeable
= 1;
1234 wwin
->client_flags
.no_movable
= 1;
1235 wwin
->client_flags
.omnipresent
= 1;
1236 wwin
->client_flags
.skip_window_list
= 1;
1237 wwin
->client_flags
.skip_switchpanel
= 1;
1238 wwin
->client_flags
.dont_move_off
= 1;
1239 wwin
->flags
.net_skip_pager
= 1;
1240 } else if (type
== net_wm_window_type_toolbar
||
1241 type
== net_wm_window_type_menu
) {
1242 wwin
->client_flags
.no_resizable
= 1;
1243 wwin
->client_flags
.no_miniaturizable
= 1;
1244 wwin
->client_flags
.no_resizebar
= 1;
1245 wwin
->client_flags
.no_shadeable
= 1;
1246 wwin
->client_flags
.skip_window_list
= 1;
1247 wwin
->client_flags
.skip_switchpanel
= 1;
1248 wwin
->client_flags
.dont_move_off
= 1;
1249 wwin
->client_flags
.no_appicon
= 1;
1250 } else if (type
== net_wm_window_type_dropdown_menu
||
1251 type
== net_wm_window_type_popup_menu
||
1252 type
== net_wm_window_type_combo
) {
1253 wwin
->client_flags
.no_titlebar
= 1;
1254 wwin
->client_flags
.no_resizable
= 1;
1255 wwin
->client_flags
.no_miniaturizable
= 1;
1256 wwin
->client_flags
.no_resizebar
= 1;
1257 wwin
->client_flags
.no_shadeable
= 1;
1258 wwin
->client_flags
.skip_window_list
= 1;
1259 wwin
->client_flags
.skip_switchpanel
= 1;
1260 wwin
->client_flags
.dont_move_off
= 1;
1261 wwin
->client_flags
.no_appicon
= 1;
1262 } else if (type
== net_wm_window_type_utility
) {
1263 wwin
->client_flags
.no_appicon
= 1;
1264 } else if (type
== net_wm_window_type_splash
) {
1265 wwin
->client_flags
.no_titlebar
= 1;
1266 wwin
->client_flags
.no_resizable
= 1;
1267 wwin
->client_flags
.no_miniaturizable
= 1;
1268 wwin
->client_flags
.no_resizebar
= 1;
1269 wwin
->client_flags
.no_shadeable
= 1;
1270 wwin
->client_flags
.no_movable
= 1;
1271 wwin
->client_flags
.skip_window_list
= 1;
1272 wwin
->client_flags
.skip_switchpanel
= 1;
1273 wwin
->client_flags
.dont_move_off
= 1;
1274 wwin
->client_flags
.no_appicon
= 1;
1275 wwin
->flags
.net_skip_pager
= 1;
1276 } else if (type
== net_wm_window_type_dialog
) {
1277 /* These also seem a bad idea in our context -Dan
1278 // wwin->client_flags.skip_window_list = 1;
1279 // wwin->client_flags.no_appicon = 1;
1281 } else if (wwin
->type
== net_wm_window_type_tooltip
) {
1282 wwin
->client_flags
.no_titlebar
= 1;
1283 wwin
->client_flags
.no_resizable
= 1;
1284 wwin
->client_flags
.no_miniaturizable
= 1;
1285 wwin
->client_flags
.no_resizebar
= 1;
1286 wwin
->client_flags
.no_shadeable
= 1;
1287 wwin
->client_flags
.no_movable
= 1;
1288 wwin
->client_flags
.skip_window_list
= 1;
1289 wwin
->client_flags
.skip_switchpanel
= 1;
1290 wwin
->client_flags
.dont_move_off
= 1;
1291 wwin
->client_flags
.no_appicon
= 1;
1292 wwin
->client_flags
.no_focusable
= 1;
1293 wwin
->flags
.net_skip_pager
= 1;
1294 } else if (wwin
->type
== net_wm_window_type_notification
) {
1295 wwin
->client_flags
.no_titlebar
= 1;
1296 wwin
->client_flags
.no_resizable
= 1;
1297 wwin
->client_flags
.no_miniaturizable
= 1;
1298 wwin
->client_flags
.no_border
= 1;
1299 wwin
->client_flags
.no_resizebar
= 1;
1300 wwin
->client_flags
.no_shadeable
= 1;
1301 wwin
->client_flags
.no_movable
= 1;
1302 wwin
->client_flags
.omnipresent
= 1;
1303 wwin
->client_flags
.skip_window_list
= 1;
1304 wwin
->client_flags
.skip_switchpanel
= 1;
1305 wwin
->client_flags
.dont_move_off
= 1;
1306 wwin
->client_flags
.no_hide_others
= 1;
1307 wwin
->client_flags
.no_appicon
= 1;
1308 wwin
->client_flags
.no_focusable
= 1;
1309 wwin
->flags
.net_skip_pager
= 1;
1310 } else if (wwin
->type
== net_wm_window_type_dnd
) {
1311 wwin
->client_flags
.no_titlebar
= 1;
1312 wwin
->client_flags
.no_resizable
= 1;
1313 wwin
->client_flags
.no_miniaturizable
= 1;
1314 wwin
->client_flags
.no_border
= 1;
1315 wwin
->client_flags
.no_resizebar
= 1;
1316 wwin
->client_flags
.no_shadeable
= 1;
1317 wwin
->client_flags
.no_movable
= 1;
1318 wwin
->client_flags
.skip_window_list
= 1;
1319 wwin
->client_flags
.skip_switchpanel
= 1;
1320 wwin
->client_flags
.dont_move_off
= 1;
1321 wwin
->client_flags
.no_appicon
= 1;
1322 wwin
->flags
.net_skip_pager
= 1;
1323 } else if (type
== net_wm_window_type_normal
) {
1329 *layer
= getWindowLayer(wwin
);
1334 void wNETWMPositionSplash(WWindow
*wwin
, int *x
, int *y
, int width
, int height
)
1336 if (wwin
->type
== net_wm_window_type_splash
) {
1337 WScreen
*scr
= wwin
->screen_ptr
;
1338 WMRect rect
= wGetRectForHead(scr
, wGetHeadForPointerLocation(scr
));
1339 *x
= rect
.pos
.x
+ (rect
.size
.width
- width
) / 2;
1340 *y
= rect
.pos
.y
+ (rect
.size
.height
- height
) / 2;
1344 static void updateWindowType(WWindow
*wwin
)
1348 unsigned long nitems_ret
, bytes_after_ret
;
1351 if (XGetWindowProperty(dpy
, wwin
->client_win
, net_wm_window_type
, 0, 1,
1352 False
, XA_ATOM
, &type_ret
, &fmt_ret
, &nitems_ret
,
1353 &bytes_after_ret
, (unsigned char **)&data
) == Success
&& data
) {
1356 Atom
*type
= (Atom
*) data
;
1357 for (i
= 0; i
< nitems_ret
; ++i
) {
1358 if (handleWindowType(wwin
, type
[i
], &layer
))
1364 if (wwin
->frame
!= NULL
) {
1365 ChangeStackingLevel(wwin
->frame
->core
, layer
);
1366 wwin
->frame
->flags
.need_texture_change
= 1;
1367 wWindowConfigureBorders(wwin
);
1368 wFrameWindowPaint(wwin
->frame
);
1369 wNETWMUpdateActions(wwin
, False
);
1373 void wNETWMCheckClientHints(WWindow
*wwin
, int *layer
, int *workspace
)
1377 unsigned long nitems_ret
, bytes_after_ret
;
1380 if (XGetWindowProperty(dpy
, wwin
->client_win
, net_wm_desktop
, 0, 1, False
,
1381 XA_CARDINAL
, &type_ret
, &fmt_ret
, &nitems_ret
,
1382 &bytes_after_ret
, (unsigned char **)&data
) == Success
&& data
) {
1384 long desktop
= *data
;
1388 wwin
->client_flags
.omnipresent
= 1;
1390 *workspace
= desktop
;
1393 if (XGetWindowProperty(dpy
, wwin
->client_win
, net_wm_state
, 0, 1, False
,
1394 XA_ATOM
, &type_ret
, &fmt_ret
, &nitems_ret
,
1395 &bytes_after_ret
, (unsigned char **)&data
) == Success
&& data
) {
1397 Atom
*state
= (Atom
*) data
;
1398 for (i
= 0; i
< nitems_ret
; ++i
)
1399 doStateAtom(wwin
, state
[i
], _NET_WM_STATE_ADD
, True
);
1404 if (XGetWindowProperty(dpy
, wwin
->client_win
, net_wm_window_type
, 0, 1, False
,
1405 XA_ATOM
, &type_ret
, &fmt_ret
, &nitems_ret
,
1406 &bytes_after_ret
, (unsigned char **)&data
) == Success
&& data
) {
1408 Atom
*type
= (Atom
*) data
;
1409 for (i
= 0; i
< nitems_ret
; ++i
) {
1410 if (handleWindowType(wwin
, type
[i
], layer
))
1416 wNETWMUpdateActions(wwin
, False
);
1417 updateStrut(wwin
->screen_ptr
, wwin
->client_win
, False
);
1418 updateStrut(wwin
->screen_ptr
, wwin
->client_win
, True
);
1420 wScreenUpdateUsableArea(wwin
->screen_ptr
);
1423 static Bool
updateNetIconInfo(WWindow
*wwin
)
1427 unsigned long nitems_ret
, bytes_after_ret
;
1429 Bool hasState
= False
;
1430 Bool old_state
= wwin
->flags
.net_handle_icon
;
1432 if (XGetWindowProperty(dpy
, wwin
->client_win
, net_wm_handled_icons
, 0, 1, False
,
1433 XA_CARDINAL
, &type_ret
, &fmt_ret
, &nitems_ret
,
1434 &bytes_after_ret
, (unsigned char **)&data
) == Success
&& data
) {
1435 long handled
= *data
;
1436 wwin
->flags
.net_handle_icon
= (handled
!= 0);
1441 wwin
->flags
.net_handle_icon
= False
;
1444 if (XGetWindowProperty(dpy
, wwin
->client_win
, net_wm_icon_geometry
, 0, 4, False
,
1445 XA_CARDINAL
, &type_ret
, &fmt_ret
, &nitems_ret
,
1446 &bytes_after_ret
, (unsigned char **)&data
) == Success
&& data
) {
1449 if (wwin
->flags
.net_handle_icon
)
1451 wwin
->flags
.net_handle_icon
= True
;
1454 wwin
->icon_x
= data
[0];
1455 wwin
->icon_y
= data
[1];
1456 wwin
->icon_w
= data
[2];
1457 wwin
->icon_h
= data
[3];
1464 wwin
->flags
.net_handle_icon
= False
;
1467 if (wwin
->flags
.miniaturized
&& old_state
!= wwin
->flags
.net_handle_icon
) {
1468 if (wwin
->flags
.net_handle_icon
) {
1471 wwin
->flags
.miniaturized
= False
;
1472 wwin
->flags
.skip_next_animation
= True
;
1473 wIconifyWindow(wwin
);
1480 void wNETWMCheckInitialClientState(WWindow
*wwin
)
1483 wmessage("wNETWMCheckInitialClientState");
1486 wNETWMShowingDesktop(wwin
->screen_ptr
, False
);
1488 updateWindowType(wwin
);
1489 updateNetIconInfo(wwin
);
1490 updateIconImage(wwin
);
1493 void wNETWMCheckInitialFrameState(WWindow
*wwin
)
1496 wmessage("wNETWMCheckInitialFrameState");
1499 updateWindowOpacity(wwin
);
1502 static void handleDesktopNames(WScreen
*scr
)
1504 unsigned long nitems_ret
, bytes_after_ret
;
1505 char *data
, *names
[32];
1509 if (XGetWindowProperty(dpy
, scr
->root_win
, net_desktop_names
, 0, 1, False
,
1510 utf8_string
, &type_ret
, &fmt_ret
, &nitems_ret
,
1511 &bytes_after_ret
, (unsigned char **)&data
) != Success
)
1517 if (type_ret
!= utf8_string
|| fmt_ret
!= 8)
1522 for (i
= 0; i
< nitems_ret
; i
++) {
1525 names
[n
] = &data
[i
];
1526 } else if (*names
[n
] == 0) {
1527 names
[n
] = &data
[i
];
1528 wWorkspaceRename(scr
, n
, names
[n
]);
1533 Bool
wNETWMProcessClientMessage(XClientMessageEvent
*event
)
1539 wmessage("processClientMessage type %s", XGetAtomName(dpy
, event
->message_type
));
1542 scr
= wScreenForWindow(event
->window
);
1544 /* generic client messages */
1545 if (event
->message_type
== net_current_desktop
) {
1546 wWorkspaceChange(scr
, event
->data
.l
[0]);
1549 } else if (event
->message_type
== net_number_of_desktops
) {
1552 value
= event
->data
.l
[0];
1553 if (value
> scr
->workspace_count
) {
1554 wWorkspaceMake(scr
, value
- scr
->workspace_count
);
1555 } else if (value
< scr
->workspace_count
) {
1557 Bool rebuild
= False
;
1559 for (i
= scr
->workspace_count
- 1; i
>= value
; i
--) {
1560 if (!wWorkspaceDelete(scr
, i
)) {
1567 updateWorkspaceCount(scr
);
1571 } else if (event
->message_type
== net_showing_desktop
) {
1572 wNETWMShowingDesktop(scr
, event
->data
.l
[0]);
1575 } else if (event
->message_type
== net_desktop_names
) {
1576 handleDesktopNames(scr
);
1581 /* window specific client messages */
1583 wwin
= wWindowFor(event
->window
);
1587 if (event
->message_type
== net_active_window
) {
1589 * Satisfy a client's focus request only if
1590 * - request comes from a pager, or
1591 * - it's explicitly allowed in Advanced Options, or
1592 * - giving the client the focus does not cause a change in
1593 * the active workspace (XXX: or the active head if Xinerama)
1595 if (wwin
->frame
->workspace
== wwin
->screen_ptr
->current_workspace
/* No workspace change */
1596 || event
->data
.l
[0] == 2 /* Requested by pager */
1597 || WFLAGP(wwin
, focus_across_wksp
) /* Explicitly allowed */) {
1598 wNETWMShowingDesktop(scr
, False
);
1599 wMakeWindowVisible(wwin
);
1603 } else if (event
->message_type
== net_close_window
) {
1604 if (!WFLAGP(wwin
, no_closable
)) {
1605 if (wwin
->protocols
.DELETE_WINDOW
)
1606 wClientSendProtocol(wwin
, w_global
.atom
.wm
.delete_window
,
1607 w_global
.timestamp
.last_event
);
1611 } else if (event
->message_type
== net_wm_state
) {
1612 int maximized
= wwin
->flags
.maximized
;
1613 long set
= event
->data
.l
[0];
1616 wmessage("net_wm_state set %ld a1 %s a2 %s", set
,
1617 XGetAtomName(dpy
, event
->data
.l
[1]), XGetAtomName(dpy
, event
->data
.l
[2]));
1620 doStateAtom(wwin
, (Atom
) event
->data
.l
[1], set
, False
);
1621 if (event
->data
.l
[2])
1622 doStateAtom(wwin
, (Atom
) event
->data
.l
[2], set
, False
);
1624 if (wwin
->flags
.maximized
!= maximized
) {
1625 if (!wwin
->flags
.maximized
) {
1626 wwin
->flags
.maximized
= maximized
;
1627 wUnmaximizeWindow(wwin
);
1629 wMaximizeWindow(wwin
, wwin
->flags
.maximized
,
1630 wGetHeadForWindow(wwin
));
1633 updateStateHint(wwin
, False
, False
);
1636 } else if (event
->message_type
== net_wm_handled_icons
|| event
->message_type
== net_wm_icon_geometry
) {
1637 updateNetIconInfo(wwin
);
1640 } else if (event
->message_type
== net_wm_desktop
) {
1641 long desktop
= event
->data
.l
[0];
1643 if (desktop
== -1) {
1644 wWindowSetOmnipresent(wwin
, True
);
1646 if (IS_OMNIPRESENT(wwin
))
1647 wWindowSetOmnipresent(wwin
, False
);
1648 wWindowChangeWorkspace(wwin
, desktop
);
1656 void wNETWMCheckClientHintChange(WWindow
*wwin
, XPropertyEvent
*event
)
1659 wmessage("clientHintChange type %s", XGetAtomName(dpy
, event
->atom
));
1662 if (event
->atom
== net_wm_strut
|| event
->atom
== net_wm_strut_partial
) {
1663 updateStrut(wwin
->screen_ptr
, wwin
->client_win
, False
);
1664 updateStrut(wwin
->screen_ptr
, wwin
->client_win
, True
);
1665 wScreenUpdateUsableArea(wwin
->screen_ptr
);
1666 } else if (event
->atom
== net_wm_handled_icons
|| event
->atom
== net_wm_icon_geometry
) {
1667 updateNetIconInfo(wwin
);
1668 } else if (event
->atom
== net_wm_window_type
) {
1669 updateWindowType(wwin
);
1670 } else if (event
->atom
== net_wm_name
) {
1671 char *name
= wNETWMGetWindowName(wwin
->client_win
);
1672 wWindowUpdateName(wwin
, name
);
1675 } else if (event
->atom
== net_wm_icon_name
) {
1677 wIconChangeTitle(wwin
->icon
, wwin
);
1678 wIconPaint(wwin
->icon
);
1680 } else if (event
->atom
== net_wm_icon
) {
1681 updateIconImage(wwin
);
1682 } else if (event
->atom
== net_wm_window_opacity
) {
1683 updateWindowOpacity(wwin
);
1687 int wNETWMGetPidForWindow(Window window
)
1691 unsigned long nitems_ret
, bytes_after_ret
;
1695 if (XGetWindowProperty(dpy
, window
, net_wm_pid
, 0, 1, False
,
1696 XA_CARDINAL
, &type_ret
, &fmt_ret
, &nitems_ret
,
1697 &bytes_after_ret
, (unsigned char **)&data
) == Success
&& data
) {
1707 char *wNETWMGetWindowName(Window window
)
1713 name
= (char *)PropGetCheckProperty(window
, net_wm_name
, utf8_string
, 0, 0, &size
);
1715 ret
= wstrndup(name
, size
);
1724 char *wNETWMGetIconName(Window window
)
1730 name
= (char *)PropGetCheckProperty(window
, net_wm_icon_name
, utf8_string
, 0, 0, &size
);
1732 ret
= wstrndup(name
, size
);
1741 static void observer(void *self
, WMNotification
*notif
)
1743 WWindow
*wwin
= (WWindow
*) WMGetNotificationObject(notif
);
1744 const char *name
= WMGetNotificationName(notif
);
1745 void *data
= WMGetNotificationClientData(notif
);
1746 NetData
*ndata
= (NetData
*) self
;
1748 if (strcmp(name
, WMNManaged
) == 0 && wwin
) {
1749 updateClientList(wwin
->screen_ptr
);
1750 updateClientListStacking(wwin
->screen_ptr
, NULL
);
1751 updateStateHint(wwin
, True
, False
);
1753 updateStrut(wwin
->screen_ptr
, wwin
->client_win
, False
);
1754 updateStrut(wwin
->screen_ptr
, wwin
->client_win
, True
);
1755 wScreenUpdateUsableArea(wwin
->screen_ptr
);
1756 } else if (strcmp(name
, WMNUnmanaged
) == 0 && wwin
) {
1757 updateClientList(wwin
->screen_ptr
);
1758 updateClientListStacking(wwin
->screen_ptr
, wwin
);
1759 updateWorkspaceHint(wwin
, False
, True
);
1760 updateStateHint(wwin
, False
, True
);
1761 wNETWMUpdateActions(wwin
, True
);
1763 updateStrut(wwin
->screen_ptr
, wwin
->client_win
, False
);
1764 wScreenUpdateUsableArea(wwin
->screen_ptr
);
1765 } else if (strcmp(name
, WMNResetStacking
) == 0 && wwin
) {
1766 updateClientListStacking(wwin
->screen_ptr
, NULL
);
1767 updateStateHint(wwin
, False
, False
);
1768 } else if (strcmp(name
, WMNChangedStacking
) == 0 && wwin
) {
1769 updateClientListStacking(wwin
->screen_ptr
, NULL
);
1770 updateStateHint(wwin
, False
, False
);
1771 } else if (strcmp(name
, WMNChangedFocus
) == 0) {
1772 updateFocusHint(ndata
->scr
);
1773 } else if (strcmp(name
, WMNChangedWorkspace
) == 0 && wwin
) {
1774 updateWorkspaceHint(wwin
, False
, False
);
1775 updateStateHint(wwin
, True
, False
);
1776 } else if (strcmp(name
, WMNChangedState
) == 0 && wwin
) {
1777 updateStateHint(wwin
, !strcmp(data
, "omnipresent"), False
);
1781 static void wsobserver(void *self
, WMNotification
*notif
)
1783 WScreen
*scr
= (WScreen
*) WMGetNotificationObject(notif
);
1784 const char *name
= WMGetNotificationName(notif
);
1786 /* Parameter not used, but tell the compiler that it is ok */
1789 if (strcmp(name
, WMNWorkspaceCreated
) == 0) {
1790 updateWorkspaceCount(scr
);
1791 updateWorkspaceNames(scr
);
1792 wNETWMUpdateWorkarea(scr
);
1793 } else if (strcmp(name
, WMNWorkspaceDestroyed
) == 0) {
1794 updateWorkspaceCount(scr
);
1795 updateWorkspaceNames(scr
);
1796 wNETWMUpdateWorkarea(scr
);
1797 } else if (strcmp(name
, WMNWorkspaceChanged
) == 0) {
1798 updateCurrentWorkspace(scr
);
1799 } else if (strcmp(name
, WMNWorkspaceNameChanged
) == 0) {
1800 updateWorkspaceNames(scr
);
1804 void wNETFrameExtents(WWindow
*wwin
)
1806 long extents
[4] = { 0, 0, 0, 0 };
1808 /* The extents array describes dimensions which are not
1809 * part of the client window. In our case that means
1810 * widths of the border and heights of the titlebar and resizebar.
1817 if (wwin
->frame
->titlebar
)
1818 extents
[2] = wwin
->frame
->titlebar
->height
;
1819 if (wwin
->frame
->resizebar
)
1820 extents
[3] = wwin
->frame
->resizebar
->height
;
1821 if (HAS_BORDER(wwin
)) {
1822 extents
[0] += wwin
->screen_ptr
->frame_border_width
;
1823 extents
[1] += wwin
->screen_ptr
->frame_border_width
;
1824 extents
[2] += wwin
->screen_ptr
->frame_border_width
;
1825 extents
[3] += wwin
->screen_ptr
->frame_border_width
;
1828 XChangeProperty(dpy
, wwin
->client_win
, net_frame_extents
, XA_CARDINAL
, 32, PropModeReplace
, (unsigned char *) extents
, 4);
1831 void wNETCleanupFrameExtents(WWindow
*wwin
)
1833 XDeleteProperty(dpy
, wwin
->client_win
, net_frame_extents
);