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
);
233 typedef struct NetData
{
235 WReservedArea
*strut
;
236 WWindow
**show_desktop
;
239 static void setSupportedHints(WScreen
* scr
)
244 /* set supported hints list */
245 /* XXX: extend this !!! */
247 atom
[i
++] = net_client_list
;
248 atom
[i
++] = net_client_list_stacking
;
249 atom
[i
++] = net_number_of_desktops
;
250 atom
[i
++] = net_desktop_geometry
;
251 atom
[i
++] = net_desktop_viewport
;
252 atom
[i
++] = net_current_desktop
;
253 atom
[i
++] = net_desktop_names
;
254 atom
[i
++] = net_active_window
;
255 atom
[i
++] = net_supporting_wm_check
;
256 atom
[i
++] = net_showing_desktop
;
258 atom
[i
++] = net_wm_moveresize
;
260 atom
[i
++] = net_wm_desktop
;
261 atom
[i
++] = net_wm_window_type
;
262 atom
[i
++] = net_wm_window_type_desktop
;
263 atom
[i
++] = net_wm_window_type_dock
;
264 atom
[i
++] = net_wm_window_type_toolbar
;
265 atom
[i
++] = net_wm_window_type_menu
;
266 atom
[i
++] = net_wm_window_type_utility
;
267 atom
[i
++] = net_wm_window_type_splash
;
268 atom
[i
++] = net_wm_window_type_dialog
;
269 atom
[i
++] = net_wm_window_type_normal
;
271 atom
[i
++] = net_wm_state
;
272 /* atom[i++] = net_wm_state_modal; *//* XXX: not sure where/when to use it. */
273 atom
[i
++] = net_wm_state_sticky
;
274 atom
[i
++] = net_wm_state_shaded
;
275 atom
[i
++] = net_wm_state_maximized_horz
;
276 atom
[i
++] = net_wm_state_maximized_vert
;
277 atom
[i
++] = net_wm_state_skip_taskbar
;
278 atom
[i
++] = net_wm_state_skip_pager
;
279 atom
[i
++] = net_wm_state_hidden
;
280 atom
[i
++] = net_wm_state_fullscreen
;
281 atom
[i
++] = net_wm_state_above
;
282 atom
[i
++] = net_wm_state_below
;
284 atom
[i
++] = net_wm_allowed_actions
;
285 atom
[i
++] = net_wm_action_move
;
286 atom
[i
++] = net_wm_action_resize
;
287 atom
[i
++] = net_wm_action_minimize
;
288 atom
[i
++] = net_wm_action_shade
;
289 atom
[i
++] = net_wm_action_stick
;
290 atom
[i
++] = net_wm_action_maximize_horz
;
291 atom
[i
++] = net_wm_action_maximize_vert
;
292 atom
[i
++] = net_wm_action_fullscreen
;
293 atom
[i
++] = net_wm_action_change_desktop
;
294 atom
[i
++] = net_wm_action_close
;
296 atom
[i
++] = net_wm_strut
;
297 atom
[i
++] = net_wm_icon_geometry
;
298 atom
[i
++] = net_wm_icon
;
299 atom
[i
++] = net_wm_handled_icons
;
301 atom
[i
++] = net_frame_extents
;
303 atom
[i
++] = net_wm_name
;
304 atom
[i
++] = net_wm_icon_name
;
306 XChangeProperty(dpy
, scr
->root_win
, net_supported
, XA_ATOM
, 32, PropModeReplace
, (unsigned char *)atom
, i
);
308 /* set supporting wm hint */
309 XChangeProperty(dpy
, scr
->root_win
, net_supporting_wm_check
, XA_WINDOW
, 32,
310 PropModeReplace
, (unsigned char *)&scr
->info_window
, 1);
312 XChangeProperty(dpy
, scr
->info_window
, net_supporting_wm_check
, XA_WINDOW
,
313 32, PropModeReplace
, (unsigned char *)&scr
->info_window
, 1);
316 void wNETWMUpdateDesktop(WScreen
* scr
)
318 long *views
, sizes
[2];
321 if (scr
->workspace_count
== 0)
324 count
= scr
->workspace_count
* 2;
325 views
= wmalloc(sizeof(long) * count
);
326 /*memset(views, 0, sizeof(long) * count); */
327 sizes
[0] = scr
->scr_width
;
328 sizes
[1] = scr
->scr_height
;
330 for (i
= 0; i
< scr
->workspace_count
; i
++) {
331 views
[2 * i
+ 0] = 0;
332 views
[2 * i
+ 1] = 0;
335 XChangeProperty(dpy
, scr
->root_win
, net_desktop_geometry
, XA_CARDINAL
, 32,
336 PropModeReplace
, (unsigned char *)sizes
, 2);
338 XChangeProperty(dpy
, scr
->root_win
, net_desktop_viewport
, XA_CARDINAL
, 32,
339 PropModeReplace
, (unsigned char *)views
, count
);
344 int wNETWMGetCurrentDesktopFromHint(WScreen
* scr
)
349 prop
= PropGetCheckProperty(scr
->root_win
, net_current_desktop
, XA_CARDINAL
, 0, 1, &count
);
351 int desktop
= *(long *)prop
;
359 * Find the best icon to be used by Window Maker for appicon/miniwindows.
360 * Currently the algorithm is to take the image with the size closest
361 * to icon_size x icon_size, but never bigger than that.
363 * This algorithm is very poorly implemented and needs to be redone (it can
364 * easily select images with very large widths and very small heights over
365 * square images, if the area of the former is closer to the desired one).
367 * The logic can also be changed to accept bigger images and scale them down.
369 static unsigned long *findBestIcon(unsigned long *data
, unsigned long items
)
372 unsigned long i
, distance
;
375 /* better use only 75% of icon_size. For 64x64 this means 48x48
376 * This leaves room around the icon for the miniwindow title and
377 * results in better overall aesthetics -Dan */
378 wanted
= wPreferences
.icon_size
* wPreferences
.icon_size
;
380 for (icon
= NULL
, distance
= wanted
, i
= 0L; i
< items
- 1;) {
381 size
= data
[i
] * data
[i
+ 1];
385 if (d
>= 0 && d
<= distance
&& (i
+ size
+ 2) <= items
) {
395 static RImage
*makeRImageFromARGBData(unsigned long *data
)
397 int size
, width
, height
, i
;
399 unsigned char *imgdata
;
404 size
= width
* height
;
409 image
= RCreateImage(width
, height
, True
);
411 for (imgdata
= image
->data
, i
= 2; i
< size
+ 2; i
++, imgdata
+= 4) {
413 imgdata
[3] = (pixel
>> 24) & 0xff; /* A */
414 imgdata
[0] = (pixel
>> 16) & 0xff; /* R */
415 imgdata
[1] = (pixel
>> 8) & 0xff; /* G */
416 imgdata
[2] = (pixel
>> 0) & 0xff; /* B */
422 static RImage
*get_wwindow_image_from_x11(WWindow
*wwin
)
427 unsigned long items
, rest
;
428 unsigned long *property
, *data
;
430 /* Get the icon from X11 Window */
431 if (XGetWindowProperty(dpy
, wwin
->client_win
, net_wm_icon
, 0L, LONG_MAX
,
432 False
, XA_CARDINAL
, &type
, &format
, &items
, &rest
,
433 (unsigned char **)&property
) != Success
|| !property
)
436 if (type
!= XA_CARDINAL
|| format
!= 32 || items
< 2) {
441 /* Find the best icon */
442 data
= findBestIcon(property
, items
);
448 /* Save the best icon in the X11 icon */
449 image
= makeRImageFromARGBData(data
);
453 /* Resize the image to the correct value */
454 image
= wIconValidateIconSize(image
, wPreferences
.icon_size
);
459 static void updateIconImage(WWindow
*wwin
)
461 /* Remove the icon image from X11 */
462 if (wwin
->net_icon_image
)
463 RReleaseImage(wwin
->net_icon_image
);
465 /* Save the icon in the X11 icon */
466 wwin
->net_icon_image
= get_wwindow_image_from_x11(wwin
);
468 /* Refresh the Window Icon */
470 wIconUpdate(wwin
->icon
);
472 /* Refresh the application icon */
473 WApplication
*app
= wApplicationOf(wwin
->main_window
);
474 if (app
&& app
->app_icon
) {
475 wIconUpdate(app
->app_icon
->icon
);
476 wAppIconPaint(app
->app_icon
);
480 static void updateShowDesktop(WScreen
* scr
, Bool show
)
484 foo
= (show
== True
);
485 XChangeProperty(dpy
, scr
->root_win
, net_showing_desktop
, XA_CARDINAL
, 32,
486 PropModeReplace
, (unsigned char *)&foo
, 1);
489 void wNETWMShowingDesktop(WScreen
* scr
, Bool show
)
491 if (show
&& scr
->netdata
->show_desktop
== NULL
) {
492 WWindow
*tmp
, **wins
;
495 wins
= (WWindow
**) wmalloc(sizeof(WWindow
*) * (scr
->window_count
+ 1));
497 tmp
= scr
->focused_window
;
499 if (!tmp
->flags
.hidden
&& !tmp
->flags
.miniaturized
&& !WFLAGP(tmp
, skip_window_list
)) {
502 tmp
->flags
.skip_next_animation
= 1;
503 tmp
->flags
.net_show_desktop
= 1;
511 scr
->netdata
->show_desktop
= wins
;
512 updateShowDesktop(scr
, True
);
513 } else if (scr
->netdata
->show_desktop
!= NULL
) {
514 /* FIXME: get rid of workspace flashing ! */
515 int ws
= scr
->current_workspace
;
517 for (tmp
= scr
->netdata
->show_desktop
; *tmp
; ++tmp
) {
518 wDeiconifyWindow(*tmp
);
519 (*tmp
)->flags
.net_show_desktop
= 0;
521 if (ws
!= scr
->current_workspace
)
522 wWorkspaceChange(scr
, ws
);
523 wfree(scr
->netdata
->show_desktop
);
524 scr
->netdata
->show_desktop
= NULL
;
525 updateShowDesktop(scr
, False
);
529 void wNETWMInitStuff(WScreen
* scr
)
538 #ifdef HAVE_XINTERNATOMS
543 for (i
= 0; i
< atomNr
; ++i
) {
544 names
[i
] = atomNames
[i
].name
;
546 XInternAtoms(dpy
, &names
[0], atomNr
, False
, atoms
);
547 for (i
= 0; i
< atomNr
; ++i
) {
548 *atomNames
[i
].atom
= atoms
[i
];
552 for (i
= 0; i
< atomNr
; i
++) {
553 *atomNames
[i
].atom
= XInternAtom(dpy
, atomNames
[i
].name
, False
);
557 data
= wmalloc(sizeof(NetData
));
560 data
->show_desktop
= NULL
;
564 setSupportedHints(scr
);
566 WMAddNotificationObserver(observer
, data
, WMNManaged
, NULL
);
567 WMAddNotificationObserver(observer
, data
, WMNUnmanaged
, NULL
);
568 WMAddNotificationObserver(observer
, data
, WMNChangedWorkspace
, NULL
);
569 WMAddNotificationObserver(observer
, data
, WMNChangedState
, NULL
);
570 WMAddNotificationObserver(observer
, data
, WMNChangedFocus
, NULL
);
571 WMAddNotificationObserver(observer
, data
, WMNChangedStacking
, NULL
);
572 WMAddNotificationObserver(observer
, data
, WMNChangedName
, NULL
);
574 WMAddNotificationObserver(wsobserver
, data
, WMNWorkspaceCreated
, NULL
);
575 WMAddNotificationObserver(wsobserver
, data
, WMNWorkspaceDestroyed
, NULL
);
576 WMAddNotificationObserver(wsobserver
, data
, WMNWorkspaceChanged
, NULL
);
577 WMAddNotificationObserver(wsobserver
, data
, WMNWorkspaceNameChanged
, NULL
);
579 updateClientList(scr
);
580 updateClientListStacking(scr
, NULL
);
581 updateWorkspaceCount(scr
);
582 updateWorkspaceNames(scr
);
583 updateShowDesktop(scr
, False
);
585 wScreenUpdateUsableArea(scr
);
588 void wNETWMCleanup(WScreen
* scr
)
592 for (i
= 0; i
< atomNr
; i
++)
593 XDeleteProperty(dpy
, scr
->root_win
, *atomNames
[i
].atom
);
596 void wNETWMUpdateActions(WWindow
* wwin
, Bool del
)
598 Atom action
[10]; /* nr of actions atoms defined */
602 XDeleteProperty(dpy
, wwin
->client_win
, net_wm_allowed_actions
);
606 if (IS_MOVABLE(wwin
))
607 action
[i
++] = net_wm_action_move
;
609 if (IS_RESIZABLE(wwin
))
610 action
[i
++] = net_wm_action_resize
;
612 if (!WFLAGP(wwin
, no_miniaturizable
))
613 action
[i
++] = net_wm_action_minimize
;
615 if (!WFLAGP(wwin
, no_shadeable
))
616 action
[i
++] = net_wm_action_shade
;
618 /* if (!WFLAGP(wwin, no_stickable)) */
619 action
[i
++] = net_wm_action_stick
;
621 /* if (!(WFLAGP(wwin, no_maximizeable) & MAX_HORIZONTAL)) */
622 if (IS_RESIZABLE(wwin
))
623 action
[i
++] = net_wm_action_maximize_horz
;
625 /* if (!(WFLAGP(wwin, no_maximizeable) & MAX_VERTICAL)) */
626 if (IS_RESIZABLE(wwin
))
627 action
[i
++] = net_wm_action_maximize_vert
;
629 /* if (!WFLAGP(wwin, no_fullscreen)) */
630 action
[i
++] = net_wm_action_fullscreen
;
632 /* if (!WFLAGP(wwin, no_change_desktop)) */
633 action
[i
++] = net_wm_action_change_desktop
;
635 if (!WFLAGP(wwin
, no_closable
))
636 action
[i
++] = net_wm_action_close
;
638 XChangeProperty(dpy
, wwin
->client_win
, net_wm_allowed_actions
,
639 XA_ATOM
, 32, PropModeReplace
, (unsigned char *)action
, i
);
642 Bool
wNETWMGetUsableArea(WScreen
* scr
, int head
, WArea
* area
)
647 if (!scr
->netdata
|| !scr
->netdata
->strut
)
650 area
->x1
= area
->y1
= area
->x2
= area
->y2
= 0;
652 for (cur
= scr
->netdata
->strut
; cur
; cur
= cur
->next
) {
653 WWindow
*wwin
= wWindowFor(cur
->window
);
654 if (wWindowTouchesHead(wwin
, head
)) {
655 if (cur
->area
.x1
> area
->x1
)
656 area
->x1
= cur
->area
.x1
;
657 if (cur
->area
.y1
> area
->y1
)
658 area
->y1
= cur
->area
.y1
;
659 if (cur
->area
.x2
> area
->x2
)
660 area
->x2
= cur
->area
.x2
;
661 if (cur
->area
.y2
> area
->y2
)
662 area
->y2
= cur
->area
.y2
;
666 if (area
->x1
== 0 && area
->x2
== 0 && area
->y1
== 0 && area
->y2
== 0)
669 rect
= wGetRectForHead(scr
, head
);
671 area
->x1
= rect
.pos
.x
+ area
->x1
;
672 area
->x2
= rect
.pos
.x
+ rect
.size
.width
- area
->x2
;
673 area
->y1
= rect
.pos
.y
+ area
->y1
;
674 area
->y2
= rect
.pos
.y
+ rect
.size
.height
- area
->y2
;
679 static void updateClientList(WScreen
* scr
)
685 windows
= (Window
*) wmalloc(sizeof(Window
) * (scr
->window_count
+ 1));
688 wwin
= scr
->focused_window
;
690 windows
[count
++] = wwin
->client_win
;
693 XChangeProperty(dpy
, scr
->root_win
, net_client_list
, XA_WINDOW
, 32,
694 PropModeReplace
, (unsigned char *)windows
, count
);
700 static void updateClientListStacking(WScreen
* scr
, WWindow
* wwin_excl
)
704 Window
*client_list_reverse
;
710 /* update client list */
711 i
= scr
->window_count
+ 1;
712 client_list
= (Window
*) wmalloc(sizeof(Window
) * i
);
713 client_list_reverse
= (Window
*) wmalloc(sizeof(Window
) * i
);
716 WM_ETARETI_BAG(scr
->stacking_list
, tmp
, iter
) {
718 wwin
= wWindowFor(tmp
->window
);
719 /* wwin_excl is a window to exclude from the list
720 (e.g. it's now unmanaged) */
721 if (wwin
&& (wwin
!= wwin_excl
))
722 client_list
[client_count
++] = wwin
->client_win
;
723 tmp
= tmp
->stacking
->under
;
727 for (i
= 0; i
< client_count
; i
++) {
728 Window w
= client_list
[client_count
- i
- 1];
729 client_list_reverse
[i
] = w
;
732 XChangeProperty(dpy
, scr
->root_win
, net_client_list_stacking
, XA_WINDOW
, 32,
733 PropModeReplace
, (unsigned char *)client_list_reverse
, client_count
);
736 wfree(client_list_reverse
);
741 static void updateWorkspaceCount(WScreen
* scr
)
745 count
= scr
->workspace_count
;
747 XChangeProperty(dpy
, scr
->root_win
, net_number_of_desktops
, XA_CARDINAL
,
748 32, PropModeReplace
, (unsigned char *)&count
, 1);
751 static void updateCurrentWorkspace(WScreen
* scr
)
755 count
= scr
->current_workspace
;
757 XChangeProperty(dpy
, scr
->root_win
, net_current_desktop
, XA_CARDINAL
, 32,
758 PropModeReplace
, (unsigned char *)&count
, 1);
761 static void updateWorkspaceNames(WScreen
* scr
)
763 char buf
[MAX_WORKSPACES
* (MAX_WORKSPACENAME_WIDTH
+ 1)], *pos
;
764 unsigned int i
, len
, curr_size
;
768 for (i
= 0; i
< scr
->workspace_count
; i
++) {
769 curr_size
= strlen(scr
->workspaces
[i
]->name
);
770 strcpy(pos
, scr
->workspaces
[i
]->name
);
771 pos
+= (curr_size
+ 1);
772 len
+= (curr_size
+ 1);
775 XChangeProperty(dpy
, scr
->root_win
, net_desktop_names
, utf8_string
, 8,
776 PropModeReplace
, (unsigned char *)buf
, len
);
779 static void updateFocusHint(WScreen
* scr
, WWindow
* wwin
)
783 if (!scr
->focused_window
|| !scr
->focused_window
->flags
.focused
)
786 window
= scr
->focused_window
->client_win
;
788 XChangeProperty(dpy
, scr
->root_win
, net_active_window
, XA_WINDOW
, 32,
789 PropModeReplace
, (unsigned char *)&window
, 1);
792 static void updateWorkspaceHint(WWindow
* wwin
, Bool fake
, Bool del
)
797 XDeleteProperty(dpy
, wwin
->client_win
, net_wm_desktop
);
799 l
= ((fake
|| IS_OMNIPRESENT(wwin
)) ? -1 : wwin
->frame
->workspace
);
800 XChangeProperty(dpy
, wwin
->client_win
, net_wm_desktop
, XA_CARDINAL
,
801 32, PropModeReplace
, (unsigned char *)&l
, 1);
805 static void updateStateHint(WWindow
* wwin
, Bool changedWorkspace
, Bool del
)
808 XDeleteProperty(dpy
, wwin
->client_win
, net_wm_state
);
810 Atom state
[15]; /* nr of defined state atoms */
813 if (changedWorkspace
|| (wPreferences
.sticky_icons
&& !IS_OMNIPRESENT(wwin
)))
814 updateWorkspaceHint(wwin
, False
, False
);
816 if (IS_OMNIPRESENT(wwin
))
817 state
[i
++] = net_wm_state_sticky
;
818 if (wwin
->flags
.shaded
)
819 state
[i
++] = net_wm_state_shaded
;
820 if (wwin
->flags
.maximized
& MAX_HORIZONTAL
)
821 state
[i
++] = net_wm_state_maximized_horz
;
822 if (wwin
->flags
.maximized
& MAX_VERTICAL
)
823 state
[i
++] = net_wm_state_maximized_vert
;
824 if (WFLAGP(wwin
, skip_window_list
))
825 state
[i
++] = net_wm_state_skip_taskbar
;
826 if (wwin
->flags
.net_skip_pager
)
827 state
[i
++] = net_wm_state_skip_pager
;
828 if ((wwin
->flags
.hidden
|| wwin
->flags
.miniaturized
) && !wwin
->flags
.net_show_desktop
) {
829 state
[i
++] = net_wm_state_hidden
;
830 state
[i
++] = net_wm_state_skip_pager
;
832 if (wwin
->flags
.miniaturized
&& wPreferences
.sticky_icons
) {
833 if (!IS_OMNIPRESENT(wwin
))
834 updateWorkspaceHint(wwin
, True
, False
);
835 state
[i
++] = net_wm_state_sticky
;
838 if (WFLAGP(wwin
, sunken
))
839 state
[i
++] = net_wm_state_below
;
840 if (WFLAGP(wwin
, floating
))
841 state
[i
++] = net_wm_state_above
;
842 if (wwin
->flags
.fullscreen
)
843 state
[i
++] = net_wm_state_fullscreen
;
845 XChangeProperty(dpy
, wwin
->client_win
, net_wm_state
, XA_ATOM
, 32,
846 PropModeReplace
, (unsigned char *)state
, i
);
850 static Bool
updateStrut(WWindow
* wwin
, Bool adding
)
854 Bool hasState
= False
;
856 scr
= wwin
->screen_ptr
;
861 unsigned long nitems_ret
;
862 unsigned long bytes_after_ret
;
865 if (XGetWindowProperty(dpy
, wwin
->client_win
, net_wm_strut
, 0, 4, False
,
866 XA_CARDINAL
, &type_ret
, &fmt_ret
, &nitems_ret
,
867 &bytes_after_ret
, (unsigned char **)&data
) == Success
&& data
) {
869 area
= (WReservedArea
*) wmalloc(sizeof(WReservedArea
));
870 area
->area
.x1
= data
[0];
871 area
->area
.x2
= data
[1];
872 area
->area
.y1
= data
[2];
873 area
->area
.y2
= data
[3];
875 area
->window
= wwin
->client_win
;
877 area
->next
= scr
->netdata
->strut
;
878 scr
->netdata
->strut
= area
;
886 area
= scr
->netdata
->strut
;
889 if (area
->window
== wwin
->client_win
) {
890 scr
->netdata
->strut
= area
->next
;
894 while (area
->next
&& area
->next
->window
!= wwin
->client_win
)
900 next
= area
->next
->next
;
913 static int getWindowLayer(WWindow
* wwin
)
915 int layer
= WMNormalLevel
;
917 if (wwin
->type
== net_wm_window_type_desktop
) {
918 layer
= WMDesktopLevel
;
919 } else if (wwin
->type
== net_wm_window_type_dock
) {
921 } else if (wwin
->type
== net_wm_window_type_toolbar
) {
922 layer
= WMMainMenuLevel
;
923 } else if (wwin
->type
== net_wm_window_type_menu
) {
924 layer
= WMSubmenuLevel
;
925 } else if (wwin
->type
== net_wm_window_type_utility
) {
926 } else if (wwin
->type
== net_wm_window_type_splash
) {
927 } else if (wwin
->type
== net_wm_window_type_dialog
) {
928 if (wwin
->transient_for
) {
929 WWindow
*parent
= wWindowFor(wwin
->transient_for
);
930 if (parent
&& parent
->flags
.fullscreen
) {
931 layer
= WMFullscreenLevel
;
934 /* //layer = WMPopUpLevel; // this seems a bad idea -Dan */
935 } else if (wwin
->type
== net_wm_window_type_normal
) {
938 if (wwin
->client_flags
.sunken
&& WMSunkenLevel
< layer
)
939 layer
= WMSunkenLevel
;
940 if (wwin
->client_flags
.floating
&& WMFloatingLevel
> layer
)
941 layer
= WMFloatingLevel
;
946 static void doStateAtom(WWindow
* wwin
, Atom state
, int set
, Bool init
)
949 if (state
== net_wm_state_sticky
) {
950 if (set
== _NET_WM_STATE_TOGGLE
) {
951 set
= !IS_OMNIPRESENT(wwin
);
953 if (set
!= wwin
->flags
.omnipresent
) {
954 wWindowSetOmnipresent(wwin
, set
);
956 } else if (state
== net_wm_state_shaded
) {
957 if (set
== _NET_WM_STATE_TOGGLE
) {
958 set
= !wwin
->flags
.shaded
;
961 wwin
->flags
.shaded
= set
;
966 wUnshadeWindow(wwin
);
969 } else if (state
== net_wm_state_skip_taskbar
) {
970 if (set
== _NET_WM_STATE_TOGGLE
) {
971 set
= !wwin
->client_flags
.skip_window_list
;
973 wwin
->client_flags
.skip_window_list
= set
;
974 } else if (state
== net_wm_state_skip_pager
) {
975 if (set
== _NET_WM_STATE_TOGGLE
) {
976 set
= !wwin
->flags
.net_skip_pager
;
978 wwin
->flags
.net_skip_pager
= set
;
979 } else if (state
== net_wm_state_maximized_vert
) {
980 if (set
== _NET_WM_STATE_TOGGLE
) {
981 set
= !(wwin
->flags
.maximized
& MAX_VERTICAL
);
984 wwin
->flags
.maximized
|= (set
? MAX_VERTICAL
: 0);
987 wMaximizeWindow(wwin
, wwin
->flags
.maximized
| MAX_VERTICAL
);
989 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
);
1005 } else if (state
== net_wm_state_hidden
) {
1006 if (set
== _NET_WM_STATE_TOGGLE
) {
1007 set
= !(wwin
->flags
.miniaturized
);
1010 wwin
->flags
.miniaturized
= set
;
1013 wIconifyWindow(wwin
);
1015 wDeiconifyWindow(wwin
);
1018 } else if (state
== net_wm_state_fullscreen
) {
1019 if (set
== _NET_WM_STATE_TOGGLE
) {
1020 set
= !(wwin
->flags
.fullscreen
);
1023 wwin
->flags
.fullscreen
= set
;
1026 wFullscreenWindow(wwin
);
1028 wUnfullscreenWindow(wwin
);
1031 } else if (state
== net_wm_state_above
) {
1032 if (set
== _NET_WM_STATE_TOGGLE
) {
1033 set
= !(wwin
->client_flags
.floating
);
1036 wwin
->client_flags
.floating
= set
;
1038 wwin
->client_flags
.floating
= set
;
1039 ChangeStackingLevel(wwin
->frame
->core
, getWindowLayer(wwin
));
1042 } else if (state
== net_wm_state_below
) {
1043 if (set
== _NET_WM_STATE_TOGGLE
) {
1044 set
= !(wwin
->client_flags
.sunken
);
1047 wwin
->client_flags
.sunken
= set
;
1049 wwin
->client_flags
.sunken
= set
;
1050 ChangeStackingLevel(wwin
->frame
->core
, getWindowLayer(wwin
));
1055 wmessage("doStateAtom unknown atom %s set %d\n", XGetAtomName(dpy
, state
), set
);
1060 static void removeIcon(WWindow
* wwin
)
1062 if (wwin
->icon
== NULL
)
1064 if (wwin
->flags
.miniaturized
&& wwin
->icon
->mapped
) {
1065 XUnmapWindow(dpy
, wwin
->icon
->core
->window
);
1066 RemoveFromStackList(wwin
->icon
->core
);
1067 wIconDestroy(wwin
->icon
);
1072 static Bool
handleWindowType(WWindow
* wwin
, Atom type
, int *layer
)
1076 if (type
== net_wm_window_type_desktop
) {
1077 wwin
->client_flags
.no_titlebar
= 1;
1078 wwin
->client_flags
.no_resizable
= 1;
1079 wwin
->client_flags
.no_miniaturizable
= 1;
1080 wwin
->client_flags
.no_border
= 1;
1081 wwin
->client_flags
.no_resizebar
= 1;
1082 wwin
->client_flags
.no_shadeable
= 1;
1083 wwin
->client_flags
.no_movable
= 1;
1084 wwin
->client_flags
.omnipresent
= 1;
1085 wwin
->client_flags
.skip_window_list
= 1;
1086 wwin
->client_flags
.skip_switchpanel
= 1;
1087 wwin
->client_flags
.dont_move_off
= 1;
1088 wwin
->client_flags
.no_appicon
= 1;
1089 wwin
->flags
.net_skip_pager
= 1;
1092 } else if (type
== net_wm_window_type_dock
) {
1093 wwin
->client_flags
.no_titlebar
= 1;
1094 wwin
->client_flags
.no_resizable
= 1;
1095 wwin
->client_flags
.no_miniaturizable
= 1;
1096 wwin
->client_flags
.no_border
= 1; /* XXX: really not a single decoration. */
1097 wwin
->client_flags
.no_resizebar
= 1;
1098 wwin
->client_flags
.no_shadeable
= 1;
1099 wwin
->client_flags
.no_movable
= 1;
1100 wwin
->client_flags
.omnipresent
= 1;
1101 wwin
->client_flags
.skip_window_list
= 1;
1102 wwin
->client_flags
.skip_switchpanel
= 1;
1103 wwin
->client_flags
.dont_move_off
= 1;
1104 wwin
->flags
.net_skip_pager
= 1;
1105 } else if (type
== net_wm_window_type_toolbar
) {
1106 wwin
->client_flags
.no_titlebar
= 1;
1107 wwin
->client_flags
.no_resizable
= 1;
1108 wwin
->client_flags
.no_miniaturizable
= 1;
1109 wwin
->client_flags
.no_resizebar
= 1;
1110 wwin
->client_flags
.no_shadeable
= 1;
1111 wwin
->client_flags
.skip_window_list
= 1;
1112 wwin
->client_flags
.skip_switchpanel
= 1;
1113 wwin
->client_flags
.dont_move_off
= 1;
1114 wwin
->client_flags
.no_appicon
= 1;
1115 } else if (type
== net_wm_window_type_menu
) {
1116 wwin
->client_flags
.no_titlebar
= 1;
1117 wwin
->client_flags
.no_resizable
= 1;
1118 wwin
->client_flags
.no_miniaturizable
= 1;
1119 wwin
->client_flags
.no_resizebar
= 1;
1120 wwin
->client_flags
.no_shadeable
= 1;
1121 wwin
->client_flags
.skip_window_list
= 1;
1122 wwin
->client_flags
.skip_switchpanel
= 1;
1123 wwin
->client_flags
.dont_move_off
= 1;
1124 wwin
->client_flags
.no_appicon
= 1;
1125 } else if (type
== net_wm_window_type_utility
) {
1126 wwin
->client_flags
.no_appicon
= 1;
1127 } else if (type
== net_wm_window_type_splash
) {
1128 wwin
->client_flags
.no_titlebar
= 1;
1129 wwin
->client_flags
.no_resizable
= 1;
1130 wwin
->client_flags
.no_miniaturizable
= 1;
1131 wwin
->client_flags
.no_resizebar
= 1;
1132 wwin
->client_flags
.no_shadeable
= 1;
1133 wwin
->client_flags
.no_movable
= 1;
1134 wwin
->client_flags
.skip_window_list
= 1;
1135 wwin
->client_flags
.skip_switchpanel
= 1;
1136 wwin
->client_flags
.dont_move_off
= 1;
1137 wwin
->client_flags
.no_appicon
= 1;
1138 wwin
->flags
.net_skip_pager
= 1;
1139 } else if (type
== net_wm_window_type_dialog
) {
1140 /* These also seem a bad idea in our context -Dan
1141 // wwin->client_flags.skip_window_list = 1;
1142 // wwin->client_flags.no_appicon = 1;
1144 } else if (type
== net_wm_window_type_normal
) {
1150 *layer
= getWindowLayer(wwin
);
1155 void wNETWMPositionSplash(WWindow
* wwin
, int *x
, int *y
, int width
, int height
)
1157 if (wwin
->type
== net_wm_window_type_splash
) {
1158 WScreen
*scr
= wwin
->screen_ptr
;
1159 WMRect rect
= wGetRectForHead(scr
, wGetHeadForPointerLocation(scr
));
1160 *x
= rect
.pos
.x
+ (rect
.size
.width
- width
) / 2;
1161 *y
= rect
.pos
.y
+ (rect
.size
.height
- height
) / 2;
1165 static void updateWindowType(WWindow
* wwin
)
1169 unsigned long nitems_ret
;
1170 unsigned long bytes_after_ret
;
1173 if (XGetWindowProperty(dpy
, wwin
->client_win
, net_wm_window_type
, 0, 1,
1174 False
, XA_ATOM
, &type_ret
, &fmt_ret
, &nitems_ret
,
1175 &bytes_after_ret
, (unsigned char **)&data
) == Success
&& data
) {
1178 Atom
*type
= (Atom
*) data
;
1179 for (i
= 0; i
< nitems_ret
; ++i
) {
1180 if (handleWindowType(wwin
, type
[i
], &layer
))
1186 if (wwin
->frame
!= NULL
) {
1187 ChangeStackingLevel(wwin
->frame
->core
, layer
);
1188 wwin
->frame
->flags
.need_texture_change
= 1;
1189 wWindowConfigureBorders(wwin
);
1190 wFrameWindowPaint(wwin
->frame
);
1191 wNETWMUpdateActions(wwin
, False
);
1195 Bool
wNETWMCheckClientHints(WWindow
* wwin
, int *layer
, int *workspace
)
1199 unsigned long nitems_ret
;
1200 unsigned long bytes_after_ret
;
1202 Bool hasState
= False
;
1205 if (XGetWindowProperty(dpy
, wwin
->client_win
, net_wm_desktop
, 0, 1, False
,
1206 XA_CARDINAL
, &type_ret
, &fmt_ret
, &nitems_ret
,
1207 &bytes_after_ret
, (unsigned char **)&data
) == Success
&& data
) {
1209 long desktop
= *data
;
1213 wwin
->client_flags
.omnipresent
= 1;
1215 *workspace
= desktop
;
1220 if (XGetWindowProperty(dpy
, wwin
->client_win
, net_wm_state
, 0, 1, False
,
1221 XA_ATOM
, &type_ret
, &fmt_ret
, &nitems_ret
,
1222 &bytes_after_ret
, (unsigned char **)&data
) == Success
&& data
) {
1224 Atom
*state
= (Atom
*) data
;
1225 for (i
= 0; i
< nitems_ret
; ++i
) {
1226 doStateAtom(wwin
, state
[i
], _NET_WM_STATE_ADD
, True
);
1232 if (XGetWindowProperty(dpy
, wwin
->client_win
, net_wm_window_type
, 0, 1, False
,
1233 XA_ATOM
, &type_ret
, &fmt_ret
, &nitems_ret
,
1234 &bytes_after_ret
, (unsigned char **)&data
) == Success
&& data
) {
1236 Atom
*type
= (Atom
*) data
;
1237 for (i
= 0; i
< nitems_ret
; ++i
) {
1238 if (handleWindowType(wwin
, type
[i
], layer
))
1245 wNETWMUpdateActions(wwin
, False
);
1246 updateStrut(wwin
, False
);
1247 if (updateStrut(wwin
, True
)) {
1250 wScreenUpdateUsableArea(wwin
->screen_ptr
);
1255 static Bool
updateNetIconInfo(WWindow
* wwin
)
1260 unsigned long nitems_ret
;
1261 unsigned long bytes_after_ret
;
1263 Bool hasState
= False
;
1264 Bool old_state
= wwin
->flags
.net_handle_icon
;
1266 if (XGetWindowProperty(dpy
, wwin
->client_win
, net_wm_handled_icons
, 0, 1, False
,
1267 XA_CARDINAL
, &type_ret
, &fmt_ret
, &nitems_ret
,
1268 &bytes_after_ret
, (unsigned char **)&data
) == Success
&& data
) {
1269 long handled
= *data
;
1270 wwin
->flags
.net_handle_icon
= (handled
!= 0);
1275 wwin
->flags
.net_handle_icon
= False
;
1277 if (XGetWindowProperty(dpy
, wwin
->client_win
, net_wm_icon_geometry
, 0, 4, False
,
1278 XA_CARDINAL
, &type_ret
, &fmt_ret
, &nitems_ret
,
1279 &bytes_after_ret
, (unsigned char **)&data
) == Success
&& data
) {
1282 if (wwin
->flags
.net_handle_icon
)
1284 wwin
->flags
.net_handle_icon
= True
;
1287 wwin
->icon_x
= data
[0];
1288 wwin
->icon_y
= data
[1];
1289 wwin
->icon_w
= data
[2];
1290 wwin
->icon_h
= data
[3];
1297 wwin
->flags
.net_handle_icon
= False
;
1299 if (wwin
->flags
.miniaturized
&& old_state
!= wwin
->flags
.net_handle_icon
) {
1300 if (wwin
->flags
.net_handle_icon
) {
1303 wwin
->flags
.miniaturized
= False
;
1304 wwin
->flags
.skip_next_animation
= True
;
1305 wIconifyWindow(wwin
);
1312 Bool
wNETWMCheckInitialClientState(WWindow
* wwin
)
1314 Bool hasState
= False
;
1320 wNETWMShowingDesktop(wwin
->screen_ptr
, False
);
1322 hasState
|= updateNetIconInfo(wwin
);
1324 updateIconImage(wwin
);
1329 static void handleDesktopNames(XClientMessageEvent
* event
, WScreen
* scr
)
1331 unsigned long nitems_ret
, bytes_after_ret
;
1332 char *data
, *names
[32];
1336 if (XGetWindowProperty(dpy
, scr
->root_win
, net_desktop_names
, 0, 1, False
,
1337 utf8_string
, &type_ret
, &fmt_ret
, &nitems_ret
,
1338 &bytes_after_ret
, (unsigned char **)&data
) != Success
) {
1345 if (type_ret
!= utf8_string
|| fmt_ret
!= 8)
1350 for (i
= 0; i
< nitems_ret
; i
++) {
1353 names
[n
] = &data
[i
];
1354 } else if (*names
[n
] == 0) {
1355 names
[n
] = &data
[i
];
1356 wWorkspaceRename(scr
, n
, names
[n
]);
1361 Bool
wNETWMProcessClientMessage(XClientMessageEvent
* event
)
1368 wmessage("processClientMessage type %s\n", XGetAtomName(dpy
, event
->message_type
));
1371 scr
= wScreenForWindow(event
->window
);
1373 /* generic client messages */
1374 if (event
->message_type
== net_current_desktop
) {
1375 wWorkspaceChange(scr
, event
->data
.l
[0]);
1376 } else if (event
->message_type
== net_number_of_desktops
) {
1379 value
= event
->data
.l
[0];
1380 if (value
> scr
->workspace_count
) {
1381 wWorkspaceMake(scr
, value
- scr
->workspace_count
);
1382 } else if (value
< scr
->workspace_count
) {
1384 Bool rebuild
= False
;
1386 for (i
= scr
->workspace_count
- 1; i
>= value
; i
--) {
1387 if (!wWorkspaceDelete(scr
, i
)) {
1394 updateWorkspaceCount(scr
);
1397 } else if (event
->message_type
== net_showing_desktop
) {
1398 wNETWMShowingDesktop(scr
, event
->data
.l
[0]);
1399 } else if (event
->message_type
== net_desktop_names
) {
1400 handleDesktopNames(event
, scr
);
1409 /* window specific client messages */
1411 wwin
= wWindowFor(event
->window
);
1415 if (event
->message_type
== net_active_window
) {
1417 * Satisfy a client's focus request only if
1418 * - request comes from a pager, or
1419 * - it's explicitly allowed in Advanced Options, or
1420 * - giving the client the focus does not cause a change in
1421 * the active workspace (XXX: or the active head if Xinerama)
1423 if (wwin
->frame
->workspace
== wwin
->screen_ptr
->current_workspace
/* No workspace change */
1424 || event
->data
.l
[0] == 2 /* Requested by pager */
1425 || WFLAGP(wwin
, focus_across_wksp
) /* Explicitly allowed */) {
1426 wNETWMShowingDesktop(scr
, False
);
1427 wMakeWindowVisible(wwin
);
1429 } else if (event
->message_type
== net_close_window
) {
1430 if (!WFLAGP(wwin
, no_closable
)) {
1431 if (wwin
->protocols
.DELETE_WINDOW
)
1432 wClientSendProtocol(wwin
, _XA_WM_DELETE_WINDOW
, LastTimestamp
);
1434 } else if (event
->message_type
== net_wm_state
) {
1435 int maximized
= wwin
->flags
.maximized
;
1436 long set
= event
->data
.l
[0];
1439 wmessage("net_wm_state set %ld a1 %s a2 %s\n", set
,
1440 XGetAtomName(dpy
, event
->data
.l
[1]), XGetAtomName(dpy
, event
->data
.l
[2]));
1443 doStateAtom(wwin
, (Atom
) event
->data
.l
[1], set
, False
);
1444 if (event
->data
.l
[2])
1445 doStateAtom(wwin
, (Atom
) event
->data
.l
[2], set
, False
);
1447 if (wwin
->flags
.maximized
!= maximized
) {
1448 if (!wwin
->flags
.maximized
) {
1449 wwin
->flags
.maximized
= maximized
;
1450 wUnmaximizeWindow(wwin
);
1452 wMaximizeWindow(wwin
, wwin
->flags
.maximized
);
1455 updateStateHint(wwin
, False
, False
);
1456 } else if (event
->message_type
== net_wm_handled_icons
|| event
->message_type
== net_wm_icon_geometry
) {
1457 updateNetIconInfo(wwin
);
1458 } else if (event
->message_type
== net_wm_desktop
) {
1459 long desktop
= event
->data
.l
[0];
1460 if (desktop
== -1) {
1461 wWindowSetOmnipresent(wwin
, True
);
1463 if (IS_OMNIPRESENT(wwin
))
1464 wWindowSetOmnipresent(wwin
, False
);
1465 wWindowChangeWorkspace(wwin
, desktop
);
1474 Bool
wNETWMCheckClientHintChange(WWindow
* wwin
, XPropertyEvent
* event
)
1479 wmessage("clientHintChange type %s\n", XGetAtomName(dpy
, event
->atom
));
1482 if (event
->atom
== net_wm_strut
) {
1483 updateStrut(wwin
, False
);
1484 updateStrut(wwin
, True
);
1485 wScreenUpdateUsableArea(wwin
->screen_ptr
);
1486 } else if (event
->atom
== net_wm_handled_icons
|| event
->atom
== net_wm_icon_geometry
) {
1487 updateNetIconInfo(wwin
);
1488 } else if (event
->atom
== net_wm_window_type
) {
1489 updateWindowType(wwin
);
1490 } else if (event
->atom
== net_wm_name
) {
1491 char *name
= wNETWMGetWindowName(wwin
->client_win
);
1492 wWindowUpdateName(wwin
, name
);
1495 } else if (event
->atom
== net_wm_icon_name
) {
1497 char *name
= wNETWMGetIconName(wwin
->client_win
);
1498 wIconChangeTitle(wwin
->icon
, name
);
1500 } else if (event
->atom
== net_wm_icon
) {
1501 updateIconImage(wwin
);
1509 int wNETWMGetPidForWindow(Window window
)
1513 unsigned long nitems_ret
;
1514 unsigned long bytes_after_ret
;
1518 if (XGetWindowProperty(dpy
, window
, net_wm_pid
, 0, 1, False
,
1519 XA_CARDINAL
, &type_ret
, &fmt_ret
, &nitems_ret
,
1520 &bytes_after_ret
, (unsigned char **)&data
) == Success
&& data
) {
1531 char *wNETWMGetWindowName(Window window
)
1537 name
= (char *)PropGetCheckProperty(window
, net_wm_name
, utf8_string
, 0, 0, &size
);
1539 ret
= wstrndup(name
, size
);
1546 char *wNETWMGetIconName(Window window
)
1552 name
= (char *)PropGetCheckProperty(window
, net_wm_icon_name
, utf8_string
, 0, 0, &size
);
1554 ret
= wstrndup(name
, size
);
1561 static void observer(void *self
, WMNotification
* notif
)
1563 WWindow
*wwin
= (WWindow
*) WMGetNotificationObject(notif
);
1564 const char *name
= WMGetNotificationName(notif
);
1565 void *data
= WMGetNotificationClientData(notif
);
1566 NetData
*ndata
= (NetData
*) self
;
1568 if (strcmp(name
, WMNManaged
) == 0 && wwin
) {
1569 updateClientList(wwin
->screen_ptr
);
1570 updateClientListStacking(wwin
->screen_ptr
, NULL
);
1571 updateStateHint(wwin
, True
, False
);
1573 updateStrut(wwin
, False
);
1574 updateStrut(wwin
, True
);
1575 wScreenUpdateUsableArea(wwin
->screen_ptr
);
1576 } else if (strcmp(name
, WMNUnmanaged
) == 0 && wwin
) {
1577 updateClientList(wwin
->screen_ptr
);
1578 updateClientListStacking(wwin
->screen_ptr
, wwin
);
1579 updateWorkspaceHint(wwin
, False
, True
);
1580 updateStateHint(wwin
, False
, True
);
1581 wNETWMUpdateActions(wwin
, True
);
1583 updateStrut(wwin
, False
);
1584 wScreenUpdateUsableArea(wwin
->screen_ptr
);
1585 } else if (strcmp(name
, WMNResetStacking
) == 0 && wwin
) {
1586 updateClientListStacking(wwin
->screen_ptr
, NULL
);
1587 updateStateHint(wwin
, False
, False
);
1588 } else if (strcmp(name
, WMNChangedStacking
) == 0 && wwin
) {
1589 updateClientListStacking(wwin
->screen_ptr
, NULL
);
1590 updateStateHint(wwin
, False
, False
);
1591 } else if (strcmp(name
, WMNChangedFocus
) == 0) {
1592 updateFocusHint(ndata
->scr
, wwin
);
1593 } else if (strcmp(name
, WMNChangedWorkspace
) == 0 && wwin
) {
1594 updateWorkspaceHint(wwin
, False
, False
);
1595 updateStateHint(wwin
, True
, False
);
1596 } else if (strcmp(name
, WMNChangedState
) == 0 && wwin
) {
1597 updateStateHint(wwin
, !strcmp(data
, "omnipresent"), False
);
1601 static void wsobserver(void *self
, WMNotification
* notif
)
1603 WScreen
*scr
= (WScreen
*) WMGetNotificationObject(notif
);
1604 const char *name
= WMGetNotificationName(notif
);
1606 if (strcmp(name
, WMNWorkspaceCreated
) == 0) {
1607 updateWorkspaceCount(scr
);
1608 updateWorkspaceNames(scr
);
1609 } else if (strcmp(name
, WMNWorkspaceDestroyed
) == 0) {
1610 updateWorkspaceCount(scr
);
1611 updateWorkspaceNames(scr
);
1612 } else if (strcmp(name
, WMNWorkspaceChanged
) == 0) {
1613 updateCurrentWorkspace(scr
);
1614 } else if (strcmp(name
, WMNWorkspaceNameChanged
) == 0) {
1615 updateWorkspaceNames(scr
);
1619 void wNETFrameExtents(WWindow
*wwin
)
1621 long extents
[4] = { 0, 0, 0, 0 };
1623 /* The extents array describes dimensions which are not
1624 * part of the client window. In our case that means
1625 * widths of the border and heights of the titlebar and resizebar.
1632 if (wwin
->frame
->titlebar
)
1633 extents
[2] = wwin
->frame
->titlebar
->height
;
1634 if (wwin
->frame
->resizebar
)
1635 extents
[3] = wwin
->frame
->resizebar
->height
;
1636 if (HAS_BORDER(wwin
)) {
1637 extents
[0] += FRAME_BORDER_WIDTH
;
1638 extents
[1] += FRAME_BORDER_WIDTH
;
1639 extents
[2] += FRAME_BORDER_WIDTH
;
1640 extents
[3] += FRAME_BORDER_WIDTH
;
1643 XChangeProperty(dpy
, wwin
->client_win
, net_frame_extents
, XA_CARDINAL
, 32, PropModeReplace
, (unsigned char *) extents
, 4);
1646 void wNETCleanupFrameExtents(WWindow
*wwin
)
1648 XDeleteProperty(dpy
, wwin
->client_win
, net_frame_extents
);