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
220 #define _NET_WM_MOVERESIZE_SIZE_TOPLEFT 0
221 #define _NET_WM_MOVERESIZE_SIZE_TOP 1
222 #define _NET_WM_MOVERESIZE_SIZE_TOPRIGHT 2
223 #define _NET_WM_MOVERESIZE_SIZE_RIGHT 3
224 #define _NET_WM_MOVERESIZE_SIZE_BOTTOMRIGHT 4
225 #define _NET_WM_MOVERESIZE_SIZE_BOTTOM 5
226 #define _NET_WM_MOVERESIZE_SIZE_BOTTOMLEFT 6
227 #define _NET_WM_MOVERESIZE_SIZE_LEFT 7
228 #define _NET_WM_MOVERESIZE_MOVE 8 /* movement only */
229 #define _NET_WM_MOVERESIZE_SIZE_KEYBOARD 9 /* size via keyboard */
230 #define _NET_WM_MOVERESIZE_MOVE_KEYBOARD 10 /* move via keyboard */
232 static void observer(void *self
, WMNotification
*notif
);
233 static void wsobserver(void *self
, WMNotification
*notif
);
235 static void updateClientList(WScreen
*scr
);
236 static void updateClientListStacking(WScreen
*scr
, WWindow
*);
238 static void updateWorkspaceNames(WScreen
*scr
);
239 static void updateCurrentWorkspace(WScreen
*scr
);
240 static void updateWorkspaceCount(WScreen
*scr
);
241 static void wNETWMShowingDesktop(WScreen
*scr
, Bool show
);
243 typedef struct NetData
{
245 WReservedArea
*strut
;
246 WWindow
**show_desktop
;
249 static void setSupportedHints(WScreen
*scr
)
251 Atom atom
[wlengthof(atomNames
)];
254 /* set supported hints list */
255 /* XXX: extend this !!! */
257 atom
[i
++] = net_client_list
;
258 atom
[i
++] = net_client_list_stacking
;
259 atom
[i
++] = net_number_of_desktops
;
260 atom
[i
++] = net_desktop_geometry
;
261 atom
[i
++] = net_desktop_viewport
;
262 atom
[i
++] = net_current_desktop
;
263 atom
[i
++] = net_desktop_names
;
264 atom
[i
++] = net_active_window
;
265 atom
[i
++] = net_workarea
;
266 atom
[i
++] = net_supporting_wm_check
;
267 atom
[i
++] = net_showing_desktop
;
269 atom
[i
++] = net_wm_moveresize
;
271 atom
[i
++] = net_wm_desktop
;
272 atom
[i
++] = net_wm_window_type
;
273 atom
[i
++] = net_wm_window_type_desktop
;
274 atom
[i
++] = net_wm_window_type_dock
;
275 atom
[i
++] = net_wm_window_type_toolbar
;
276 atom
[i
++] = net_wm_window_type_menu
;
277 atom
[i
++] = net_wm_window_type_utility
;
278 atom
[i
++] = net_wm_window_type_splash
;
279 atom
[i
++] = net_wm_window_type_dialog
;
280 atom
[i
++] = net_wm_window_type_dropdown_menu
;
281 atom
[i
++] = net_wm_window_type_popup_menu
;
282 atom
[i
++] = net_wm_window_type_tooltip
;
283 atom
[i
++] = net_wm_window_type_notification
;
284 atom
[i
++] = net_wm_window_type_combo
;
285 atom
[i
++] = net_wm_window_type_dnd
;
286 atom
[i
++] = net_wm_window_type_normal
;
288 atom
[i
++] = net_wm_state
;
289 /* atom[i++] = net_wm_state_modal; *//* XXX: not sure where/when to use it. */
290 atom
[i
++] = net_wm_state_sticky
;
291 atom
[i
++] = net_wm_state_shaded
;
292 atom
[i
++] = net_wm_state_maximized_horz
;
293 atom
[i
++] = net_wm_state_maximized_vert
;
294 atom
[i
++] = net_wm_state_skip_taskbar
;
295 atom
[i
++] = net_wm_state_skip_pager
;
296 atom
[i
++] = net_wm_state_hidden
;
297 atom
[i
++] = net_wm_state_fullscreen
;
298 atom
[i
++] = net_wm_state_above
;
299 atom
[i
++] = net_wm_state_below
;
301 atom
[i
++] = net_wm_allowed_actions
;
302 atom
[i
++] = net_wm_action_move
;
303 atom
[i
++] = net_wm_action_resize
;
304 atom
[i
++] = net_wm_action_minimize
;
305 atom
[i
++] = net_wm_action_shade
;
306 atom
[i
++] = net_wm_action_stick
;
307 atom
[i
++] = net_wm_action_maximize_horz
;
308 atom
[i
++] = net_wm_action_maximize_vert
;
309 atom
[i
++] = net_wm_action_fullscreen
;
310 atom
[i
++] = net_wm_action_change_desktop
;
311 atom
[i
++] = net_wm_action_close
;
313 atom
[i
++] = net_wm_strut
;
314 atom
[i
++] = net_wm_icon_geometry
;
315 atom
[i
++] = net_wm_icon
;
316 atom
[i
++] = net_wm_handled_icons
;
317 atom
[i
++] = net_wm_window_opacity
;
319 atom
[i
++] = net_frame_extents
;
321 atom
[i
++] = net_wm_name
;
322 atom
[i
++] = net_wm_icon_name
;
324 XChangeProperty(dpy
, scr
->root_win
, net_supported
, XA_ATOM
, 32, PropModeReplace
, (unsigned char *)atom
, i
);
326 /* set supporting wm hint */
327 XChangeProperty(dpy
, scr
->root_win
, net_supporting_wm_check
, XA_WINDOW
, 32,
328 PropModeReplace
, (unsigned char *)&scr
->info_window
, 1);
330 XChangeProperty(dpy
, scr
->info_window
, net_supporting_wm_check
, XA_WINDOW
,
331 32, PropModeReplace
, (unsigned char *)&scr
->info_window
, 1);
334 void wNETWMUpdateDesktop(WScreen
*scr
)
336 long *views
, sizes
[2];
339 if (scr
->workspace_count
== 0)
342 count
= scr
->workspace_count
* 2;
343 views
= wmalloc(sizeof(long) * count
);
344 sizes
[0] = scr
->scr_width
;
345 sizes
[1] = scr
->scr_height
;
347 for (i
= 0; i
< scr
->workspace_count
; i
++) {
348 views
[2 * i
+ 0] = 0;
349 views
[2 * i
+ 1] = 0;
352 XChangeProperty(dpy
, scr
->root_win
, net_desktop_geometry
, XA_CARDINAL
, 32,
353 PropModeReplace
, (unsigned char *)sizes
, 2);
355 XChangeProperty(dpy
, scr
->root_win
, net_desktop_viewport
, XA_CARDINAL
, 32,
356 PropModeReplace
, (unsigned char *)views
, count
);
361 int wNETWMGetCurrentDesktopFromHint(WScreen
*scr
)
366 prop
= PropGetCheckProperty(scr
->root_win
, net_current_desktop
, XA_CARDINAL
, 0, 1, &count
);
368 int desktop
= *(long *)prop
;
376 * Find the best icon to be used by Window Maker for appicon/miniwindows.
377 * Currently the algorithm is to take the image with the size closest
378 * to icon_size x icon_size, but never bigger than that.
380 * This algorithm is very poorly implemented and needs to be redone (it can
381 * easily select images with very large widths and very small heights over
382 * square images, if the area of the former is closer to the desired one).
384 * The logic can also be changed to accept bigger images and scale them down.
386 static unsigned long *findBestIcon(unsigned long *data
, unsigned long items
)
389 unsigned long i
, distance
;
392 /* better use only 75% of icon_size. For 64x64 this means 48x48
393 * This leaves room around the icon for the miniwindow title and
394 * results in better overall aesthetics -Dan */
395 wanted
= wPreferences
.icon_size
* wPreferences
.icon_size
;
397 for (icon
= NULL
, distance
= wanted
, i
= 0L; i
< items
- 1;) {
398 size
= data
[i
] * data
[i
+ 1];
402 if (d
>= 0 && d
<= distance
&& (i
+ size
+ 2) <= items
) {
412 static RImage
*makeRImageFromARGBData(unsigned long *data
)
414 int size
, width
, height
, i
;
416 unsigned char *imgdata
;
421 size
= width
* height
;
426 image
= RCreateImage(width
, height
, True
);
428 for (imgdata
= image
->data
, i
= 2; i
< size
+ 2; i
++, imgdata
+= 4) {
430 imgdata
[3] = (pixel
>> 24) & 0xff; /* A */
431 imgdata
[0] = (pixel
>> 16) & 0xff; /* R */
432 imgdata
[1] = (pixel
>> 8) & 0xff; /* G */
433 imgdata
[2] = (pixel
>> 0) & 0xff; /* B */
439 RImage
*get_window_image_from_x11(Window window
)
444 unsigned long items
, rest
;
445 unsigned long *property
, *data
;
447 /* Get the icon from X11 Window */
448 if (XGetWindowProperty(dpy
, window
, net_wm_icon
, 0L, LONG_MAX
,
449 False
, XA_CARDINAL
, &type
, &format
, &items
, &rest
,
450 (unsigned char **)&property
) != Success
|| !property
)
453 if (type
!= XA_CARDINAL
|| format
!= 32 || items
< 2) {
458 /* Find the best icon */
459 data
= findBestIcon(property
, items
);
465 /* Save the best icon in the X11 icon */
466 image
= makeRImageFromARGBData(data
);
470 /* Resize the image to the correct value */
471 image
= wIconValidateIconSize(image
, wPreferences
.icon_size
);
476 static void updateIconImage(WWindow
*wwin
)
478 /* Remove the icon image from X11 */
479 if (wwin
->net_icon_image
)
480 RReleaseImage(wwin
->net_icon_image
);
482 /* Save the icon in the X11 icon */
483 wwin
->net_icon_image
= get_window_image_from_x11(wwin
->client_win
);
485 /* Refresh the Window Icon */
487 wIconUpdate(wwin
->icon
);
489 /* Refresh the application icon */
490 WApplication
*app
= wApplicationOf(wwin
->main_window
);
491 if (app
&& app
->app_icon
) {
492 wIconUpdate(app
->app_icon
->icon
);
493 wAppIconPaint(app
->app_icon
);
497 static void updateWindowOpacity(WWindow
*wwin
)
501 unsigned long items
, rest
;
502 unsigned long *property
;
507 /* We don't care about this ourselves, but other programs need us to copy
508 * this to the frame window. */
509 if (XGetWindowProperty(dpy
, wwin
->client_win
, net_wm_window_opacity
, 0L, 1L,
510 False
, XA_CARDINAL
, &type
, &format
, &items
, &rest
,
511 (unsigned char **)&property
) != Success
)
515 XDeleteProperty(dpy
, wwin
->frame
->core
->window
, net_wm_window_opacity
);
516 } else if (type
== XA_CARDINAL
&& format
== 32 && items
== 1 && property
) {
517 XChangeProperty(dpy
, wwin
->frame
->core
->window
, net_wm_window_opacity
,
518 XA_CARDINAL
, 32, PropModeReplace
, (unsigned char *)property
, 1L);
525 static void updateShowDesktop(WScreen
*scr
, Bool show
)
529 foo
= (show
== True
);
530 XChangeProperty(dpy
, scr
->root_win
, net_showing_desktop
, XA_CARDINAL
, 32,
531 PropModeReplace
, (unsigned char *)&foo
, 1);
534 static void wNETWMShowingDesktop(WScreen
*scr
, Bool show
)
536 if (show
&& scr
->netdata
->show_desktop
== NULL
) {
537 WWindow
*tmp
, **wins
;
540 wins
= (WWindow
**) wmalloc(sizeof(WWindow
*) * (scr
->window_count
+ 1));
542 tmp
= scr
->focused_window
;
544 if (!tmp
->flags
.hidden
&& !tmp
->flags
.miniaturized
&& !WFLAGP(tmp
, skip_window_list
)) {
547 tmp
->flags
.skip_next_animation
= 1;
548 tmp
->flags
.net_show_desktop
= 1;
556 scr
->netdata
->show_desktop
= wins
;
557 updateShowDesktop(scr
, True
);
558 } else if (scr
->netdata
->show_desktop
!= NULL
) {
559 /* FIXME: get rid of workspace flashing ! */
560 int ws
= scr
->current_workspace
;
562 for (tmp
= scr
->netdata
->show_desktop
; *tmp
; ++tmp
) {
563 wDeiconifyWindow(*tmp
);
564 (*tmp
)->flags
.net_show_desktop
= 0;
566 if (ws
!= scr
->current_workspace
)
567 wWorkspaceChange(scr
, ws
);
568 wfree(scr
->netdata
->show_desktop
);
569 scr
->netdata
->show_desktop
= NULL
;
570 updateShowDesktop(scr
, False
);
574 void wNETWMInitStuff(WScreen
*scr
)
580 wmessage("wNETWMInitStuff");
583 #ifdef HAVE_XINTERNATOMS
585 Atom atoms
[wlengthof(atomNames
)];
586 char *names
[wlengthof(atomNames
)];
588 for (i
= 0; i
< wlengthof(atomNames
); ++i
)
589 names
[i
] = atomNames
[i
].name
;
591 XInternAtoms(dpy
, &names
[0], wlengthof(atomNames
), False
, atoms
);
592 for (i
= 0; i
< wlengthof(atomNames
); ++i
)
593 *atomNames
[i
].atom
= atoms
[i
];
597 for (i
= 0; i
< wlengthof(atomNames
); i
++)
598 *atomNames
[i
].atom
= XInternAtom(dpy
, atomNames
[i
].name
, False
);
601 data
= wmalloc(sizeof(NetData
));
604 data
->show_desktop
= NULL
;
608 setSupportedHints(scr
);
610 WMAddNotificationObserver(observer
, data
, WMNManaged
, NULL
);
611 WMAddNotificationObserver(observer
, data
, WMNUnmanaged
, NULL
);
612 WMAddNotificationObserver(observer
, data
, WMNChangedWorkspace
, NULL
);
613 WMAddNotificationObserver(observer
, data
, WMNChangedState
, NULL
);
614 WMAddNotificationObserver(observer
, data
, WMNChangedFocus
, NULL
);
615 WMAddNotificationObserver(observer
, data
, WMNChangedStacking
, NULL
);
616 WMAddNotificationObserver(observer
, data
, WMNChangedName
, NULL
);
618 WMAddNotificationObserver(wsobserver
, data
, WMNWorkspaceCreated
, NULL
);
619 WMAddNotificationObserver(wsobserver
, data
, WMNWorkspaceDestroyed
, NULL
);
620 WMAddNotificationObserver(wsobserver
, data
, WMNWorkspaceChanged
, NULL
);
621 WMAddNotificationObserver(wsobserver
, data
, WMNWorkspaceNameChanged
, NULL
);
623 updateClientList(scr
);
624 updateClientListStacking(scr
, NULL
);
625 updateWorkspaceCount(scr
);
626 updateWorkspaceNames(scr
);
627 updateShowDesktop(scr
, False
);
629 wScreenUpdateUsableArea(scr
);
632 void wNETWMCleanup(WScreen
*scr
)
636 for (i
= 0; i
< wlengthof(atomNames
); i
++)
637 XDeleteProperty(dpy
, scr
->root_win
, *atomNames
[i
].atom
);
640 void wNETWMUpdateActions(WWindow
*wwin
, Bool del
)
642 Atom action
[10]; /* nr of actions atoms defined */
646 XDeleteProperty(dpy
, wwin
->client_win
, net_wm_allowed_actions
);
650 if (IS_MOVABLE(wwin
))
651 action
[i
++] = net_wm_action_move
;
653 if (IS_RESIZABLE(wwin
))
654 action
[i
++] = net_wm_action_resize
;
656 if (!WFLAGP(wwin
, no_miniaturizable
))
657 action
[i
++] = net_wm_action_minimize
;
659 if (!WFLAGP(wwin
, no_shadeable
))
660 action
[i
++] = net_wm_action_shade
;
662 /* if (!WFLAGP(wwin, no_stickable)) */
663 action
[i
++] = net_wm_action_stick
;
665 /* if (!(WFLAGP(wwin, no_maximizeable) & MAX_HORIZONTAL)) */
666 if (IS_RESIZABLE(wwin
))
667 action
[i
++] = net_wm_action_maximize_horz
;
669 /* if (!(WFLAGP(wwin, no_maximizeable) & MAX_VERTICAL)) */
670 if (IS_RESIZABLE(wwin
))
671 action
[i
++] = net_wm_action_maximize_vert
;
673 /* if (!WFLAGP(wwin, no_fullscreen)) */
674 action
[i
++] = net_wm_action_fullscreen
;
676 /* if (!WFLAGP(wwin, no_change_desktop)) */
677 action
[i
++] = net_wm_action_change_desktop
;
679 if (!WFLAGP(wwin
, no_closable
))
680 action
[i
++] = net_wm_action_close
;
682 XChangeProperty(dpy
, wwin
->client_win
, net_wm_allowed_actions
,
683 XA_ATOM
, 32, PropModeReplace
, (unsigned char *)action
, i
);
686 void wNETWMUpdateWorkarea(WScreen
*scr
)
691 if (!scr
->netdata
|| scr
->workspace_count
== 0 || !scr
->usableArea
)
694 count
= scr
->workspace_count
* 4;
695 area
= wmalloc(sizeof(long) * count
);
697 for (i
= 0; i
< scr
->workspace_count
; i
++) {
698 area
[4 * i
+ 0] = scr
->usableArea
[0].x1
;
699 area
[4 * i
+ 1] = scr
->usableArea
[0].y1
;
700 area
[4 * i
+ 2] = scr
->usableArea
[0].x2
- scr
->usableArea
[0].x1
;
701 area
[4 * i
+ 3] = scr
->usableArea
[0].y2
- scr
->usableArea
[0].y1
;
704 XChangeProperty(dpy
, scr
->root_win
, net_workarea
, XA_CARDINAL
, 32,
705 PropModeReplace
, (unsigned char *)area
, count
);
709 Bool
wNETWMGetUsableArea(WScreen
*scr
, int head
, WArea
*area
)
714 if (!scr
->netdata
|| !scr
->netdata
->strut
)
717 area
->x1
= area
->y1
= area
->x2
= area
->y2
= 0;
719 for (cur
= scr
->netdata
->strut
; cur
; cur
= cur
->next
) {
720 WWindow
*wwin
= wWindowFor(cur
->window
);
721 if (wWindowTouchesHead(wwin
, head
)) {
722 if (cur
->area
.x1
> area
->x1
)
723 area
->x1
= cur
->area
.x1
;
724 if (cur
->area
.y1
> area
->y1
)
725 area
->y1
= cur
->area
.y1
;
726 if (cur
->area
.x2
> area
->x2
)
727 area
->x2
= cur
->area
.x2
;
728 if (cur
->area
.y2
> area
->y2
)
729 area
->y2
= cur
->area
.y2
;
733 if (area
->x1
== 0 && area
->x2
== 0 && area
->y1
== 0 && area
->y2
== 0)
736 rect
= wGetRectForHead(scr
, head
);
738 area
->x1
= rect
.pos
.x
+ area
->x1
;
739 area
->x2
= rect
.pos
.x
+ rect
.size
.width
- area
->x2
;
740 area
->y1
= rect
.pos
.y
+ area
->y1
;
741 area
->y2
= rect
.pos
.y
+ rect
.size
.height
- area
->y2
;
746 static void updateClientList(WScreen
*scr
)
752 windows
= (Window
*) wmalloc(sizeof(Window
) * (scr
->window_count
+ 1));
755 wwin
= scr
->focused_window
;
757 windows
[count
++] = wwin
->client_win
;
760 XChangeProperty(dpy
, scr
->root_win
, net_client_list
, XA_WINDOW
, 32,
761 PropModeReplace
, (unsigned char *)windows
, count
);
767 static void updateClientListStacking(WScreen
*scr
, WWindow
*wwin_excl
)
770 Window
*client_list
, *client_list_reverse
;
775 /* update client list */
776 i
= scr
->window_count
+ 1;
777 client_list
= (Window
*) wmalloc(sizeof(Window
) * i
);
778 client_list_reverse
= (Window
*) wmalloc(sizeof(Window
) * i
);
781 WM_ETARETI_BAG(scr
->stacking_list
, tmp
, iter
) {
783 wwin
= wWindowFor(tmp
->window
);
784 /* wwin_excl is a window to exclude from the list
785 (e.g. it's now unmanaged) */
786 if (wwin
&& (wwin
!= wwin_excl
))
787 client_list
[client_count
++] = wwin
->client_win
;
788 tmp
= tmp
->stacking
->under
;
792 for (i
= 0; i
< client_count
; i
++) {
793 Window w
= client_list
[client_count
- i
- 1];
794 client_list_reverse
[i
] = w
;
797 XChangeProperty(dpy
, scr
->root_win
, net_client_list_stacking
, XA_WINDOW
, 32,
798 PropModeReplace
, (unsigned char *)client_list_reverse
, client_count
);
801 wfree(client_list_reverse
);
806 static void updateWorkspaceCount(WScreen
*scr
)
810 count
= scr
->workspace_count
;
812 XChangeProperty(dpy
, scr
->root_win
, net_number_of_desktops
, XA_CARDINAL
,
813 32, PropModeReplace
, (unsigned char *)&count
, 1);
816 static void updateCurrentWorkspace(WScreen
*scr
)
820 count
= scr
->current_workspace
;
822 XChangeProperty(dpy
, scr
->root_win
, net_current_desktop
, XA_CARDINAL
, 32,
823 PropModeReplace
, (unsigned char *)&count
, 1);
826 static void updateWorkspaceNames(WScreen
*scr
)
828 char buf
[MAX_WORKSPACES
* (MAX_WORKSPACENAME_WIDTH
+ 1)], *pos
;
829 unsigned int i
, len
, curr_size
;
833 for (i
= 0; i
< scr
->workspace_count
; i
++) {
834 curr_size
= strlen(scr
->workspaces
[i
]->name
);
835 strcpy(pos
, scr
->workspaces
[i
]->name
);
836 pos
+= (curr_size
+ 1);
837 len
+= (curr_size
+ 1);
840 XChangeProperty(dpy
, scr
->root_win
, net_desktop_names
, utf8_string
, 8,
841 PropModeReplace
, (unsigned char *)buf
, len
);
844 static void updateFocusHint(WScreen
*scr
)
848 if (!scr
->focused_window
|| !scr
->focused_window
->flags
.focused
)
851 window
= scr
->focused_window
->client_win
;
853 XChangeProperty(dpy
, scr
->root_win
, net_active_window
, XA_WINDOW
, 32,
854 PropModeReplace
, (unsigned char *)&window
, 1);
857 static void updateWorkspaceHint(WWindow
*wwin
, Bool fake
, Bool del
)
862 XDeleteProperty(dpy
, wwin
->client_win
, net_wm_desktop
);
864 l
= ((fake
|| IS_OMNIPRESENT(wwin
)) ? -1 : wwin
->frame
->workspace
);
865 XChangeProperty(dpy
, wwin
->client_win
, net_wm_desktop
, XA_CARDINAL
,
866 32, PropModeReplace
, (unsigned char *)&l
, 1);
870 static void updateStateHint(WWindow
*wwin
, Bool changedWorkspace
, Bool del
)
873 XDeleteProperty(dpy
, wwin
->client_win
, net_wm_state
);
875 Atom state
[15]; /* nr of defined state atoms */
878 if (changedWorkspace
|| (wPreferences
.sticky_icons
&& !IS_OMNIPRESENT(wwin
)))
879 updateWorkspaceHint(wwin
, False
, False
);
881 if (IS_OMNIPRESENT(wwin
))
882 state
[i
++] = net_wm_state_sticky
;
883 if (wwin
->flags
.shaded
)
884 state
[i
++] = net_wm_state_shaded
;
885 if (wwin
->flags
.maximized
& MAX_HORIZONTAL
)
886 state
[i
++] = net_wm_state_maximized_horz
;
887 if (wwin
->flags
.maximized
& MAX_VERTICAL
)
888 state
[i
++] = net_wm_state_maximized_vert
;
889 if (WFLAGP(wwin
, skip_window_list
))
890 state
[i
++] = net_wm_state_skip_taskbar
;
891 if (wwin
->flags
.net_skip_pager
)
892 state
[i
++] = net_wm_state_skip_pager
;
893 if ((wwin
->flags
.hidden
|| wwin
->flags
.miniaturized
) && !wwin
->flags
.net_show_desktop
) {
894 state
[i
++] = net_wm_state_hidden
;
895 state
[i
++] = net_wm_state_skip_pager
;
897 if (wwin
->flags
.miniaturized
&& wPreferences
.sticky_icons
) {
898 if (!IS_OMNIPRESENT(wwin
))
899 updateWorkspaceHint(wwin
, True
, False
);
900 state
[i
++] = net_wm_state_sticky
;
903 if (WFLAGP(wwin
, sunken
))
904 state
[i
++] = net_wm_state_below
;
905 if (WFLAGP(wwin
, floating
))
906 state
[i
++] = net_wm_state_above
;
907 if (wwin
->flags
.fullscreen
)
908 state
[i
++] = net_wm_state_fullscreen
;
910 XChangeProperty(dpy
, wwin
->client_win
, net_wm_state
, XA_ATOM
, 32,
911 PropModeReplace
, (unsigned char *)state
, i
);
915 static Bool
updateStrut(WScreen
*scr
, Window w
, Bool adding
)
918 Bool hasState
= False
;
923 unsigned long nitems_ret
, bytes_after_ret
;
926 if ((XGetWindowProperty(dpy
, w
, net_wm_strut
, 0, 4, False
,
927 XA_CARDINAL
, &type_ret
, &fmt_ret
, &nitems_ret
,
928 &bytes_after_ret
, (unsigned char **)&data
) == Success
&& data
) ||
929 ((XGetWindowProperty(dpy
, w
, net_wm_strut_partial
, 0, 12, False
,
930 XA_CARDINAL
, &type_ret
, &fmt_ret
, &nitems_ret
,
931 &bytes_after_ret
, (unsigned char **)&data
) == Success
&& data
))) {
933 /* XXX: This is strictly incorrect in the case of net_wm_strut_partial...
934 * Discard the start and end properties from the partial strut and treat it as
935 * a (deprecated) strut.
936 * This means we are marking the whole width or height of the screen as
937 * reserved, which is not necessarily what the strut defines. However for the
938 * purposes of determining placement or maximization it's probably good enough.
940 area
= (WReservedArea
*) wmalloc(sizeof(WReservedArea
));
941 area
->area
.x1
= data
[0];
942 area
->area
.x2
= data
[1];
943 area
->area
.y1
= data
[2];
944 area
->area
.y2
= data
[3];
948 area
->next
= scr
->netdata
->strut
;
949 scr
->netdata
->strut
= area
;
956 area
= scr
->netdata
->strut
;
959 if (area
->window
== w
) {
960 scr
->netdata
->strut
= area
->next
;
964 while (area
->next
&& area
->next
->window
!= w
)
970 next
= area
->next
->next
;
983 static int getWindowLayer(WWindow
*wwin
)
985 int layer
= WMNormalLevel
;
987 if (wwin
->type
== net_wm_window_type_desktop
) {
988 layer
= WMDesktopLevel
;
989 } else if (wwin
->type
== net_wm_window_type_dock
) {
991 } else if (wwin
->type
== net_wm_window_type_toolbar
) {
992 layer
= WMMainMenuLevel
;
993 } else if (wwin
->type
== net_wm_window_type_menu
) {
994 layer
= WMSubmenuLevel
;
995 } else if (wwin
->type
== net_wm_window_type_utility
) {
996 } else if (wwin
->type
== net_wm_window_type_splash
) {
997 } else if (wwin
->type
== net_wm_window_type_dialog
) {
998 if (wwin
->transient_for
) {
999 WWindow
*parent
= wWindowFor(wwin
->transient_for
);
1000 if (parent
&& parent
->flags
.fullscreen
)
1001 layer
= WMNormalLevel
;
1003 /* //layer = WMPopUpLevel; // this seems a bad idea -Dan */
1004 } else if (wwin
->type
== net_wm_window_type_dropdown_menu
) {
1005 layer
= WMSubmenuLevel
;
1006 } else if (wwin
->type
== net_wm_window_type_popup_menu
) {
1007 layer
= WMSubmenuLevel
;
1008 } else if (wwin
->type
== net_wm_window_type_tooltip
) {
1009 } else if (wwin
->type
== net_wm_window_type_notification
) {
1010 layer
= WMPopUpLevel
;
1011 } else if (wwin
->type
== net_wm_window_type_combo
) {
1012 layer
= WMSubmenuLevel
;
1013 } else if (wwin
->type
== net_wm_window_type_dnd
) {
1014 } else if (wwin
->type
== net_wm_window_type_normal
) {
1017 if (wwin
->client_flags
.sunken
&& WMSunkenLevel
< layer
)
1018 layer
= WMSunkenLevel
;
1019 if (wwin
->client_flags
.floating
&& WMFloatingLevel
> layer
)
1020 layer
= WMFloatingLevel
;
1025 static void doStateAtom(WWindow
*wwin
, Atom state
, int set
, Bool init
)
1027 if (state
== net_wm_state_sticky
) {
1028 if (set
== _NET_WM_STATE_TOGGLE
)
1029 set
= !IS_OMNIPRESENT(wwin
);
1031 if (set
!= wwin
->flags
.omnipresent
)
1032 wWindowSetOmnipresent(wwin
, set
);
1034 } else if (state
== net_wm_state_shaded
) {
1035 if (set
== _NET_WM_STATE_TOGGLE
)
1036 set
= !wwin
->flags
.shaded
;
1039 wwin
->flags
.shaded
= set
;
1044 wUnshadeWindow(wwin
);
1046 } else if (state
== net_wm_state_skip_taskbar
) {
1047 if (set
== _NET_WM_STATE_TOGGLE
)
1048 set
= !wwin
->client_flags
.skip_window_list
;
1050 wwin
->client_flags
.skip_window_list
= set
;
1051 } else if (state
== net_wm_state_skip_pager
) {
1052 if (set
== _NET_WM_STATE_TOGGLE
)
1053 set
= !wwin
->flags
.net_skip_pager
;
1055 wwin
->flags
.net_skip_pager
= set
;
1056 } else if (state
== net_wm_state_maximized_vert
) {
1057 if (set
== _NET_WM_STATE_TOGGLE
)
1058 set
= !(wwin
->flags
.maximized
& MAX_VERTICAL
);
1061 wwin
->flags
.maximized
|= (set
? MAX_VERTICAL
: 0);
1064 wMaximizeWindow(wwin
, wwin
->flags
.maximized
| MAX_VERTICAL
);
1066 wMaximizeWindow(wwin
, wwin
->flags
.maximized
& ~MAX_VERTICAL
);
1068 } else if (state
== net_wm_state_maximized_horz
) {
1069 if (set
== _NET_WM_STATE_TOGGLE
)
1070 set
= !(wwin
->flags
.maximized
& MAX_HORIZONTAL
);
1073 wwin
->flags
.maximized
|= (set
? MAX_HORIZONTAL
: 0);
1076 wMaximizeWindow(wwin
, wwin
->flags
.maximized
| MAX_HORIZONTAL
);
1078 wMaximizeWindow(wwin
, wwin
->flags
.maximized
& ~MAX_HORIZONTAL
);
1080 } else if (state
== net_wm_state_hidden
) {
1081 if (set
== _NET_WM_STATE_TOGGLE
)
1082 set
= !(wwin
->flags
.miniaturized
);
1085 wwin
->flags
.miniaturized
= set
;
1088 wIconifyWindow(wwin
);
1090 wDeiconifyWindow(wwin
);
1092 } else if (state
== net_wm_state_fullscreen
) {
1093 if (set
== _NET_WM_STATE_TOGGLE
)
1094 set
= !(wwin
->flags
.fullscreen
);
1097 wwin
->flags
.fullscreen
= set
;
1100 wFullscreenWindow(wwin
);
1102 wUnfullscreenWindow(wwin
);
1104 } else if (state
== net_wm_state_above
) {
1105 if (set
== _NET_WM_STATE_TOGGLE
)
1106 set
= !(wwin
->client_flags
.floating
);
1109 wwin
->client_flags
.floating
= set
;
1111 wwin
->client_flags
.floating
= set
;
1112 ChangeStackingLevel(wwin
->frame
->core
, getWindowLayer(wwin
));
1115 } else if (state
== net_wm_state_below
) {
1116 if (set
== _NET_WM_STATE_TOGGLE
)
1117 set
= !(wwin
->client_flags
.sunken
);
1120 wwin
->client_flags
.sunken
= set
;
1122 wwin
->client_flags
.sunken
= set
;
1123 ChangeStackingLevel(wwin
->frame
->core
, getWindowLayer(wwin
));
1128 wmessage("doStateAtom unknown atom %s set %d", XGetAtomName(dpy
, state
), set
);
1133 static void removeIcon(WWindow
*wwin
)
1135 if (wwin
->icon
== NULL
)
1137 if (wwin
->flags
.miniaturized
&& wwin
->icon
->mapped
) {
1138 XUnmapWindow(dpy
, wwin
->icon
->core
->window
);
1139 RemoveFromStackList(wwin
->icon
->core
);
1140 wIconDestroy(wwin
->icon
);
1145 static Bool
handleWindowType(WWindow
*wwin
, Atom type
, int *layer
)
1149 if (type
== net_wm_window_type_desktop
) {
1150 wwin
->client_flags
.no_titlebar
= 1;
1151 wwin
->client_flags
.no_resizable
= 1;
1152 wwin
->client_flags
.no_miniaturizable
= 1;
1153 wwin
->client_flags
.no_border
= 1;
1154 wwin
->client_flags
.no_resizebar
= 1;
1155 wwin
->client_flags
.no_shadeable
= 1;
1156 wwin
->client_flags
.no_movable
= 1;
1157 wwin
->client_flags
.omnipresent
= 1;
1158 wwin
->client_flags
.skip_window_list
= 1;
1159 wwin
->client_flags
.skip_switchpanel
= 1;
1160 wwin
->client_flags
.dont_move_off
= 1;
1161 wwin
->client_flags
.no_appicon
= 1;
1162 wwin
->flags
.net_skip_pager
= 1;
1165 } else if (type
== net_wm_window_type_dock
) {
1166 wwin
->client_flags
.no_titlebar
= 1;
1167 wwin
->client_flags
.no_resizable
= 1;
1168 wwin
->client_flags
.no_miniaturizable
= 1;
1169 wwin
->client_flags
.no_border
= 1; /* XXX: really not a single decoration. */
1170 wwin
->client_flags
.no_resizebar
= 1;
1171 wwin
->client_flags
.no_shadeable
= 1;
1172 wwin
->client_flags
.no_movable
= 1;
1173 wwin
->client_flags
.omnipresent
= 1;
1174 wwin
->client_flags
.skip_window_list
= 1;
1175 wwin
->client_flags
.skip_switchpanel
= 1;
1176 wwin
->client_flags
.dont_move_off
= 1;
1177 wwin
->flags
.net_skip_pager
= 1;
1178 } else if (type
== net_wm_window_type_toolbar
||
1179 type
== net_wm_window_type_menu
) {
1180 wwin
->client_flags
.no_resizable
= 1;
1181 wwin
->client_flags
.no_miniaturizable
= 1;
1182 wwin
->client_flags
.no_resizebar
= 1;
1183 wwin
->client_flags
.no_shadeable
= 1;
1184 wwin
->client_flags
.skip_window_list
= 1;
1185 wwin
->client_flags
.skip_switchpanel
= 1;
1186 wwin
->client_flags
.dont_move_off
= 1;
1187 wwin
->client_flags
.no_appicon
= 1;
1188 } else if (type
== net_wm_window_type_dropdown_menu
||
1189 type
== net_wm_window_type_popup_menu
||
1190 type
== net_wm_window_type_combo
) {
1191 wwin
->client_flags
.no_titlebar
= 1;
1192 wwin
->client_flags
.no_resizable
= 1;
1193 wwin
->client_flags
.no_miniaturizable
= 1;
1194 wwin
->client_flags
.no_resizebar
= 1;
1195 wwin
->client_flags
.no_shadeable
= 1;
1196 wwin
->client_flags
.skip_window_list
= 1;
1197 wwin
->client_flags
.skip_switchpanel
= 1;
1198 wwin
->client_flags
.dont_move_off
= 1;
1199 wwin
->client_flags
.no_appicon
= 1;
1200 } else if (type
== net_wm_window_type_utility
) {
1201 wwin
->client_flags
.no_appicon
= 1;
1202 } else if (type
== net_wm_window_type_splash
) {
1203 wwin
->client_flags
.no_titlebar
= 1;
1204 wwin
->client_flags
.no_resizable
= 1;
1205 wwin
->client_flags
.no_miniaturizable
= 1;
1206 wwin
->client_flags
.no_resizebar
= 1;
1207 wwin
->client_flags
.no_shadeable
= 1;
1208 wwin
->client_flags
.no_movable
= 1;
1209 wwin
->client_flags
.skip_window_list
= 1;
1210 wwin
->client_flags
.skip_switchpanel
= 1;
1211 wwin
->client_flags
.dont_move_off
= 1;
1212 wwin
->client_flags
.no_appicon
= 1;
1213 wwin
->flags
.net_skip_pager
= 1;
1214 } else if (type
== net_wm_window_type_dialog
) {
1215 /* These also seem a bad idea in our context -Dan
1216 // wwin->client_flags.skip_window_list = 1;
1217 // wwin->client_flags.no_appicon = 1;
1219 } else if (wwin
->type
== net_wm_window_type_tooltip
) {
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
->client_flags
.no_focusable
= 1;
1231 wwin
->flags
.net_skip_pager
= 1;
1232 } else if (wwin
->type
== net_wm_window_type_notification
) {
1233 wwin
->client_flags
.no_titlebar
= 1;
1234 wwin
->client_flags
.no_resizable
= 1;
1235 wwin
->client_flags
.no_miniaturizable
= 1;
1236 wwin
->client_flags
.no_border
= 1;
1237 wwin
->client_flags
.no_resizebar
= 1;
1238 wwin
->client_flags
.no_shadeable
= 1;
1239 wwin
->client_flags
.no_movable
= 1;
1240 wwin
->client_flags
.omnipresent
= 1;
1241 wwin
->client_flags
.skip_window_list
= 1;
1242 wwin
->client_flags
.skip_switchpanel
= 1;
1243 wwin
->client_flags
.dont_move_off
= 1;
1244 wwin
->client_flags
.no_hide_others
= 1;
1245 wwin
->client_flags
.no_appicon
= 1;
1246 wwin
->client_flags
.no_focusable
= 1;
1247 wwin
->flags
.net_skip_pager
= 1;
1248 } else if (wwin
->type
== net_wm_window_type_dnd
) {
1249 wwin
->client_flags
.no_titlebar
= 1;
1250 wwin
->client_flags
.no_resizable
= 1;
1251 wwin
->client_flags
.no_miniaturizable
= 1;
1252 wwin
->client_flags
.no_border
= 1;
1253 wwin
->client_flags
.no_resizebar
= 1;
1254 wwin
->client_flags
.no_shadeable
= 1;
1255 wwin
->client_flags
.no_movable
= 1;
1256 wwin
->client_flags
.skip_window_list
= 1;
1257 wwin
->client_flags
.skip_switchpanel
= 1;
1258 wwin
->client_flags
.dont_move_off
= 1;
1259 wwin
->client_flags
.no_appicon
= 1;
1260 wwin
->flags
.net_skip_pager
= 1;
1261 } else if (type
== net_wm_window_type_normal
) {
1267 *layer
= getWindowLayer(wwin
);
1272 void wNETWMPositionSplash(WWindow
*wwin
, int *x
, int *y
, int width
, int height
)
1274 if (wwin
->type
== net_wm_window_type_splash
) {
1275 WScreen
*scr
= wwin
->screen_ptr
;
1276 WMRect rect
= wGetRectForHead(scr
, wGetHeadForPointerLocation(scr
));
1277 *x
= rect
.pos
.x
+ (rect
.size
.width
- width
) / 2;
1278 *y
= rect
.pos
.y
+ (rect
.size
.height
- height
) / 2;
1282 static void updateWindowType(WWindow
*wwin
)
1286 unsigned long nitems_ret
, bytes_after_ret
;
1289 if (XGetWindowProperty(dpy
, wwin
->client_win
, net_wm_window_type
, 0, 1,
1290 False
, XA_ATOM
, &type_ret
, &fmt_ret
, &nitems_ret
,
1291 &bytes_after_ret
, (unsigned char **)&data
) == Success
&& data
) {
1294 Atom
*type
= (Atom
*) data
;
1295 for (i
= 0; i
< nitems_ret
; ++i
) {
1296 if (handleWindowType(wwin
, type
[i
], &layer
))
1302 if (wwin
->frame
!= NULL
) {
1303 ChangeStackingLevel(wwin
->frame
->core
, layer
);
1304 wwin
->frame
->flags
.need_texture_change
= 1;
1305 wWindowConfigureBorders(wwin
);
1306 wFrameWindowPaint(wwin
->frame
);
1307 wNETWMUpdateActions(wwin
, False
);
1311 void wNETWMCheckClientHints(WWindow
*wwin
, int *layer
, int *workspace
)
1315 unsigned long nitems_ret
, bytes_after_ret
;
1318 if (XGetWindowProperty(dpy
, wwin
->client_win
, net_wm_desktop
, 0, 1, False
,
1319 XA_CARDINAL
, &type_ret
, &fmt_ret
, &nitems_ret
,
1320 &bytes_after_ret
, (unsigned char **)&data
) == Success
&& data
) {
1322 long desktop
= *data
;
1326 wwin
->client_flags
.omnipresent
= 1;
1328 *workspace
= desktop
;
1331 if (XGetWindowProperty(dpy
, wwin
->client_win
, net_wm_state
, 0, 1, False
,
1332 XA_ATOM
, &type_ret
, &fmt_ret
, &nitems_ret
,
1333 &bytes_after_ret
, (unsigned char **)&data
) == Success
&& data
) {
1335 Atom
*state
= (Atom
*) data
;
1336 for (i
= 0; i
< nitems_ret
; ++i
)
1337 doStateAtom(wwin
, state
[i
], _NET_WM_STATE_ADD
, True
);
1342 if (XGetWindowProperty(dpy
, wwin
->client_win
, net_wm_window_type
, 0, 1, False
,
1343 XA_ATOM
, &type_ret
, &fmt_ret
, &nitems_ret
,
1344 &bytes_after_ret
, (unsigned char **)&data
) == Success
&& data
) {
1346 Atom
*type
= (Atom
*) data
;
1347 for (i
= 0; i
< nitems_ret
; ++i
) {
1348 if (handleWindowType(wwin
, type
[i
], layer
))
1354 wNETWMUpdateActions(wwin
, False
);
1355 updateStrut(wwin
->screen_ptr
, wwin
->client_win
, False
);
1356 updateStrut(wwin
->screen_ptr
, wwin
->client_win
, True
);
1358 wScreenUpdateUsableArea(wwin
->screen_ptr
);
1361 static Bool
updateNetIconInfo(WWindow
*wwin
)
1365 unsigned long nitems_ret
, bytes_after_ret
;
1367 Bool hasState
= False
;
1368 Bool old_state
= wwin
->flags
.net_handle_icon
;
1370 if (XGetWindowProperty(dpy
, wwin
->client_win
, net_wm_handled_icons
, 0, 1, False
,
1371 XA_CARDINAL
, &type_ret
, &fmt_ret
, &nitems_ret
,
1372 &bytes_after_ret
, (unsigned char **)&data
) == Success
&& data
) {
1373 long handled
= *data
;
1374 wwin
->flags
.net_handle_icon
= (handled
!= 0);
1379 wwin
->flags
.net_handle_icon
= False
;
1382 if (XGetWindowProperty(dpy
, wwin
->client_win
, net_wm_icon_geometry
, 0, 4, False
,
1383 XA_CARDINAL
, &type_ret
, &fmt_ret
, &nitems_ret
,
1384 &bytes_after_ret
, (unsigned char **)&data
) == Success
&& data
) {
1387 if (wwin
->flags
.net_handle_icon
)
1389 wwin
->flags
.net_handle_icon
= True
;
1392 wwin
->icon_x
= data
[0];
1393 wwin
->icon_y
= data
[1];
1394 wwin
->icon_w
= data
[2];
1395 wwin
->icon_h
= data
[3];
1402 wwin
->flags
.net_handle_icon
= False
;
1405 if (wwin
->flags
.miniaturized
&& old_state
!= wwin
->flags
.net_handle_icon
) {
1406 if (wwin
->flags
.net_handle_icon
) {
1409 wwin
->flags
.miniaturized
= False
;
1410 wwin
->flags
.skip_next_animation
= True
;
1411 wIconifyWindow(wwin
);
1418 void wNETWMCheckInitialClientState(WWindow
*wwin
)
1421 wmessage("wNETWMCheckInitialClientState");
1424 wNETWMShowingDesktop(wwin
->screen_ptr
, False
);
1426 updateWindowType(wwin
);
1427 updateNetIconInfo(wwin
);
1428 updateIconImage(wwin
);
1431 void wNETWMCheckInitialFrameState(WWindow
*wwin
)
1434 wmessage("wNETWMCheckInitialFrameState");
1437 updateWindowOpacity(wwin
);
1440 static void handleDesktopNames(WScreen
*scr
)
1442 unsigned long nitems_ret
, bytes_after_ret
;
1443 char *data
, *names
[32];
1447 if (XGetWindowProperty(dpy
, scr
->root_win
, net_desktop_names
, 0, 1, False
,
1448 utf8_string
, &type_ret
, &fmt_ret
, &nitems_ret
,
1449 &bytes_after_ret
, (unsigned char **)&data
) != Success
)
1455 if (type_ret
!= utf8_string
|| fmt_ret
!= 8)
1460 for (i
= 0; i
< nitems_ret
; i
++) {
1463 names
[n
] = &data
[i
];
1464 } else if (*names
[n
] == 0) {
1465 names
[n
] = &data
[i
];
1466 wWorkspaceRename(scr
, n
, names
[n
]);
1471 Bool
wNETWMProcessClientMessage(XClientMessageEvent
*event
)
1478 wmessage("processClientMessage type %s", XGetAtomName(dpy
, event
->message_type
));
1481 scr
= wScreenForWindow(event
->window
);
1483 /* generic client messages */
1484 if (event
->message_type
== net_current_desktop
) {
1485 wWorkspaceChange(scr
, event
->data
.l
[0]);
1486 } else if (event
->message_type
== net_number_of_desktops
) {
1489 value
= event
->data
.l
[0];
1490 if (value
> scr
->workspace_count
) {
1491 wWorkspaceMake(scr
, value
- scr
->workspace_count
);
1492 } else if (value
< scr
->workspace_count
) {
1494 Bool rebuild
= False
;
1496 for (i
= scr
->workspace_count
- 1; i
>= value
; i
--) {
1497 if (!wWorkspaceDelete(scr
, i
)) {
1504 updateWorkspaceCount(scr
);
1506 } else if (event
->message_type
== net_showing_desktop
) {
1507 wNETWMShowingDesktop(scr
, event
->data
.l
[0]);
1508 } else if (event
->message_type
== net_desktop_names
) {
1509 handleDesktopNames(scr
);
1518 /* window specific client messages */
1520 wwin
= wWindowFor(event
->window
);
1524 if (event
->message_type
== net_active_window
) {
1526 * Satisfy a client's focus request only if
1527 * - request comes from a pager, or
1528 * - it's explicitly allowed in Advanced Options, or
1529 * - giving the client the focus does not cause a change in
1530 * the active workspace (XXX: or the active head if Xinerama)
1532 if (wwin
->frame
->workspace
== wwin
->screen_ptr
->current_workspace
/* No workspace change */
1533 || event
->data
.l
[0] == 2 /* Requested by pager */
1534 || WFLAGP(wwin
, focus_across_wksp
) /* Explicitly allowed */) {
1535 wNETWMShowingDesktop(scr
, False
);
1536 wMakeWindowVisible(wwin
);
1538 } else if (event
->message_type
== net_close_window
) {
1539 if (!WFLAGP(wwin
, no_closable
)) {
1540 if (wwin
->protocols
.DELETE_WINDOW
)
1541 wClientSendProtocol(wwin
, w_global
.atom
.wm
.delete_window
,
1542 w_global
.timestamp
.last_event
);
1544 } else if (event
->message_type
== net_wm_state
) {
1545 int maximized
= wwin
->flags
.maximized
;
1546 long set
= event
->data
.l
[0];
1549 wmessage("net_wm_state set %ld a1 %s a2 %s", set
,
1550 XGetAtomName(dpy
, event
->data
.l
[1]), XGetAtomName(dpy
, event
->data
.l
[2]));
1553 doStateAtom(wwin
, (Atom
) event
->data
.l
[1], set
, False
);
1554 if (event
->data
.l
[2])
1555 doStateAtom(wwin
, (Atom
) event
->data
.l
[2], set
, False
);
1557 if (wwin
->flags
.maximized
!= maximized
) {
1558 if (!wwin
->flags
.maximized
) {
1559 wwin
->flags
.maximized
= maximized
;
1560 wUnmaximizeWindow(wwin
);
1562 wMaximizeWindow(wwin
, wwin
->flags
.maximized
);
1565 updateStateHint(wwin
, False
, False
);
1566 } else if (event
->message_type
== net_wm_handled_icons
|| event
->message_type
== net_wm_icon_geometry
) {
1567 updateNetIconInfo(wwin
);
1568 } else if (event
->message_type
== net_wm_desktop
) {
1569 long desktop
= event
->data
.l
[0];
1570 if (desktop
== -1) {
1571 wWindowSetOmnipresent(wwin
, True
);
1573 if (IS_OMNIPRESENT(wwin
))
1574 wWindowSetOmnipresent(wwin
, False
);
1575 wWindowChangeWorkspace(wwin
, desktop
);
1584 void wNETWMCheckClientHintChange(WWindow
*wwin
, XPropertyEvent
*event
)
1587 wmessage("clientHintChange type %s", XGetAtomName(dpy
, event
->atom
));
1590 if (event
->atom
== net_wm_strut
|| event
->atom
== net_wm_strut_partial
) {
1591 updateStrut(wwin
->screen_ptr
, wwin
->client_win
, False
);
1592 updateStrut(wwin
->screen_ptr
, wwin
->client_win
, True
);
1593 wScreenUpdateUsableArea(wwin
->screen_ptr
);
1594 } else if (event
->atom
== net_wm_handled_icons
|| event
->atom
== net_wm_icon_geometry
) {
1595 updateNetIconInfo(wwin
);
1596 } else if (event
->atom
== net_wm_window_type
) {
1597 updateWindowType(wwin
);
1598 } else if (event
->atom
== net_wm_name
) {
1599 char *name
= wNETWMGetWindowName(wwin
->client_win
);
1600 wWindowUpdateName(wwin
, name
);
1603 } else if (event
->atom
== net_wm_icon_name
) {
1605 wIconChangeTitle(wwin
->icon
, wwin
);
1606 wIconPaint(wwin
->icon
);
1608 } else if (event
->atom
== net_wm_icon
) {
1609 updateIconImage(wwin
);
1610 } else if (event
->atom
== net_wm_window_opacity
) {
1611 updateWindowOpacity(wwin
);
1615 int wNETWMGetPidForWindow(Window window
)
1619 unsigned long nitems_ret
, bytes_after_ret
;
1623 if (XGetWindowProperty(dpy
, window
, net_wm_pid
, 0, 1, False
,
1624 XA_CARDINAL
, &type_ret
, &fmt_ret
, &nitems_ret
,
1625 &bytes_after_ret
, (unsigned char **)&data
) == Success
&& data
) {
1635 char *wNETWMGetWindowName(Window window
)
1641 name
= (char *)PropGetCheckProperty(window
, net_wm_name
, utf8_string
, 0, 0, &size
);
1643 ret
= wstrndup(name
, size
);
1652 char *wNETWMGetIconName(Window window
)
1658 name
= (char *)PropGetCheckProperty(window
, net_wm_icon_name
, utf8_string
, 0, 0, &size
);
1660 ret
= wstrndup(name
, size
);
1669 static void observer(void *self
, WMNotification
*notif
)
1671 WWindow
*wwin
= (WWindow
*) WMGetNotificationObject(notif
);
1672 const char *name
= WMGetNotificationName(notif
);
1673 void *data
= WMGetNotificationClientData(notif
);
1674 NetData
*ndata
= (NetData
*) self
;
1676 if (strcmp(name
, WMNManaged
) == 0 && wwin
) {
1677 updateClientList(wwin
->screen_ptr
);
1678 updateClientListStacking(wwin
->screen_ptr
, NULL
);
1679 updateStateHint(wwin
, True
, False
);
1681 updateStrut(wwin
->screen_ptr
, wwin
->client_win
, False
);
1682 updateStrut(wwin
->screen_ptr
, wwin
->client_win
, True
);
1683 wScreenUpdateUsableArea(wwin
->screen_ptr
);
1684 } else if (strcmp(name
, WMNUnmanaged
) == 0 && wwin
) {
1685 updateClientList(wwin
->screen_ptr
);
1686 updateClientListStacking(wwin
->screen_ptr
, wwin
);
1687 updateWorkspaceHint(wwin
, False
, True
);
1688 updateStateHint(wwin
, False
, True
);
1689 wNETWMUpdateActions(wwin
, True
);
1691 updateStrut(wwin
->screen_ptr
, wwin
->client_win
, False
);
1692 wScreenUpdateUsableArea(wwin
->screen_ptr
);
1693 } else if (strcmp(name
, WMNResetStacking
) == 0 && wwin
) {
1694 updateClientListStacking(wwin
->screen_ptr
, NULL
);
1695 updateStateHint(wwin
, False
, False
);
1696 } else if (strcmp(name
, WMNChangedStacking
) == 0 && wwin
) {
1697 updateClientListStacking(wwin
->screen_ptr
, NULL
);
1698 updateStateHint(wwin
, False
, False
);
1699 } else if (strcmp(name
, WMNChangedFocus
) == 0) {
1700 updateFocusHint(ndata
->scr
);
1701 } else if (strcmp(name
, WMNChangedWorkspace
) == 0 && wwin
) {
1702 updateWorkspaceHint(wwin
, False
, False
);
1703 updateStateHint(wwin
, True
, False
);
1704 } else if (strcmp(name
, WMNChangedState
) == 0 && wwin
) {
1705 updateStateHint(wwin
, !strcmp(data
, "omnipresent"), False
);
1709 static void wsobserver(void *self
, WMNotification
*notif
)
1711 WScreen
*scr
= (WScreen
*) WMGetNotificationObject(notif
);
1712 const char *name
= WMGetNotificationName(notif
);
1714 /* Parameter not used, but tell the compiler that it is ok */
1717 if (strcmp(name
, WMNWorkspaceCreated
) == 0) {
1718 updateWorkspaceCount(scr
);
1719 updateWorkspaceNames(scr
);
1720 wNETWMUpdateWorkarea(scr
);
1721 } else if (strcmp(name
, WMNWorkspaceDestroyed
) == 0) {
1722 updateWorkspaceCount(scr
);
1723 updateWorkspaceNames(scr
);
1724 wNETWMUpdateWorkarea(scr
);
1725 } else if (strcmp(name
, WMNWorkspaceChanged
) == 0) {
1726 updateCurrentWorkspace(scr
);
1727 } else if (strcmp(name
, WMNWorkspaceNameChanged
) == 0) {
1728 updateWorkspaceNames(scr
);
1732 void wNETFrameExtents(WWindow
*wwin
)
1734 long extents
[4] = { 0, 0, 0, 0 };
1736 /* The extents array describes dimensions which are not
1737 * part of the client window. In our case that means
1738 * widths of the border and heights of the titlebar and resizebar.
1745 if (wwin
->frame
->titlebar
)
1746 extents
[2] = wwin
->frame
->titlebar
->height
;
1747 if (wwin
->frame
->resizebar
)
1748 extents
[3] = wwin
->frame
->resizebar
->height
;
1749 if (HAS_BORDER(wwin
)) {
1750 extents
[0] += wwin
->screen_ptr
->frame_border_width
;
1751 extents
[1] += wwin
->screen_ptr
->frame_border_width
;
1752 extents
[2] += wwin
->screen_ptr
->frame_border_width
;
1753 extents
[3] += wwin
->screen_ptr
->frame_border_width
;
1756 XChangeProperty(dpy
, wwin
->client_win
, net_frame_extents
, XA_CARDINAL
, 32, PropModeReplace
, (unsigned char *) extents
, 4);
1759 void wNETCleanupFrameExtents(WWindow
*wwin
)
1761 XDeleteProperty(dpy
, wwin
->client_win
, net_frame_extents
);