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_REMOVE 0
217 #define _NET_WM_STATE_ADD 1
218 #define _NET_WM_STATE_TOGGLE 2
222 * These constant provide information on the kind of window move/resize when
223 * it is initiated by the application instead of by WindowMaker. They are
224 * parameter for the client message _NET_WM_MOVERESIZE, as defined by the
225 * FreeDesktop wm-spec standard:
226 * http://standards.freedesktop.org/wm-spec/1.5/ar01s04.html
228 * Today, WindowMaker does not support this at all (the corresponding Atom
229 * is not added to the list in setSupportedHints), probably because there is
230 * nothing it needs to do about it, the application is assumed to know what
231 * it is doing, and WindowMaker won't get in the way.
233 * The definition of the constants (taken from the standard) are disabled to
234 * avoid a spurious warning (-Wunused-macros).
236 #define _NET_WM_MOVERESIZE_SIZE_TOPLEFT 0
237 #define _NET_WM_MOVERESIZE_SIZE_TOP 1
238 #define _NET_WM_MOVERESIZE_SIZE_TOPRIGHT 2
239 #define _NET_WM_MOVERESIZE_SIZE_RIGHT 3
240 #define _NET_WM_MOVERESIZE_SIZE_BOTTOMRIGHT 4
241 #define _NET_WM_MOVERESIZE_SIZE_BOTTOM 5
242 #define _NET_WM_MOVERESIZE_SIZE_BOTTOMLEFT 6
243 #define _NET_WM_MOVERESIZE_SIZE_LEFT 7
244 #define _NET_WM_MOVERESIZE_MOVE 8 /* movement only */
245 #define _NET_WM_MOVERESIZE_SIZE_KEYBOARD 9 /* size via keyboard */
246 #define _NET_WM_MOVERESIZE_MOVE_KEYBOARD 10 /* move via keyboard */
249 static void observer(void *self
, WMNotification
*notif
);
250 static void wsobserver(void *self
, WMNotification
*notif
);
252 static void updateClientList(WScreen
*scr
);
253 static void updateClientListStacking(WScreen
*scr
, WWindow
*);
255 static void updateWorkspaceNames(WScreen
*scr
);
256 static void updateCurrentWorkspace(WScreen
*scr
);
257 static void updateWorkspaceCount(WScreen
*scr
);
258 static void wNETWMShowingDesktop(WScreen
*scr
, Bool show
);
260 typedef struct NetData
{
262 WReservedArea
*strut
;
263 WWindow
**show_desktop
;
266 static void setSupportedHints(WScreen
*scr
)
268 Atom atom
[wlengthof(atomNames
)];
271 /* set supported hints list */
272 /* XXX: extend this !!! */
274 atom
[i
++] = net_client_list
;
275 atom
[i
++] = net_client_list_stacking
;
276 atom
[i
++] = net_number_of_desktops
;
277 atom
[i
++] = net_desktop_geometry
;
278 atom
[i
++] = net_desktop_viewport
;
279 atom
[i
++] = net_current_desktop
;
280 atom
[i
++] = net_desktop_names
;
281 atom
[i
++] = net_active_window
;
282 atom
[i
++] = net_workarea
;
283 atom
[i
++] = net_supporting_wm_check
;
284 atom
[i
++] = net_showing_desktop
;
286 atom
[i
++] = net_wm_moveresize
;
288 atom
[i
++] = net_wm_desktop
;
289 atom
[i
++] = net_wm_window_type
;
290 atom
[i
++] = net_wm_window_type_desktop
;
291 atom
[i
++] = net_wm_window_type_dock
;
292 atom
[i
++] = net_wm_window_type_toolbar
;
293 atom
[i
++] = net_wm_window_type_menu
;
294 atom
[i
++] = net_wm_window_type_utility
;
295 atom
[i
++] = net_wm_window_type_splash
;
296 atom
[i
++] = net_wm_window_type_dialog
;
297 atom
[i
++] = net_wm_window_type_dropdown_menu
;
298 atom
[i
++] = net_wm_window_type_popup_menu
;
299 atom
[i
++] = net_wm_window_type_tooltip
;
300 atom
[i
++] = net_wm_window_type_notification
;
301 atom
[i
++] = net_wm_window_type_combo
;
302 atom
[i
++] = net_wm_window_type_dnd
;
303 atom
[i
++] = net_wm_window_type_normal
;
305 atom
[i
++] = net_wm_state
;
306 /* atom[i++] = net_wm_state_modal; *//* XXX: not sure where/when to use it. */
307 atom
[i
++] = net_wm_state_sticky
;
308 atom
[i
++] = net_wm_state_shaded
;
309 atom
[i
++] = net_wm_state_maximized_horz
;
310 atom
[i
++] = net_wm_state_maximized_vert
;
311 atom
[i
++] = net_wm_state_skip_taskbar
;
312 atom
[i
++] = net_wm_state_skip_pager
;
313 atom
[i
++] = net_wm_state_hidden
;
314 atom
[i
++] = net_wm_state_fullscreen
;
315 atom
[i
++] = net_wm_state_above
;
316 atom
[i
++] = net_wm_state_below
;
318 atom
[i
++] = net_wm_allowed_actions
;
319 atom
[i
++] = net_wm_action_move
;
320 atom
[i
++] = net_wm_action_resize
;
321 atom
[i
++] = net_wm_action_minimize
;
322 atom
[i
++] = net_wm_action_shade
;
323 atom
[i
++] = net_wm_action_stick
;
324 atom
[i
++] = net_wm_action_maximize_horz
;
325 atom
[i
++] = net_wm_action_maximize_vert
;
326 atom
[i
++] = net_wm_action_fullscreen
;
327 atom
[i
++] = net_wm_action_change_desktop
;
328 atom
[i
++] = net_wm_action_close
;
330 atom
[i
++] = net_wm_strut
;
331 atom
[i
++] = net_wm_icon_geometry
;
332 atom
[i
++] = net_wm_icon
;
333 atom
[i
++] = net_wm_handled_icons
;
334 atom
[i
++] = net_wm_window_opacity
;
336 atom
[i
++] = net_frame_extents
;
338 atom
[i
++] = net_wm_name
;
339 atom
[i
++] = net_wm_icon_name
;
341 XChangeProperty(dpy
, scr
->root_win
, net_supported
, XA_ATOM
, 32, PropModeReplace
, (unsigned char *)atom
, i
);
343 /* set supporting wm hint */
344 XChangeProperty(dpy
, scr
->root_win
, net_supporting_wm_check
, XA_WINDOW
, 32,
345 PropModeReplace
, (unsigned char *)&scr
->info_window
, 1);
347 XChangeProperty(dpy
, scr
->info_window
, net_supporting_wm_check
, XA_WINDOW
,
348 32, PropModeReplace
, (unsigned char *)&scr
->info_window
, 1);
351 void wNETWMUpdateDesktop(WScreen
*scr
)
353 long *views
, sizes
[2];
356 if (scr
->workspace_count
== 0)
359 count
= scr
->workspace_count
* 2;
360 views
= wmalloc(sizeof(long) * count
);
361 sizes
[0] = scr
->scr_width
;
362 sizes
[1] = scr
->scr_height
;
364 for (i
= 0; i
< scr
->workspace_count
; i
++) {
365 views
[2 * i
+ 0] = 0;
366 views
[2 * i
+ 1] = 0;
369 XChangeProperty(dpy
, scr
->root_win
, net_desktop_geometry
, XA_CARDINAL
, 32,
370 PropModeReplace
, (unsigned char *)sizes
, 2);
372 XChangeProperty(dpy
, scr
->root_win
, net_desktop_viewport
, XA_CARDINAL
, 32,
373 PropModeReplace
, (unsigned char *)views
, count
);
378 int wNETWMGetCurrentDesktopFromHint(WScreen
*scr
)
383 prop
= PropGetCheckProperty(scr
->root_win
, net_current_desktop
, XA_CARDINAL
, 0, 1, &count
);
385 int desktop
= *(long *)prop
;
393 * Find the best icon to be used by Window Maker for appicon/miniwindows.
394 * Currently the algorithm is to take the image with the size closest
395 * to icon_size x icon_size, but never bigger than that.
397 * This algorithm is very poorly implemented and needs to be redone (it can
398 * easily select images with very large widths and very small heights over
399 * square images, if the area of the former is closer to the desired one).
401 * The logic can also be changed to accept bigger images and scale them down.
403 static unsigned long *findBestIcon(unsigned long *data
, unsigned long items
)
406 unsigned long i
, distance
;
409 /* better use only 75% of icon_size. For 64x64 this means 48x48
410 * This leaves room around the icon for the miniwindow title and
411 * results in better overall aesthetics -Dan */
412 wanted
= wPreferences
.icon_size
* wPreferences
.icon_size
;
414 for (icon
= NULL
, distance
= wanted
, i
= 0L; i
< items
- 1;) {
415 size
= data
[i
] * data
[i
+ 1];
419 if (d
>= 0 && d
<= distance
&& (i
+ size
+ 2) <= items
) {
429 static RImage
*makeRImageFromARGBData(unsigned long *data
)
431 int size
, width
, height
, i
;
433 unsigned char *imgdata
;
438 size
= width
* height
;
443 image
= RCreateImage(width
, height
, True
);
445 for (imgdata
= image
->data
, i
= 2; i
< size
+ 2; i
++, imgdata
+= 4) {
447 imgdata
[3] = (pixel
>> 24) & 0xff; /* A */
448 imgdata
[0] = (pixel
>> 16) & 0xff; /* R */
449 imgdata
[1] = (pixel
>> 8) & 0xff; /* G */
450 imgdata
[2] = (pixel
>> 0) & 0xff; /* B */
456 RImage
*get_window_image_from_x11(Window window
)
461 unsigned long items
, rest
;
462 unsigned long *property
, *data
;
464 /* Get the icon from X11 Window */
465 if (XGetWindowProperty(dpy
, window
, net_wm_icon
, 0L, LONG_MAX
,
466 False
, XA_CARDINAL
, &type
, &format
, &items
, &rest
,
467 (unsigned char **)&property
) != Success
|| !property
)
470 if (type
!= XA_CARDINAL
|| format
!= 32 || items
< 2) {
475 /* Find the best icon */
476 data
= findBestIcon(property
, items
);
482 /* Save the best icon in the X11 icon */
483 image
= makeRImageFromARGBData(data
);
487 /* Resize the image to the correct value */
488 image
= wIconValidateIconSize(image
, wPreferences
.icon_size
);
493 static void updateIconImage(WWindow
*wwin
)
495 /* Remove the icon image from X11 */
496 if (wwin
->net_icon_image
)
497 RReleaseImage(wwin
->net_icon_image
);
499 /* Save the icon in the X11 icon */
500 wwin
->net_icon_image
= get_window_image_from_x11(wwin
->client_win
);
502 /* Refresh the Window Icon */
504 wIconUpdate(wwin
->icon
);
506 /* Refresh the application icon */
507 WApplication
*app
= wApplicationOf(wwin
->main_window
);
508 if (app
&& app
->app_icon
) {
509 wIconUpdate(app
->app_icon
->icon
);
510 wAppIconPaint(app
->app_icon
);
514 static void updateWindowOpacity(WWindow
*wwin
)
518 unsigned long items
, rest
;
519 unsigned long *property
;
524 /* We don't care about this ourselves, but other programs need us to copy
525 * this to the frame window. */
526 if (XGetWindowProperty(dpy
, wwin
->client_win
, net_wm_window_opacity
, 0L, 1L,
527 False
, XA_CARDINAL
, &type
, &format
, &items
, &rest
,
528 (unsigned char **)&property
) != Success
)
532 XDeleteProperty(dpy
, wwin
->frame
->core
->window
, net_wm_window_opacity
);
533 } else if (type
== XA_CARDINAL
&& format
== 32 && items
== 1 && property
) {
534 XChangeProperty(dpy
, wwin
->frame
->core
->window
, net_wm_window_opacity
,
535 XA_CARDINAL
, 32, PropModeReplace
, (unsigned char *)property
, 1L);
542 static void updateShowDesktop(WScreen
*scr
, Bool show
)
546 foo
= (show
== True
);
547 XChangeProperty(dpy
, scr
->root_win
, net_showing_desktop
, XA_CARDINAL
, 32,
548 PropModeReplace
, (unsigned char *)&foo
, 1);
551 static void wNETWMShowingDesktop(WScreen
*scr
, Bool show
)
553 if (show
&& scr
->netdata
->show_desktop
== NULL
) {
554 WWindow
*tmp
, **wins
;
557 wins
= (WWindow
**) wmalloc(sizeof(WWindow
*) * (scr
->window_count
+ 1));
559 tmp
= scr
->focused_window
;
561 if (!tmp
->flags
.hidden
&& !tmp
->flags
.miniaturized
&& !WFLAGP(tmp
, skip_window_list
)) {
564 tmp
->flags
.skip_next_animation
= 1;
565 tmp
->flags
.net_show_desktop
= 1;
573 scr
->netdata
->show_desktop
= wins
;
574 updateShowDesktop(scr
, True
);
575 } else if (scr
->netdata
->show_desktop
!= NULL
) {
576 /* FIXME: get rid of workspace flashing ! */
577 int ws
= scr
->current_workspace
;
579 for (tmp
= scr
->netdata
->show_desktop
; *tmp
; ++tmp
) {
580 wDeiconifyWindow(*tmp
);
581 (*tmp
)->flags
.net_show_desktop
= 0;
583 if (ws
!= scr
->current_workspace
)
584 wWorkspaceChange(scr
, ws
);
585 wfree(scr
->netdata
->show_desktop
);
586 scr
->netdata
->show_desktop
= NULL
;
587 updateShowDesktop(scr
, False
);
591 void wNETWMInitStuff(WScreen
*scr
)
597 wmessage("wNETWMInitStuff");
600 #ifdef HAVE_XINTERNATOMS
602 Atom atoms
[wlengthof(atomNames
)];
603 char *names
[wlengthof(atomNames
)];
605 for (i
= 0; i
< wlengthof(atomNames
); ++i
)
606 names
[i
] = atomNames
[i
].name
;
608 XInternAtoms(dpy
, &names
[0], wlengthof(atomNames
), False
, atoms
);
609 for (i
= 0; i
< wlengthof(atomNames
); ++i
)
610 *atomNames
[i
].atom
= atoms
[i
];
614 for (i
= 0; i
< wlengthof(atomNames
); i
++)
615 *atomNames
[i
].atom
= XInternAtom(dpy
, atomNames
[i
].name
, False
);
618 data
= wmalloc(sizeof(NetData
));
621 data
->show_desktop
= NULL
;
625 setSupportedHints(scr
);
627 WMAddNotificationObserver(observer
, data
, WMNManaged
, NULL
);
628 WMAddNotificationObserver(observer
, data
, WMNUnmanaged
, NULL
);
629 WMAddNotificationObserver(observer
, data
, WMNChangedWorkspace
, NULL
);
630 WMAddNotificationObserver(observer
, data
, WMNChangedState
, NULL
);
631 WMAddNotificationObserver(observer
, data
, WMNChangedFocus
, NULL
);
632 WMAddNotificationObserver(observer
, data
, WMNChangedStacking
, NULL
);
633 WMAddNotificationObserver(observer
, data
, WMNChangedName
, NULL
);
635 WMAddNotificationObserver(wsobserver
, data
, WMNWorkspaceCreated
, NULL
);
636 WMAddNotificationObserver(wsobserver
, data
, WMNWorkspaceDestroyed
, NULL
);
637 WMAddNotificationObserver(wsobserver
, data
, WMNWorkspaceChanged
, NULL
);
638 WMAddNotificationObserver(wsobserver
, data
, WMNWorkspaceNameChanged
, NULL
);
640 updateClientList(scr
);
641 updateClientListStacking(scr
, NULL
);
642 updateWorkspaceCount(scr
);
643 updateWorkspaceNames(scr
);
644 updateShowDesktop(scr
, False
);
646 wScreenUpdateUsableArea(scr
);
649 void wNETWMCleanup(WScreen
*scr
)
653 for (i
= 0; i
< wlengthof(atomNames
); i
++)
654 XDeleteProperty(dpy
, scr
->root_win
, *atomNames
[i
].atom
);
657 void wNETWMUpdateActions(WWindow
*wwin
, Bool del
)
659 Atom action
[10]; /* nr of actions atoms defined */
663 XDeleteProperty(dpy
, wwin
->client_win
, net_wm_allowed_actions
);
667 if (IS_MOVABLE(wwin
))
668 action
[i
++] = net_wm_action_move
;
670 if (IS_RESIZABLE(wwin
))
671 action
[i
++] = net_wm_action_resize
;
673 if (!WFLAGP(wwin
, no_miniaturizable
))
674 action
[i
++] = net_wm_action_minimize
;
676 if (!WFLAGP(wwin
, no_shadeable
))
677 action
[i
++] = net_wm_action_shade
;
679 /* if (!WFLAGP(wwin, no_stickable)) */
680 action
[i
++] = net_wm_action_stick
;
682 /* if (!(WFLAGP(wwin, no_maximizeable) & MAX_HORIZONTAL)) */
683 if (IS_RESIZABLE(wwin
))
684 action
[i
++] = net_wm_action_maximize_horz
;
686 /* if (!(WFLAGP(wwin, no_maximizeable) & MAX_VERTICAL)) */
687 if (IS_RESIZABLE(wwin
))
688 action
[i
++] = net_wm_action_maximize_vert
;
690 /* if (!WFLAGP(wwin, no_fullscreen)) */
691 action
[i
++] = net_wm_action_fullscreen
;
693 /* if (!WFLAGP(wwin, no_change_desktop)) */
694 action
[i
++] = net_wm_action_change_desktop
;
696 if (!WFLAGP(wwin
, no_closable
))
697 action
[i
++] = net_wm_action_close
;
699 XChangeProperty(dpy
, wwin
->client_win
, net_wm_allowed_actions
,
700 XA_ATOM
, 32, PropModeReplace
, (unsigned char *)action
, i
);
703 void wNETWMUpdateWorkarea(WScreen
*scr
)
708 if (!scr
->netdata
|| scr
->workspace_count
== 0 || !scr
->usableArea
)
711 count
= scr
->workspace_count
* 4;
712 area
= wmalloc(sizeof(long) * count
);
714 for (i
= 0; i
< scr
->workspace_count
; i
++) {
715 area
[4 * i
+ 0] = scr
->usableArea
[0].x1
;
716 area
[4 * i
+ 1] = scr
->usableArea
[0].y1
;
717 area
[4 * i
+ 2] = scr
->usableArea
[0].x2
- scr
->usableArea
[0].x1
;
718 area
[4 * i
+ 3] = scr
->usableArea
[0].y2
- scr
->usableArea
[0].y1
;
721 XChangeProperty(dpy
, scr
->root_win
, net_workarea
, XA_CARDINAL
, 32,
722 PropModeReplace
, (unsigned char *)area
, count
);
726 Bool
wNETWMGetUsableArea(WScreen
*scr
, int head
, WArea
*area
)
731 if (!scr
->netdata
|| !scr
->netdata
->strut
)
734 area
->x1
= area
->y1
= area
->x2
= area
->y2
= 0;
736 for (cur
= scr
->netdata
->strut
; cur
; cur
= cur
->next
) {
737 WWindow
*wwin
= wWindowFor(cur
->window
);
738 if (wWindowTouchesHead(wwin
, head
)) {
739 if (cur
->area
.x1
> area
->x1
)
740 area
->x1
= cur
->area
.x1
;
741 if (cur
->area
.y1
> area
->y1
)
742 area
->y1
= cur
->area
.y1
;
743 if (cur
->area
.x2
> area
->x2
)
744 area
->x2
= cur
->area
.x2
;
745 if (cur
->area
.y2
> area
->y2
)
746 area
->y2
= cur
->area
.y2
;
750 if (area
->x1
== 0 && area
->x2
== 0 && area
->y1
== 0 && area
->y2
== 0)
753 rect
= wGetRectForHead(scr
, head
);
755 area
->x1
= rect
.pos
.x
+ area
->x1
;
756 area
->x2
= rect
.pos
.x
+ rect
.size
.width
- area
->x2
;
757 area
->y1
= rect
.pos
.y
+ area
->y1
;
758 area
->y2
= rect
.pos
.y
+ rect
.size
.height
- area
->y2
;
763 static void updateClientList(WScreen
*scr
)
769 windows
= (Window
*) wmalloc(sizeof(Window
) * (scr
->window_count
+ 1));
772 wwin
= scr
->focused_window
;
774 windows
[count
++] = wwin
->client_win
;
777 XChangeProperty(dpy
, scr
->root_win
, net_client_list
, XA_WINDOW
, 32,
778 PropModeReplace
, (unsigned char *)windows
, count
);
784 static void updateClientListStacking(WScreen
*scr
, WWindow
*wwin_excl
)
787 Window
*client_list
, *client_list_reverse
;
792 /* update client list */
793 i
= scr
->window_count
+ 1;
794 client_list
= (Window
*) wmalloc(sizeof(Window
) * i
);
795 client_list_reverse
= (Window
*) wmalloc(sizeof(Window
) * i
);
798 WM_ETARETI_BAG(scr
->stacking_list
, tmp
, iter
) {
800 wwin
= wWindowFor(tmp
->window
);
801 /* wwin_excl is a window to exclude from the list
802 (e.g. it's now unmanaged) */
803 if (wwin
&& (wwin
!= wwin_excl
))
804 client_list
[client_count
++] = wwin
->client_win
;
805 tmp
= tmp
->stacking
->under
;
809 for (i
= 0; i
< client_count
; i
++) {
810 Window w
= client_list
[client_count
- i
- 1];
811 client_list_reverse
[i
] = w
;
814 XChangeProperty(dpy
, scr
->root_win
, net_client_list_stacking
, XA_WINDOW
, 32,
815 PropModeReplace
, (unsigned char *)client_list_reverse
, client_count
);
818 wfree(client_list_reverse
);
823 static void updateWorkspaceCount(WScreen
*scr
)
827 count
= scr
->workspace_count
;
829 XChangeProperty(dpy
, scr
->root_win
, net_number_of_desktops
, XA_CARDINAL
,
830 32, PropModeReplace
, (unsigned char *)&count
, 1);
833 static void updateCurrentWorkspace(WScreen
*scr
)
837 count
= scr
->current_workspace
;
839 XChangeProperty(dpy
, scr
->root_win
, net_current_desktop
, XA_CARDINAL
, 32,
840 PropModeReplace
, (unsigned char *)&count
, 1);
843 static void updateWorkspaceNames(WScreen
*scr
)
845 char buf
[MAX_WORKSPACES
* (MAX_WORKSPACENAME_WIDTH
+ 1)], *pos
;
846 unsigned int i
, len
, curr_size
;
850 for (i
= 0; i
< scr
->workspace_count
; i
++) {
851 curr_size
= strlen(scr
->workspaces
[i
]->name
);
852 strcpy(pos
, scr
->workspaces
[i
]->name
);
853 pos
+= (curr_size
+ 1);
854 len
+= (curr_size
+ 1);
857 XChangeProperty(dpy
, scr
->root_win
, net_desktop_names
, utf8_string
, 8,
858 PropModeReplace
, (unsigned char *)buf
, len
);
861 static void updateFocusHint(WScreen
*scr
)
865 if (!scr
->focused_window
|| !scr
->focused_window
->flags
.focused
)
868 window
= scr
->focused_window
->client_win
;
870 XChangeProperty(dpy
, scr
->root_win
, net_active_window
, XA_WINDOW
, 32,
871 PropModeReplace
, (unsigned char *)&window
, 1);
874 static void updateWorkspaceHint(WWindow
*wwin
, Bool fake
, Bool del
)
879 XDeleteProperty(dpy
, wwin
->client_win
, net_wm_desktop
);
881 l
= ((fake
|| IS_OMNIPRESENT(wwin
)) ? -1 : wwin
->frame
->workspace
);
882 XChangeProperty(dpy
, wwin
->client_win
, net_wm_desktop
, XA_CARDINAL
,
883 32, PropModeReplace
, (unsigned char *)&l
, 1);
887 static void updateStateHint(WWindow
*wwin
, Bool changedWorkspace
, Bool del
)
890 XDeleteProperty(dpy
, wwin
->client_win
, net_wm_state
);
892 Atom state
[15]; /* nr of defined state atoms */
895 if (changedWorkspace
|| (wPreferences
.sticky_icons
&& !IS_OMNIPRESENT(wwin
)))
896 updateWorkspaceHint(wwin
, False
, False
);
898 if (IS_OMNIPRESENT(wwin
))
899 state
[i
++] = net_wm_state_sticky
;
900 if (wwin
->flags
.shaded
)
901 state
[i
++] = net_wm_state_shaded
;
902 if (wwin
->flags
.maximized
& MAX_HORIZONTAL
)
903 state
[i
++] = net_wm_state_maximized_horz
;
904 if (wwin
->flags
.maximized
& MAX_VERTICAL
)
905 state
[i
++] = net_wm_state_maximized_vert
;
906 if (WFLAGP(wwin
, skip_window_list
))
907 state
[i
++] = net_wm_state_skip_taskbar
;
908 if (wwin
->flags
.net_skip_pager
)
909 state
[i
++] = net_wm_state_skip_pager
;
910 if ((wwin
->flags
.hidden
|| wwin
->flags
.miniaturized
) && !wwin
->flags
.net_show_desktop
) {
911 state
[i
++] = net_wm_state_hidden
;
912 state
[i
++] = net_wm_state_skip_pager
;
914 if (wwin
->flags
.miniaturized
&& wPreferences
.sticky_icons
) {
915 if (!IS_OMNIPRESENT(wwin
))
916 updateWorkspaceHint(wwin
, True
, False
);
917 state
[i
++] = net_wm_state_sticky
;
920 if (WFLAGP(wwin
, sunken
))
921 state
[i
++] = net_wm_state_below
;
922 if (WFLAGP(wwin
, floating
))
923 state
[i
++] = net_wm_state_above
;
924 if (wwin
->flags
.fullscreen
)
925 state
[i
++] = net_wm_state_fullscreen
;
927 XChangeProperty(dpy
, wwin
->client_win
, net_wm_state
, XA_ATOM
, 32,
928 PropModeReplace
, (unsigned char *)state
, i
);
932 static Bool
updateStrut(WScreen
*scr
, Window w
, Bool adding
)
935 Bool hasState
= False
;
940 unsigned long nitems_ret
, bytes_after_ret
;
943 if ((XGetWindowProperty(dpy
, w
, net_wm_strut
, 0, 4, False
,
944 XA_CARDINAL
, &type_ret
, &fmt_ret
, &nitems_ret
,
945 &bytes_after_ret
, (unsigned char **)&data
) == Success
&& data
) ||
946 ((XGetWindowProperty(dpy
, w
, net_wm_strut_partial
, 0, 12, False
,
947 XA_CARDINAL
, &type_ret
, &fmt_ret
, &nitems_ret
,
948 &bytes_after_ret
, (unsigned char **)&data
) == Success
&& data
))) {
950 /* XXX: This is strictly incorrect in the case of net_wm_strut_partial...
951 * Discard the start and end properties from the partial strut and treat it as
952 * a (deprecated) strut.
953 * This means we are marking the whole width or height of the screen as
954 * reserved, which is not necessarily what the strut defines. However for the
955 * purposes of determining placement or maximization it's probably good enough.
957 area
= (WReservedArea
*) wmalloc(sizeof(WReservedArea
));
958 area
->area
.x1
= data
[0];
959 area
->area
.x2
= data
[1];
960 area
->area
.y1
= data
[2];
961 area
->area
.y2
= data
[3];
965 area
->next
= scr
->netdata
->strut
;
966 scr
->netdata
->strut
= area
;
973 area
= scr
->netdata
->strut
;
976 if (area
->window
== w
) {
977 scr
->netdata
->strut
= area
->next
;
981 while (area
->next
&& area
->next
->window
!= w
)
987 next
= area
->next
->next
;
1000 static int getWindowLayer(WWindow
*wwin
)
1002 int layer
= WMNormalLevel
;
1004 if (wwin
->type
== net_wm_window_type_desktop
) {
1005 layer
= WMDesktopLevel
;
1006 } else if (wwin
->type
== net_wm_window_type_dock
) {
1007 layer
= WMDockLevel
;
1008 } else if (wwin
->type
== net_wm_window_type_toolbar
) {
1009 layer
= WMMainMenuLevel
;
1010 } else if (wwin
->type
== net_wm_window_type_menu
) {
1011 layer
= WMSubmenuLevel
;
1012 } else if (wwin
->type
== net_wm_window_type_utility
) {
1013 } else if (wwin
->type
== net_wm_window_type_splash
) {
1014 } else if (wwin
->type
== net_wm_window_type_dialog
) {
1015 if (wwin
->transient_for
) {
1016 WWindow
*parent
= wWindowFor(wwin
->transient_for
);
1017 if (parent
&& parent
->flags
.fullscreen
)
1018 layer
= WMNormalLevel
;
1020 /* //layer = WMPopUpLevel; // this seems a bad idea -Dan */
1021 } else if (wwin
->type
== net_wm_window_type_dropdown_menu
) {
1022 layer
= WMSubmenuLevel
;
1023 } else if (wwin
->type
== net_wm_window_type_popup_menu
) {
1024 layer
= WMSubmenuLevel
;
1025 } else if (wwin
->type
== net_wm_window_type_tooltip
) {
1026 } else if (wwin
->type
== net_wm_window_type_notification
) {
1027 layer
= WMPopUpLevel
;
1028 } else if (wwin
->type
== net_wm_window_type_combo
) {
1029 layer
= WMSubmenuLevel
;
1030 } else if (wwin
->type
== net_wm_window_type_dnd
) {
1031 } else if (wwin
->type
== net_wm_window_type_normal
) {
1034 if (wwin
->client_flags
.sunken
&& WMSunkenLevel
< layer
)
1035 layer
= WMSunkenLevel
;
1036 if (wwin
->client_flags
.floating
&& WMFloatingLevel
> layer
)
1037 layer
= WMFloatingLevel
;
1042 static void doStateAtom(WWindow
*wwin
, Atom state
, int set
, Bool init
)
1044 if (state
== net_wm_state_sticky
) {
1045 if (set
== _NET_WM_STATE_TOGGLE
)
1046 set
= !IS_OMNIPRESENT(wwin
);
1048 if (set
!= wwin
->flags
.omnipresent
)
1049 wWindowSetOmnipresent(wwin
, set
);
1051 } else if (state
== net_wm_state_shaded
) {
1052 if (set
== _NET_WM_STATE_TOGGLE
)
1053 set
= !wwin
->flags
.shaded
;
1056 wwin
->flags
.shaded
= set
;
1061 wUnshadeWindow(wwin
);
1063 } else if (state
== net_wm_state_skip_taskbar
) {
1064 if (set
== _NET_WM_STATE_TOGGLE
)
1065 set
= !wwin
->client_flags
.skip_window_list
;
1067 wwin
->client_flags
.skip_window_list
= set
;
1068 } else if (state
== net_wm_state_skip_pager
) {
1069 if (set
== _NET_WM_STATE_TOGGLE
)
1070 set
= !wwin
->flags
.net_skip_pager
;
1072 wwin
->flags
.net_skip_pager
= set
;
1073 } else if (state
== net_wm_state_maximized_vert
) {
1074 if (set
== _NET_WM_STATE_TOGGLE
)
1075 set
= !(wwin
->flags
.maximized
& MAX_VERTICAL
);
1078 wwin
->flags
.maximized
|= (set
? MAX_VERTICAL
: 0);
1081 wMaximizeWindow(wwin
, wwin
->flags
.maximized
| MAX_VERTICAL
);
1083 wMaximizeWindow(wwin
, wwin
->flags
.maximized
& ~MAX_VERTICAL
);
1085 } else if (state
== net_wm_state_maximized_horz
) {
1086 if (set
== _NET_WM_STATE_TOGGLE
)
1087 set
= !(wwin
->flags
.maximized
& MAX_HORIZONTAL
);
1090 wwin
->flags
.maximized
|= (set
? MAX_HORIZONTAL
: 0);
1093 wMaximizeWindow(wwin
, wwin
->flags
.maximized
| MAX_HORIZONTAL
);
1095 wMaximizeWindow(wwin
, wwin
->flags
.maximized
& ~MAX_HORIZONTAL
);
1097 } else if (state
== net_wm_state_hidden
) {
1098 if (set
== _NET_WM_STATE_TOGGLE
)
1099 set
= !(wwin
->flags
.miniaturized
);
1102 wwin
->flags
.miniaturized
= set
;
1105 wIconifyWindow(wwin
);
1107 wDeiconifyWindow(wwin
);
1109 } else if (state
== net_wm_state_fullscreen
) {
1110 if (set
== _NET_WM_STATE_TOGGLE
)
1111 set
= !(wwin
->flags
.fullscreen
);
1114 wwin
->flags
.fullscreen
= set
;
1117 wFullscreenWindow(wwin
);
1119 wUnfullscreenWindow(wwin
);
1121 } else if (state
== net_wm_state_above
) {
1122 if (set
== _NET_WM_STATE_TOGGLE
)
1123 set
= !(wwin
->client_flags
.floating
);
1126 wwin
->client_flags
.floating
= set
;
1128 wwin
->client_flags
.floating
= set
;
1129 ChangeStackingLevel(wwin
->frame
->core
, getWindowLayer(wwin
));
1132 } else if (state
== net_wm_state_below
) {
1133 if (set
== _NET_WM_STATE_TOGGLE
)
1134 set
= !(wwin
->client_flags
.sunken
);
1137 wwin
->client_flags
.sunken
= set
;
1139 wwin
->client_flags
.sunken
= set
;
1140 ChangeStackingLevel(wwin
->frame
->core
, getWindowLayer(wwin
));
1145 wmessage("doStateAtom unknown atom %s set %d", XGetAtomName(dpy
, state
), set
);
1150 static void removeIcon(WWindow
*wwin
)
1152 if (wwin
->icon
== NULL
)
1154 if (wwin
->flags
.miniaturized
&& wwin
->icon
->mapped
) {
1155 XUnmapWindow(dpy
, wwin
->icon
->core
->window
);
1156 RemoveFromStackList(wwin
->icon
->core
);
1157 wIconDestroy(wwin
->icon
);
1162 static Bool
handleWindowType(WWindow
*wwin
, Atom type
, int *layer
)
1166 if (type
== net_wm_window_type_desktop
) {
1167 wwin
->client_flags
.no_titlebar
= 1;
1168 wwin
->client_flags
.no_resizable
= 1;
1169 wwin
->client_flags
.no_miniaturizable
= 1;
1170 wwin
->client_flags
.no_border
= 1;
1171 wwin
->client_flags
.no_resizebar
= 1;
1172 wwin
->client_flags
.no_shadeable
= 1;
1173 wwin
->client_flags
.no_movable
= 1;
1174 wwin
->client_flags
.omnipresent
= 1;
1175 wwin
->client_flags
.skip_window_list
= 1;
1176 wwin
->client_flags
.skip_switchpanel
= 1;
1177 wwin
->client_flags
.dont_move_off
= 1;
1178 wwin
->client_flags
.no_appicon
= 1;
1179 wwin
->flags
.net_skip_pager
= 1;
1182 } else if (type
== net_wm_window_type_dock
) {
1183 wwin
->client_flags
.no_titlebar
= 1;
1184 wwin
->client_flags
.no_resizable
= 1;
1185 wwin
->client_flags
.no_miniaturizable
= 1;
1186 wwin
->client_flags
.no_border
= 1; /* XXX: really not a single decoration. */
1187 wwin
->client_flags
.no_resizebar
= 1;
1188 wwin
->client_flags
.no_shadeable
= 1;
1189 wwin
->client_flags
.no_movable
= 1;
1190 wwin
->client_flags
.omnipresent
= 1;
1191 wwin
->client_flags
.skip_window_list
= 1;
1192 wwin
->client_flags
.skip_switchpanel
= 1;
1193 wwin
->client_flags
.dont_move_off
= 1;
1194 wwin
->flags
.net_skip_pager
= 1;
1195 } else if (type
== net_wm_window_type_toolbar
||
1196 type
== net_wm_window_type_menu
) {
1197 wwin
->client_flags
.no_resizable
= 1;
1198 wwin
->client_flags
.no_miniaturizable
= 1;
1199 wwin
->client_flags
.no_resizebar
= 1;
1200 wwin
->client_flags
.no_shadeable
= 1;
1201 wwin
->client_flags
.skip_window_list
= 1;
1202 wwin
->client_flags
.skip_switchpanel
= 1;
1203 wwin
->client_flags
.dont_move_off
= 1;
1204 wwin
->client_flags
.no_appicon
= 1;
1205 } else if (type
== net_wm_window_type_dropdown_menu
||
1206 type
== net_wm_window_type_popup_menu
||
1207 type
== net_wm_window_type_combo
) {
1208 wwin
->client_flags
.no_titlebar
= 1;
1209 wwin
->client_flags
.no_resizable
= 1;
1210 wwin
->client_flags
.no_miniaturizable
= 1;
1211 wwin
->client_flags
.no_resizebar
= 1;
1212 wwin
->client_flags
.no_shadeable
= 1;
1213 wwin
->client_flags
.skip_window_list
= 1;
1214 wwin
->client_flags
.skip_switchpanel
= 1;
1215 wwin
->client_flags
.dont_move_off
= 1;
1216 wwin
->client_flags
.no_appicon
= 1;
1217 } else if (type
== net_wm_window_type_utility
) {
1218 wwin
->client_flags
.no_appicon
= 1;
1219 } else if (type
== net_wm_window_type_splash
) {
1220 wwin
->client_flags
.no_titlebar
= 1;
1221 wwin
->client_flags
.no_resizable
= 1;
1222 wwin
->client_flags
.no_miniaturizable
= 1;
1223 wwin
->client_flags
.no_resizebar
= 1;
1224 wwin
->client_flags
.no_shadeable
= 1;
1225 wwin
->client_flags
.no_movable
= 1;
1226 wwin
->client_flags
.skip_window_list
= 1;
1227 wwin
->client_flags
.skip_switchpanel
= 1;
1228 wwin
->client_flags
.dont_move_off
= 1;
1229 wwin
->client_flags
.no_appicon
= 1;
1230 wwin
->flags
.net_skip_pager
= 1;
1231 } else if (type
== net_wm_window_type_dialog
) {
1232 /* These also seem a bad idea in our context -Dan
1233 // wwin->client_flags.skip_window_list = 1;
1234 // wwin->client_flags.no_appicon = 1;
1236 } else if (wwin
->type
== net_wm_window_type_tooltip
) {
1237 wwin
->client_flags
.no_titlebar
= 1;
1238 wwin
->client_flags
.no_resizable
= 1;
1239 wwin
->client_flags
.no_miniaturizable
= 1;
1240 wwin
->client_flags
.no_resizebar
= 1;
1241 wwin
->client_flags
.no_shadeable
= 1;
1242 wwin
->client_flags
.no_movable
= 1;
1243 wwin
->client_flags
.skip_window_list
= 1;
1244 wwin
->client_flags
.skip_switchpanel
= 1;
1245 wwin
->client_flags
.dont_move_off
= 1;
1246 wwin
->client_flags
.no_appicon
= 1;
1247 wwin
->client_flags
.no_focusable
= 1;
1248 wwin
->flags
.net_skip_pager
= 1;
1249 } else if (wwin
->type
== net_wm_window_type_notification
) {
1250 wwin
->client_flags
.no_titlebar
= 1;
1251 wwin
->client_flags
.no_resizable
= 1;
1252 wwin
->client_flags
.no_miniaturizable
= 1;
1253 wwin
->client_flags
.no_border
= 1;
1254 wwin
->client_flags
.no_resizebar
= 1;
1255 wwin
->client_flags
.no_shadeable
= 1;
1256 wwin
->client_flags
.no_movable
= 1;
1257 wwin
->client_flags
.omnipresent
= 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_hide_others
= 1;
1262 wwin
->client_flags
.no_appicon
= 1;
1263 wwin
->client_flags
.no_focusable
= 1;
1264 wwin
->flags
.net_skip_pager
= 1;
1265 } else if (wwin
->type
== net_wm_window_type_dnd
) {
1266 wwin
->client_flags
.no_titlebar
= 1;
1267 wwin
->client_flags
.no_resizable
= 1;
1268 wwin
->client_flags
.no_miniaturizable
= 1;
1269 wwin
->client_flags
.no_border
= 1;
1270 wwin
->client_flags
.no_resizebar
= 1;
1271 wwin
->client_flags
.no_shadeable
= 1;
1272 wwin
->client_flags
.no_movable
= 1;
1273 wwin
->client_flags
.skip_window_list
= 1;
1274 wwin
->client_flags
.skip_switchpanel
= 1;
1275 wwin
->client_flags
.dont_move_off
= 1;
1276 wwin
->client_flags
.no_appicon
= 1;
1277 wwin
->flags
.net_skip_pager
= 1;
1278 } else if (type
== net_wm_window_type_normal
) {
1284 *layer
= getWindowLayer(wwin
);
1289 void wNETWMPositionSplash(WWindow
*wwin
, int *x
, int *y
, int width
, int height
)
1291 if (wwin
->type
== net_wm_window_type_splash
) {
1292 WScreen
*scr
= wwin
->screen_ptr
;
1293 WMRect rect
= wGetRectForHead(scr
, wGetHeadForPointerLocation(scr
));
1294 *x
= rect
.pos
.x
+ (rect
.size
.width
- width
) / 2;
1295 *y
= rect
.pos
.y
+ (rect
.size
.height
- height
) / 2;
1299 static void updateWindowType(WWindow
*wwin
)
1303 unsigned long nitems_ret
, bytes_after_ret
;
1306 if (XGetWindowProperty(dpy
, wwin
->client_win
, net_wm_window_type
, 0, 1,
1307 False
, XA_ATOM
, &type_ret
, &fmt_ret
, &nitems_ret
,
1308 &bytes_after_ret
, (unsigned char **)&data
) == Success
&& data
) {
1311 Atom
*type
= (Atom
*) data
;
1312 for (i
= 0; i
< nitems_ret
; ++i
) {
1313 if (handleWindowType(wwin
, type
[i
], &layer
))
1319 if (wwin
->frame
!= NULL
) {
1320 ChangeStackingLevel(wwin
->frame
->core
, layer
);
1321 wwin
->frame
->flags
.need_texture_change
= 1;
1322 wWindowConfigureBorders(wwin
);
1323 wFrameWindowPaint(wwin
->frame
);
1324 wNETWMUpdateActions(wwin
, False
);
1328 void wNETWMCheckClientHints(WWindow
*wwin
, int *layer
, int *workspace
)
1332 unsigned long nitems_ret
, bytes_after_ret
;
1335 if (XGetWindowProperty(dpy
, wwin
->client_win
, net_wm_desktop
, 0, 1, False
,
1336 XA_CARDINAL
, &type_ret
, &fmt_ret
, &nitems_ret
,
1337 &bytes_after_ret
, (unsigned char **)&data
) == Success
&& data
) {
1339 long desktop
= *data
;
1343 wwin
->client_flags
.omnipresent
= 1;
1345 *workspace
= desktop
;
1348 if (XGetWindowProperty(dpy
, wwin
->client_win
, net_wm_state
, 0, 1, False
,
1349 XA_ATOM
, &type_ret
, &fmt_ret
, &nitems_ret
,
1350 &bytes_after_ret
, (unsigned char **)&data
) == Success
&& data
) {
1352 Atom
*state
= (Atom
*) data
;
1353 for (i
= 0; i
< nitems_ret
; ++i
)
1354 doStateAtom(wwin
, state
[i
], _NET_WM_STATE_ADD
, True
);
1359 if (XGetWindowProperty(dpy
, wwin
->client_win
, net_wm_window_type
, 0, 1, False
,
1360 XA_ATOM
, &type_ret
, &fmt_ret
, &nitems_ret
,
1361 &bytes_after_ret
, (unsigned char **)&data
) == Success
&& data
) {
1363 Atom
*type
= (Atom
*) data
;
1364 for (i
= 0; i
< nitems_ret
; ++i
) {
1365 if (handleWindowType(wwin
, type
[i
], layer
))
1371 wNETWMUpdateActions(wwin
, False
);
1372 updateStrut(wwin
->screen_ptr
, wwin
->client_win
, False
);
1373 updateStrut(wwin
->screen_ptr
, wwin
->client_win
, True
);
1375 wScreenUpdateUsableArea(wwin
->screen_ptr
);
1378 static Bool
updateNetIconInfo(WWindow
*wwin
)
1382 unsigned long nitems_ret
, bytes_after_ret
;
1384 Bool hasState
= False
;
1385 Bool old_state
= wwin
->flags
.net_handle_icon
;
1387 if (XGetWindowProperty(dpy
, wwin
->client_win
, net_wm_handled_icons
, 0, 1, False
,
1388 XA_CARDINAL
, &type_ret
, &fmt_ret
, &nitems_ret
,
1389 &bytes_after_ret
, (unsigned char **)&data
) == Success
&& data
) {
1390 long handled
= *data
;
1391 wwin
->flags
.net_handle_icon
= (handled
!= 0);
1396 wwin
->flags
.net_handle_icon
= False
;
1399 if (XGetWindowProperty(dpy
, wwin
->client_win
, net_wm_icon_geometry
, 0, 4, False
,
1400 XA_CARDINAL
, &type_ret
, &fmt_ret
, &nitems_ret
,
1401 &bytes_after_ret
, (unsigned char **)&data
) == Success
&& data
) {
1404 if (wwin
->flags
.net_handle_icon
)
1406 wwin
->flags
.net_handle_icon
= True
;
1409 wwin
->icon_x
= data
[0];
1410 wwin
->icon_y
= data
[1];
1411 wwin
->icon_w
= data
[2];
1412 wwin
->icon_h
= data
[3];
1419 wwin
->flags
.net_handle_icon
= False
;
1422 if (wwin
->flags
.miniaturized
&& old_state
!= wwin
->flags
.net_handle_icon
) {
1423 if (wwin
->flags
.net_handle_icon
) {
1426 wwin
->flags
.miniaturized
= False
;
1427 wwin
->flags
.skip_next_animation
= True
;
1428 wIconifyWindow(wwin
);
1435 void wNETWMCheckInitialClientState(WWindow
*wwin
)
1438 wmessage("wNETWMCheckInitialClientState");
1441 wNETWMShowingDesktop(wwin
->screen_ptr
, False
);
1443 updateWindowType(wwin
);
1444 updateNetIconInfo(wwin
);
1445 updateIconImage(wwin
);
1448 void wNETWMCheckInitialFrameState(WWindow
*wwin
)
1451 wmessage("wNETWMCheckInitialFrameState");
1454 updateWindowOpacity(wwin
);
1457 static void handleDesktopNames(WScreen
*scr
)
1459 unsigned long nitems_ret
, bytes_after_ret
;
1460 char *data
, *names
[32];
1464 if (XGetWindowProperty(dpy
, scr
->root_win
, net_desktop_names
, 0, 1, False
,
1465 utf8_string
, &type_ret
, &fmt_ret
, &nitems_ret
,
1466 &bytes_after_ret
, (unsigned char **)&data
) != Success
)
1472 if (type_ret
!= utf8_string
|| fmt_ret
!= 8)
1477 for (i
= 0; i
< nitems_ret
; i
++) {
1480 names
[n
] = &data
[i
];
1481 } else if (*names
[n
] == 0) {
1482 names
[n
] = &data
[i
];
1483 wWorkspaceRename(scr
, n
, names
[n
]);
1488 Bool
wNETWMProcessClientMessage(XClientMessageEvent
*event
)
1494 wmessage("processClientMessage type %s", XGetAtomName(dpy
, event
->message_type
));
1497 scr
= wScreenForWindow(event
->window
);
1499 /* generic client messages */
1500 if (event
->message_type
== net_current_desktop
) {
1501 wWorkspaceChange(scr
, event
->data
.l
[0]);
1504 } else if (event
->message_type
== net_number_of_desktops
) {
1507 value
= event
->data
.l
[0];
1508 if (value
> scr
->workspace_count
) {
1509 wWorkspaceMake(scr
, value
- scr
->workspace_count
);
1510 } else if (value
< scr
->workspace_count
) {
1512 Bool rebuild
= False
;
1514 for (i
= scr
->workspace_count
- 1; i
>= value
; i
--) {
1515 if (!wWorkspaceDelete(scr
, i
)) {
1522 updateWorkspaceCount(scr
);
1526 } else if (event
->message_type
== net_showing_desktop
) {
1527 wNETWMShowingDesktop(scr
, event
->data
.l
[0]);
1530 } else if (event
->message_type
== net_desktop_names
) {
1531 handleDesktopNames(scr
);
1536 /* window specific client messages */
1538 wwin
= wWindowFor(event
->window
);
1542 if (event
->message_type
== net_active_window
) {
1544 * Satisfy a client's focus request only if
1545 * - request comes from a pager, or
1546 * - it's explicitly allowed in Advanced Options, or
1547 * - giving the client the focus does not cause a change in
1548 * the active workspace (XXX: or the active head if Xinerama)
1550 if (wwin
->frame
->workspace
== wwin
->screen_ptr
->current_workspace
/* No workspace change */
1551 || event
->data
.l
[0] == 2 /* Requested by pager */
1552 || WFLAGP(wwin
, focus_across_wksp
) /* Explicitly allowed */) {
1553 wNETWMShowingDesktop(scr
, False
);
1554 wMakeWindowVisible(wwin
);
1558 } else if (event
->message_type
== net_close_window
) {
1559 if (!WFLAGP(wwin
, no_closable
)) {
1560 if (wwin
->protocols
.DELETE_WINDOW
)
1561 wClientSendProtocol(wwin
, w_global
.atom
.wm
.delete_window
,
1562 w_global
.timestamp
.last_event
);
1566 } else if (event
->message_type
== net_wm_state
) {
1567 int maximized
= wwin
->flags
.maximized
;
1568 long set
= event
->data
.l
[0];
1571 wmessage("net_wm_state set %ld a1 %s a2 %s", set
,
1572 XGetAtomName(dpy
, event
->data
.l
[1]), XGetAtomName(dpy
, event
->data
.l
[2]));
1575 doStateAtom(wwin
, (Atom
) event
->data
.l
[1], set
, False
);
1576 if (event
->data
.l
[2])
1577 doStateAtom(wwin
, (Atom
) event
->data
.l
[2], set
, False
);
1579 if (wwin
->flags
.maximized
!= maximized
) {
1580 if (!wwin
->flags
.maximized
) {
1581 wwin
->flags
.maximized
= maximized
;
1582 wUnmaximizeWindow(wwin
);
1584 wMaximizeWindow(wwin
, wwin
->flags
.maximized
);
1587 updateStateHint(wwin
, False
, False
);
1590 } else if (event
->message_type
== net_wm_handled_icons
|| event
->message_type
== net_wm_icon_geometry
) {
1591 updateNetIconInfo(wwin
);
1594 } else if (event
->message_type
== net_wm_desktop
) {
1595 long desktop
= event
->data
.l
[0];
1597 if (desktop
== -1) {
1598 wWindowSetOmnipresent(wwin
, True
);
1600 if (IS_OMNIPRESENT(wwin
))
1601 wWindowSetOmnipresent(wwin
, False
);
1602 wWindowChangeWorkspace(wwin
, desktop
);
1610 void wNETWMCheckClientHintChange(WWindow
*wwin
, XPropertyEvent
*event
)
1613 wmessage("clientHintChange type %s", XGetAtomName(dpy
, event
->atom
));
1616 if (event
->atom
== net_wm_strut
|| event
->atom
== net_wm_strut_partial
) {
1617 updateStrut(wwin
->screen_ptr
, wwin
->client_win
, False
);
1618 updateStrut(wwin
->screen_ptr
, wwin
->client_win
, True
);
1619 wScreenUpdateUsableArea(wwin
->screen_ptr
);
1620 } else if (event
->atom
== net_wm_handled_icons
|| event
->atom
== net_wm_icon_geometry
) {
1621 updateNetIconInfo(wwin
);
1622 } else if (event
->atom
== net_wm_window_type
) {
1623 updateWindowType(wwin
);
1624 } else if (event
->atom
== net_wm_name
) {
1625 char *name
= wNETWMGetWindowName(wwin
->client_win
);
1626 wWindowUpdateName(wwin
, name
);
1629 } else if (event
->atom
== net_wm_icon_name
) {
1631 wIconChangeTitle(wwin
->icon
, wwin
);
1632 wIconPaint(wwin
->icon
);
1634 } else if (event
->atom
== net_wm_icon
) {
1635 updateIconImage(wwin
);
1636 } else if (event
->atom
== net_wm_window_opacity
) {
1637 updateWindowOpacity(wwin
);
1641 int wNETWMGetPidForWindow(Window window
)
1645 unsigned long nitems_ret
, bytes_after_ret
;
1649 if (XGetWindowProperty(dpy
, window
, net_wm_pid
, 0, 1, False
,
1650 XA_CARDINAL
, &type_ret
, &fmt_ret
, &nitems_ret
,
1651 &bytes_after_ret
, (unsigned char **)&data
) == Success
&& data
) {
1661 char *wNETWMGetWindowName(Window window
)
1667 name
= (char *)PropGetCheckProperty(window
, net_wm_name
, utf8_string
, 0, 0, &size
);
1669 ret
= wstrndup(name
, size
);
1678 char *wNETWMGetIconName(Window window
)
1684 name
= (char *)PropGetCheckProperty(window
, net_wm_icon_name
, utf8_string
, 0, 0, &size
);
1686 ret
= wstrndup(name
, size
);
1695 static void observer(void *self
, WMNotification
*notif
)
1697 WWindow
*wwin
= (WWindow
*) WMGetNotificationObject(notif
);
1698 const char *name
= WMGetNotificationName(notif
);
1699 void *data
= WMGetNotificationClientData(notif
);
1700 NetData
*ndata
= (NetData
*) self
;
1702 if (strcmp(name
, WMNManaged
) == 0 && wwin
) {
1703 updateClientList(wwin
->screen_ptr
);
1704 updateClientListStacking(wwin
->screen_ptr
, NULL
);
1705 updateStateHint(wwin
, True
, False
);
1707 updateStrut(wwin
->screen_ptr
, wwin
->client_win
, False
);
1708 updateStrut(wwin
->screen_ptr
, wwin
->client_win
, True
);
1709 wScreenUpdateUsableArea(wwin
->screen_ptr
);
1710 } else if (strcmp(name
, WMNUnmanaged
) == 0 && wwin
) {
1711 updateClientList(wwin
->screen_ptr
);
1712 updateClientListStacking(wwin
->screen_ptr
, wwin
);
1713 updateWorkspaceHint(wwin
, False
, True
);
1714 updateStateHint(wwin
, False
, True
);
1715 wNETWMUpdateActions(wwin
, True
);
1717 updateStrut(wwin
->screen_ptr
, wwin
->client_win
, False
);
1718 wScreenUpdateUsableArea(wwin
->screen_ptr
);
1719 } else if (strcmp(name
, WMNResetStacking
) == 0 && wwin
) {
1720 updateClientListStacking(wwin
->screen_ptr
, NULL
);
1721 updateStateHint(wwin
, False
, False
);
1722 } else if (strcmp(name
, WMNChangedStacking
) == 0 && wwin
) {
1723 updateClientListStacking(wwin
->screen_ptr
, NULL
);
1724 updateStateHint(wwin
, False
, False
);
1725 } else if (strcmp(name
, WMNChangedFocus
) == 0) {
1726 updateFocusHint(ndata
->scr
);
1727 } else if (strcmp(name
, WMNChangedWorkspace
) == 0 && wwin
) {
1728 updateWorkspaceHint(wwin
, False
, False
);
1729 updateStateHint(wwin
, True
, False
);
1730 } else if (strcmp(name
, WMNChangedState
) == 0 && wwin
) {
1731 updateStateHint(wwin
, !strcmp(data
, "omnipresent"), False
);
1735 static void wsobserver(void *self
, WMNotification
*notif
)
1737 WScreen
*scr
= (WScreen
*) WMGetNotificationObject(notif
);
1738 const char *name
= WMGetNotificationName(notif
);
1740 /* Parameter not used, but tell the compiler that it is ok */
1743 if (strcmp(name
, WMNWorkspaceCreated
) == 0) {
1744 updateWorkspaceCount(scr
);
1745 updateWorkspaceNames(scr
);
1746 wNETWMUpdateWorkarea(scr
);
1747 } else if (strcmp(name
, WMNWorkspaceDestroyed
) == 0) {
1748 updateWorkspaceCount(scr
);
1749 updateWorkspaceNames(scr
);
1750 wNETWMUpdateWorkarea(scr
);
1751 } else if (strcmp(name
, WMNWorkspaceChanged
) == 0) {
1752 updateCurrentWorkspace(scr
);
1753 } else if (strcmp(name
, WMNWorkspaceNameChanged
) == 0) {
1754 updateWorkspaceNames(scr
);
1758 void wNETFrameExtents(WWindow
*wwin
)
1760 long extents
[4] = { 0, 0, 0, 0 };
1762 /* The extents array describes dimensions which are not
1763 * part of the client window. In our case that means
1764 * widths of the border and heights of the titlebar and resizebar.
1771 if (wwin
->frame
->titlebar
)
1772 extents
[2] = wwin
->frame
->titlebar
->height
;
1773 if (wwin
->frame
->resizebar
)
1774 extents
[3] = wwin
->frame
->resizebar
->height
;
1775 if (HAS_BORDER(wwin
)) {
1776 extents
[0] += wwin
->screen_ptr
->frame_border_width
;
1777 extents
[1] += wwin
->screen_ptr
->frame_border_width
;
1778 extents
[2] += wwin
->screen_ptr
->frame_border_width
;
1779 extents
[3] += wwin
->screen_ptr
->frame_border_width
;
1782 XChangeProperty(dpy
, wwin
->client_win
, net_frame_extents
, XA_CARDINAL
, 32, PropModeReplace
, (unsigned char *) extents
, 4);
1785 void wNETCleanupFrameExtents(WWindow
*wwin
)
1787 XDeleteProperty(dpy
, wwin
->client_win
, net_frame_extents
);