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 /* Window Manager Protocols */
124 static Atom net_wm_ping
; /* TODO */
126 static Atom utf8_string
;
133 static atomitem_t atomNames
[] = {
134 {"_NET_SUPPORTED", &net_supported
},
135 {"_NET_CLIENT_LIST", &net_client_list
},
136 {"_NET_CLIENT_LIST_STACKING", &net_client_list_stacking
},
137 {"_NET_NUMBER_OF_DESKTOPS", &net_number_of_desktops
},
138 {"_NET_DESKTOP_GEOMETRY", &net_desktop_geometry
},
139 {"_NET_DESKTOP_VIEWPORT", &net_desktop_viewport
},
140 {"_NET_CURRENT_DESKTOP", &net_current_desktop
},
141 {"_NET_DESKTOP_NAMES", &net_desktop_names
},
142 {"_NET_ACTIVE_WINDOW", &net_active_window
},
143 {"_NET_SUPPORTING_WM_CHECK", &net_supporting_wm_check
},
144 {"_NET_VIRTUAL_ROOTS", &net_virtual_roots
},
145 {"_NET_DESKTOP_LAYOUT", &net_desktop_layout
},
146 {"_NET_SHOWING_DESKTOP", &net_showing_desktop
},
148 {"_NET_CLOSE_WINDOW", &net_close_window
},
149 {"_NET_MOVERESIZE_WINDOW", &net_moveresize_window
},
150 {"_NET_WM_MOVERESIZE", &net_wm_moveresize
},
152 {"_NET_WM_NAME", &net_wm_name
},
153 {"_NET_WM_VISIBLE_NAME", &net_wm_visible_name
},
154 {"_NET_WM_ICON_NAME", &net_wm_icon_name
},
155 {"_NET_WM_VISIBLE_ICON_NAME", &net_wm_visible_icon_name
},
156 {"_NET_WM_DESKTOP", &net_wm_desktop
},
157 {"_NET_WM_WINDOW_TYPE", &net_wm_window_type
},
158 {"_NET_WM_WINDOW_TYPE_DESKTOP", &net_wm_window_type_desktop
},
159 {"_NET_WM_WINDOW_TYPE_DOCK", &net_wm_window_type_dock
},
160 {"_NET_WM_WINDOW_TYPE_TOOLBAR", &net_wm_window_type_toolbar
},
161 {"_NET_WM_WINDOW_TYPE_MENU", &net_wm_window_type_menu
},
162 {"_NET_WM_WINDOW_TYPE_UTILITY", &net_wm_window_type_utility
},
163 {"_NET_WM_WINDOW_TYPE_SPLASH", &net_wm_window_type_splash
},
164 {"_NET_WM_WINDOW_TYPE_DIALOG", &net_wm_window_type_dialog
},
165 {"_NET_WM_WINDOW_TYPE_NORMAL", &net_wm_window_type_normal
},
166 {"_NET_WM_STATE", &net_wm_state
},
167 {"_NET_WM_STATE_MODAL", &net_wm_state_modal
},
168 {"_NET_WM_STATE_STICKY", &net_wm_state_sticky
},
169 {"_NET_WM_STATE_MAXIMIZED_VERT", &net_wm_state_maximized_vert
},
170 {"_NET_WM_STATE_MAXIMIZED_HORZ", &net_wm_state_maximized_horz
},
171 {"_NET_WM_STATE_SHADED", &net_wm_state_shaded
},
172 {"_NET_WM_STATE_SKIP_TASKBAR", &net_wm_state_skip_taskbar
},
173 {"_NET_WM_STATE_SKIP_PAGER", &net_wm_state_skip_pager
},
174 {"_NET_WM_STATE_HIDDEN", &net_wm_state_hidden
},
175 {"_NET_WM_STATE_FULLSCREEN", &net_wm_state_fullscreen
},
176 {"_NET_WM_STATE_ABOVE", &net_wm_state_above
},
177 {"_NET_WM_STATE_BELOW", &net_wm_state_below
},
178 {"_NET_WM_ALLOWED_ACTIONS", &net_wm_allowed_actions
},
179 {"_NET_WM_ACTION_MOVE", &net_wm_action_move
},
180 {"_NET_WM_ACTION_RESIZE", &net_wm_action_resize
},
181 {"_NET_WM_ACTION_MINIMIZE", &net_wm_action_minimize
},
182 {"_NET_WM_ACTION_SHADE", &net_wm_action_shade
},
183 {"_NET_WM_ACTION_STICK", &net_wm_action_stick
},
184 {"_NET_WM_ACTION_MAXIMIZE_HORZ", &net_wm_action_maximize_horz
},
185 {"_NET_WM_ACTION_MAXIMIZE_VERT", &net_wm_action_maximize_vert
},
186 {"_NET_WM_ACTION_FULLSCREEN", &net_wm_action_fullscreen
},
187 {"_NET_WM_ACTION_CHANGE_DESKTOP", &net_wm_action_change_desktop
},
188 {"_NET_WM_ACTION_CLOSE", &net_wm_action_close
},
189 {"_NET_WM_STRUT", &net_wm_strut
},
190 {"_NET_WM_STRUT_PARTIAL", &net_wm_strut_partial
},
191 {"_NET_WM_ICON_GEOMETRY", &net_wm_icon_geometry
},
192 {"_NET_WM_ICON", &net_wm_icon
},
193 {"_NET_WM_PID", &net_wm_pid
},
194 {"_NET_WM_HANDLED_ICONS", &net_wm_handled_icons
},
196 {"_NET_WM_PING", &net_wm_ping
},
198 {"UTF8_STRING", &utf8_string
},
201 #define atomNr (sizeof(atomNames)/sizeof(atomitem_t))
203 #define _NET_WM_STATE_REMOVE 0
204 #define _NET_WM_STATE_ADD 1
205 #define _NET_WM_STATE_TOGGLE 2
207 #define _NET_WM_MOVERESIZE_SIZE_TOPLEFT 0
208 #define _NET_WM_MOVERESIZE_SIZE_TOP 1
209 #define _NET_WM_MOVERESIZE_SIZE_TOPRIGHT 2
210 #define _NET_WM_MOVERESIZE_SIZE_RIGHT 3
211 #define _NET_WM_MOVERESIZE_SIZE_BOTTOMRIGHT 4
212 #define _NET_WM_MOVERESIZE_SIZE_BOTTOM 5
213 #define _NET_WM_MOVERESIZE_SIZE_BOTTOMLEFT 6
214 #define _NET_WM_MOVERESIZE_SIZE_LEFT 7
215 #define _NET_WM_MOVERESIZE_MOVE 8 /* movement only */
216 #define _NET_WM_MOVERESIZE_SIZE_KEYBOARD 9 /* size via keyboard */
217 #define _NET_WM_MOVERESIZE_MOVE_KEYBOARD 10 /* move via keyboard */
219 static void observer(void *self
, WMNotification
* notif
);
220 static void wsobserver(void *self
, WMNotification
* notif
);
222 static void updateClientList(WScreen
* scr
);
223 static void updateClientListStacking(WScreen
* scr
, WWindow
*);
225 static void updateWorkspaceNames(WScreen
* scr
);
226 static void updateCurrentWorkspace(WScreen
* scr
);
227 static void updateWorkspaceCount(WScreen
* scr
);
229 typedef struct NetData
{
231 WReservedArea
*strut
;
232 WWindow
**show_desktop
;
235 static void setSupportedHints(WScreen
* scr
)
240 /* set supported hints list */
241 /* XXX: extend this !!! */
243 atom
[i
++] = net_client_list
;
244 atom
[i
++] = net_client_list_stacking
;
245 atom
[i
++] = net_number_of_desktops
;
246 atom
[i
++] = net_desktop_geometry
;
247 atom
[i
++] = net_desktop_viewport
;
248 atom
[i
++] = net_current_desktop
;
249 atom
[i
++] = net_desktop_names
;
250 atom
[i
++] = net_active_window
;
251 atom
[i
++] = net_supporting_wm_check
;
252 atom
[i
++] = net_showing_desktop
;
254 atom
[i
++] = net_wm_moveresize
;
256 atom
[i
++] = net_wm_desktop
;
257 atom
[i
++] = net_wm_window_type
;
258 atom
[i
++] = net_wm_window_type_desktop
;
259 atom
[i
++] = net_wm_window_type_dock
;
260 atom
[i
++] = net_wm_window_type_toolbar
;
261 atom
[i
++] = net_wm_window_type_menu
;
262 atom
[i
++] = net_wm_window_type_utility
;
263 atom
[i
++] = net_wm_window_type_splash
;
264 atom
[i
++] = net_wm_window_type_dialog
;
265 atom
[i
++] = net_wm_window_type_normal
;
267 atom
[i
++] = net_wm_state
;
268 /* atom[i++] = net_wm_state_modal; *//* XXX: not sure where/when to use it. */
269 atom
[i
++] = net_wm_state_sticky
;
270 atom
[i
++] = net_wm_state_shaded
;
271 atom
[i
++] = net_wm_state_maximized_horz
;
272 atom
[i
++] = net_wm_state_maximized_vert
;
273 atom
[i
++] = net_wm_state_skip_taskbar
;
274 atom
[i
++] = net_wm_state_skip_pager
;
275 atom
[i
++] = net_wm_state_hidden
;
276 atom
[i
++] = net_wm_state_fullscreen
;
277 atom
[i
++] = net_wm_state_above
;
278 atom
[i
++] = net_wm_state_below
;
280 atom
[i
++] = net_wm_allowed_actions
;
281 atom
[i
++] = net_wm_action_move
;
282 atom
[i
++] = net_wm_action_resize
;
283 atom
[i
++] = net_wm_action_minimize
;
284 atom
[i
++] = net_wm_action_shade
;
285 atom
[i
++] = net_wm_action_stick
;
286 atom
[i
++] = net_wm_action_maximize_horz
;
287 atom
[i
++] = net_wm_action_maximize_vert
;
288 atom
[i
++] = net_wm_action_fullscreen
;
289 atom
[i
++] = net_wm_action_change_desktop
;
290 atom
[i
++] = net_wm_action_close
;
292 atom
[i
++] = net_wm_strut
;
293 atom
[i
++] = net_wm_icon_geometry
;
294 atom
[i
++] = net_wm_icon
;
295 atom
[i
++] = net_wm_handled_icons
;
297 atom
[i
++] = net_wm_name
;
298 atom
[i
++] = net_wm_icon_name
;
300 XChangeProperty(dpy
, scr
->root_win
, net_supported
, XA_ATOM
, 32, PropModeReplace
, (unsigned char *)atom
, i
);
302 /* set supporting wm hint */
303 XChangeProperty(dpy
, scr
->root_win
, net_supporting_wm_check
, XA_WINDOW
, 32,
304 PropModeReplace
, (unsigned char *)&scr
->info_window
, 1);
306 XChangeProperty(dpy
, scr
->info_window
, net_supporting_wm_check
, XA_WINDOW
,
307 32, PropModeReplace
, (unsigned char *)&scr
->info_window
, 1);
310 void wNETWMUpdateDesktop(WScreen
* scr
)
312 long *views
, sizes
[2];
315 if (scr
->workspace_count
== 0)
318 count
= scr
->workspace_count
* 2;
319 views
= wmalloc(sizeof(long) * count
);
320 /*memset(views, 0, sizeof(long) * count); */
321 sizes
[0] = scr
->scr_width
;
322 sizes
[1] = scr
->scr_height
;
324 for (i
= 0; i
< scr
->workspace_count
; i
++) {
325 views
[2 * i
+ 0] = 0;
326 views
[2 * i
+ 1] = 0;
329 XChangeProperty(dpy
, scr
->root_win
, net_desktop_geometry
, XA_CARDINAL
, 32,
330 PropModeReplace
, (unsigned char *)sizes
, 2);
332 XChangeProperty(dpy
, scr
->root_win
, net_desktop_viewport
, XA_CARDINAL
, 32,
333 PropModeReplace
, (unsigned char *)views
, count
);
338 int wNETWMGetCurrentDesktopFromHint(WScreen
* scr
)
343 prop
= PropGetCheckProperty(scr
->root_win
, net_current_desktop
, XA_CARDINAL
, 0, 1, &count
);
345 int desktop
= *(long *)prop
;
353 * Find the best icon to be used by Window Maker for appicon/miniwindows.
354 * Currently the algorithm is to take the image with the size closest
355 * to icon_size x icon_size, but never bigger than that.
357 * This algorithm is very poorly implemented and needs to be redone (it can
358 * easily select images with very large widths and very small heights over
359 * square images, if the area of the former is closer to the desired one).
361 * The logic can also be changed to accept bigger images and scale them down.
363 static unsigned long *findBestIcon(unsigned long *data
, unsigned long items
)
366 unsigned long i
, distance
;
369 /* better use only 75% of icon_size. For 64x64 this means 48x48
370 * This leaves room around the icon for the miniwindow title and
371 * results in better overall aesthetics -Dan */
372 wanted
= wPreferences
.icon_size
* wPreferences
.icon_size
;
374 for (icon
= NULL
, distance
= wanted
, i
= 0L; i
< items
- 1;) {
375 size
= data
[i
] * data
[i
+ 1];
379 if (d
>= 0 && d
<= distance
&& (i
+ size
+ 2) <= items
) {
389 static RImage
*makeRImageFromARGBData(unsigned long *data
)
391 int size
, width
, height
, i
;
393 unsigned char *imgdata
;
398 size
= width
* height
;
403 image
= RCreateImage(width
, height
, True
);
405 for (imgdata
= image
->data
, i
= 2; i
< size
+ 2; i
++, imgdata
+= 4) {
407 imgdata
[3] = (pixel
>> 24) & 0xff; /* A */
408 imgdata
[0] = (pixel
>> 16) & 0xff; /* R */
409 imgdata
[1] = (pixel
>> 8) & 0xff; /* G */
410 imgdata
[2] = (pixel
>> 0) & 0xff; /* B */
416 static RImage
*get_wwindow_image_from_x11(WWindow
*wwin
)
421 unsigned long items
, rest
;
422 unsigned long *property
, *data
;
424 /* Get the icon from X11 Window */
425 if (XGetWindowProperty(dpy
, wwin
->client_win
, net_wm_icon
, 0L, LONG_MAX
,
426 False
, XA_CARDINAL
, &type
, &format
, &items
, &rest
,
427 (unsigned char **)&property
) != Success
|| !property
)
430 if (type
!= XA_CARDINAL
|| format
!= 32 || items
< 2) {
435 /* Find the best icon */
436 data
= findBestIcon(property
, items
);
442 /* Save the best icon in the X11 icon */
443 image
= makeRImageFromARGBData(data
);
449 static void updateIconImage(WWindow
*wwin
)
451 /* Remove the icon image from X11 */
452 if (wwin
->net_icon_image
)
453 RReleaseImage(wwin
->net_icon_image
);
455 /* Save the icon in the X11 icon */
456 wwin
->net_icon_image
= get_wwindow_image_from_x11(wwin
);
458 /* Refresh the Window Icon */
460 wIconUpdate(wwin
->icon
);
462 /* Refresh the application icon */
463 WApplication
*app
= wApplicationOf(wwin
->main_window
);
464 if (app
&& app
->app_icon
) {
465 wIconUpdate(app
->app_icon
->icon
);
466 wAppIconPaint(app
->app_icon
);
470 static void updateShowDesktop(WScreen
* scr
, Bool show
)
474 foo
= (show
== True
);
475 XChangeProperty(dpy
, scr
->root_win
, net_showing_desktop
, XA_CARDINAL
, 32,
476 PropModeReplace
, (unsigned char *)&foo
, 1);
479 void wNETWMShowingDesktop(WScreen
* scr
, Bool show
)
481 if (show
&& scr
->netdata
->show_desktop
== NULL
) {
482 WWindow
*tmp
, **wins
;
485 wins
= (WWindow
**) wmalloc(sizeof(WWindow
*) * (scr
->window_count
+ 1));
487 tmp
= scr
->focused_window
;
489 if (!tmp
->flags
.hidden
&& !tmp
->flags
.miniaturized
&& !WFLAGP(tmp
, skip_window_list
)) {
492 tmp
->flags
.skip_next_animation
= 1;
493 tmp
->flags
.net_show_desktop
= 1;
501 scr
->netdata
->show_desktop
= wins
;
502 updateShowDesktop(scr
, True
);
503 } else if (scr
->netdata
->show_desktop
!= NULL
) {
504 /* FIXME: get rid of workspace flashing ! */
505 int ws
= scr
->current_workspace
;
507 for (tmp
= scr
->netdata
->show_desktop
; *tmp
; ++tmp
) {
508 wDeiconifyWindow(*tmp
);
509 (*tmp
)->flags
.net_show_desktop
= 0;
511 if (ws
!= scr
->current_workspace
)
512 wWorkspaceChange(scr
, ws
);
513 wfree(scr
->netdata
->show_desktop
);
514 scr
->netdata
->show_desktop
= NULL
;
515 updateShowDesktop(scr
, False
);
519 void wNETWMInitStuff(WScreen
* scr
)
528 #ifdef HAVE_XINTERNATOMS
533 for (i
= 0; i
< atomNr
; ++i
) {
534 names
[i
] = atomNames
[i
].name
;
536 XInternAtoms(dpy
, &names
[0], atomNr
, False
, atoms
);
537 for (i
= 0; i
< atomNr
; ++i
) {
538 *atomNames
[i
].atom
= atoms
[i
];
542 for (i
= 0; i
< atomNr
; i
++) {
543 *atomNames
[i
].atom
= XInternAtom(dpy
, atomNames
[i
].name
, False
);
547 data
= wmalloc(sizeof(NetData
));
550 data
->show_desktop
= NULL
;
554 setSupportedHints(scr
);
556 WMAddNotificationObserver(observer
, data
, WMNManaged
, NULL
);
557 WMAddNotificationObserver(observer
, data
, WMNUnmanaged
, NULL
);
558 WMAddNotificationObserver(observer
, data
, WMNChangedWorkspace
, NULL
);
559 WMAddNotificationObserver(observer
, data
, WMNChangedState
, NULL
);
560 WMAddNotificationObserver(observer
, data
, WMNChangedFocus
, NULL
);
561 WMAddNotificationObserver(observer
, data
, WMNChangedStacking
, NULL
);
562 WMAddNotificationObserver(observer
, data
, WMNChangedName
, NULL
);
564 WMAddNotificationObserver(wsobserver
, data
, WMNWorkspaceCreated
, NULL
);
565 WMAddNotificationObserver(wsobserver
, data
, WMNWorkspaceDestroyed
, NULL
);
566 WMAddNotificationObserver(wsobserver
, data
, WMNWorkspaceChanged
, NULL
);
567 WMAddNotificationObserver(wsobserver
, data
, WMNWorkspaceNameChanged
, NULL
);
569 updateClientList(scr
);
570 updateClientListStacking(scr
, NULL
);
571 updateWorkspaceCount(scr
);
572 updateWorkspaceNames(scr
);
573 updateShowDesktop(scr
, False
);
575 wScreenUpdateUsableArea(scr
);
578 void wNETWMCleanup(WScreen
* scr
)
582 for (i
= 0; i
< atomNr
; i
++)
583 XDeleteProperty(dpy
, scr
->root_win
, *atomNames
[i
].atom
);
586 void wNETWMUpdateActions(WWindow
* wwin
, Bool del
)
588 Atom action
[10]; /* nr of actions atoms defined */
592 XDeleteProperty(dpy
, wwin
->client_win
, net_wm_allowed_actions
);
596 if (IS_MOVABLE(wwin
))
597 action
[i
++] = net_wm_action_move
;
599 if (IS_RESIZABLE(wwin
))
600 action
[i
++] = net_wm_action_resize
;
602 if (!WFLAGP(wwin
, no_miniaturizable
))
603 action
[i
++] = net_wm_action_minimize
;
605 if (!WFLAGP(wwin
, no_shadeable
))
606 action
[i
++] = net_wm_action_shade
;
608 /* if (!WFLAGP(wwin, no_stickable)) */
609 action
[i
++] = net_wm_action_stick
;
611 /* if (!(WFLAGP(wwin, no_maximizeable) & MAX_HORIZONTAL)) */
612 if (IS_RESIZABLE(wwin
))
613 action
[i
++] = net_wm_action_maximize_horz
;
615 /* if (!(WFLAGP(wwin, no_maximizeable) & MAX_VERTICAL)) */
616 if (IS_RESIZABLE(wwin
))
617 action
[i
++] = net_wm_action_maximize_vert
;
619 /* if (!WFLAGP(wwin, no_fullscreen)) */
620 action
[i
++] = net_wm_action_fullscreen
;
622 /* if (!WFLAGP(wwin, no_change_desktop)) */
623 action
[i
++] = net_wm_action_change_desktop
;
625 if (!WFLAGP(wwin
, no_closable
))
626 action
[i
++] = net_wm_action_close
;
628 XChangeProperty(dpy
, wwin
->client_win
, net_wm_allowed_actions
,
629 XA_ATOM
, 32, PropModeReplace
, (unsigned char *)action
, i
);
632 Bool
wNETWMGetUsableArea(WScreen
* scr
, int head
, WArea
* area
)
637 if (!scr
->netdata
|| !scr
->netdata
->strut
)
640 area
->x1
= area
->y1
= area
->x2
= area
->y2
= 0;
642 for (cur
= scr
->netdata
->strut
; cur
; cur
= cur
->next
) {
643 WWindow
*wwin
= wWindowFor(cur
->window
);
644 if (wWindowTouchesHead(wwin
, head
)) {
645 if (cur
->area
.x1
> area
->x1
)
646 area
->x1
= cur
->area
.x1
;
647 if (cur
->area
.y1
> area
->y1
)
648 area
->y1
= cur
->area
.y1
;
649 if (cur
->area
.x2
> area
->x2
)
650 area
->x2
= cur
->area
.x2
;
651 if (cur
->area
.y2
> area
->y2
)
652 area
->y2
= cur
->area
.y2
;
656 if (area
->x1
== 0 && area
->x2
== 0 && area
->y1
== 0 && area
->y2
== 0)
659 rect
= wGetRectForHead(scr
, head
);
661 area
->x1
= rect
.pos
.x
+ area
->x1
;
662 area
->x2
= rect
.pos
.x
+ rect
.size
.width
- area
->x2
;
663 area
->y1
= rect
.pos
.y
+ area
->y1
;
664 area
->y2
= rect
.pos
.y
+ rect
.size
.height
- area
->y2
;
669 static void updateClientList(WScreen
* scr
)
675 windows
= (Window
*) wmalloc(sizeof(Window
) * (scr
->window_count
+ 1));
678 wwin
= scr
->focused_window
;
680 windows
[count
++] = wwin
->client_win
;
683 XChangeProperty(dpy
, scr
->root_win
, net_client_list
, XA_WINDOW
, 32,
684 PropModeReplace
, (unsigned char *)windows
, count
);
690 static void updateClientListStacking(WScreen
* scr
, WWindow
* wwin_excl
)
694 Window
*client_list_reverse
;
700 /* update client list */
701 i
= scr
->window_count
+ 1;
702 client_list
= (Window
*) wmalloc(sizeof(Window
) * i
);
703 client_list_reverse
= (Window
*) wmalloc(sizeof(Window
) * i
);
706 WM_ETARETI_BAG(scr
->stacking_list
, tmp
, iter
) {
708 wwin
= wWindowFor(tmp
->window
);
709 /* wwin_excl is a window to exclude from the list
710 (e.g. it's now unmanaged) */
711 if (wwin
&& (wwin
!= wwin_excl
))
712 client_list
[client_count
++] = wwin
->client_win
;
713 tmp
= tmp
->stacking
->under
;
717 for (i
= 0; i
< client_count
; i
++) {
718 Window w
= client_list
[client_count
- i
- 1];
719 client_list_reverse
[i
] = w
;
722 XChangeProperty(dpy
, scr
->root_win
, net_client_list_stacking
, XA_WINDOW
, 32,
723 PropModeReplace
, (unsigned char *)client_list_reverse
, client_count
);
726 wfree(client_list_reverse
);
731 static void updateWorkspaceCount(WScreen
* scr
)
735 count
= scr
->workspace_count
;
737 XChangeProperty(dpy
, scr
->root_win
, net_number_of_desktops
, XA_CARDINAL
,
738 32, PropModeReplace
, (unsigned char *)&count
, 1);
741 static void updateCurrentWorkspace(WScreen
* scr
)
745 count
= scr
->current_workspace
;
747 XChangeProperty(dpy
, scr
->root_win
, net_current_desktop
, XA_CARDINAL
, 32,
748 PropModeReplace
, (unsigned char *)&count
, 1);
751 static void updateWorkspaceNames(WScreen
* scr
)
753 char buf
[MAX_WORKSPACES
* (MAX_WORKSPACENAME_WIDTH
+ 1)], *pos
;
754 unsigned int i
, len
, curr_size
;
758 for (i
= 0; i
< scr
->workspace_count
; i
++) {
759 curr_size
= strlen(scr
->workspaces
[i
]->name
);
760 strcpy(pos
, scr
->workspaces
[i
]->name
);
761 pos
+= (curr_size
+ 1);
762 len
+= (curr_size
+ 1);
765 XChangeProperty(dpy
, scr
->root_win
, net_desktop_names
, utf8_string
, 8,
766 PropModeReplace
, (unsigned char *)buf
, len
);
769 static void updateFocusHint(WScreen
* scr
, WWindow
* wwin
)
773 if (!scr
->focused_window
|| !scr
->focused_window
->flags
.focused
)
776 window
= scr
->focused_window
->client_win
;
778 XChangeProperty(dpy
, scr
->root_win
, net_active_window
, XA_WINDOW
, 32,
779 PropModeReplace
, (unsigned char *)&window
, 1);
782 static void updateWorkspaceHint(WWindow
* wwin
, Bool fake
, Bool del
)
787 XDeleteProperty(dpy
, wwin
->client_win
, net_wm_desktop
);
789 l
= ((fake
|| IS_OMNIPRESENT(wwin
)) ? -1 : wwin
->frame
->workspace
);
790 XChangeProperty(dpy
, wwin
->client_win
, net_wm_desktop
, XA_CARDINAL
,
791 32, PropModeReplace
, (unsigned char *)&l
, 1);
795 static void updateStateHint(WWindow
* wwin
, Bool changedWorkspace
, Bool del
)
798 if (!wwin
->flags
.net_state_from_client
) {
799 XDeleteProperty(dpy
, wwin
->client_win
, net_wm_state
);
802 Atom state
[15]; /* nr of defined state atoms */
805 if (changedWorkspace
|| (wPreferences
.sticky_icons
&& !IS_OMNIPRESENT(wwin
)))
806 updateWorkspaceHint(wwin
, False
, False
);
808 if (IS_OMNIPRESENT(wwin
))
809 state
[i
++] = net_wm_state_sticky
;
810 if (wwin
->flags
.shaded
)
811 state
[i
++] = net_wm_state_shaded
;
812 if (wwin
->flags
.maximized
& MAX_HORIZONTAL
)
813 state
[i
++] = net_wm_state_maximized_horz
;
814 if (wwin
->flags
.maximized
& MAX_VERTICAL
)
815 state
[i
++] = net_wm_state_maximized_vert
;
816 if (WFLAGP(wwin
, skip_window_list
))
817 state
[i
++] = net_wm_state_skip_taskbar
;
818 if (wwin
->flags
.net_skip_pager
)
819 state
[i
++] = net_wm_state_skip_pager
;
820 if ((wwin
->flags
.hidden
|| wwin
->flags
.miniaturized
) && !wwin
->flags
.net_show_desktop
) {
821 state
[i
++] = net_wm_state_hidden
;
822 state
[i
++] = net_wm_state_skip_pager
;
824 if (wwin
->flags
.miniaturized
&& wPreferences
.sticky_icons
) {
825 if (!IS_OMNIPRESENT(wwin
))
826 updateWorkspaceHint(wwin
, True
, False
);
827 state
[i
++] = net_wm_state_sticky
;
830 if (WFLAGP(wwin
, sunken
))
831 state
[i
++] = net_wm_state_below
;
832 if (WFLAGP(wwin
, floating
))
833 state
[i
++] = net_wm_state_above
;
834 if (wwin
->flags
.fullscreen
)
835 state
[i
++] = net_wm_state_fullscreen
;
837 XChangeProperty(dpy
, wwin
->client_win
, net_wm_state
, XA_ATOM
, 32,
838 PropModeReplace
, (unsigned char *)state
, i
);
842 static Bool
updateStrut(WWindow
* wwin
, Bool adding
)
846 Bool hasState
= False
;
848 scr
= wwin
->screen_ptr
;
853 unsigned long nitems_ret
;
854 unsigned long bytes_after_ret
;
857 if (XGetWindowProperty(dpy
, wwin
->client_win
, net_wm_strut
, 0, 4, False
,
858 XA_CARDINAL
, &type_ret
, &fmt_ret
, &nitems_ret
,
859 &bytes_after_ret
, (unsigned char **)&data
) == Success
&& data
) {
861 area
= (WReservedArea
*) wmalloc(sizeof(WReservedArea
));
862 area
->area
.x1
= data
[0];
863 area
->area
.x2
= data
[1];
864 area
->area
.y1
= data
[2];
865 area
->area
.y2
= data
[3];
867 area
->window
= wwin
->client_win
;
869 area
->next
= scr
->netdata
->strut
;
870 scr
->netdata
->strut
= area
;
878 area
= scr
->netdata
->strut
;
881 if (area
->window
== wwin
->client_win
) {
882 scr
->netdata
->strut
= area
->next
;
886 while (area
->next
&& area
->next
->window
!= wwin
->client_win
)
892 next
= area
->next
->next
;
905 static int getWindowLayer(WWindow
* wwin
)
907 int layer
= WMNormalLevel
;
909 if (wwin
->type
== net_wm_window_type_desktop
) {
910 layer
= WMDesktopLevel
;
911 } else if (wwin
->type
== net_wm_window_type_dock
) {
913 } else if (wwin
->type
== net_wm_window_type_toolbar
) {
914 layer
= WMMainMenuLevel
;
915 } else if (wwin
->type
== net_wm_window_type_menu
) {
916 layer
= WMSubmenuLevel
;
917 } else if (wwin
->type
== net_wm_window_type_utility
) {
918 } else if (wwin
->type
== net_wm_window_type_splash
) {
919 } else if (wwin
->type
== net_wm_window_type_dialog
) {
920 if (wwin
->transient_for
) {
921 WWindow
*parent
= wWindowFor(wwin
->transient_for
);
922 if (parent
&& parent
->flags
.fullscreen
) {
923 layer
= WMFullscreenLevel
;
926 /* //layer = WMPopUpLevel; // this seems a bad idea -Dan */
927 } else if (wwin
->type
== net_wm_window_type_normal
) {
930 if (wwin
->client_flags
.sunken
&& WMSunkenLevel
< layer
)
931 layer
= WMSunkenLevel
;
932 if (wwin
->client_flags
.floating
&& WMFloatingLevel
> layer
)
933 layer
= WMFloatingLevel
;
938 static void doStateAtom(WWindow
* wwin
, Atom state
, int set
, Bool init
)
941 if (state
== net_wm_state_sticky
) {
942 if (set
== _NET_WM_STATE_TOGGLE
) {
943 set
= !IS_OMNIPRESENT(wwin
);
945 if (set
!= wwin
->flags
.omnipresent
) {
946 wWindowSetOmnipresent(wwin
, set
);
948 } else if (state
== net_wm_state_shaded
) {
949 if (set
== _NET_WM_STATE_TOGGLE
) {
950 set
= !wwin
->flags
.shaded
;
953 wwin
->flags
.shaded
= set
;
958 wUnshadeWindow(wwin
);
961 } else if (state
== net_wm_state_skip_taskbar
) {
962 if (set
== _NET_WM_STATE_TOGGLE
) {
963 set
= !wwin
->client_flags
.skip_window_list
;
965 wwin
->client_flags
.skip_window_list
= set
;
966 } else if (state
== net_wm_state_skip_pager
) {
967 if (set
== _NET_WM_STATE_TOGGLE
) {
968 set
= !wwin
->flags
.net_skip_pager
;
970 wwin
->flags
.net_skip_pager
= set
;
971 } else if (state
== net_wm_state_maximized_vert
) {
972 if (set
== _NET_WM_STATE_TOGGLE
) {
973 set
= !(wwin
->flags
.maximized
& MAX_VERTICAL
);
976 wwin
->flags
.maximized
|= (set
? MAX_VERTICAL
: 0);
979 wMaximizeWindow(wwin
, wwin
->flags
.maximized
| MAX_VERTICAL
);
981 wMaximizeWindow(wwin
, wwin
->flags
.maximized
& ~MAX_VERTICAL
);
984 } else if (state
== net_wm_state_maximized_horz
) {
985 if (set
== _NET_WM_STATE_TOGGLE
) {
986 set
= !(wwin
->flags
.maximized
& MAX_HORIZONTAL
);
989 wwin
->flags
.maximized
|= (set
? MAX_HORIZONTAL
: 0);
992 wMaximizeWindow(wwin
, wwin
->flags
.maximized
| MAX_HORIZONTAL
);
994 wMaximizeWindow(wwin
, wwin
->flags
.maximized
& ~MAX_HORIZONTAL
);
997 } else if (state
== net_wm_state_hidden
) {
998 if (set
== _NET_WM_STATE_TOGGLE
) {
999 set
= !(wwin
->flags
.miniaturized
);
1002 wwin
->flags
.miniaturized
= set
;
1005 wIconifyWindow(wwin
);
1007 wDeiconifyWindow(wwin
);
1010 } else if (state
== net_wm_state_fullscreen
) {
1011 if (set
== _NET_WM_STATE_TOGGLE
) {
1012 set
= !(wwin
->flags
.fullscreen
);
1015 wwin
->flags
.fullscreen
= set
;
1018 wFullscreenWindow(wwin
);
1020 wUnfullscreenWindow(wwin
);
1023 } else if (state
== net_wm_state_above
) {
1024 if (set
== _NET_WM_STATE_TOGGLE
) {
1025 set
= !(wwin
->client_flags
.floating
);
1028 wwin
->client_flags
.floating
= set
;
1030 wwin
->client_flags
.floating
= set
;
1031 ChangeStackingLevel(wwin
->frame
->core
, getWindowLayer(wwin
));
1034 } else if (state
== net_wm_state_below
) {
1035 if (set
== _NET_WM_STATE_TOGGLE
) {
1036 set
= !(wwin
->client_flags
.sunken
);
1039 wwin
->client_flags
.sunken
= set
;
1041 wwin
->client_flags
.sunken
= set
;
1042 ChangeStackingLevel(wwin
->frame
->core
, getWindowLayer(wwin
));
1047 wmessage("doStateAtom unknown atom %s set %d\n", XGetAtomName(dpy
, state
), set
);
1052 static void removeIcon(WWindow
* wwin
)
1054 if (wwin
->icon
== NULL
)
1056 if (wwin
->flags
.miniaturized
&& wwin
->icon
->mapped
) {
1057 XUnmapWindow(dpy
, wwin
->icon
->core
->window
);
1058 RemoveFromStackList(wwin
->icon
->core
);
1059 wIconDestroy(wwin
->icon
);
1064 static Bool
handleWindowType(WWindow
* wwin
, Atom type
, int *layer
)
1068 if (type
== net_wm_window_type_desktop
) {
1069 wwin
->client_flags
.no_titlebar
= 1;
1070 wwin
->client_flags
.no_resizable
= 1;
1071 wwin
->client_flags
.no_miniaturizable
= 1;
1072 wwin
->client_flags
.no_border
= 1;
1073 wwin
->client_flags
.no_resizebar
= 1;
1074 wwin
->client_flags
.no_shadeable
= 1;
1075 wwin
->client_flags
.no_movable
= 1;
1076 wwin
->client_flags
.omnipresent
= 1;
1077 wwin
->client_flags
.skip_window_list
= 1;
1078 wwin
->client_flags
.skip_switchpanel
= 1;
1079 wwin
->client_flags
.dont_move_off
= 1;
1080 wwin
->client_flags
.no_appicon
= 1;
1081 wwin
->flags
.net_skip_pager
= 1;
1084 } else if (type
== net_wm_window_type_dock
) {
1085 wwin
->client_flags
.no_titlebar
= 1;
1086 wwin
->client_flags
.no_resizable
= 1;
1087 wwin
->client_flags
.no_miniaturizable
= 1;
1088 wwin
->client_flags
.no_border
= 1; /* XXX: really not a single decoration. */
1089 wwin
->client_flags
.no_resizebar
= 1;
1090 wwin
->client_flags
.no_shadeable
= 1;
1091 wwin
->client_flags
.no_movable
= 1;
1092 wwin
->client_flags
.omnipresent
= 1;
1093 wwin
->client_flags
.skip_window_list
= 1;
1094 wwin
->client_flags
.skip_switchpanel
= 1;
1095 wwin
->client_flags
.dont_move_off
= 1;
1096 wwin
->flags
.net_skip_pager
= 1;
1097 } else if (type
== net_wm_window_type_toolbar
) {
1098 wwin
->client_flags
.no_titlebar
= 1;
1099 wwin
->client_flags
.no_resizable
= 1;
1100 wwin
->client_flags
.no_miniaturizable
= 1;
1101 wwin
->client_flags
.no_resizebar
= 1;
1102 wwin
->client_flags
.no_shadeable
= 1;
1103 wwin
->client_flags
.skip_window_list
= 1;
1104 wwin
->client_flags
.skip_switchpanel
= 1;
1105 wwin
->client_flags
.dont_move_off
= 1;
1106 wwin
->client_flags
.no_appicon
= 1;
1107 } else if (type
== net_wm_window_type_menu
) {
1108 wwin
->client_flags
.no_titlebar
= 1;
1109 wwin
->client_flags
.no_resizable
= 1;
1110 wwin
->client_flags
.no_miniaturizable
= 1;
1111 wwin
->client_flags
.no_resizebar
= 1;
1112 wwin
->client_flags
.no_shadeable
= 1;
1113 wwin
->client_flags
.skip_window_list
= 1;
1114 wwin
->client_flags
.skip_switchpanel
= 1;
1115 wwin
->client_flags
.dont_move_off
= 1;
1116 wwin
->client_flags
.no_appicon
= 1;
1117 } else if (type
== net_wm_window_type_utility
) {
1118 wwin
->client_flags
.no_appicon
= 1;
1119 } else if (type
== net_wm_window_type_splash
) {
1120 wwin
->client_flags
.no_titlebar
= 1;
1121 wwin
->client_flags
.no_resizable
= 1;
1122 wwin
->client_flags
.no_miniaturizable
= 1;
1123 wwin
->client_flags
.no_resizebar
= 1;
1124 wwin
->client_flags
.no_shadeable
= 1;
1125 wwin
->client_flags
.no_movable
= 1;
1126 wwin
->client_flags
.skip_window_list
= 1;
1127 wwin
->client_flags
.skip_switchpanel
= 1;
1128 wwin
->client_flags
.dont_move_off
= 1;
1129 wwin
->client_flags
.no_appicon
= 1;
1130 wwin
->flags
.net_skip_pager
= 1;
1131 } else if (type
== net_wm_window_type_dialog
) {
1132 /* These also seem a bad idea in our context -Dan
1133 // wwin->client_flags.skip_window_list = 1;
1134 // wwin->client_flags.no_appicon = 1;
1136 } else if (type
== net_wm_window_type_normal
) {
1142 *layer
= getWindowLayer(wwin
);
1147 void wNETWMPositionSplash(WWindow
* wwin
, int *x
, int *y
, int width
, int height
)
1149 if (wwin
->type
== net_wm_window_type_splash
) {
1150 WScreen
*scr
= wwin
->screen_ptr
;
1151 WMRect rect
= wGetRectForHead(scr
, wGetHeadForPointerLocation(scr
));
1152 *x
= rect
.pos
.x
+ (rect
.size
.width
- width
) / 2;
1153 *y
= rect
.pos
.y
+ (rect
.size
.height
- height
) / 2;
1157 static void updateWindowType(WWindow
* wwin
)
1161 unsigned long nitems_ret
;
1162 unsigned long bytes_after_ret
;
1165 if (XGetWindowProperty(dpy
, wwin
->client_win
, net_wm_window_type
, 0, 1,
1166 False
, XA_ATOM
, &type_ret
, &fmt_ret
, &nitems_ret
,
1167 &bytes_after_ret
, (unsigned char **)&data
) == Success
&& data
) {
1170 Atom
*type
= (Atom
*) data
;
1171 for (i
= 0; i
< nitems_ret
; ++i
) {
1172 if (handleWindowType(wwin
, type
[i
], &layer
))
1178 if (wwin
->frame
!= NULL
) {
1179 ChangeStackingLevel(wwin
->frame
->core
, layer
);
1180 wwin
->frame
->flags
.need_texture_change
= 1;
1181 wWindowConfigureBorders(wwin
);
1182 wFrameWindowPaint(wwin
->frame
);
1183 wNETWMUpdateActions(wwin
, False
);
1187 Bool
wNETWMCheckClientHints(WWindow
* wwin
, int *layer
, int *workspace
)
1191 unsigned long nitems_ret
;
1192 unsigned long bytes_after_ret
;
1194 Bool hasState
= False
;
1197 if (XGetWindowProperty(dpy
, wwin
->client_win
, net_wm_desktop
, 0, 1, False
,
1198 XA_CARDINAL
, &type_ret
, &fmt_ret
, &nitems_ret
,
1199 &bytes_after_ret
, (unsigned char **)&data
) == Success
&& data
) {
1201 long desktop
= *data
;
1205 wwin
->client_flags
.omnipresent
= 1;
1207 *workspace
= desktop
;
1212 if (XGetWindowProperty(dpy
, wwin
->client_win
, net_wm_state
, 0, 1, False
,
1213 XA_ATOM
, &type_ret
, &fmt_ret
, &nitems_ret
,
1214 &bytes_after_ret
, (unsigned char **)&data
) == Success
&& data
) {
1216 Atom
*state
= (Atom
*) data
;
1217 for (i
= 0; i
< nitems_ret
; ++i
) {
1218 doStateAtom(wwin
, state
[i
], _NET_WM_STATE_ADD
, True
);
1224 if (XGetWindowProperty(dpy
, wwin
->client_win
, net_wm_window_type
, 0, 1, False
,
1225 XA_ATOM
, &type_ret
, &fmt_ret
, &nitems_ret
,
1226 &bytes_after_ret
, (unsigned char **)&data
) == Success
&& data
) {
1228 Atom
*type
= (Atom
*) data
;
1229 for (i
= 0; i
< nitems_ret
; ++i
) {
1230 if (handleWindowType(wwin
, type
[i
], layer
))
1237 wNETWMUpdateActions(wwin
, False
);
1238 updateStrut(wwin
, False
);
1239 if (updateStrut(wwin
, True
)) {
1242 wScreenUpdateUsableArea(wwin
->screen_ptr
);
1247 static Bool
updateNetIconInfo(WWindow
* wwin
)
1252 unsigned long nitems_ret
;
1253 unsigned long bytes_after_ret
;
1255 Bool hasState
= False
;
1256 Bool old_state
= wwin
->flags
.net_handle_icon
;
1258 if (XGetWindowProperty(dpy
, wwin
->client_win
, net_wm_handled_icons
, 0, 1, False
,
1259 XA_CARDINAL
, &type_ret
, &fmt_ret
, &nitems_ret
,
1260 &bytes_after_ret
, (unsigned char **)&data
) == Success
&& data
) {
1261 long handled
= *data
;
1262 wwin
->flags
.net_handle_icon
= (handled
!= 0);
1267 wwin
->flags
.net_handle_icon
= False
;
1269 if (XGetWindowProperty(dpy
, wwin
->client_win
, net_wm_icon_geometry
, 0, 4, False
,
1270 XA_CARDINAL
, &type_ret
, &fmt_ret
, &nitems_ret
,
1271 &bytes_after_ret
, (unsigned char **)&data
) == Success
&& data
) {
1274 if (wwin
->flags
.net_handle_icon
)
1276 wwin
->flags
.net_handle_icon
= True
;
1279 wwin
->icon_x
= data
[0];
1280 wwin
->icon_y
= data
[1];
1281 wwin
->icon_w
= data
[2];
1282 wwin
->icon_h
= data
[3];
1289 wwin
->flags
.net_handle_icon
= False
;
1291 if (wwin
->flags
.miniaturized
&& old_state
!= wwin
->flags
.net_handle_icon
) {
1292 if (wwin
->flags
.net_handle_icon
) {
1295 wwin
->flags
.miniaturized
= False
;
1296 wwin
->flags
.skip_next_animation
= True
;
1297 wIconifyWindow(wwin
);
1304 Bool
wNETWMCheckInitialClientState(WWindow
* wwin
)
1306 Bool hasState
= False
;
1312 wNETWMShowingDesktop(wwin
->screen_ptr
, False
);
1314 hasState
|= updateNetIconInfo(wwin
);
1316 updateIconImage(wwin
);
1321 static void handleDesktopNames(XClientMessageEvent
* event
, WScreen
* scr
)
1323 unsigned long nitems_ret
, bytes_after_ret
;
1324 char *data
, *names
[32];
1328 if (XGetWindowProperty(dpy
, scr
->root_win
, net_desktop_names
, 0, 1, False
,
1329 utf8_string
, &type_ret
, &fmt_ret
, &nitems_ret
,
1330 &bytes_after_ret
, (unsigned char **)&data
) != Success
) {
1337 if (type_ret
!= utf8_string
|| fmt_ret
!= 8)
1342 for (i
= 0; i
< nitems_ret
; i
++) {
1345 names
[n
] = &data
[i
];
1346 } else if (*names
[n
] == 0) {
1347 names
[n
] = &data
[i
];
1348 wWorkspaceRename(scr
, n
, names
[n
]);
1353 Bool
wNETWMProcessClientMessage(XClientMessageEvent
* event
)
1360 wmessage("processClientMessage type %s\n", XGetAtomName(dpy
, event
->message_type
));
1363 scr
= wScreenForWindow(event
->window
);
1365 /* generic client messages */
1366 if (event
->message_type
== net_current_desktop
) {
1367 wWorkspaceChange(scr
, event
->data
.l
[0]);
1368 } else if (event
->message_type
== net_number_of_desktops
) {
1371 value
= event
->data
.l
[0];
1372 if (value
> scr
->workspace_count
) {
1373 wWorkspaceMake(scr
, value
- scr
->workspace_count
);
1374 } else if (value
< scr
->workspace_count
) {
1376 Bool rebuild
= False
;
1378 for (i
= scr
->workspace_count
- 1; i
>= value
; i
--) {
1379 if (!wWorkspaceDelete(scr
, i
)) {
1386 updateWorkspaceCount(scr
);
1389 } else if (event
->message_type
== net_showing_desktop
) {
1390 wNETWMShowingDesktop(scr
, event
->data
.l
[0]);
1391 } else if (event
->message_type
== net_desktop_names
) {
1392 handleDesktopNames(event
, scr
);
1401 /* window specific client messages */
1403 wwin
= wWindowFor(event
->window
);
1407 if (event
->message_type
== net_active_window
) {
1409 * Satisfy a client's focus request only if
1410 * - request comes from a pager, or
1411 * - it's explicitly allowed in Advanced Options, or
1412 * - giving the client the focus does not cause a change in
1413 * the active workspace (XXX: or the active head if Xinerama)
1415 if (wwin
->frame
->workspace
== wwin
->screen_ptr
->current_workspace
/* No workspace change */
1416 || event
->data
.l
[0] == 2 /* Requested by pager */
1417 || WFLAGP(wwin
, focus_across_wksp
) /* Explicitly allowed */) {
1418 wNETWMShowingDesktop(scr
, False
);
1419 wMakeWindowVisible(wwin
);
1421 } else if (event
->message_type
== net_close_window
) {
1422 if (!WFLAGP(wwin
, no_closable
)) {
1423 if (wwin
->protocols
.DELETE_WINDOW
)
1424 wClientSendProtocol(wwin
, _XA_WM_DELETE_WINDOW
, LastTimestamp
);
1426 } else if (event
->message_type
== net_wm_state
) {
1427 int maximized
= wwin
->flags
.maximized
;
1428 long set
= event
->data
.l
[0];
1431 wmessage("net_wm_state set %ld a1 %s a2 %s\n", set
,
1432 XGetAtomName(dpy
, event
->data
.l
[1]), XGetAtomName(dpy
, event
->data
.l
[2]));
1435 doStateAtom(wwin
, (Atom
) event
->data
.l
[1], set
, False
);
1436 if (event
->data
.l
[2])
1437 doStateAtom(wwin
, (Atom
) event
->data
.l
[2], set
, False
);
1439 if (wwin
->flags
.maximized
!= maximized
) {
1440 if (!wwin
->flags
.maximized
) {
1441 wwin
->flags
.maximized
= maximized
;
1442 wUnmaximizeWindow(wwin
);
1444 wMaximizeWindow(wwin
, wwin
->flags
.maximized
);
1447 updateStateHint(wwin
, False
, False
);
1448 } else if (event
->message_type
== net_wm_handled_icons
|| event
->message_type
== net_wm_icon_geometry
) {
1449 updateNetIconInfo(wwin
);
1450 } else if (event
->message_type
== net_wm_desktop
) {
1451 long desktop
= event
->data
.l
[0];
1452 if (desktop
== -1) {
1453 wWindowSetOmnipresent(wwin
, True
);
1455 if (IS_OMNIPRESENT(wwin
))
1456 wWindowSetOmnipresent(wwin
, False
);
1457 wWindowChangeWorkspace(wwin
, desktop
);
1466 Bool
wNETWMCheckClientHintChange(WWindow
* wwin
, XPropertyEvent
* event
)
1471 wmessage("clientHintChange type %s\n", XGetAtomName(dpy
, event
->atom
));
1474 if (event
->atom
== net_wm_strut
) {
1475 updateStrut(wwin
, False
);
1476 updateStrut(wwin
, True
);
1477 wScreenUpdateUsableArea(wwin
->screen_ptr
);
1478 } else if (event
->atom
== net_wm_handled_icons
|| event
->atom
== net_wm_icon_geometry
) {
1479 updateNetIconInfo(wwin
);
1480 } else if (event
->atom
== net_wm_window_type
) {
1481 updateWindowType(wwin
);
1482 } else if (event
->atom
== net_wm_name
) {
1483 char *name
= wNETWMGetWindowName(wwin
->client_win
);
1484 wWindowUpdateName(wwin
, name
);
1487 } else if (event
->atom
== net_wm_icon_name
) {
1489 char *name
= wNETWMGetIconName(wwin
->client_win
);
1490 wIconChangeTitle(wwin
->icon
, name
);
1492 } else if (event
->atom
== net_wm_icon
) {
1493 updateIconImage(wwin
);
1501 int wNETWMGetPidForWindow(Window window
)
1505 unsigned long nitems_ret
;
1506 unsigned long bytes_after_ret
;
1510 if (XGetWindowProperty(dpy
, window
, net_wm_pid
, 0, 1, False
,
1511 XA_CARDINAL
, &type_ret
, &fmt_ret
, &nitems_ret
,
1512 &bytes_after_ret
, (unsigned char **)&data
) == Success
&& data
) {
1523 char *wNETWMGetWindowName(Window window
)
1529 name
= (char *)PropGetCheckProperty(window
, net_wm_name
, utf8_string
, 0, 0, &size
);
1531 ret
= wstrndup(name
, size
);
1538 char *wNETWMGetIconName(Window window
)
1544 name
= (char *)PropGetCheckProperty(window
, net_wm_icon_name
, utf8_string
, 0, 0, &size
);
1546 ret
= wstrndup(name
, size
);
1553 static void observer(void *self
, WMNotification
* notif
)
1555 WWindow
*wwin
= (WWindow
*) WMGetNotificationObject(notif
);
1556 const char *name
= WMGetNotificationName(notif
);
1557 void *data
= WMGetNotificationClientData(notif
);
1558 NetData
*ndata
= (NetData
*) self
;
1560 if (strcmp(name
, WMNManaged
) == 0 && wwin
) {
1561 updateClientList(wwin
->screen_ptr
);
1562 updateClientListStacking(wwin
->screen_ptr
, NULL
);
1563 updateStateHint(wwin
, True
, False
);
1565 updateStrut(wwin
, False
);
1566 updateStrut(wwin
, True
);
1567 wScreenUpdateUsableArea(wwin
->screen_ptr
);
1568 } else if (strcmp(name
, WMNUnmanaged
) == 0 && wwin
) {
1569 updateClientList(wwin
->screen_ptr
);
1570 updateClientListStacking(wwin
->screen_ptr
, wwin
);
1571 updateWorkspaceHint(wwin
, False
, True
);
1572 updateStateHint(wwin
, False
, True
);
1573 wNETWMUpdateActions(wwin
, True
);
1575 updateStrut(wwin
, False
);
1576 wScreenUpdateUsableArea(wwin
->screen_ptr
);
1577 } else if (strcmp(name
, WMNResetStacking
) == 0 && wwin
) {
1578 updateClientListStacking(wwin
->screen_ptr
, NULL
);
1579 updateStateHint(wwin
, False
, False
);
1580 } else if (strcmp(name
, WMNChangedStacking
) == 0 && wwin
) {
1581 updateClientListStacking(wwin
->screen_ptr
, NULL
);
1582 updateStateHint(wwin
, False
, False
);
1583 } else if (strcmp(name
, WMNChangedFocus
) == 0) {
1584 updateFocusHint(ndata
->scr
, wwin
);
1585 } else if (strcmp(name
, WMNChangedWorkspace
) == 0 && wwin
) {
1586 updateWorkspaceHint(wwin
, False
, False
);
1587 updateStateHint(wwin
, True
, False
);
1588 } else if (strcmp(name
, WMNChangedState
) == 0 && wwin
) {
1589 updateStateHint(wwin
, !strcmp(data
, "omnipresent"), False
);
1593 static void wsobserver(void *self
, WMNotification
* notif
)
1595 WScreen
*scr
= (WScreen
*) WMGetNotificationObject(notif
);
1596 const char *name
= WMGetNotificationName(notif
);
1598 if (strcmp(name
, WMNWorkspaceCreated
) == 0) {
1599 updateWorkspaceCount(scr
);
1600 updateWorkspaceNames(scr
);
1601 } else if (strcmp(name
, WMNWorkspaceDestroyed
) == 0) {
1602 updateWorkspaceCount(scr
);
1603 updateWorkspaceNames(scr
);
1604 } else if (strcmp(name
, WMNWorkspaceChanged
) == 0) {
1605 updateCurrentWorkspace(scr
);
1606 } else if (strcmp(name
, WMNWorkspaceNameChanged
) == 0) {
1607 updateWorkspaceNames(scr
);