1 /* wmspec.c-- support for the wm-spec Hints
3 * Window Maker window manager
5 * Copyright (c) 1998-2003 Alfredo K. Kojima
7 * This program is free software; you can redistribute it and/or modify
8 * it under the terms of the GNU General Public License as published by
9 * the Free Software Foundation; either version 2 of the License, or
10 * (at your option) any later version.
12 * This program is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 * GNU General Public License for more details.
17 * You should have received a copy of the GNU General Public License along
18 * with this program; if not, write to the Free Software Foundation, Inc.,
19 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
26 * This file needs to be checked for all calls to XGetWindowProperty() and
27 * proper checks need to be made on the returned values. Only checking for
28 * return to be Success is not enough. -Dan
34 #include <X11/Xatom.h>
35 #include <X11/Xarch.h>
38 #include <WINGs/WUtil.h>
39 #include "WindowMaker.h"
42 #include "workspace.h"
51 #include "properties.h"
54 /* Root Window Properties */
55 static Atom net_supported
;
56 static Atom net_client_list
;
57 static Atom net_client_list_stacking
;
58 static Atom net_number_of_desktops
;
59 static Atom net_desktop_geometry
;
60 static Atom net_desktop_viewport
;
61 static Atom net_current_desktop
;
62 static Atom net_desktop_names
;
63 static Atom net_active_window
;
64 static Atom net_workarea
;
65 static Atom net_supporting_wm_check
;
66 static Atom net_virtual_roots
; /* N/A */
67 static Atom net_desktop_layout
; /* XXX */
68 static Atom net_showing_desktop
;
70 /* Other Root Window Messages */
71 static Atom net_close_window
;
72 static Atom net_moveresize_window
; /* TODO */
73 static Atom net_wm_moveresize
; /* TODO */
75 /* Application Window Properties */
76 static Atom net_wm_name
;
77 static Atom net_wm_visible_name
; /* TODO (unnecessary?) */
78 static Atom net_wm_icon_name
;
79 static Atom net_wm_visible_icon_name
; /* TODO (unnecessary?) */
80 static Atom net_wm_desktop
;
81 static Atom net_wm_window_type
;
82 static Atom net_wm_window_type_desktop
;
83 static Atom net_wm_window_type_dock
;
84 static Atom net_wm_window_type_toolbar
;
85 static Atom net_wm_window_type_menu
;
86 static Atom net_wm_window_type_utility
;
87 static Atom net_wm_window_type_splash
;
88 static Atom net_wm_window_type_dialog
;
89 static Atom net_wm_window_type_dropdown_menu
;
90 static Atom net_wm_window_type_popup_menu
;
91 static Atom net_wm_window_type_tooltip
;
92 static Atom net_wm_window_type_notification
;
93 static Atom net_wm_window_type_combo
;
94 static Atom net_wm_window_type_dnd
;
95 static Atom net_wm_window_type_normal
;
96 static Atom net_wm_state
;
97 static Atom net_wm_state_modal
; /* XXX: what is this?!? */
98 static Atom net_wm_state_sticky
;
99 static Atom net_wm_state_maximized_vert
;
100 static Atom net_wm_state_maximized_horz
;
101 static Atom net_wm_state_shaded
;
102 static Atom net_wm_state_skip_taskbar
;
103 static Atom net_wm_state_skip_pager
;
104 static Atom net_wm_state_hidden
;
105 static Atom net_wm_state_fullscreen
;
106 static Atom net_wm_state_above
;
107 static Atom net_wm_state_below
;
108 static Atom net_wm_allowed_actions
;
109 static Atom net_wm_action_move
;
110 static Atom net_wm_action_resize
;
111 static Atom net_wm_action_minimize
;
112 static Atom net_wm_action_shade
;
113 static Atom net_wm_action_stick
;
114 static Atom net_wm_action_maximize_horz
;
115 static Atom net_wm_action_maximize_vert
;
116 static Atom net_wm_action_fullscreen
;
117 static Atom net_wm_action_change_desktop
;
118 static Atom net_wm_action_close
;
119 static Atom net_wm_strut
;
120 static Atom net_wm_strut_partial
; /* TODO: doesn't really fit into the current strut scheme */
121 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. */
122 static Atom net_wm_icon
;
123 static Atom net_wm_pid
; /* TODO */
124 static Atom net_wm_handled_icons
; /* FIXME: see net_wm_icon_geometry */
125 static Atom net_wm_window_opacity
;
127 static Atom net_frame_extents
;
129 /* Window Manager Protocols */
130 static Atom net_wm_ping
; /* TODO */
132 static Atom utf8_string
;
139 static atomitem_t atomNames
[] = {
140 {"_NET_SUPPORTED", &net_supported
},
141 {"_NET_CLIENT_LIST", &net_client_list
},
142 {"_NET_CLIENT_LIST_STACKING", &net_client_list_stacking
},
143 {"_NET_NUMBER_OF_DESKTOPS", &net_number_of_desktops
},
144 {"_NET_DESKTOP_GEOMETRY", &net_desktop_geometry
},
145 {"_NET_DESKTOP_VIEWPORT", &net_desktop_viewport
},
146 {"_NET_CURRENT_DESKTOP", &net_current_desktop
},
147 {"_NET_DESKTOP_NAMES", &net_desktop_names
},
148 {"_NET_ACTIVE_WINDOW", &net_active_window
},
149 {"_NET_WORKAREA", &net_workarea
},
150 {"_NET_SUPPORTING_WM_CHECK", &net_supporting_wm_check
},
151 {"_NET_VIRTUAL_ROOTS", &net_virtual_roots
},
152 {"_NET_DESKTOP_LAYOUT", &net_desktop_layout
},
153 {"_NET_SHOWING_DESKTOP", &net_showing_desktop
},
155 {"_NET_CLOSE_WINDOW", &net_close_window
},
156 {"_NET_MOVERESIZE_WINDOW", &net_moveresize_window
},
157 {"_NET_WM_MOVERESIZE", &net_wm_moveresize
},
159 {"_NET_WM_NAME", &net_wm_name
},
160 {"_NET_WM_VISIBLE_NAME", &net_wm_visible_name
},
161 {"_NET_WM_ICON_NAME", &net_wm_icon_name
},
162 {"_NET_WM_VISIBLE_ICON_NAME", &net_wm_visible_icon_name
},
163 {"_NET_WM_DESKTOP", &net_wm_desktop
},
164 {"_NET_WM_WINDOW_TYPE", &net_wm_window_type
},
165 {"_NET_WM_WINDOW_TYPE_DESKTOP", &net_wm_window_type_desktop
},
166 {"_NET_WM_WINDOW_TYPE_DOCK", &net_wm_window_type_dock
},
167 {"_NET_WM_WINDOW_TYPE_TOOLBAR", &net_wm_window_type_toolbar
},
168 {"_NET_WM_WINDOW_TYPE_MENU", &net_wm_window_type_menu
},
169 {"_NET_WM_WINDOW_TYPE_UTILITY", &net_wm_window_type_utility
},
170 {"_NET_WM_WINDOW_TYPE_SPLASH", &net_wm_window_type_splash
},
171 {"_NET_WM_WINDOW_TYPE_DIALOG", &net_wm_window_type_dialog
},
172 {"_NET_WM_WINDOW_TYPE_DROPDOWN_MENU", &net_wm_window_type_dropdown_menu
},
173 {"_NET_WM_WINDOW_TYPE_POPUP_MENU", &net_wm_window_type_popup_menu
},
174 {"_NET_WM_WINDOW_TYPE_TOOLTIP", &net_wm_window_type_tooltip
},
175 {"_NET_WM_WINDOW_TYPE_NOTIFICATION", &net_wm_window_type_notification
},
176 {"_NET_WM_WINDOW_TYPE_COMBO", &net_wm_window_type_combo
},
177 {"_NET_WM_WINDOW_TYPE_DND", &net_wm_window_type_dnd
},
178 {"_NET_WM_WINDOW_TYPE_NORMAL", &net_wm_window_type_normal
},
179 {"_NET_WM_STATE", &net_wm_state
},
180 {"_NET_WM_STATE_MODAL", &net_wm_state_modal
},
181 {"_NET_WM_STATE_STICKY", &net_wm_state_sticky
},
182 {"_NET_WM_STATE_MAXIMIZED_VERT", &net_wm_state_maximized_vert
},
183 {"_NET_WM_STATE_MAXIMIZED_HORZ", &net_wm_state_maximized_horz
},
184 {"_NET_WM_STATE_SHADED", &net_wm_state_shaded
},
185 {"_NET_WM_STATE_SKIP_TASKBAR", &net_wm_state_skip_taskbar
},
186 {"_NET_WM_STATE_SKIP_PAGER", &net_wm_state_skip_pager
},
187 {"_NET_WM_STATE_HIDDEN", &net_wm_state_hidden
},
188 {"_NET_WM_STATE_FULLSCREEN", &net_wm_state_fullscreen
},
189 {"_NET_WM_STATE_ABOVE", &net_wm_state_above
},
190 {"_NET_WM_STATE_BELOW", &net_wm_state_below
},
191 {"_NET_WM_ALLOWED_ACTIONS", &net_wm_allowed_actions
},
192 {"_NET_WM_ACTION_MOVE", &net_wm_action_move
},
193 {"_NET_WM_ACTION_RESIZE", &net_wm_action_resize
},
194 {"_NET_WM_ACTION_MINIMIZE", &net_wm_action_minimize
},
195 {"_NET_WM_ACTION_SHADE", &net_wm_action_shade
},
196 {"_NET_WM_ACTION_STICK", &net_wm_action_stick
},
197 {"_NET_WM_ACTION_MAXIMIZE_HORZ", &net_wm_action_maximize_horz
},
198 {"_NET_WM_ACTION_MAXIMIZE_VERT", &net_wm_action_maximize_vert
},
199 {"_NET_WM_ACTION_FULLSCREEN", &net_wm_action_fullscreen
},
200 {"_NET_WM_ACTION_CHANGE_DESKTOP", &net_wm_action_change_desktop
},
201 {"_NET_WM_ACTION_CLOSE", &net_wm_action_close
},
202 {"_NET_WM_STRUT", &net_wm_strut
},
203 {"_NET_WM_STRUT_PARTIAL", &net_wm_strut_partial
},
204 {"_NET_WM_ICON_GEOMETRY", &net_wm_icon_geometry
},
205 {"_NET_WM_ICON", &net_wm_icon
},
206 {"_NET_WM_PID", &net_wm_pid
},
207 {"_NET_WM_HANDLED_ICONS", &net_wm_handled_icons
},
208 {"_NET_WM_WINDOW_OPACITY", &net_wm_window_opacity
},
210 {"_NET_FRAME_EXTENTS", &net_frame_extents
},
212 {"_NET_WM_PING", &net_wm_ping
},
214 {"UTF8_STRING", &utf8_string
},
217 #define _NET_WM_STATE_REMOVE 0
218 #define _NET_WM_STATE_ADD 1
219 #define _NET_WM_STATE_TOGGLE 2
221 #define _NET_WM_MOVERESIZE_SIZE_TOPLEFT 0
222 #define _NET_WM_MOVERESIZE_SIZE_TOP 1
223 #define _NET_WM_MOVERESIZE_SIZE_TOPRIGHT 2
224 #define _NET_WM_MOVERESIZE_SIZE_RIGHT 3
225 #define _NET_WM_MOVERESIZE_SIZE_BOTTOMRIGHT 4
226 #define _NET_WM_MOVERESIZE_SIZE_BOTTOM 5
227 #define _NET_WM_MOVERESIZE_SIZE_BOTTOMLEFT 6
228 #define _NET_WM_MOVERESIZE_SIZE_LEFT 7
229 #define _NET_WM_MOVERESIZE_MOVE 8 /* movement only */
230 #define _NET_WM_MOVERESIZE_SIZE_KEYBOARD 9 /* size via keyboard */
231 #define _NET_WM_MOVERESIZE_MOVE_KEYBOARD 10 /* move via keyboard */
233 static void observer(void *self
, WMNotification
*notif
);
234 static void wsobserver(void *self
, WMNotification
*notif
);
236 static void updateClientList(WScreen
*scr
);
237 static void updateClientListStacking(WScreen
*scr
, WWindow
*);
239 static void updateWorkspaceNames(WScreen
*scr
);
240 static void updateCurrentWorkspace(WScreen
*scr
);
241 static void updateWorkspaceCount(WScreen
*scr
);
242 static void wNETWMShowingDesktop(WScreen
*scr
, Bool show
);
244 typedef struct NetData
{
246 WReservedArea
*strut
;
247 WWindow
**show_desktop
;
250 static void setSupportedHints(WScreen
*scr
)
252 Atom atom
[wlengthof(atomNames
)];
255 /* set supported hints list */
256 /* XXX: extend this !!! */
258 atom
[i
++] = net_client_list
;
259 atom
[i
++] = net_client_list_stacking
;
260 atom
[i
++] = net_number_of_desktops
;
261 atom
[i
++] = net_desktop_geometry
;
262 atom
[i
++] = net_desktop_viewport
;
263 atom
[i
++] = net_current_desktop
;
264 atom
[i
++] = net_desktop_names
;
265 atom
[i
++] = net_active_window
;
266 atom
[i
++] = net_workarea
;
267 atom
[i
++] = net_supporting_wm_check
;
268 atom
[i
++] = net_showing_desktop
;
270 atom
[i
++] = net_wm_moveresize
;
272 atom
[i
++] = net_wm_desktop
;
273 atom
[i
++] = net_wm_window_type
;
274 atom
[i
++] = net_wm_window_type_desktop
;
275 atom
[i
++] = net_wm_window_type_dock
;
276 atom
[i
++] = net_wm_window_type_toolbar
;
277 atom
[i
++] = net_wm_window_type_menu
;
278 atom
[i
++] = net_wm_window_type_utility
;
279 atom
[i
++] = net_wm_window_type_splash
;
280 atom
[i
++] = net_wm_window_type_dialog
;
281 atom
[i
++] = net_wm_window_type_dropdown_menu
;
282 atom
[i
++] = net_wm_window_type_popup_menu
;
283 atom
[i
++] = net_wm_window_type_tooltip
;
284 atom
[i
++] = net_wm_window_type_notification
;
285 atom
[i
++] = net_wm_window_type_combo
;
286 atom
[i
++] = net_wm_window_type_dnd
;
287 atom
[i
++] = net_wm_window_type_normal
;
289 atom
[i
++] = net_wm_state
;
290 /* atom[i++] = net_wm_state_modal; *//* XXX: not sure where/when to use it. */
291 atom
[i
++] = net_wm_state_sticky
;
292 atom
[i
++] = net_wm_state_shaded
;
293 atom
[i
++] = net_wm_state_maximized_horz
;
294 atom
[i
++] = net_wm_state_maximized_vert
;
295 atom
[i
++] = net_wm_state_skip_taskbar
;
296 atom
[i
++] = net_wm_state_skip_pager
;
297 atom
[i
++] = net_wm_state_hidden
;
298 atom
[i
++] = net_wm_state_fullscreen
;
299 atom
[i
++] = net_wm_state_above
;
300 atom
[i
++] = net_wm_state_below
;
302 atom
[i
++] = net_wm_allowed_actions
;
303 atom
[i
++] = net_wm_action_move
;
304 atom
[i
++] = net_wm_action_resize
;
305 atom
[i
++] = net_wm_action_minimize
;
306 atom
[i
++] = net_wm_action_shade
;
307 atom
[i
++] = net_wm_action_stick
;
308 atom
[i
++] = net_wm_action_maximize_horz
;
309 atom
[i
++] = net_wm_action_maximize_vert
;
310 atom
[i
++] = net_wm_action_fullscreen
;
311 atom
[i
++] = net_wm_action_change_desktop
;
312 atom
[i
++] = net_wm_action_close
;
314 atom
[i
++] = net_wm_strut
;
315 atom
[i
++] = net_wm_icon_geometry
;
316 atom
[i
++] = net_wm_icon
;
317 atom
[i
++] = net_wm_handled_icons
;
318 atom
[i
++] = net_wm_window_opacity
;
320 atom
[i
++] = net_frame_extents
;
322 atom
[i
++] = net_wm_name
;
323 atom
[i
++] = net_wm_icon_name
;
325 XChangeProperty(dpy
, scr
->root_win
, net_supported
, XA_ATOM
, 32, PropModeReplace
, (unsigned char *)atom
, i
);
327 /* set supporting wm hint */
328 XChangeProperty(dpy
, scr
->root_win
, net_supporting_wm_check
, XA_WINDOW
, 32,
329 PropModeReplace
, (unsigned char *)&scr
->info_window
, 1);
331 XChangeProperty(dpy
, scr
->info_window
, net_supporting_wm_check
, XA_WINDOW
,
332 32, PropModeReplace
, (unsigned char *)&scr
->info_window
, 1);
335 void wNETWMUpdateDesktop(WScreen
*scr
)
337 long *views
, sizes
[2];
340 if (w_global
.workspace
.count
== 0)
343 count
= w_global
.workspace
.count
* 2;
344 views
= wmalloc(sizeof(long) * count
);
345 sizes
[0] = scr
->scr_width
;
346 sizes
[1] = scr
->scr_height
;
348 for (i
= 0; i
< w_global
.workspace
.count
; i
++) {
349 views
[2 * i
+ 0] = 0;
350 views
[2 * i
+ 1] = 0;
353 XChangeProperty(dpy
, scr
->root_win
, net_desktop_geometry
, XA_CARDINAL
, 32,
354 PropModeReplace
, (unsigned char *)sizes
, 2);
356 XChangeProperty(dpy
, scr
->root_win
, net_desktop_viewport
, XA_CARDINAL
, 32,
357 PropModeReplace
, (unsigned char *)views
, count
);
362 int wNETWMGetCurrentDesktopFromHint(WScreen
*scr
)
367 prop
= PropGetCheckProperty(scr
->root_win
, net_current_desktop
, XA_CARDINAL
, 0, 1, &count
);
369 int desktop
= *(long *)prop
;
377 * Find the best icon to be used by Window Maker for appicon/miniwindows.
378 * Currently the algorithm is to take the image with the size closest
379 * to icon_size x icon_size, but never bigger than that.
381 * This algorithm is very poorly implemented and needs to be redone (it can
382 * easily select images with very large widths and very small heights over
383 * square images, if the area of the former is closer to the desired one).
385 * The logic can also be changed to accept bigger images and scale them down.
387 static unsigned long *findBestIcon(unsigned long *data
, unsigned long items
)
390 unsigned long i
, distance
;
393 /* better use only 75% of icon_size. For 64x64 this means 48x48
394 * This leaves room around the icon for the miniwindow title and
395 * results in better overall aesthetics -Dan */
396 wanted
= wPreferences
.icon_size
* wPreferences
.icon_size
;
398 for (icon
= NULL
, distance
= wanted
, i
= 0L; i
< items
- 1;) {
399 size
= data
[i
] * data
[i
+ 1];
403 if (d
>= 0 && d
<= distance
&& (i
+ size
+ 2) <= items
) {
413 static RImage
*makeRImageFromARGBData(unsigned long *data
)
415 int size
, width
, height
, i
;
417 unsigned char *imgdata
;
422 size
= width
* height
;
427 image
= RCreateImage(width
, height
, True
);
429 for (imgdata
= image
->data
, i
= 2; i
< size
+ 2; i
++, imgdata
+= 4) {
431 imgdata
[3] = (pixel
>> 24) & 0xff; /* A */
432 imgdata
[0] = (pixel
>> 16) & 0xff; /* R */
433 imgdata
[1] = (pixel
>> 8) & 0xff; /* G */
434 imgdata
[2] = (pixel
>> 0) & 0xff; /* B */
440 RImage
*get_window_image_from_x11(Window window
)
445 unsigned long items
, rest
;
446 unsigned long *property
, *data
;
448 /* Get the icon from X11 Window */
449 if (XGetWindowProperty(dpy
, window
, net_wm_icon
, 0L, LONG_MAX
,
450 False
, XA_CARDINAL
, &type
, &format
, &items
, &rest
,
451 (unsigned char **)&property
) != Success
|| !property
)
454 if (type
!= XA_CARDINAL
|| format
!= 32 || items
< 2) {
459 /* Find the best icon */
460 data
= findBestIcon(property
, items
);
466 /* Save the best icon in the X11 icon */
467 image
= makeRImageFromARGBData(data
);
471 /* Resize the image to the correct value */
472 image
= wIconValidateIconSize(image
, wPreferences
.icon_size
);
477 static void updateIconImage(WWindow
*wwin
)
479 /* Remove the icon image from X11 */
480 if (wwin
->net_icon_image
)
481 RReleaseImage(wwin
->net_icon_image
);
483 /* Save the icon in the X11 icon */
484 wwin
->net_icon_image
= get_window_image_from_x11(wwin
->client_win
);
486 /* Refresh the Window Icon */
488 wIconUpdate(wwin
->icon
);
490 /* Refresh the application icon */
491 WApplication
*app
= wApplicationOf(wwin
->main_window
);
492 if (app
&& app
->app_icon
) {
493 wIconUpdate(app
->app_icon
->icon
);
494 wAppIconPaint(app
->app_icon
);
498 static void updateWindowOpacity(WWindow
*wwin
)
502 unsigned long items
, rest
;
503 unsigned long *property
;
508 /* We don't care about this ourselves, but other programs need us to copy
509 * this to the frame window. */
510 if (XGetWindowProperty(dpy
, wwin
->client_win
, net_wm_window_opacity
, 0L, 1L,
511 False
, XA_CARDINAL
, &type
, &format
, &items
, &rest
,
512 (unsigned char **)&property
) != Success
)
516 XDeleteProperty(dpy
, wwin
->frame
->core
->window
, net_wm_window_opacity
);
517 } else if (type
== XA_CARDINAL
&& format
== 32 && items
== 1 && property
) {
518 XChangeProperty(dpy
, wwin
->frame
->core
->window
, net_wm_window_opacity
,
519 XA_CARDINAL
, 32, PropModeReplace
, (unsigned char *)property
, 1L);
526 static void updateShowDesktop(WScreen
*scr
, Bool show
)
530 foo
= (show
== True
);
531 XChangeProperty(dpy
, scr
->root_win
, net_showing_desktop
, XA_CARDINAL
, 32,
532 PropModeReplace
, (unsigned char *)&foo
, 1);
535 static void wNETWMShowingDesktop(WScreen
*scr
, Bool show
)
537 if (show
&& scr
->netdata
->show_desktop
== NULL
) {
538 WWindow
*tmp
, **wins
;
541 wins
= (WWindow
**) wmalloc(sizeof(WWindow
*) * (scr
->window_count
+ 1));
543 tmp
= scr
->focused_window
;
545 if (!tmp
->flags
.hidden
&& !tmp
->flags
.miniaturized
&& !WFLAGP(tmp
, skip_window_list
)) {
548 tmp
->flags
.skip_next_animation
= 1;
549 tmp
->flags
.net_show_desktop
= 1;
557 scr
->netdata
->show_desktop
= wins
;
558 updateShowDesktop(scr
, True
);
559 } else if (scr
->netdata
->show_desktop
!= NULL
) {
560 /* FIXME: get rid of workspace flashing ! */
561 int ws
= w_global
.workspace
.current
;
563 for (tmp
= scr
->netdata
->show_desktop
; *tmp
; ++tmp
) {
564 wDeiconifyWindow(*tmp
);
565 (*tmp
)->flags
.net_show_desktop
= 0;
567 if (ws
!= w_global
.workspace
.current
)
568 wWorkspaceChange(scr
, ws
);
569 wfree(scr
->netdata
->show_desktop
);
570 scr
->netdata
->show_desktop
= NULL
;
571 updateShowDesktop(scr
, False
);
575 void wNETWMInitStuff(WScreen
*scr
)
581 wmessage("wNETWMInitStuff");
584 #ifdef HAVE_XINTERNATOMS
586 Atom atoms
[wlengthof(atomNames
)];
587 char *names
[wlengthof(atomNames
)];
589 for (i
= 0; i
< wlengthof(atomNames
); ++i
)
590 names
[i
] = atomNames
[i
].name
;
592 XInternAtoms(dpy
, &names
[0], wlengthof(atomNames
), False
, atoms
);
593 for (i
= 0; i
< wlengthof(atomNames
); ++i
)
594 *atomNames
[i
].atom
= atoms
[i
];
598 for (i
= 0; i
< wlengthof(atomNames
); i
++)
599 *atomNames
[i
].atom
= XInternAtom(dpy
, atomNames
[i
].name
, False
);
602 data
= wmalloc(sizeof(NetData
));
605 data
->show_desktop
= NULL
;
609 setSupportedHints(scr
);
611 WMAddNotificationObserver(observer
, data
, WMNManaged
, NULL
);
612 WMAddNotificationObserver(observer
, data
, WMNUnmanaged
, NULL
);
613 WMAddNotificationObserver(observer
, data
, WMNChangedWorkspace
, NULL
);
614 WMAddNotificationObserver(observer
, data
, WMNChangedState
, NULL
);
615 WMAddNotificationObserver(observer
, data
, WMNChangedFocus
, NULL
);
616 WMAddNotificationObserver(observer
, data
, WMNChangedStacking
, NULL
);
617 WMAddNotificationObserver(observer
, data
, WMNChangedName
, NULL
);
619 WMAddNotificationObserver(wsobserver
, data
, WMNWorkspaceCreated
, NULL
);
620 WMAddNotificationObserver(wsobserver
, data
, WMNWorkspaceDestroyed
, NULL
);
621 WMAddNotificationObserver(wsobserver
, data
, WMNWorkspaceChanged
, NULL
);
622 WMAddNotificationObserver(wsobserver
, data
, WMNWorkspaceNameChanged
, NULL
);
624 updateClientList(scr
);
625 updateClientListStacking(scr
, NULL
);
626 updateWorkspaceCount(scr
);
627 updateWorkspaceNames(scr
);
628 updateShowDesktop(scr
, False
);
630 wScreenUpdateUsableArea(scr
);
633 void wNETWMCleanup(WScreen
*scr
)
637 for (i
= 0; i
< wlengthof(atomNames
); i
++)
638 XDeleteProperty(dpy
, scr
->root_win
, *atomNames
[i
].atom
);
641 void wNETWMUpdateActions(WWindow
*wwin
, Bool del
)
643 Atom action
[10]; /* nr of actions atoms defined */
647 XDeleteProperty(dpy
, wwin
->client_win
, net_wm_allowed_actions
);
651 if (IS_MOVABLE(wwin
))
652 action
[i
++] = net_wm_action_move
;
654 if (IS_RESIZABLE(wwin
))
655 action
[i
++] = net_wm_action_resize
;
657 if (!WFLAGP(wwin
, no_miniaturizable
))
658 action
[i
++] = net_wm_action_minimize
;
660 if (!WFLAGP(wwin
, no_shadeable
))
661 action
[i
++] = net_wm_action_shade
;
663 /* if (!WFLAGP(wwin, no_stickable)) */
664 action
[i
++] = net_wm_action_stick
;
666 /* if (!(WFLAGP(wwin, no_maximizeable) & MAX_HORIZONTAL)) */
667 if (IS_RESIZABLE(wwin
))
668 action
[i
++] = net_wm_action_maximize_horz
;
670 /* if (!(WFLAGP(wwin, no_maximizeable) & MAX_VERTICAL)) */
671 if (IS_RESIZABLE(wwin
))
672 action
[i
++] = net_wm_action_maximize_vert
;
674 /* if (!WFLAGP(wwin, no_fullscreen)) */
675 action
[i
++] = net_wm_action_fullscreen
;
677 /* if (!WFLAGP(wwin, no_change_desktop)) */
678 action
[i
++] = net_wm_action_change_desktop
;
680 if (!WFLAGP(wwin
, no_closable
))
681 action
[i
++] = net_wm_action_close
;
683 XChangeProperty(dpy
, wwin
->client_win
, net_wm_allowed_actions
,
684 XA_ATOM
, 32, PropModeReplace
, (unsigned char *)action
, i
);
687 void wNETWMUpdateWorkarea(WScreen
*scr
)
692 if (!scr
->netdata
|| w_global
.workspace
.count
== 0 || !scr
->usableArea
)
695 count
= w_global
.workspace
.count
* 4;
696 area
= wmalloc(sizeof(long) * count
);
698 for (i
= 0; i
< w_global
.workspace
.count
; i
++) {
699 area
[4 * i
+ 0] = scr
->usableArea
[0].x1
;
700 area
[4 * i
+ 1] = scr
->usableArea
[0].y1
;
701 area
[4 * i
+ 2] = scr
->usableArea
[0].x2
- scr
->usableArea
[0].x1
;
702 area
[4 * i
+ 3] = scr
->usableArea
[0].y2
- scr
->usableArea
[0].y1
;
705 XChangeProperty(dpy
, scr
->root_win
, net_workarea
, XA_CARDINAL
, 32,
706 PropModeReplace
, (unsigned char *)area
, count
);
710 Bool
wNETWMGetUsableArea(WScreen
*scr
, int head
, WArea
*area
)
715 if (!scr
->netdata
|| !scr
->netdata
->strut
)
718 area
->x1
= area
->y1
= area
->x2
= area
->y2
= 0;
720 for (cur
= scr
->netdata
->strut
; cur
; cur
= cur
->next
) {
721 WWindow
*wwin
= wWindowFor(cur
->window
);
722 if (wWindowTouchesHead(wwin
, head
)) {
723 if (cur
->area
.x1
> area
->x1
)
724 area
->x1
= cur
->area
.x1
;
725 if (cur
->area
.y1
> area
->y1
)
726 area
->y1
= cur
->area
.y1
;
727 if (cur
->area
.x2
> area
->x2
)
728 area
->x2
= cur
->area
.x2
;
729 if (cur
->area
.y2
> area
->y2
)
730 area
->y2
= cur
->area
.y2
;
734 if (area
->x1
== 0 && area
->x2
== 0 && area
->y1
== 0 && area
->y2
== 0)
737 rect
= wGetRectForHead(scr
, head
);
739 area
->x1
= rect
.pos
.x
+ area
->x1
;
740 area
->x2
= rect
.pos
.x
+ rect
.size
.width
- area
->x2
;
741 area
->y1
= rect
.pos
.y
+ area
->y1
;
742 area
->y2
= rect
.pos
.y
+ rect
.size
.height
- area
->y2
;
747 static void updateClientList(WScreen
*scr
)
753 windows
= (Window
*) wmalloc(sizeof(Window
) * (scr
->window_count
+ 1));
756 wwin
= scr
->focused_window
;
758 windows
[count
++] = wwin
->client_win
;
761 XChangeProperty(dpy
, scr
->root_win
, net_client_list
, XA_WINDOW
, 32,
762 PropModeReplace
, (unsigned char *)windows
, count
);
768 static void updateClientListStacking(WScreen
*scr
, WWindow
*wwin_excl
)
771 Window
*client_list
, *client_list_reverse
;
776 /* update client list */
777 i
= scr
->window_count
+ 1;
778 client_list
= (Window
*) wmalloc(sizeof(Window
) * i
);
779 client_list_reverse
= (Window
*) wmalloc(sizeof(Window
) * i
);
782 WM_ETARETI_BAG(scr
->stacking_list
, tmp
, iter
) {
784 wwin
= wWindowFor(tmp
->window
);
785 /* wwin_excl is a window to exclude from the list
786 (e.g. it's now unmanaged) */
787 if (wwin
&& (wwin
!= wwin_excl
))
788 client_list
[client_count
++] = wwin
->client_win
;
789 tmp
= tmp
->stacking
->under
;
793 for (i
= 0; i
< client_count
; i
++) {
794 Window w
= client_list
[client_count
- i
- 1];
795 client_list_reverse
[i
] = w
;
798 XChangeProperty(dpy
, scr
->root_win
, net_client_list_stacking
, XA_WINDOW
, 32,
799 PropModeReplace
, (unsigned char *)client_list_reverse
, client_count
);
802 wfree(client_list_reverse
);
807 static void updateWorkspaceCount(WScreen
*scr
)
811 count
= w_global
.workspace
.count
;
813 XChangeProperty(dpy
, scr
->root_win
, net_number_of_desktops
, XA_CARDINAL
,
814 32, PropModeReplace
, (unsigned char *)&count
, 1);
817 static void updateCurrentWorkspace(WScreen
*scr
)
821 count
= w_global
.workspace
.current
;
823 XChangeProperty(dpy
, scr
->root_win
, net_current_desktop
, XA_CARDINAL
, 32,
824 PropModeReplace
, (unsigned char *)&count
, 1);
827 static void updateWorkspaceNames(WScreen
*scr
)
829 char buf
[MAX_WORKSPACES
* (MAX_WORKSPACENAME_WIDTH
+ 1)], *pos
;
830 unsigned int i
, len
, curr_size
;
834 for (i
= 0; i
< w_global
.workspace
.count
; i
++) {
835 curr_size
= strlen(w_global
.workspace
.array
[i
]->name
);
836 strcpy(pos
, w_global
.workspace
.array
[i
]->name
);
837 pos
+= (curr_size
+ 1);
838 len
+= (curr_size
+ 1);
841 XChangeProperty(dpy
, scr
->root_win
, net_desktop_names
, utf8_string
, 8,
842 PropModeReplace
, (unsigned char *)buf
, len
);
845 static void updateFocusHint(WScreen
*scr
)
849 if (!scr
->focused_window
|| !scr
->focused_window
->flags
.focused
)
852 window
= scr
->focused_window
->client_win
;
854 XChangeProperty(dpy
, scr
->root_win
, net_active_window
, XA_WINDOW
, 32,
855 PropModeReplace
, (unsigned char *)&window
, 1);
858 static void updateWorkspaceHint(WWindow
*wwin
, Bool fake
, Bool del
)
863 XDeleteProperty(dpy
, wwin
->client_win
, net_wm_desktop
);
865 l
= ((fake
|| IS_OMNIPRESENT(wwin
)) ? -1 : wwin
->frame
->workspace
);
866 XChangeProperty(dpy
, wwin
->client_win
, net_wm_desktop
, XA_CARDINAL
,
867 32, PropModeReplace
, (unsigned char *)&l
, 1);
871 static void updateStateHint(WWindow
*wwin
, Bool changedWorkspace
, Bool del
)
874 XDeleteProperty(dpy
, wwin
->client_win
, net_wm_state
);
876 Atom state
[15]; /* nr of defined state atoms */
879 if (changedWorkspace
|| (wPreferences
.sticky_icons
&& !IS_OMNIPRESENT(wwin
)))
880 updateWorkspaceHint(wwin
, False
, False
);
882 if (IS_OMNIPRESENT(wwin
))
883 state
[i
++] = net_wm_state_sticky
;
884 if (wwin
->flags
.shaded
)
885 state
[i
++] = net_wm_state_shaded
;
886 if (wwin
->flags
.maximized
& MAX_HORIZONTAL
)
887 state
[i
++] = net_wm_state_maximized_horz
;
888 if (wwin
->flags
.maximized
& MAX_VERTICAL
)
889 state
[i
++] = net_wm_state_maximized_vert
;
890 if (WFLAGP(wwin
, skip_window_list
))
891 state
[i
++] = net_wm_state_skip_taskbar
;
892 if (wwin
->flags
.net_skip_pager
)
893 state
[i
++] = net_wm_state_skip_pager
;
894 if ((wwin
->flags
.hidden
|| wwin
->flags
.miniaturized
) && !wwin
->flags
.net_show_desktop
) {
895 state
[i
++] = net_wm_state_hidden
;
896 state
[i
++] = net_wm_state_skip_pager
;
898 if (wwin
->flags
.miniaturized
&& wPreferences
.sticky_icons
) {
899 if (!IS_OMNIPRESENT(wwin
))
900 updateWorkspaceHint(wwin
, True
, False
);
901 state
[i
++] = net_wm_state_sticky
;
904 if (WFLAGP(wwin
, sunken
))
905 state
[i
++] = net_wm_state_below
;
906 if (WFLAGP(wwin
, floating
))
907 state
[i
++] = net_wm_state_above
;
908 if (wwin
->flags
.fullscreen
)
909 state
[i
++] = net_wm_state_fullscreen
;
911 XChangeProperty(dpy
, wwin
->client_win
, net_wm_state
, XA_ATOM
, 32,
912 PropModeReplace
, (unsigned char *)state
, i
);
916 static Bool
updateStrut(WScreen
*scr
, Window w
, Bool adding
)
919 Bool hasState
= False
;
924 unsigned long nitems_ret
, bytes_after_ret
;
927 if ((XGetWindowProperty(dpy
, w
, net_wm_strut
, 0, 4, False
,
928 XA_CARDINAL
, &type_ret
, &fmt_ret
, &nitems_ret
,
929 &bytes_after_ret
, (unsigned char **)&data
) == Success
&& data
) ||
930 ((XGetWindowProperty(dpy
, w
, net_wm_strut_partial
, 0, 12, False
,
931 XA_CARDINAL
, &type_ret
, &fmt_ret
, &nitems_ret
,
932 &bytes_after_ret
, (unsigned char **)&data
) == Success
&& data
))) {
934 /* XXX: This is strictly incorrect in the case of net_wm_strut_partial...
935 * Discard the start and end properties from the partial strut and treat it as
936 * a (deprecated) strut.
937 * This means we are marking the whole width or height of the screen as
938 * reserved, which is not necessarily what the strut defines. However for the
939 * purposes of determining placement or maximization it's probably good enough.
941 area
= (WReservedArea
*) wmalloc(sizeof(WReservedArea
));
942 area
->area
.x1
= data
[0];
943 area
->area
.x2
= data
[1];
944 area
->area
.y1
= data
[2];
945 area
->area
.y2
= data
[3];
949 area
->next
= scr
->netdata
->strut
;
950 scr
->netdata
->strut
= area
;
957 area
= scr
->netdata
->strut
;
960 if (area
->window
== w
) {
961 scr
->netdata
->strut
= area
->next
;
965 while (area
->next
&& area
->next
->window
!= w
)
971 next
= area
->next
->next
;
984 static int getWindowLayer(WWindow
*wwin
)
986 int layer
= WMNormalLevel
;
988 if (wwin
->type
== net_wm_window_type_desktop
) {
989 layer
= WMDesktopLevel
;
990 } else if (wwin
->type
== net_wm_window_type_dock
) {
992 } else if (wwin
->type
== net_wm_window_type_toolbar
) {
993 layer
= WMMainMenuLevel
;
994 } else if (wwin
->type
== net_wm_window_type_menu
) {
995 layer
= WMSubmenuLevel
;
996 } else if (wwin
->type
== net_wm_window_type_utility
) {
997 } else if (wwin
->type
== net_wm_window_type_splash
) {
998 } else if (wwin
->type
== net_wm_window_type_dialog
) {
999 if (wwin
->transient_for
) {
1000 WWindow
*parent
= wWindowFor(wwin
->transient_for
);
1001 if (parent
&& parent
->flags
.fullscreen
)
1002 layer
= WMNormalLevel
;
1004 /* //layer = WMPopUpLevel; // this seems a bad idea -Dan */
1005 } else if (wwin
->type
== net_wm_window_type_dropdown_menu
) {
1006 layer
= WMSubmenuLevel
;
1007 } else if (wwin
->type
== net_wm_window_type_popup_menu
) {
1008 layer
= WMSubmenuLevel
;
1009 } else if (wwin
->type
== net_wm_window_type_tooltip
) {
1010 } else if (wwin
->type
== net_wm_window_type_notification
) {
1011 layer
= WMPopUpLevel
;
1012 } else if (wwin
->type
== net_wm_window_type_combo
) {
1013 layer
= WMSubmenuLevel
;
1014 } else if (wwin
->type
== net_wm_window_type_dnd
) {
1015 } else if (wwin
->type
== net_wm_window_type_normal
) {
1018 if (wwin
->client_flags
.sunken
&& WMSunkenLevel
< layer
)
1019 layer
= WMSunkenLevel
;
1020 if (wwin
->client_flags
.floating
&& WMFloatingLevel
> layer
)
1021 layer
= WMFloatingLevel
;
1026 static void doStateAtom(WWindow
*wwin
, Atom state
, int set
, Bool init
)
1028 if (state
== net_wm_state_sticky
) {
1029 if (set
== _NET_WM_STATE_TOGGLE
)
1030 set
= !IS_OMNIPRESENT(wwin
);
1032 if (set
!= wwin
->flags
.omnipresent
)
1033 wWindowSetOmnipresent(wwin
, set
);
1035 } else if (state
== net_wm_state_shaded
) {
1036 if (set
== _NET_WM_STATE_TOGGLE
)
1037 set
= !wwin
->flags
.shaded
;
1040 wwin
->flags
.shaded
= set
;
1045 wUnshadeWindow(wwin
);
1047 } else if (state
== net_wm_state_skip_taskbar
) {
1048 if (set
== _NET_WM_STATE_TOGGLE
)
1049 set
= !wwin
->client_flags
.skip_window_list
;
1051 wwin
->client_flags
.skip_window_list
= set
;
1052 } else if (state
== net_wm_state_skip_pager
) {
1053 if (set
== _NET_WM_STATE_TOGGLE
)
1054 set
= !wwin
->flags
.net_skip_pager
;
1056 wwin
->flags
.net_skip_pager
= set
;
1057 } else if (state
== net_wm_state_maximized_vert
) {
1058 if (set
== _NET_WM_STATE_TOGGLE
)
1059 set
= !(wwin
->flags
.maximized
& MAX_VERTICAL
);
1062 wwin
->flags
.maximized
|= (set
? MAX_VERTICAL
: 0);
1065 wMaximizeWindow(wwin
, wwin
->flags
.maximized
| MAX_VERTICAL
);
1067 wMaximizeWindow(wwin
, wwin
->flags
.maximized
& ~MAX_VERTICAL
);
1069 } else if (state
== net_wm_state_maximized_horz
) {
1070 if (set
== _NET_WM_STATE_TOGGLE
)
1071 set
= !(wwin
->flags
.maximized
& MAX_HORIZONTAL
);
1074 wwin
->flags
.maximized
|= (set
? MAX_HORIZONTAL
: 0);
1077 wMaximizeWindow(wwin
, wwin
->flags
.maximized
| MAX_HORIZONTAL
);
1079 wMaximizeWindow(wwin
, wwin
->flags
.maximized
& ~MAX_HORIZONTAL
);
1081 } else if (state
== net_wm_state_hidden
) {
1082 if (set
== _NET_WM_STATE_TOGGLE
)
1083 set
= !(wwin
->flags
.miniaturized
);
1086 wwin
->flags
.miniaturized
= set
;
1089 wIconifyWindow(wwin
);
1091 wDeiconifyWindow(wwin
);
1093 } else if (state
== net_wm_state_fullscreen
) {
1094 if (set
== _NET_WM_STATE_TOGGLE
)
1095 set
= !(wwin
->flags
.fullscreen
);
1098 wwin
->flags
.fullscreen
= set
;
1101 wFullscreenWindow(wwin
);
1103 wUnfullscreenWindow(wwin
);
1105 } else if (state
== net_wm_state_above
) {
1106 if (set
== _NET_WM_STATE_TOGGLE
)
1107 set
= !(wwin
->client_flags
.floating
);
1110 wwin
->client_flags
.floating
= set
;
1112 wwin
->client_flags
.floating
= set
;
1113 ChangeStackingLevel(wwin
->frame
->core
, getWindowLayer(wwin
));
1116 } else if (state
== net_wm_state_below
) {
1117 if (set
== _NET_WM_STATE_TOGGLE
)
1118 set
= !(wwin
->client_flags
.sunken
);
1121 wwin
->client_flags
.sunken
= set
;
1123 wwin
->client_flags
.sunken
= set
;
1124 ChangeStackingLevel(wwin
->frame
->core
, getWindowLayer(wwin
));
1129 wmessage("doStateAtom unknown atom %s set %d", XGetAtomName(dpy
, state
), set
);
1134 static void removeIcon(WWindow
*wwin
)
1136 if (wwin
->icon
== NULL
)
1138 if (wwin
->flags
.miniaturized
&& wwin
->icon
->mapped
) {
1139 XUnmapWindow(dpy
, wwin
->icon
->core
->window
);
1140 RemoveFromStackList(wwin
->icon
->core
);
1141 wIconDestroy(wwin
->icon
);
1146 static Bool
handleWindowType(WWindow
*wwin
, Atom type
, int *layer
)
1150 if (type
== net_wm_window_type_desktop
) {
1151 wwin
->client_flags
.no_titlebar
= 1;
1152 wwin
->client_flags
.no_resizable
= 1;
1153 wwin
->client_flags
.no_miniaturizable
= 1;
1154 wwin
->client_flags
.no_border
= 1;
1155 wwin
->client_flags
.no_resizebar
= 1;
1156 wwin
->client_flags
.no_shadeable
= 1;
1157 wwin
->client_flags
.no_movable
= 1;
1158 wwin
->client_flags
.omnipresent
= 1;
1159 wwin
->client_flags
.skip_window_list
= 1;
1160 wwin
->client_flags
.skip_switchpanel
= 1;
1161 wwin
->client_flags
.dont_move_off
= 1;
1162 wwin
->client_flags
.no_appicon
= 1;
1163 wwin
->flags
.net_skip_pager
= 1;
1166 } else if (type
== net_wm_window_type_dock
) {
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; /* XXX: really not a single decoration. */
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
->flags
.net_skip_pager
= 1;
1179 } else if (type
== net_wm_window_type_toolbar
) {
1180 wwin
->client_flags
.no_titlebar
= 1;
1181 wwin
->client_flags
.no_resizable
= 1;
1182 wwin
->client_flags
.no_miniaturizable
= 1;
1183 wwin
->client_flags
.no_resizebar
= 1;
1184 wwin
->client_flags
.no_shadeable
= 1;
1185 wwin
->client_flags
.skip_window_list
= 1;
1186 wwin
->client_flags
.skip_switchpanel
= 1;
1187 wwin
->client_flags
.dont_move_off
= 1;
1188 wwin
->client_flags
.no_appicon
= 1;
1189 } else if (type
== net_wm_window_type_menu
||
1190 type
== net_wm_window_type_dropdown_menu
||
1191 type
== net_wm_window_type_popup_menu
||
1192 type
== net_wm_window_type_combo
) {
1193 wwin
->client_flags
.no_titlebar
= 1;
1194 wwin
->client_flags
.no_resizable
= 1;
1195 wwin
->client_flags
.no_miniaturizable
= 1;
1196 wwin
->client_flags
.no_resizebar
= 1;
1197 wwin
->client_flags
.no_shadeable
= 1;
1198 wwin
->client_flags
.skip_window_list
= 1;
1199 wwin
->client_flags
.skip_switchpanel
= 1;
1200 wwin
->client_flags
.dont_move_off
= 1;
1201 wwin
->client_flags
.no_appicon
= 1;
1202 } else if (type
== net_wm_window_type_utility
) {
1203 wwin
->client_flags
.no_appicon
= 1;
1204 } else if (type
== net_wm_window_type_splash
) {
1205 wwin
->client_flags
.no_titlebar
= 1;
1206 wwin
->client_flags
.no_resizable
= 1;
1207 wwin
->client_flags
.no_miniaturizable
= 1;
1208 wwin
->client_flags
.no_resizebar
= 1;
1209 wwin
->client_flags
.no_shadeable
= 1;
1210 wwin
->client_flags
.no_movable
= 1;
1211 wwin
->client_flags
.skip_window_list
= 1;
1212 wwin
->client_flags
.skip_switchpanel
= 1;
1213 wwin
->client_flags
.dont_move_off
= 1;
1214 wwin
->client_flags
.no_appicon
= 1;
1215 wwin
->flags
.net_skip_pager
= 1;
1216 } else if (type
== net_wm_window_type_dialog
) {
1217 /* These also seem a bad idea in our context -Dan
1218 // wwin->client_flags.skip_window_list = 1;
1219 // wwin->client_flags.no_appicon = 1;
1221 } else if (wwin
->type
== net_wm_window_type_tooltip
) {
1222 wwin
->client_flags
.no_titlebar
= 1;
1223 wwin
->client_flags
.no_resizable
= 1;
1224 wwin
->client_flags
.no_miniaturizable
= 1;
1225 wwin
->client_flags
.no_resizebar
= 1;
1226 wwin
->client_flags
.no_shadeable
= 1;
1227 wwin
->client_flags
.no_movable
= 1;
1228 wwin
->client_flags
.skip_window_list
= 1;
1229 wwin
->client_flags
.skip_switchpanel
= 1;
1230 wwin
->client_flags
.dont_move_off
= 1;
1231 wwin
->client_flags
.no_appicon
= 1;
1232 wwin
->client_flags
.no_focusable
= 1;
1233 wwin
->flags
.net_skip_pager
= 1;
1234 } else if (wwin
->type
== net_wm_window_type_notification
) {
1235 wwin
->client_flags
.no_titlebar
= 1;
1236 wwin
->client_flags
.no_resizable
= 1;
1237 wwin
->client_flags
.no_miniaturizable
= 1;
1238 wwin
->client_flags
.no_border
= 1;
1239 wwin
->client_flags
.no_resizebar
= 1;
1240 wwin
->client_flags
.no_shadeable
= 1;
1241 wwin
->client_flags
.no_movable
= 1;
1242 wwin
->client_flags
.omnipresent
= 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_hide_others
= 1;
1247 wwin
->client_flags
.no_appicon
= 1;
1248 wwin
->client_flags
.no_focusable
= 1;
1249 wwin
->flags
.net_skip_pager
= 1;
1250 } else if (wwin
->type
== net_wm_window_type_dnd
) {
1251 wwin
->client_flags
.no_titlebar
= 1;
1252 wwin
->client_flags
.no_resizable
= 1;
1253 wwin
->client_flags
.no_miniaturizable
= 1;
1254 wwin
->client_flags
.no_border
= 1;
1255 wwin
->client_flags
.no_resizebar
= 1;
1256 wwin
->client_flags
.no_shadeable
= 1;
1257 wwin
->client_flags
.no_movable
= 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 wwin
->flags
.net_skip_pager
= 1;
1263 } else if (type
== net_wm_window_type_normal
) {
1269 *layer
= getWindowLayer(wwin
);
1274 void wNETWMPositionSplash(WWindow
*wwin
, int *x
, int *y
, int width
, int height
)
1276 if (wwin
->type
== net_wm_window_type_splash
) {
1277 WScreen
*scr
= wwin
->screen_ptr
;
1278 WMRect rect
= wGetRectForHead(scr
, wGetHeadForPointerLocation(scr
));
1279 *x
= rect
.pos
.x
+ (rect
.size
.width
- width
) / 2;
1280 *y
= rect
.pos
.y
+ (rect
.size
.height
- height
) / 2;
1284 static void updateWindowType(WWindow
*wwin
)
1288 unsigned long nitems_ret
, bytes_after_ret
;
1291 if (XGetWindowProperty(dpy
, wwin
->client_win
, net_wm_window_type
, 0, 1,
1292 False
, XA_ATOM
, &type_ret
, &fmt_ret
, &nitems_ret
,
1293 &bytes_after_ret
, (unsigned char **)&data
) == Success
&& data
) {
1296 Atom
*type
= (Atom
*) data
;
1297 for (i
= 0; i
< nitems_ret
; ++i
) {
1298 if (handleWindowType(wwin
, type
[i
], &layer
))
1304 if (wwin
->frame
!= NULL
) {
1305 ChangeStackingLevel(wwin
->frame
->core
, layer
);
1306 wwin
->frame
->flags
.need_texture_change
= 1;
1307 wWindowConfigureBorders(wwin
);
1308 wFrameWindowPaint(wwin
->frame
);
1309 wNETWMUpdateActions(wwin
, False
);
1313 void wNETWMCheckClientHints(WWindow
*wwin
, int *layer
, int *workspace
)
1317 unsigned long nitems_ret
, bytes_after_ret
;
1320 if (XGetWindowProperty(dpy
, wwin
->client_win
, net_wm_desktop
, 0, 1, False
,
1321 XA_CARDINAL
, &type_ret
, &fmt_ret
, &nitems_ret
,
1322 &bytes_after_ret
, (unsigned char **)&data
) == Success
&& data
) {
1324 long desktop
= *data
;
1328 wwin
->client_flags
.omnipresent
= 1;
1330 *workspace
= desktop
;
1333 if (XGetWindowProperty(dpy
, wwin
->client_win
, net_wm_state
, 0, 1, False
,
1334 XA_ATOM
, &type_ret
, &fmt_ret
, &nitems_ret
,
1335 &bytes_after_ret
, (unsigned char **)&data
) == Success
&& data
) {
1337 Atom
*state
= (Atom
*) data
;
1338 for (i
= 0; i
< nitems_ret
; ++i
)
1339 doStateAtom(wwin
, state
[i
], _NET_WM_STATE_ADD
, True
);
1344 if (XGetWindowProperty(dpy
, wwin
->client_win
, net_wm_window_type
, 0, 1, False
,
1345 XA_ATOM
, &type_ret
, &fmt_ret
, &nitems_ret
,
1346 &bytes_after_ret
, (unsigned char **)&data
) == Success
&& data
) {
1348 Atom
*type
= (Atom
*) data
;
1349 for (i
= 0; i
< nitems_ret
; ++i
) {
1350 if (handleWindowType(wwin
, type
[i
], layer
))
1356 wNETWMUpdateActions(wwin
, False
);
1357 updateStrut(wwin
->screen_ptr
, wwin
->client_win
, False
);
1358 updateStrut(wwin
->screen_ptr
, wwin
->client_win
, True
);
1360 wScreenUpdateUsableArea(wwin
->screen_ptr
);
1363 static Bool
updateNetIconInfo(WWindow
*wwin
)
1367 unsigned long nitems_ret
, bytes_after_ret
;
1369 Bool hasState
= False
;
1370 Bool old_state
= wwin
->flags
.net_handle_icon
;
1372 if (XGetWindowProperty(dpy
, wwin
->client_win
, net_wm_handled_icons
, 0, 1, False
,
1373 XA_CARDINAL
, &type_ret
, &fmt_ret
, &nitems_ret
,
1374 &bytes_after_ret
, (unsigned char **)&data
) == Success
&& data
) {
1375 long handled
= *data
;
1376 wwin
->flags
.net_handle_icon
= (handled
!= 0);
1381 wwin
->flags
.net_handle_icon
= False
;
1384 if (XGetWindowProperty(dpy
, wwin
->client_win
, net_wm_icon_geometry
, 0, 4, False
,
1385 XA_CARDINAL
, &type_ret
, &fmt_ret
, &nitems_ret
,
1386 &bytes_after_ret
, (unsigned char **)&data
) == Success
&& data
) {
1389 if (wwin
->flags
.net_handle_icon
)
1391 wwin
->flags
.net_handle_icon
= True
;
1394 wwin
->icon_x
= data
[0];
1395 wwin
->icon_y
= data
[1];
1396 wwin
->icon_w
= data
[2];
1397 wwin
->icon_h
= data
[3];
1404 wwin
->flags
.net_handle_icon
= False
;
1407 if (wwin
->flags
.miniaturized
&& old_state
!= wwin
->flags
.net_handle_icon
) {
1408 if (wwin
->flags
.net_handle_icon
) {
1411 wwin
->flags
.miniaturized
= False
;
1412 wwin
->flags
.skip_next_animation
= True
;
1413 wIconifyWindow(wwin
);
1420 void wNETWMCheckInitialClientState(WWindow
*wwin
)
1423 wmessage("wNETWMCheckInitialClientState");
1426 wNETWMShowingDesktop(wwin
->screen_ptr
, False
);
1428 updateWindowType(wwin
);
1429 updateNetIconInfo(wwin
);
1430 updateIconImage(wwin
);
1433 void wNETWMCheckInitialFrameState(WWindow
*wwin
)
1436 wmessage("wNETWMCheckInitialFrameState");
1439 updateWindowOpacity(wwin
);
1442 static void handleDesktopNames(WScreen
*scr
)
1444 unsigned long nitems_ret
, bytes_after_ret
;
1445 char *data
, *names
[32];
1449 if (XGetWindowProperty(dpy
, scr
->root_win
, net_desktop_names
, 0, 1, False
,
1450 utf8_string
, &type_ret
, &fmt_ret
, &nitems_ret
,
1451 &bytes_after_ret
, (unsigned char **)&data
) != Success
)
1457 if (type_ret
!= utf8_string
|| fmt_ret
!= 8)
1462 for (i
= 0; i
< nitems_ret
; i
++) {
1465 names
[n
] = &data
[i
];
1466 } else if (*names
[n
] == 0) {
1467 names
[n
] = &data
[i
];
1468 wWorkspaceRename(scr
, n
, names
[n
]);
1473 Bool
wNETWMProcessClientMessage(XClientMessageEvent
*event
)
1480 wmessage("processClientMessage type %s", XGetAtomName(dpy
, event
->message_type
));
1483 scr
= wScreenForWindow(event
->window
);
1485 /* generic client messages */
1486 if (event
->message_type
== net_current_desktop
) {
1487 wWorkspaceChange(scr
, event
->data
.l
[0]);
1488 } else if (event
->message_type
== net_number_of_desktops
) {
1491 value
= event
->data
.l
[0];
1492 if (value
> w_global
.workspace
.count
) {
1493 wWorkspaceMake(scr
, value
- w_global
.workspace
.count
);
1494 } else if (value
< w_global
.workspace
.count
) {
1496 Bool rebuild
= False
;
1498 for (i
= w_global
.workspace
.count
- 1; i
>= value
; i
--) {
1499 if (!wWorkspaceDelete(scr
, i
)) {
1506 updateWorkspaceCount(scr
);
1508 } else if (event
->message_type
== net_showing_desktop
) {
1509 wNETWMShowingDesktop(scr
, event
->data
.l
[0]);
1510 } else if (event
->message_type
== net_desktop_names
) {
1511 handleDesktopNames(scr
);
1520 /* window specific client messages */
1522 wwin
= wWindowFor(event
->window
);
1526 if (event
->message_type
== net_active_window
) {
1528 * Satisfy a client's focus request only if
1529 * - request comes from a pager, or
1530 * - it's explicitly allowed in Advanced Options, or
1531 * - giving the client the focus does not cause a change in
1532 * the active workspace (XXX: or the active head if Xinerama)
1534 if (wwin
->frame
->workspace
== w_global
.workspace
.current
/* No workspace change */
1535 || event
->data
.l
[0] == 2 /* Requested by pager */
1536 || WFLAGP(wwin
, focus_across_wksp
) /* Explicitly allowed */) {
1537 wNETWMShowingDesktop(scr
, False
);
1538 wMakeWindowVisible(wwin
);
1540 } else if (event
->message_type
== net_close_window
) {
1541 if (!WFLAGP(wwin
, no_closable
)) {
1542 if (wwin
->protocols
.DELETE_WINDOW
)
1543 wClientSendProtocol(wwin
, w_global
.atom
.wm
.delete_window
,
1544 w_global
.timestamp
.last_event
);
1546 } else if (event
->message_type
== net_wm_state
) {
1547 int maximized
= wwin
->flags
.maximized
;
1548 long set
= event
->data
.l
[0];
1551 wmessage("net_wm_state set %ld a1 %s a2 %s", set
,
1552 XGetAtomName(dpy
, event
->data
.l
[1]), XGetAtomName(dpy
, event
->data
.l
[2]));
1555 doStateAtom(wwin
, (Atom
) event
->data
.l
[1], set
, False
);
1556 if (event
->data
.l
[2])
1557 doStateAtom(wwin
, (Atom
) event
->data
.l
[2], set
, False
);
1559 if (wwin
->flags
.maximized
!= maximized
) {
1560 if (!wwin
->flags
.maximized
) {
1561 wwin
->flags
.maximized
= maximized
;
1562 wUnmaximizeWindow(wwin
);
1564 wMaximizeWindow(wwin
, wwin
->flags
.maximized
);
1567 updateStateHint(wwin
, False
, False
);
1568 } else if (event
->message_type
== net_wm_handled_icons
|| event
->message_type
== net_wm_icon_geometry
) {
1569 updateNetIconInfo(wwin
);
1570 } else if (event
->message_type
== net_wm_desktop
) {
1571 long desktop
= event
->data
.l
[0];
1572 if (desktop
== -1) {
1573 wWindowSetOmnipresent(wwin
, True
);
1575 if (IS_OMNIPRESENT(wwin
))
1576 wWindowSetOmnipresent(wwin
, False
);
1577 wWindowChangeWorkspace(wwin
, desktop
);
1586 void wNETWMCheckClientHintChange(WWindow
*wwin
, XPropertyEvent
*event
)
1589 wmessage("clientHintChange type %s", XGetAtomName(dpy
, event
->atom
));
1592 if (event
->atom
== net_wm_strut
|| event
->atom
== net_wm_strut_partial
) {
1593 updateStrut(wwin
->screen_ptr
, wwin
->client_win
, False
);
1594 updateStrut(wwin
->screen_ptr
, wwin
->client_win
, True
);
1595 wScreenUpdateUsableArea(wwin
->screen_ptr
);
1596 } else if (event
->atom
== net_wm_handled_icons
|| event
->atom
== net_wm_icon_geometry
) {
1597 updateNetIconInfo(wwin
);
1598 } else if (event
->atom
== net_wm_window_type
) {
1599 updateWindowType(wwin
);
1600 } else if (event
->atom
== net_wm_name
) {
1601 char *name
= wNETWMGetWindowName(wwin
->client_win
);
1602 wWindowUpdateName(wwin
, name
);
1605 } else if (event
->atom
== net_wm_icon_name
) {
1607 wIconChangeTitle(wwin
->icon
, wwin
);
1608 wIconPaint(wwin
->icon
);
1610 } else if (event
->atom
== net_wm_icon
) {
1611 updateIconImage(wwin
);
1612 } else if (event
->atom
== net_wm_window_opacity
) {
1613 updateWindowOpacity(wwin
);
1617 int wNETWMGetPidForWindow(Window window
)
1621 unsigned long nitems_ret
, bytes_after_ret
;
1625 if (XGetWindowProperty(dpy
, window
, net_wm_pid
, 0, 1, False
,
1626 XA_CARDINAL
, &type_ret
, &fmt_ret
, &nitems_ret
,
1627 &bytes_after_ret
, (unsigned char **)&data
) == Success
&& data
) {
1637 char *wNETWMGetWindowName(Window window
)
1643 name
= (char *)PropGetCheckProperty(window
, net_wm_name
, utf8_string
, 0, 0, &size
);
1645 ret
= wstrndup(name
, size
);
1654 char *wNETWMGetIconName(Window window
)
1660 name
= (char *)PropGetCheckProperty(window
, net_wm_icon_name
, utf8_string
, 0, 0, &size
);
1662 ret
= wstrndup(name
, size
);
1671 static void observer(void *self
, WMNotification
*notif
)
1673 WWindow
*wwin
= (WWindow
*) WMGetNotificationObject(notif
);
1674 const char *name
= WMGetNotificationName(notif
);
1675 void *data
= WMGetNotificationClientData(notif
);
1676 NetData
*ndata
= (NetData
*) self
;
1678 if (strcmp(name
, WMNManaged
) == 0 && wwin
) {
1679 updateClientList(wwin
->screen_ptr
);
1680 updateClientListStacking(wwin
->screen_ptr
, NULL
);
1681 updateStateHint(wwin
, True
, False
);
1683 updateStrut(wwin
->screen_ptr
, wwin
->client_win
, False
);
1684 updateStrut(wwin
->screen_ptr
, wwin
->client_win
, True
);
1685 wScreenUpdateUsableArea(wwin
->screen_ptr
);
1686 } else if (strcmp(name
, WMNUnmanaged
) == 0 && wwin
) {
1687 updateClientList(wwin
->screen_ptr
);
1688 updateClientListStacking(wwin
->screen_ptr
, wwin
);
1689 updateWorkspaceHint(wwin
, False
, True
);
1690 updateStateHint(wwin
, False
, True
);
1691 wNETWMUpdateActions(wwin
, True
);
1693 updateStrut(wwin
->screen_ptr
, wwin
->client_win
, False
);
1694 wScreenUpdateUsableArea(wwin
->screen_ptr
);
1695 } else if (strcmp(name
, WMNResetStacking
) == 0 && wwin
) {
1696 updateClientListStacking(wwin
->screen_ptr
, NULL
);
1697 updateStateHint(wwin
, False
, False
);
1698 } else if (strcmp(name
, WMNChangedStacking
) == 0 && wwin
) {
1699 updateClientListStacking(wwin
->screen_ptr
, NULL
);
1700 updateStateHint(wwin
, False
, False
);
1701 } else if (strcmp(name
, WMNChangedFocus
) == 0) {
1702 updateFocusHint(ndata
->scr
);
1703 } else if (strcmp(name
, WMNChangedWorkspace
) == 0 && wwin
) {
1704 updateWorkspaceHint(wwin
, False
, False
);
1705 updateStateHint(wwin
, True
, False
);
1706 } else if (strcmp(name
, WMNChangedState
) == 0 && wwin
) {
1707 updateStateHint(wwin
, !strcmp(data
, "omnipresent"), False
);
1711 static void wsobserver(void *self
, WMNotification
*notif
)
1713 WScreen
*scr
= (WScreen
*) WMGetNotificationObject(notif
);
1714 const char *name
= WMGetNotificationName(notif
);
1716 /* Parameter not used, but tell the compiler that it is ok */
1719 if (strcmp(name
, WMNWorkspaceCreated
) == 0) {
1720 updateWorkspaceCount(scr
);
1721 updateWorkspaceNames(scr
);
1722 wNETWMUpdateWorkarea(scr
);
1723 } else if (strcmp(name
, WMNWorkspaceDestroyed
) == 0) {
1724 updateWorkspaceCount(scr
);
1725 updateWorkspaceNames(scr
);
1726 wNETWMUpdateWorkarea(scr
);
1727 } else if (strcmp(name
, WMNWorkspaceChanged
) == 0) {
1728 updateCurrentWorkspace(scr
);
1729 } else if (strcmp(name
, WMNWorkspaceNameChanged
) == 0) {
1730 updateWorkspaceNames(scr
);
1734 void wNETFrameExtents(WWindow
*wwin
)
1736 long extents
[4] = { 0, 0, 0, 0 };
1738 /* The extents array describes dimensions which are not
1739 * part of the client window. In our case that means
1740 * widths of the border and heights of the titlebar and resizebar.
1747 if (wwin
->frame
->titlebar
)
1748 extents
[2] = wwin
->frame
->titlebar
->height
;
1749 if (wwin
->frame
->resizebar
)
1750 extents
[3] = wwin
->frame
->resizebar
->height
;
1751 if (HAS_BORDER(wwin
)) {
1752 extents
[0] += wwin
->screen_ptr
->frame_border_width
;
1753 extents
[1] += wwin
->screen_ptr
->frame_border_width
;
1754 extents
[2] += wwin
->screen_ptr
->frame_border_width
;
1755 extents
[3] += wwin
->screen_ptr
->frame_border_width
;
1758 XChangeProperty(dpy
, wwin
->client_win
, net_frame_extents
, XA_CARDINAL
, 32, PropModeReplace
, (unsigned char *) extents
, 4);
1761 void wNETCleanupFrameExtents(WWindow
*wwin
)
1763 XDeleteProperty(dpy
, wwin
->client_win
, net_frame_extents
);