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"
53 /* Global variables */
54 extern Atom _XA_WM_DELETE_WINDOW
;
55 extern Time LastTimestamp
;
56 extern WPreferences wPreferences
;
58 /* Root Window Properties */
59 static Atom net_supported
;
60 static Atom net_client_list
;
61 static Atom net_client_list_stacking
;
62 static Atom net_number_of_desktops
;
63 static Atom net_desktop_geometry
;
64 static Atom net_desktop_viewport
;
65 static Atom net_current_desktop
;
66 static Atom net_desktop_names
;
67 static Atom net_active_window
;
68 static Atom net_supporting_wm_check
;
69 static Atom net_virtual_roots
; /* N/A */
70 static Atom net_desktop_layout
; /* XXX */
71 static Atom net_showing_desktop
;
73 /* Other Root Window Messages */
74 static Atom net_close_window
;
75 static Atom net_moveresize_window
; /* TODO */
76 static Atom net_wm_moveresize
; /* TODO */
78 /* Application Window Properties */
79 static Atom net_wm_name
;
80 static Atom net_wm_visible_name
; /* TODO (unnecessary?) */
81 static Atom net_wm_icon_name
;
82 static Atom net_wm_visible_icon_name
; /* TODO (unnecessary?) */
83 static Atom net_wm_desktop
;
84 static Atom net_wm_window_type
;
85 static Atom net_wm_window_type_desktop
;
86 static Atom net_wm_window_type_dock
;
87 static Atom net_wm_window_type_toolbar
;
88 static Atom net_wm_window_type_menu
;
89 static Atom net_wm_window_type_utility
;
90 static Atom net_wm_window_type_splash
;
91 static Atom net_wm_window_type_dialog
;
92 static Atom net_wm_window_type_normal
;
93 static Atom net_wm_state
;
94 static Atom net_wm_state_modal
; /* XXX: what is this?!? */
95 static Atom net_wm_state_sticky
;
96 static Atom net_wm_state_maximized_vert
;
97 static Atom net_wm_state_maximized_horz
;
98 static Atom net_wm_state_shaded
;
99 static Atom net_wm_state_skip_taskbar
;
100 static Atom net_wm_state_skip_pager
;
101 static Atom net_wm_state_hidden
;
102 static Atom net_wm_state_fullscreen
;
103 static Atom net_wm_state_above
;
104 static Atom net_wm_state_below
;
105 static Atom net_wm_allowed_actions
;
106 static Atom net_wm_action_move
;
107 static Atom net_wm_action_resize
;
108 static Atom net_wm_action_minimize
;
109 static Atom net_wm_action_shade
;
110 static Atom net_wm_action_stick
;
111 static Atom net_wm_action_maximize_horz
;
112 static Atom net_wm_action_maximize_vert
;
113 static Atom net_wm_action_fullscreen
;
114 static Atom net_wm_action_change_desktop
;
115 static Atom net_wm_action_close
;
116 static Atom net_wm_strut
; /* XXX: see net_workarea */
117 static Atom net_wm_strut_partial
; /* TODO: doesn't really fit into the current strut scheme */
118 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. */
119 static Atom net_wm_icon
;
120 static Atom net_wm_pid
; /* TODO */
121 static Atom net_wm_handled_icons
; /* FIXME: see net_wm_icon_geometry */
123 static Atom net_frame_extents
;
125 /* Window Manager Protocols */
126 static Atom net_wm_ping
; /* TODO */
128 static Atom utf8_string
;
135 static atomitem_t atomNames
[] = {
136 {"_NET_SUPPORTED", &net_supported
},
137 {"_NET_CLIENT_LIST", &net_client_list
},
138 {"_NET_CLIENT_LIST_STACKING", &net_client_list_stacking
},
139 {"_NET_NUMBER_OF_DESKTOPS", &net_number_of_desktops
},
140 {"_NET_DESKTOP_GEOMETRY", &net_desktop_geometry
},
141 {"_NET_DESKTOP_VIEWPORT", &net_desktop_viewport
},
142 {"_NET_CURRENT_DESKTOP", &net_current_desktop
},
143 {"_NET_DESKTOP_NAMES", &net_desktop_names
},
144 {"_NET_ACTIVE_WINDOW", &net_active_window
},
145 {"_NET_SUPPORTING_WM_CHECK", &net_supporting_wm_check
},
146 {"_NET_VIRTUAL_ROOTS", &net_virtual_roots
},
147 {"_NET_DESKTOP_LAYOUT", &net_desktop_layout
},
148 {"_NET_SHOWING_DESKTOP", &net_showing_desktop
},
150 {"_NET_CLOSE_WINDOW", &net_close_window
},
151 {"_NET_MOVERESIZE_WINDOW", &net_moveresize_window
},
152 {"_NET_WM_MOVERESIZE", &net_wm_moveresize
},
154 {"_NET_WM_NAME", &net_wm_name
},
155 {"_NET_WM_VISIBLE_NAME", &net_wm_visible_name
},
156 {"_NET_WM_ICON_NAME", &net_wm_icon_name
},
157 {"_NET_WM_VISIBLE_ICON_NAME", &net_wm_visible_icon_name
},
158 {"_NET_WM_DESKTOP", &net_wm_desktop
},
159 {"_NET_WM_WINDOW_TYPE", &net_wm_window_type
},
160 {"_NET_WM_WINDOW_TYPE_DESKTOP", &net_wm_window_type_desktop
},
161 {"_NET_WM_WINDOW_TYPE_DOCK", &net_wm_window_type_dock
},
162 {"_NET_WM_WINDOW_TYPE_TOOLBAR", &net_wm_window_type_toolbar
},
163 {"_NET_WM_WINDOW_TYPE_MENU", &net_wm_window_type_menu
},
164 {"_NET_WM_WINDOW_TYPE_UTILITY", &net_wm_window_type_utility
},
165 {"_NET_WM_WINDOW_TYPE_SPLASH", &net_wm_window_type_splash
},
166 {"_NET_WM_WINDOW_TYPE_DIALOG", &net_wm_window_type_dialog
},
167 {"_NET_WM_WINDOW_TYPE_NORMAL", &net_wm_window_type_normal
},
168 {"_NET_WM_STATE", &net_wm_state
},
169 {"_NET_WM_STATE_MODAL", &net_wm_state_modal
},
170 {"_NET_WM_STATE_STICKY", &net_wm_state_sticky
},
171 {"_NET_WM_STATE_MAXIMIZED_VERT", &net_wm_state_maximized_vert
},
172 {"_NET_WM_STATE_MAXIMIZED_HORZ", &net_wm_state_maximized_horz
},
173 {"_NET_WM_STATE_SHADED", &net_wm_state_shaded
},
174 {"_NET_WM_STATE_SKIP_TASKBAR", &net_wm_state_skip_taskbar
},
175 {"_NET_WM_STATE_SKIP_PAGER", &net_wm_state_skip_pager
},
176 {"_NET_WM_STATE_HIDDEN", &net_wm_state_hidden
},
177 {"_NET_WM_STATE_FULLSCREEN", &net_wm_state_fullscreen
},
178 {"_NET_WM_STATE_ABOVE", &net_wm_state_above
},
179 {"_NET_WM_STATE_BELOW", &net_wm_state_below
},
180 {"_NET_WM_ALLOWED_ACTIONS", &net_wm_allowed_actions
},
181 {"_NET_WM_ACTION_MOVE", &net_wm_action_move
},
182 {"_NET_WM_ACTION_RESIZE", &net_wm_action_resize
},
183 {"_NET_WM_ACTION_MINIMIZE", &net_wm_action_minimize
},
184 {"_NET_WM_ACTION_SHADE", &net_wm_action_shade
},
185 {"_NET_WM_ACTION_STICK", &net_wm_action_stick
},
186 {"_NET_WM_ACTION_MAXIMIZE_HORZ", &net_wm_action_maximize_horz
},
187 {"_NET_WM_ACTION_MAXIMIZE_VERT", &net_wm_action_maximize_vert
},
188 {"_NET_WM_ACTION_FULLSCREEN", &net_wm_action_fullscreen
},
189 {"_NET_WM_ACTION_CHANGE_DESKTOP", &net_wm_action_change_desktop
},
190 {"_NET_WM_ACTION_CLOSE", &net_wm_action_close
},
191 {"_NET_WM_STRUT", &net_wm_strut
},
192 {"_NET_WM_STRUT_PARTIAL", &net_wm_strut_partial
},
193 {"_NET_WM_ICON_GEOMETRY", &net_wm_icon_geometry
},
194 {"_NET_WM_ICON", &net_wm_icon
},
195 {"_NET_WM_PID", &net_wm_pid
},
196 {"_NET_WM_HANDLED_ICONS", &net_wm_handled_icons
},
198 {"_NET_FRAME_EXTENTS", &net_frame_extents
},
200 {"_NET_WM_PING", &net_wm_ping
},
202 {"UTF8_STRING", &utf8_string
},
205 #define atomNr (sizeof(atomNames)/sizeof(atomitem_t))
207 #define _NET_WM_STATE_REMOVE 0
208 #define _NET_WM_STATE_ADD 1
209 #define _NET_WM_STATE_TOGGLE 2
211 #define _NET_WM_MOVERESIZE_SIZE_TOPLEFT 0
212 #define _NET_WM_MOVERESIZE_SIZE_TOP 1
213 #define _NET_WM_MOVERESIZE_SIZE_TOPRIGHT 2
214 #define _NET_WM_MOVERESIZE_SIZE_RIGHT 3
215 #define _NET_WM_MOVERESIZE_SIZE_BOTTOMRIGHT 4
216 #define _NET_WM_MOVERESIZE_SIZE_BOTTOM 5
217 #define _NET_WM_MOVERESIZE_SIZE_BOTTOMLEFT 6
218 #define _NET_WM_MOVERESIZE_SIZE_LEFT 7
219 #define _NET_WM_MOVERESIZE_MOVE 8 /* movement only */
220 #define _NET_WM_MOVERESIZE_SIZE_KEYBOARD 9 /* size via keyboard */
221 #define _NET_WM_MOVERESIZE_MOVE_KEYBOARD 10 /* move via keyboard */
223 static void observer(void *self
, WMNotification
*notif
);
224 static void wsobserver(void *self
, WMNotification
*notif
);
226 static void updateClientList(WScreen
*scr
);
227 static void updateClientListStacking(WScreen
*scr
, WWindow
*);
229 static void updateWorkspaceNames(WScreen
*scr
);
230 static void updateCurrentWorkspace(WScreen
*scr
);
231 static void updateWorkspaceCount(WScreen
*scr
);
232 static void wNETWMShowingDesktop(WScreen
*scr
, Bool show
);
234 typedef struct NetData
{
236 WReservedArea
*strut
;
237 WWindow
**show_desktop
;
240 static void setSupportedHints(WScreen
*scr
)
245 /* set supported hints list */
246 /* XXX: extend this !!! */
248 atom
[i
++] = net_client_list
;
249 atom
[i
++] = net_client_list_stacking
;
250 atom
[i
++] = net_number_of_desktops
;
251 atom
[i
++] = net_desktop_geometry
;
252 atom
[i
++] = net_desktop_viewport
;
253 atom
[i
++] = net_current_desktop
;
254 atom
[i
++] = net_desktop_names
;
255 atom
[i
++] = net_active_window
;
256 atom
[i
++] = net_supporting_wm_check
;
257 atom
[i
++] = net_showing_desktop
;
259 atom
[i
++] = net_wm_moveresize
;
261 atom
[i
++] = net_wm_desktop
;
262 atom
[i
++] = net_wm_window_type
;
263 atom
[i
++] = net_wm_window_type_desktop
;
264 atom
[i
++] = net_wm_window_type_dock
;
265 atom
[i
++] = net_wm_window_type_toolbar
;
266 atom
[i
++] = net_wm_window_type_menu
;
267 atom
[i
++] = net_wm_window_type_utility
;
268 atom
[i
++] = net_wm_window_type_splash
;
269 atom
[i
++] = net_wm_window_type_dialog
;
270 atom
[i
++] = net_wm_window_type_normal
;
272 atom
[i
++] = net_wm_state
;
273 /* atom[i++] = net_wm_state_modal; *//* XXX: not sure where/when to use it. */
274 atom
[i
++] = net_wm_state_sticky
;
275 atom
[i
++] = net_wm_state_shaded
;
276 atom
[i
++] = net_wm_state_maximized_horz
;
277 atom
[i
++] = net_wm_state_maximized_vert
;
278 atom
[i
++] = net_wm_state_skip_taskbar
;
279 atom
[i
++] = net_wm_state_skip_pager
;
280 atom
[i
++] = net_wm_state_hidden
;
281 atom
[i
++] = net_wm_state_fullscreen
;
282 atom
[i
++] = net_wm_state_above
;
283 atom
[i
++] = net_wm_state_below
;
285 atom
[i
++] = net_wm_allowed_actions
;
286 atom
[i
++] = net_wm_action_move
;
287 atom
[i
++] = net_wm_action_resize
;
288 atom
[i
++] = net_wm_action_minimize
;
289 atom
[i
++] = net_wm_action_shade
;
290 atom
[i
++] = net_wm_action_stick
;
291 atom
[i
++] = net_wm_action_maximize_horz
;
292 atom
[i
++] = net_wm_action_maximize_vert
;
293 atom
[i
++] = net_wm_action_fullscreen
;
294 atom
[i
++] = net_wm_action_change_desktop
;
295 atom
[i
++] = net_wm_action_close
;
297 atom
[i
++] = net_wm_strut
;
298 atom
[i
++] = net_wm_icon_geometry
;
299 atom
[i
++] = net_wm_icon
;
300 atom
[i
++] = net_wm_handled_icons
;
302 atom
[i
++] = net_frame_extents
;
304 atom
[i
++] = net_wm_name
;
305 atom
[i
++] = net_wm_icon_name
;
307 XChangeProperty(dpy
, scr
->root_win
, net_supported
, XA_ATOM
, 32, PropModeReplace
, (unsigned char *)atom
, i
);
309 /* set supporting wm hint */
310 XChangeProperty(dpy
, scr
->root_win
, net_supporting_wm_check
, XA_WINDOW
, 32,
311 PropModeReplace
, (unsigned char *)&scr
->info_window
, 1);
313 XChangeProperty(dpy
, scr
->info_window
, net_supporting_wm_check
, XA_WINDOW
,
314 32, PropModeReplace
, (unsigned char *)&scr
->info_window
, 1);
317 void wNETWMUpdateDesktop(WScreen
*scr
)
319 long *views
, sizes
[2];
322 if (scr
->workspace_count
== 0)
325 count
= scr
->workspace_count
* 2;
326 views
= wmalloc(sizeof(long) * count
);
327 /*memset(views, 0, sizeof(long) * count); */
328 sizes
[0] = scr
->scr_width
;
329 sizes
[1] = scr
->scr_height
;
331 for (i
= 0; i
< scr
->workspace_count
; i
++) {
332 views
[2 * i
+ 0] = 0;
333 views
[2 * i
+ 1] = 0;
336 XChangeProperty(dpy
, scr
->root_win
, net_desktop_geometry
, XA_CARDINAL
, 32,
337 PropModeReplace
, (unsigned char *)sizes
, 2);
339 XChangeProperty(dpy
, scr
->root_win
, net_desktop_viewport
, XA_CARDINAL
, 32,
340 PropModeReplace
, (unsigned char *)views
, count
);
345 int wNETWMGetCurrentDesktopFromHint(WScreen
*scr
)
350 prop
= PropGetCheckProperty(scr
->root_win
, net_current_desktop
, XA_CARDINAL
, 0, 1, &count
);
352 int desktop
= *(long *)prop
;
360 * Find the best icon to be used by Window Maker for appicon/miniwindows.
361 * Currently the algorithm is to take the image with the size closest
362 * to icon_size x icon_size, but never bigger than that.
364 * This algorithm is very poorly implemented and needs to be redone (it can
365 * easily select images with very large widths and very small heights over
366 * square images, if the area of the former is closer to the desired one).
368 * The logic can also be changed to accept bigger images and scale them down.
370 static unsigned long *findBestIcon(unsigned long *data
, unsigned long items
)
373 unsigned long i
, distance
;
376 /* better use only 75% of icon_size. For 64x64 this means 48x48
377 * This leaves room around the icon for the miniwindow title and
378 * results in better overall aesthetics -Dan */
379 wanted
= wPreferences
.icon_size
* wPreferences
.icon_size
;
381 for (icon
= NULL
, distance
= wanted
, i
= 0L; i
< items
- 1;) {
382 size
= data
[i
] * data
[i
+ 1];
386 if (d
>= 0 && d
<= distance
&& (i
+ size
+ 2) <= items
) {
396 static RImage
*makeRImageFromARGBData(unsigned long *data
)
398 int size
, width
, height
, i
;
400 unsigned char *imgdata
;
405 size
= width
* height
;
410 image
= RCreateImage(width
, height
, True
);
412 for (imgdata
= image
->data
, i
= 2; i
< size
+ 2; i
++, imgdata
+= 4) {
414 imgdata
[3] = (pixel
>> 24) & 0xff; /* A */
415 imgdata
[0] = (pixel
>> 16) & 0xff; /* R */
416 imgdata
[1] = (pixel
>> 8) & 0xff; /* G */
417 imgdata
[2] = (pixel
>> 0) & 0xff; /* B */
423 RImage
*get_window_image_from_x11(Window window
)
428 unsigned long items
, rest
;
429 unsigned long *property
, *data
;
431 /* Get the icon from X11 Window */
432 if (XGetWindowProperty(dpy
, window
, net_wm_icon
, 0L, LONG_MAX
,
433 False
, XA_CARDINAL
, &type
, &format
, &items
, &rest
,
434 (unsigned char **)&property
) != Success
|| !property
)
437 if (type
!= XA_CARDINAL
|| format
!= 32 || items
< 2) {
442 /* Find the best icon */
443 data
= findBestIcon(property
, items
);
449 /* Save the best icon in the X11 icon */
450 image
= makeRImageFromARGBData(data
);
454 /* Resize the image to the correct value */
455 image
= wIconValidateIconSize(image
, wPreferences
.icon_size
);
460 static void updateIconImage(WWindow
*wwin
)
462 /* Remove the icon image from X11 */
463 if (wwin
->net_icon_image
)
464 RReleaseImage(wwin
->net_icon_image
);
466 /* Save the icon in the X11 icon */
467 wwin
->net_icon_image
= get_window_image_from_x11(wwin
->client_win
);
469 /* Refresh the Window Icon */
471 wIconUpdate(wwin
->icon
);
473 /* Refresh the application icon */
474 WApplication
*app
= wApplicationOf(wwin
->main_window
);
475 if (app
&& app
->app_icon
) {
476 wIconUpdate(app
->app_icon
->icon
);
477 /* Icon was updated in wIconUpdate, so we don't need update it again */
478 wAppIconPaint(app
->app_icon
, False
);
482 static void updateShowDesktop(WScreen
*scr
, Bool show
)
486 foo
= (show
== True
);
487 XChangeProperty(dpy
, scr
->root_win
, net_showing_desktop
, XA_CARDINAL
, 32,
488 PropModeReplace
, (unsigned char *)&foo
, 1);
491 static void wNETWMShowingDesktop(WScreen
*scr
, Bool show
)
493 if (show
&& scr
->netdata
->show_desktop
== NULL
) {
494 WWindow
*tmp
, **wins
;
497 wins
= (WWindow
**) wmalloc(sizeof(WWindow
*) * (scr
->window_count
+ 1));
499 tmp
= scr
->focused_window
;
501 if (!tmp
->flags
.hidden
&& !tmp
->flags
.miniaturized
&& !WFLAGP(tmp
, skip_window_list
)) {
504 tmp
->flags
.skip_next_animation
= 1;
505 tmp
->flags
.net_show_desktop
= 1;
513 scr
->netdata
->show_desktop
= wins
;
514 updateShowDesktop(scr
, True
);
515 } else if (scr
->netdata
->show_desktop
!= NULL
) {
516 /* FIXME: get rid of workspace flashing ! */
517 int ws
= scr
->current_workspace
;
519 for (tmp
= scr
->netdata
->show_desktop
; *tmp
; ++tmp
) {
520 wDeiconifyWindow(*tmp
);
521 (*tmp
)->flags
.net_show_desktop
= 0;
523 if (ws
!= scr
->current_workspace
)
524 wWorkspaceChange(scr
, ws
);
525 wfree(scr
->netdata
->show_desktop
);
526 scr
->netdata
->show_desktop
= NULL
;
527 updateShowDesktop(scr
, False
);
531 void wNETWMInitStuff(WScreen
*scr
)
537 wmessage("wNETWMInitStuff");
540 #ifdef HAVE_XINTERNATOMS
545 for (i
= 0; i
< atomNr
; ++i
)
546 names
[i
] = atomNames
[i
].name
;
548 XInternAtoms(dpy
, &names
[0], atomNr
, False
, atoms
);
549 for (i
= 0; i
< atomNr
; ++i
)
550 *atomNames
[i
].atom
= atoms
[i
];
554 for (i
= 0; i
< atomNr
; i
++)
555 *atomNames
[i
].atom
= XInternAtom(dpy
, atomNames
[i
].name
, False
);
558 data
= wmalloc(sizeof(NetData
));
561 data
->show_desktop
= NULL
;
565 setSupportedHints(scr
);
567 WMAddNotificationObserver(observer
, data
, WMNManaged
, NULL
);
568 WMAddNotificationObserver(observer
, data
, WMNUnmanaged
, NULL
);
569 WMAddNotificationObserver(observer
, data
, WMNChangedWorkspace
, NULL
);
570 WMAddNotificationObserver(observer
, data
, WMNChangedState
, NULL
);
571 WMAddNotificationObserver(observer
, data
, WMNChangedFocus
, NULL
);
572 WMAddNotificationObserver(observer
, data
, WMNChangedStacking
, NULL
);
573 WMAddNotificationObserver(observer
, data
, WMNChangedName
, NULL
);
575 WMAddNotificationObserver(wsobserver
, data
, WMNWorkspaceCreated
, NULL
);
576 WMAddNotificationObserver(wsobserver
, data
, WMNWorkspaceDestroyed
, NULL
);
577 WMAddNotificationObserver(wsobserver
, data
, WMNWorkspaceChanged
, NULL
);
578 WMAddNotificationObserver(wsobserver
, data
, WMNWorkspaceNameChanged
, NULL
);
580 updateClientList(scr
);
581 updateClientListStacking(scr
, NULL
);
582 updateWorkspaceCount(scr
);
583 updateWorkspaceNames(scr
);
584 updateShowDesktop(scr
, False
);
586 wScreenUpdateUsableArea(scr
);
589 void wNETWMCleanup(WScreen
*scr
)
593 for (i
= 0; i
< atomNr
; i
++)
594 XDeleteProperty(dpy
, scr
->root_win
, *atomNames
[i
].atom
);
597 void wNETWMUpdateActions(WWindow
*wwin
, Bool del
)
599 Atom action
[10]; /* nr of actions atoms defined */
603 XDeleteProperty(dpy
, wwin
->client_win
, net_wm_allowed_actions
);
607 if (IS_MOVABLE(wwin
))
608 action
[i
++] = net_wm_action_move
;
610 if (IS_RESIZABLE(wwin
))
611 action
[i
++] = net_wm_action_resize
;
613 if (!WFLAGP(wwin
, no_miniaturizable
))
614 action
[i
++] = net_wm_action_minimize
;
616 if (!WFLAGP(wwin
, no_shadeable
))
617 action
[i
++] = net_wm_action_shade
;
619 /* if (!WFLAGP(wwin, no_stickable)) */
620 action
[i
++] = net_wm_action_stick
;
622 /* if (!(WFLAGP(wwin, no_maximizeable) & MAX_HORIZONTAL)) */
623 if (IS_RESIZABLE(wwin
))
624 action
[i
++] = net_wm_action_maximize_horz
;
626 /* if (!(WFLAGP(wwin, no_maximizeable) & MAX_VERTICAL)) */
627 if (IS_RESIZABLE(wwin
))
628 action
[i
++] = net_wm_action_maximize_vert
;
630 /* if (!WFLAGP(wwin, no_fullscreen)) */
631 action
[i
++] = net_wm_action_fullscreen
;
633 /* if (!WFLAGP(wwin, no_change_desktop)) */
634 action
[i
++] = net_wm_action_change_desktop
;
636 if (!WFLAGP(wwin
, no_closable
))
637 action
[i
++] = net_wm_action_close
;
639 XChangeProperty(dpy
, wwin
->client_win
, net_wm_allowed_actions
,
640 XA_ATOM
, 32, PropModeReplace
, (unsigned char *)action
, i
);
643 Bool
wNETWMGetUsableArea(WScreen
*scr
, int head
, WArea
*area
)
648 if (!scr
->netdata
|| !scr
->netdata
->strut
)
651 area
->x1
= area
->y1
= area
->x2
= area
->y2
= 0;
653 for (cur
= scr
->netdata
->strut
; cur
; cur
= cur
->next
) {
654 WWindow
*wwin
= wWindowFor(cur
->window
);
655 if (wWindowTouchesHead(wwin
, head
)) {
656 if (cur
->area
.x1
> area
->x1
)
657 area
->x1
= cur
->area
.x1
;
658 if (cur
->area
.y1
> area
->y1
)
659 area
->y1
= cur
->area
.y1
;
660 if (cur
->area
.x2
> area
->x2
)
661 area
->x2
= cur
->area
.x2
;
662 if (cur
->area
.y2
> area
->y2
)
663 area
->y2
= cur
->area
.y2
;
667 if (area
->x1
== 0 && area
->x2
== 0 && area
->y1
== 0 && area
->y2
== 0)
670 rect
= wGetRectForHead(scr
, head
);
672 area
->x1
= rect
.pos
.x
+ area
->x1
;
673 area
->x2
= rect
.pos
.x
+ rect
.size
.width
- area
->x2
;
674 area
->y1
= rect
.pos
.y
+ area
->y1
;
675 area
->y2
= rect
.pos
.y
+ rect
.size
.height
- area
->y2
;
680 static void updateClientList(WScreen
*scr
)
686 windows
= (Window
*) wmalloc(sizeof(Window
) * (scr
->window_count
+ 1));
689 wwin
= scr
->focused_window
;
691 windows
[count
++] = wwin
->client_win
;
694 XChangeProperty(dpy
, scr
->root_win
, net_client_list
, XA_WINDOW
, 32,
695 PropModeReplace
, (unsigned char *)windows
, count
);
701 static void updateClientListStacking(WScreen
*scr
, WWindow
*wwin_excl
)
704 Window
*client_list
, *client_list_reverse
;
709 /* update client list */
710 i
= scr
->window_count
+ 1;
711 client_list
= (Window
*) wmalloc(sizeof(Window
) * i
);
712 client_list_reverse
= (Window
*) wmalloc(sizeof(Window
) * i
);
715 WM_ETARETI_BAG(scr
->stacking_list
, tmp
, iter
) {
717 wwin
= wWindowFor(tmp
->window
);
718 /* wwin_excl is a window to exclude from the list
719 (e.g. it's now unmanaged) */
720 if (wwin
&& (wwin
!= wwin_excl
))
721 client_list
[client_count
++] = wwin
->client_win
;
722 tmp
= tmp
->stacking
->under
;
726 for (i
= 0; i
< client_count
; i
++) {
727 Window w
= client_list
[client_count
- i
- 1];
728 client_list_reverse
[i
] = w
;
731 XChangeProperty(dpy
, scr
->root_win
, net_client_list_stacking
, XA_WINDOW
, 32,
732 PropModeReplace
, (unsigned char *)client_list_reverse
, client_count
);
735 wfree(client_list_reverse
);
740 static void updateWorkspaceCount(WScreen
*scr
)
744 count
= scr
->workspace_count
;
746 XChangeProperty(dpy
, scr
->root_win
, net_number_of_desktops
, XA_CARDINAL
,
747 32, PropModeReplace
, (unsigned char *)&count
, 1);
750 static void updateCurrentWorkspace(WScreen
*scr
)
754 count
= scr
->current_workspace
;
756 XChangeProperty(dpy
, scr
->root_win
, net_current_desktop
, XA_CARDINAL
, 32,
757 PropModeReplace
, (unsigned char *)&count
, 1);
760 static void updateWorkspaceNames(WScreen
*scr
)
762 char buf
[MAX_WORKSPACES
* (MAX_WORKSPACENAME_WIDTH
+ 1)], *pos
;
763 unsigned int i
, len
, curr_size
;
767 for (i
= 0; i
< scr
->workspace_count
; i
++) {
768 curr_size
= strlen(scr
->workspaces
[i
]->name
);
769 strcpy(pos
, scr
->workspaces
[i
]->name
);
770 pos
+= (curr_size
+ 1);
771 len
+= (curr_size
+ 1);
774 XChangeProperty(dpy
, scr
->root_win
, net_desktop_names
, utf8_string
, 8,
775 PropModeReplace
, (unsigned char *)buf
, len
);
778 static void updateFocusHint(WScreen
*scr
, WWindow
*wwin
)
782 if (!scr
->focused_window
|| !scr
->focused_window
->flags
.focused
)
785 window
= scr
->focused_window
->client_win
;
787 XChangeProperty(dpy
, scr
->root_win
, net_active_window
, XA_WINDOW
, 32,
788 PropModeReplace
, (unsigned char *)&window
, 1);
791 static void updateWorkspaceHint(WWindow
*wwin
, Bool fake
, Bool del
)
796 XDeleteProperty(dpy
, wwin
->client_win
, net_wm_desktop
);
798 l
= ((fake
|| IS_OMNIPRESENT(wwin
)) ? -1 : wwin
->frame
->workspace
);
799 XChangeProperty(dpy
, wwin
->client_win
, net_wm_desktop
, XA_CARDINAL
,
800 32, PropModeReplace
, (unsigned char *)&l
, 1);
804 static void updateStateHint(WWindow
*wwin
, Bool changedWorkspace
, Bool del
)
807 XDeleteProperty(dpy
, wwin
->client_win
, net_wm_state
);
809 Atom state
[15]; /* nr of defined state atoms */
812 if (changedWorkspace
|| (wPreferences
.sticky_icons
&& !IS_OMNIPRESENT(wwin
)))
813 updateWorkspaceHint(wwin
, False
, False
);
815 if (IS_OMNIPRESENT(wwin
))
816 state
[i
++] = net_wm_state_sticky
;
817 if (wwin
->flags
.shaded
)
818 state
[i
++] = net_wm_state_shaded
;
819 if (wwin
->flags
.maximized
& MAX_HORIZONTAL
)
820 state
[i
++] = net_wm_state_maximized_horz
;
821 if (wwin
->flags
.maximized
& MAX_VERTICAL
)
822 state
[i
++] = net_wm_state_maximized_vert
;
823 if (WFLAGP(wwin
, skip_window_list
))
824 state
[i
++] = net_wm_state_skip_taskbar
;
825 if (wwin
->flags
.net_skip_pager
)
826 state
[i
++] = net_wm_state_skip_pager
;
827 if ((wwin
->flags
.hidden
|| wwin
->flags
.miniaturized
) && !wwin
->flags
.net_show_desktop
) {
828 state
[i
++] = net_wm_state_hidden
;
829 state
[i
++] = net_wm_state_skip_pager
;
831 if (wwin
->flags
.miniaturized
&& wPreferences
.sticky_icons
) {
832 if (!IS_OMNIPRESENT(wwin
))
833 updateWorkspaceHint(wwin
, True
, False
);
834 state
[i
++] = net_wm_state_sticky
;
837 if (WFLAGP(wwin
, sunken
))
838 state
[i
++] = net_wm_state_below
;
839 if (WFLAGP(wwin
, floating
))
840 state
[i
++] = net_wm_state_above
;
841 if (wwin
->flags
.fullscreen
)
842 state
[i
++] = net_wm_state_fullscreen
;
844 XChangeProperty(dpy
, wwin
->client_win
, net_wm_state
, XA_ATOM
, 32,
845 PropModeReplace
, (unsigned char *)state
, i
);
849 static Bool
updateStrut(WScreen
*scr
, Window w
, Bool adding
)
852 Bool hasState
= False
;
857 unsigned long nitems_ret
, bytes_after_ret
;
860 if ((XGetWindowProperty(dpy
, w
, net_wm_strut
, 0, 4, False
,
861 XA_CARDINAL
, &type_ret
, &fmt_ret
, &nitems_ret
,
862 &bytes_after_ret
, (unsigned char **)&data
) == Success
&& data
) ||
863 ((XGetWindowProperty(dpy
, w
, net_wm_strut_partial
, 0, 12, False
,
864 XA_CARDINAL
, &type_ret
, &fmt_ret
, &nitems_ret
,
865 &bytes_after_ret
, (unsigned char **)&data
) == Success
&& data
))) {
867 /* XXX: This is strictly incorrect in the case of net_wm_strut_partial...
868 * Discard the start and end properties from the partial strut and treat it as
869 * a (deprecated) strut.
870 * This means we are marking the whole width or height of the screen as
871 * reserved, which is not necessarily what the strut defines. However for the
872 * purposes of determining placement or maximization it's probably good enough.
874 area
= (WReservedArea
*) wmalloc(sizeof(WReservedArea
));
875 area
->area
.x1
= data
[0];
876 area
->area
.x2
= data
[1];
877 area
->area
.y1
= data
[2];
878 area
->area
.y2
= data
[3];
882 area
->next
= scr
->netdata
->strut
;
883 scr
->netdata
->strut
= area
;
890 area
= scr
->netdata
->strut
;
893 if (area
->window
== w
) {
894 scr
->netdata
->strut
= area
->next
;
898 while (area
->next
&& area
->next
->window
!= w
)
904 next
= area
->next
->next
;
917 static int getWindowLayer(WWindow
*wwin
)
919 int layer
= WMNormalLevel
;
921 if (wwin
->type
== net_wm_window_type_desktop
) {
922 layer
= WMDesktopLevel
;
923 } else if (wwin
->type
== net_wm_window_type_dock
) {
925 } else if (wwin
->type
== net_wm_window_type_toolbar
) {
926 layer
= WMMainMenuLevel
;
927 } else if (wwin
->type
== net_wm_window_type_menu
) {
928 layer
= WMSubmenuLevel
;
929 } else if (wwin
->type
== net_wm_window_type_utility
) {
930 } else if (wwin
->type
== net_wm_window_type_splash
) {
931 } else if (wwin
->type
== net_wm_window_type_dialog
) {
932 if (wwin
->transient_for
) {
933 WWindow
*parent
= wWindowFor(wwin
->transient_for
);
934 if (parent
&& parent
->flags
.fullscreen
)
935 layer
= WMFullscreenLevel
;
937 /* //layer = WMPopUpLevel; // this seems a bad idea -Dan */
938 } else if (wwin
->type
== net_wm_window_type_normal
) {
941 if (wwin
->client_flags
.sunken
&& WMSunkenLevel
< layer
)
942 layer
= WMSunkenLevel
;
943 if (wwin
->client_flags
.floating
&& WMFloatingLevel
> layer
)
944 layer
= WMFloatingLevel
;
949 static void doStateAtom(WWindow
*wwin
, Atom state
, int set
, Bool init
)
951 if (state
== net_wm_state_sticky
) {
952 if (set
== _NET_WM_STATE_TOGGLE
)
953 set
= !IS_OMNIPRESENT(wwin
);
955 if (set
!= wwin
->flags
.omnipresent
)
956 wWindowSetOmnipresent(wwin
, set
);
958 } else if (state
== net_wm_state_shaded
) {
959 if (set
== _NET_WM_STATE_TOGGLE
)
960 set
= !wwin
->flags
.shaded
;
963 wwin
->flags
.shaded
= set
;
968 wUnshadeWindow(wwin
);
970 } else if (state
== net_wm_state_skip_taskbar
) {
971 if (set
== _NET_WM_STATE_TOGGLE
)
972 set
= !wwin
->client_flags
.skip_window_list
;
974 wwin
->client_flags
.skip_window_list
= set
;
975 } else if (state
== net_wm_state_skip_pager
) {
976 if (set
== _NET_WM_STATE_TOGGLE
)
977 set
= !wwin
->flags
.net_skip_pager
;
979 wwin
->flags
.net_skip_pager
= set
;
980 } else if (state
== net_wm_state_maximized_vert
) {
981 if (set
== _NET_WM_STATE_TOGGLE
)
982 set
= !(wwin
->flags
.maximized
& MAX_VERTICAL
);
985 wwin
->flags
.maximized
|= (set
? MAX_VERTICAL
: 0);
988 wMaximizeWindow(wwin
, wwin
->flags
.maximized
| MAX_VERTICAL
);
990 wMaximizeWindow(wwin
, wwin
->flags
.maximized
& ~MAX_VERTICAL
);
992 } else if (state
== net_wm_state_maximized_horz
) {
993 if (set
== _NET_WM_STATE_TOGGLE
)
994 set
= !(wwin
->flags
.maximized
& MAX_HORIZONTAL
);
997 wwin
->flags
.maximized
|= (set
? MAX_HORIZONTAL
: 0);
1000 wMaximizeWindow(wwin
, wwin
->flags
.maximized
| MAX_HORIZONTAL
);
1002 wMaximizeWindow(wwin
, wwin
->flags
.maximized
& ~MAX_HORIZONTAL
);
1004 } else if (state
== net_wm_state_hidden
) {
1005 if (set
== _NET_WM_STATE_TOGGLE
)
1006 set
= !(wwin
->flags
.miniaturized
);
1009 wwin
->flags
.miniaturized
= set
;
1012 wIconifyWindow(wwin
);
1014 wDeiconifyWindow(wwin
);
1016 } else if (state
== net_wm_state_fullscreen
) {
1017 if (set
== _NET_WM_STATE_TOGGLE
)
1018 set
= !(wwin
->flags
.fullscreen
);
1021 wwin
->flags
.fullscreen
= set
;
1024 wFullscreenWindow(wwin
);
1026 wUnfullscreenWindow(wwin
);
1028 } else if (state
== net_wm_state_above
) {
1029 if (set
== _NET_WM_STATE_TOGGLE
)
1030 set
= !(wwin
->client_flags
.floating
);
1033 wwin
->client_flags
.floating
= set
;
1035 wwin
->client_flags
.floating
= set
;
1036 ChangeStackingLevel(wwin
->frame
->core
, getWindowLayer(wwin
));
1039 } else if (state
== net_wm_state_below
) {
1040 if (set
== _NET_WM_STATE_TOGGLE
)
1041 set
= !(wwin
->client_flags
.sunken
);
1044 wwin
->client_flags
.sunken
= set
;
1046 wwin
->client_flags
.sunken
= set
;
1047 ChangeStackingLevel(wwin
->frame
->core
, getWindowLayer(wwin
));
1052 wmessage("doStateAtom unknown atom %s set %d\n", XGetAtomName(dpy
, state
), set
);
1057 static void removeIcon(WWindow
*wwin
)
1059 if (wwin
->icon
== NULL
)
1061 if (wwin
->flags
.miniaturized
&& wwin
->icon
->mapped
) {
1062 XUnmapWindow(dpy
, wwin
->icon
->core
->window
);
1063 RemoveFromStackList(wwin
->icon
->core
);
1064 wIconDestroy(wwin
->icon
);
1069 static Bool
handleWindowType(WWindow
*wwin
, Atom type
, int *layer
)
1073 if (type
== net_wm_window_type_desktop
) {
1074 wwin
->client_flags
.no_titlebar
= 1;
1075 wwin
->client_flags
.no_resizable
= 1;
1076 wwin
->client_flags
.no_miniaturizable
= 1;
1077 wwin
->client_flags
.no_border
= 1;
1078 wwin
->client_flags
.no_resizebar
= 1;
1079 wwin
->client_flags
.no_shadeable
= 1;
1080 wwin
->client_flags
.no_movable
= 1;
1081 wwin
->client_flags
.omnipresent
= 1;
1082 wwin
->client_flags
.skip_window_list
= 1;
1083 wwin
->client_flags
.skip_switchpanel
= 1;
1084 wwin
->client_flags
.dont_move_off
= 1;
1085 wwin
->client_flags
.no_appicon
= 1;
1086 wwin
->flags
.net_skip_pager
= 1;
1089 } else if (type
== net_wm_window_type_dock
) {
1090 wwin
->client_flags
.no_titlebar
= 1;
1091 wwin
->client_flags
.no_resizable
= 1;
1092 wwin
->client_flags
.no_miniaturizable
= 1;
1093 wwin
->client_flags
.no_border
= 1; /* XXX: really not a single decoration. */
1094 wwin
->client_flags
.no_resizebar
= 1;
1095 wwin
->client_flags
.no_shadeable
= 1;
1096 wwin
->client_flags
.no_movable
= 1;
1097 wwin
->client_flags
.omnipresent
= 1;
1098 wwin
->client_flags
.skip_window_list
= 1;
1099 wwin
->client_flags
.skip_switchpanel
= 1;
1100 wwin
->client_flags
.dont_move_off
= 1;
1101 wwin
->flags
.net_skip_pager
= 1;
1102 } else if (type
== net_wm_window_type_toolbar
) {
1103 wwin
->client_flags
.no_titlebar
= 1;
1104 wwin
->client_flags
.no_resizable
= 1;
1105 wwin
->client_flags
.no_miniaturizable
= 1;
1106 wwin
->client_flags
.no_resizebar
= 1;
1107 wwin
->client_flags
.no_shadeable
= 1;
1108 wwin
->client_flags
.skip_window_list
= 1;
1109 wwin
->client_flags
.skip_switchpanel
= 1;
1110 wwin
->client_flags
.dont_move_off
= 1;
1111 wwin
->client_flags
.no_appicon
= 1;
1112 } else if (type
== net_wm_window_type_menu
) {
1113 wwin
->client_flags
.no_titlebar
= 1;
1114 wwin
->client_flags
.no_resizable
= 1;
1115 wwin
->client_flags
.no_miniaturizable
= 1;
1116 wwin
->client_flags
.no_resizebar
= 1;
1117 wwin
->client_flags
.no_shadeable
= 1;
1118 wwin
->client_flags
.skip_window_list
= 1;
1119 wwin
->client_flags
.skip_switchpanel
= 1;
1120 wwin
->client_flags
.dont_move_off
= 1;
1121 wwin
->client_flags
.no_appicon
= 1;
1122 } else if (type
== net_wm_window_type_utility
) {
1123 wwin
->client_flags
.no_appicon
= 1;
1124 } else if (type
== net_wm_window_type_splash
) {
1125 wwin
->client_flags
.no_titlebar
= 1;
1126 wwin
->client_flags
.no_resizable
= 1;
1127 wwin
->client_flags
.no_miniaturizable
= 1;
1128 wwin
->client_flags
.no_resizebar
= 1;
1129 wwin
->client_flags
.no_shadeable
= 1;
1130 wwin
->client_flags
.no_movable
= 1;
1131 wwin
->client_flags
.skip_window_list
= 1;
1132 wwin
->client_flags
.skip_switchpanel
= 1;
1133 wwin
->client_flags
.dont_move_off
= 1;
1134 wwin
->client_flags
.no_appicon
= 1;
1135 wwin
->flags
.net_skip_pager
= 1;
1136 } else if (type
== net_wm_window_type_dialog
) {
1137 /* These also seem a bad idea in our context -Dan
1138 // wwin->client_flags.skip_window_list = 1;
1139 // wwin->client_flags.no_appicon = 1;
1141 } else if (type
== net_wm_window_type_normal
) {
1147 *layer
= getWindowLayer(wwin
);
1152 void wNETWMPositionSplash(WWindow
*wwin
, int *x
, int *y
, int width
, int height
)
1154 if (wwin
->type
== net_wm_window_type_splash
) {
1155 WScreen
*scr
= wwin
->screen_ptr
;
1156 WMRect rect
= wGetRectForHead(scr
, wGetHeadForPointerLocation(scr
));
1157 *x
= rect
.pos
.x
+ (rect
.size
.width
- width
) / 2;
1158 *y
= rect
.pos
.y
+ (rect
.size
.height
- height
) / 2;
1162 static void updateWindowType(WWindow
*wwin
)
1166 unsigned long nitems_ret
, bytes_after_ret
;
1169 if (XGetWindowProperty(dpy
, wwin
->client_win
, net_wm_window_type
, 0, 1,
1170 False
, XA_ATOM
, &type_ret
, &fmt_ret
, &nitems_ret
,
1171 &bytes_after_ret
, (unsigned char **)&data
) == Success
&& data
) {
1174 Atom
*type
= (Atom
*) data
;
1175 for (i
= 0; i
< nitems_ret
; ++i
) {
1176 if (handleWindowType(wwin
, type
[i
], &layer
))
1182 if (wwin
->frame
!= NULL
) {
1183 ChangeStackingLevel(wwin
->frame
->core
, layer
);
1184 wwin
->frame
->flags
.need_texture_change
= 1;
1185 wWindowConfigureBorders(wwin
);
1186 wFrameWindowPaint(wwin
->frame
);
1187 wNETWMUpdateActions(wwin
, False
);
1191 void wNETWMCheckClientHints(WWindow
*wwin
, int *layer
, int *workspace
)
1195 unsigned long nitems_ret
, bytes_after_ret
;
1198 if (XGetWindowProperty(dpy
, wwin
->client_win
, net_wm_desktop
, 0, 1, False
,
1199 XA_CARDINAL
, &type_ret
, &fmt_ret
, &nitems_ret
,
1200 &bytes_after_ret
, (unsigned char **)&data
) == Success
&& data
) {
1202 long desktop
= *data
;
1206 wwin
->client_flags
.omnipresent
= 1;
1208 *workspace
= desktop
;
1211 if (XGetWindowProperty(dpy
, wwin
->client_win
, net_wm_state
, 0, 1, False
,
1212 XA_ATOM
, &type_ret
, &fmt_ret
, &nitems_ret
,
1213 &bytes_after_ret
, (unsigned char **)&data
) == Success
&& data
) {
1215 Atom
*state
= (Atom
*) data
;
1216 for (i
= 0; i
< nitems_ret
; ++i
)
1217 doStateAtom(wwin
, state
[i
], _NET_WM_STATE_ADD
, True
);
1222 if (XGetWindowProperty(dpy
, wwin
->client_win
, net_wm_window_type
, 0, 1, False
,
1223 XA_ATOM
, &type_ret
, &fmt_ret
, &nitems_ret
,
1224 &bytes_after_ret
, (unsigned char **)&data
) == Success
&& data
) {
1226 Atom
*type
= (Atom
*) data
;
1227 for (i
= 0; i
< nitems_ret
; ++i
) {
1228 if (handleWindowType(wwin
, type
[i
], layer
))
1234 wNETWMUpdateActions(wwin
, False
);
1235 updateStrut(wwin
->screen_ptr
, wwin
->client_win
, False
);
1236 updateStrut(wwin
->screen_ptr
, wwin
->client_win
, True
);
1238 wScreenUpdateUsableArea(wwin
->screen_ptr
);
1241 static Bool
updateNetIconInfo(WWindow
*wwin
)
1245 unsigned long nitems_ret
, bytes_after_ret
;
1247 Bool hasState
= False
;
1248 Bool old_state
= wwin
->flags
.net_handle_icon
;
1250 if (XGetWindowProperty(dpy
, wwin
->client_win
, net_wm_handled_icons
, 0, 1, False
,
1251 XA_CARDINAL
, &type_ret
, &fmt_ret
, &nitems_ret
,
1252 &bytes_after_ret
, (unsigned char **)&data
) == Success
&& data
) {
1253 long handled
= *data
;
1254 wwin
->flags
.net_handle_icon
= (handled
!= 0);
1259 wwin
->flags
.net_handle_icon
= False
;
1262 if (XGetWindowProperty(dpy
, wwin
->client_win
, net_wm_icon_geometry
, 0, 4, False
,
1263 XA_CARDINAL
, &type_ret
, &fmt_ret
, &nitems_ret
,
1264 &bytes_after_ret
, (unsigned char **)&data
) == Success
&& data
) {
1267 if (wwin
->flags
.net_handle_icon
)
1269 wwin
->flags
.net_handle_icon
= True
;
1272 wwin
->icon_x
= data
[0];
1273 wwin
->icon_y
= data
[1];
1274 wwin
->icon_w
= data
[2];
1275 wwin
->icon_h
= data
[3];
1282 wwin
->flags
.net_handle_icon
= False
;
1285 if (wwin
->flags
.miniaturized
&& old_state
!= wwin
->flags
.net_handle_icon
) {
1286 if (wwin
->flags
.net_handle_icon
) {
1289 wwin
->flags
.miniaturized
= False
;
1290 wwin
->flags
.skip_next_animation
= True
;
1291 wIconifyWindow(wwin
);
1298 void wNETWMCheckInitialClientState(WWindow
*wwin
)
1301 wmessage("wNETWMCheckInitialClientState");
1304 wNETWMShowingDesktop(wwin
->screen_ptr
, False
);
1306 updateNetIconInfo(wwin
);
1307 updateIconImage(wwin
);
1310 static void handleDesktopNames(XClientMessageEvent
*event
, WScreen
*scr
)
1312 unsigned long nitems_ret
, bytes_after_ret
;
1313 char *data
, *names
[32];
1317 if (XGetWindowProperty(dpy
, scr
->root_win
, net_desktop_names
, 0, 1, False
,
1318 utf8_string
, &type_ret
, &fmt_ret
, &nitems_ret
,
1319 &bytes_after_ret
, (unsigned char **)&data
) != Success
)
1325 if (type_ret
!= utf8_string
|| fmt_ret
!= 8)
1330 for (i
= 0; i
< nitems_ret
; i
++) {
1333 names
[n
] = &data
[i
];
1334 } else if (*names
[n
] == 0) {
1335 names
[n
] = &data
[i
];
1336 wWorkspaceRename(scr
, n
, names
[n
]);
1341 Bool
wNETWMProcessClientMessage(XClientMessageEvent
*event
)
1348 wmessage("processClientMessage type %s\n", XGetAtomName(dpy
, event
->message_type
));
1351 scr
= wScreenForWindow(event
->window
);
1353 /* generic client messages */
1354 if (event
->message_type
== net_current_desktop
) {
1355 wWorkspaceChange(scr
, event
->data
.l
[0]);
1356 } else if (event
->message_type
== net_number_of_desktops
) {
1359 value
= event
->data
.l
[0];
1360 if (value
> scr
->workspace_count
) {
1361 wWorkspaceMake(scr
, value
- scr
->workspace_count
);
1362 } else if (value
< scr
->workspace_count
) {
1364 Bool rebuild
= False
;
1366 for (i
= scr
->workspace_count
- 1; i
>= value
; i
--) {
1367 if (!wWorkspaceDelete(scr
, i
)) {
1374 updateWorkspaceCount(scr
);
1376 } else if (event
->message_type
== net_showing_desktop
) {
1377 wNETWMShowingDesktop(scr
, event
->data
.l
[0]);
1378 } else if (event
->message_type
== net_desktop_names
) {
1379 handleDesktopNames(event
, scr
);
1388 /* window specific client messages */
1390 wwin
= wWindowFor(event
->window
);
1394 if (event
->message_type
== net_active_window
) {
1396 * Satisfy a client's focus request only if
1397 * - request comes from a pager, or
1398 * - it's explicitly allowed in Advanced Options, or
1399 * - giving the client the focus does not cause a change in
1400 * the active workspace (XXX: or the active head if Xinerama)
1402 if (wwin
->frame
->workspace
== wwin
->screen_ptr
->current_workspace
/* No workspace change */
1403 || event
->data
.l
[0] == 2 /* Requested by pager */
1404 || WFLAGP(wwin
, focus_across_wksp
) /* Explicitly allowed */) {
1405 wNETWMShowingDesktop(scr
, False
);
1406 wMakeWindowVisible(wwin
);
1408 } else if (event
->message_type
== net_close_window
) {
1409 if (!WFLAGP(wwin
, no_closable
)) {
1410 if (wwin
->protocols
.DELETE_WINDOW
)
1411 wClientSendProtocol(wwin
, _XA_WM_DELETE_WINDOW
, LastTimestamp
);
1413 } else if (event
->message_type
== net_wm_state
) {
1414 int maximized
= wwin
->flags
.maximized
;
1415 long set
= event
->data
.l
[0];
1418 wmessage("net_wm_state set %ld a1 %s a2 %s\n", set
,
1419 XGetAtomName(dpy
, event
->data
.l
[1]), XGetAtomName(dpy
, event
->data
.l
[2]));
1422 doStateAtom(wwin
, (Atom
) event
->data
.l
[1], set
, False
);
1423 if (event
->data
.l
[2])
1424 doStateAtom(wwin
, (Atom
) event
->data
.l
[2], set
, False
);
1426 if (wwin
->flags
.maximized
!= maximized
) {
1427 if (!wwin
->flags
.maximized
) {
1428 wwin
->flags
.maximized
= maximized
;
1429 wUnmaximizeWindow(wwin
);
1431 wMaximizeWindow(wwin
, wwin
->flags
.maximized
);
1434 updateStateHint(wwin
, False
, False
);
1435 } else if (event
->message_type
== net_wm_handled_icons
|| event
->message_type
== net_wm_icon_geometry
) {
1436 updateNetIconInfo(wwin
);
1437 } else if (event
->message_type
== net_wm_desktop
) {
1438 long desktop
= event
->data
.l
[0];
1439 if (desktop
== -1) {
1440 wWindowSetOmnipresent(wwin
, True
);
1442 if (IS_OMNIPRESENT(wwin
))
1443 wWindowSetOmnipresent(wwin
, False
);
1444 wWindowChangeWorkspace(wwin
, desktop
);
1453 void wNETWMCheckClientHintChange(WWindow
*wwin
, XPropertyEvent
*event
)
1456 wmessage("clientHintChange type %s\n", XGetAtomName(dpy
, event
->atom
));
1459 if (event
->atom
== net_wm_strut
|| event
->atom
== net_wm_strut_partial
) {
1460 updateStrut(wwin
->screen_ptr
, wwin
->client_win
, False
);
1461 updateStrut(wwin
->screen_ptr
, wwin
->client_win
, True
);
1462 wScreenUpdateUsableArea(wwin
->screen_ptr
);
1463 } else if (event
->atom
== net_wm_handled_icons
|| event
->atom
== net_wm_icon_geometry
) {
1464 updateNetIconInfo(wwin
);
1465 } else if (event
->atom
== net_wm_window_type
) {
1466 updateWindowType(wwin
);
1467 } else if (event
->atom
== net_wm_name
) {
1468 char *name
= wNETWMGetWindowName(wwin
->client_win
);
1469 wWindowUpdateName(wwin
, name
);
1472 } else if (event
->atom
== net_wm_icon_name
) {
1474 char *name
= wNETWMGetIconName(wwin
->client_win
);
1475 wIconChangeTitle(wwin
->icon
, name
);
1477 } else if (event
->atom
== net_wm_icon
) {
1478 updateIconImage(wwin
);
1482 int wNETWMGetPidForWindow(Window window
)
1486 unsigned long nitems_ret
, bytes_after_ret
;
1490 if (XGetWindowProperty(dpy
, window
, net_wm_pid
, 0, 1, False
,
1491 XA_CARDINAL
, &type_ret
, &fmt_ret
, &nitems_ret
,
1492 &bytes_after_ret
, (unsigned char **)&data
) == Success
&& data
) {
1502 char *wNETWMGetWindowName(Window window
)
1508 name
= (char *)PropGetCheckProperty(window
, net_wm_name
, utf8_string
, 0, 0, &size
);
1510 ret
= wstrndup(name
, size
);
1519 char *wNETWMGetIconName(Window window
)
1525 name
= (char *)PropGetCheckProperty(window
, net_wm_icon_name
, utf8_string
, 0, 0, &size
);
1527 ret
= wstrndup(name
, size
);
1536 static void observer(void *self
, WMNotification
*notif
)
1538 WWindow
*wwin
= (WWindow
*) WMGetNotificationObject(notif
);
1539 const char *name
= WMGetNotificationName(notif
);
1540 void *data
= WMGetNotificationClientData(notif
);
1541 NetData
*ndata
= (NetData
*) self
;
1543 if (strcmp(name
, WMNManaged
) == 0 && wwin
) {
1544 updateClientList(wwin
->screen_ptr
);
1545 updateClientListStacking(wwin
->screen_ptr
, NULL
);
1546 updateStateHint(wwin
, True
, False
);
1548 updateStrut(wwin
->screen_ptr
, wwin
->client_win
, False
);
1549 updateStrut(wwin
->screen_ptr
, wwin
->client_win
, True
);
1550 wScreenUpdateUsableArea(wwin
->screen_ptr
);
1551 } else if (strcmp(name
, WMNUnmanaged
) == 0 && wwin
) {
1552 updateClientList(wwin
->screen_ptr
);
1553 updateClientListStacking(wwin
->screen_ptr
, wwin
);
1554 updateWorkspaceHint(wwin
, False
, True
);
1555 updateStateHint(wwin
, False
, True
);
1556 wNETWMUpdateActions(wwin
, True
);
1558 updateStrut(wwin
->screen_ptr
, wwin
->client_win
, False
);
1559 wScreenUpdateUsableArea(wwin
->screen_ptr
);
1560 } else if (strcmp(name
, WMNResetStacking
) == 0 && wwin
) {
1561 updateClientListStacking(wwin
->screen_ptr
, NULL
);
1562 updateStateHint(wwin
, False
, False
);
1563 } else if (strcmp(name
, WMNChangedStacking
) == 0 && wwin
) {
1564 updateClientListStacking(wwin
->screen_ptr
, NULL
);
1565 updateStateHint(wwin
, False
, False
);
1566 } else if (strcmp(name
, WMNChangedFocus
) == 0) {
1567 updateFocusHint(ndata
->scr
, wwin
);
1568 } else if (strcmp(name
, WMNChangedWorkspace
) == 0 && wwin
) {
1569 updateWorkspaceHint(wwin
, False
, False
);
1570 updateStateHint(wwin
, True
, False
);
1571 } else if (strcmp(name
, WMNChangedState
) == 0 && wwin
) {
1572 updateStateHint(wwin
, !strcmp(data
, "omnipresent"), False
);
1576 static void wsobserver(void *self
, WMNotification
*notif
)
1578 WScreen
*scr
= (WScreen
*) WMGetNotificationObject(notif
);
1579 const char *name
= WMGetNotificationName(notif
);
1581 if (strcmp(name
, WMNWorkspaceCreated
) == 0) {
1582 updateWorkspaceCount(scr
);
1583 updateWorkspaceNames(scr
);
1584 } else if (strcmp(name
, WMNWorkspaceDestroyed
) == 0) {
1585 updateWorkspaceCount(scr
);
1586 updateWorkspaceNames(scr
);
1587 } else if (strcmp(name
, WMNWorkspaceChanged
) == 0) {
1588 updateCurrentWorkspace(scr
);
1589 } else if (strcmp(name
, WMNWorkspaceNameChanged
) == 0) {
1590 updateWorkspaceNames(scr
);
1594 void wNETFrameExtents(WWindow
*wwin
)
1596 long extents
[4] = { 0, 0, 0, 0 };
1598 /* The extents array describes dimensions which are not
1599 * part of the client window. In our case that means
1600 * widths of the border and heights of the titlebar and resizebar.
1607 if (wwin
->frame
->titlebar
)
1608 extents
[2] = wwin
->frame
->titlebar
->height
;
1609 if (wwin
->frame
->resizebar
)
1610 extents
[3] = wwin
->frame
->resizebar
->height
;
1611 if (HAS_BORDER(wwin
)) {
1612 extents
[0] += FRAME_BORDER_WIDTH
;
1613 extents
[1] += FRAME_BORDER_WIDTH
;
1614 extents
[2] += FRAME_BORDER_WIDTH
;
1615 extents
[3] += FRAME_BORDER_WIDTH
;
1618 XChangeProperty(dpy
, wwin
->client_win
, net_frame_extents
, XA_CARDINAL
, 32, PropModeReplace
, (unsigned char *) extents
, 4);
1621 void wNETCleanupFrameExtents(WWindow
*wwin
)
1623 XDeleteProperty(dpy
, wwin
->client_win
, net_frame_extents
);