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
18 * along with this program; if not, write to the Free Software
19 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307,
27 * This file needs to be checked for all calls to XGetWindowProperty() and
28 * proper checks need to be made on the returned values. Only checking for
29 * return to be Success is not enough. -Dan
35 #include <X11/Xatom.h>
36 #include <X11/Xarch.h>
39 #include "WindowMaker.h"
42 #include "workspace.h"
50 #include "properties.h"
56 /* Global variables */
57 extern Atom _XA_WM_DELETE_WINDOW
;
58 extern Time LastTimestamp
;
59 extern WPreferences wPreferences
;
61 /* Root Window Properties */
62 static Atom net_supported
;
63 static Atom net_client_list
;
64 static Atom net_client_list_stacking
;
65 static Atom net_number_of_desktops
;
66 static Atom net_desktop_geometry
;
67 static Atom net_desktop_viewport
;
68 static Atom net_current_desktop
;
69 static Atom net_desktop_names
;
70 static Atom net_active_window
;
71 static Atom net_workarea
; /* XXX: not xinerama compatible */
72 static Atom net_supporting_wm_check
;
73 static Atom net_virtual_roots
; /* N/A */
74 static Atom net_desktop_layout
; /* XXX */
75 static Atom net_showing_desktop
;
77 /* Other Root Window Messages */
78 static Atom net_close_window
;
79 static Atom net_moveresize_window
; /* TODO */
80 static Atom net_wm_moveresize
; /* TODO */
82 /* Application Window Properties */
83 static Atom net_wm_name
;
84 static Atom net_wm_visible_name
; /* TODO (unnecessary?) */
85 static Atom net_wm_icon_name
;
86 static Atom net_wm_visible_icon_name
; /* TODO (unnecessary?) */
87 static Atom net_wm_desktop
;
88 static Atom net_wm_window_type
;
89 static Atom net_wm_window_type_desktop
;
90 static Atom net_wm_window_type_dock
;
91 static Atom net_wm_window_type_toolbar
;
92 static Atom net_wm_window_type_menu
;
93 static Atom net_wm_window_type_utility
;
94 static Atom net_wm_window_type_splash
;
95 static Atom net_wm_window_type_dialog
;
96 static Atom net_wm_window_type_normal
;
97 static Atom net_wm_state
;
98 static Atom net_wm_state_modal
; /* XXX: what is this?!? */
99 static Atom net_wm_state_sticky
;
100 static Atom net_wm_state_maximized_vert
;
101 static Atom net_wm_state_maximized_horz
;
102 static Atom net_wm_state_shaded
;
103 static Atom net_wm_state_skip_taskbar
;
104 static Atom net_wm_state_skip_pager
;
105 static Atom net_wm_state_hidden
;
106 static Atom net_wm_state_fullscreen
;
107 static Atom net_wm_state_above
;
108 static Atom net_wm_state_below
;
109 static Atom net_wm_allowed_actions
;
110 static Atom net_wm_action_move
;
111 static Atom net_wm_action_resize
;
112 static Atom net_wm_action_minimize
;
113 static Atom net_wm_action_shade
;
114 static Atom net_wm_action_stick
;
115 static Atom net_wm_action_maximize_horz
;
116 static Atom net_wm_action_maximize_vert
;
117 static Atom net_wm_action_fullscreen
;
118 static Atom net_wm_action_change_desktop
;
119 static Atom net_wm_action_close
;
120 static Atom net_wm_strut
; /* XXX: see net_workarea */
121 static Atom net_wm_strut_partial
; /* TODO: doesn't really fit into the current strut scheme */
122 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. */
123 static Atom net_wm_icon
;
124 static Atom net_wm_pid
; /* TODO */
125 static Atom net_wm_handled_icons
; /* FIXME: see net_wm_icon_geometry */
127 /* Window Manager Protocols */
128 static Atom net_wm_ping
; /* TODO */
130 static Atom utf8_string
;
137 static atomitem_t atomNames
[] = {
138 {"_NET_SUPPORTED", &net_supported
},
139 {"_NET_CLIENT_LIST", &net_client_list
},
140 {"_NET_CLIENT_LIST_STACKING", &net_client_list_stacking
},
141 {"_NET_NUMBER_OF_DESKTOPS", &net_number_of_desktops
},
142 {"_NET_DESKTOP_GEOMETRY", &net_desktop_geometry
},
143 {"_NET_DESKTOP_VIEWPORT", &net_desktop_viewport
},
144 {"_NET_CURRENT_DESKTOP", &net_current_desktop
},
145 {"_NET_DESKTOP_NAMES", &net_desktop_names
},
146 {"_NET_ACTIVE_WINDOW", &net_active_window
},
147 {"_NET_WORKAREA", &net_workarea
},
148 {"_NET_SUPPORTING_WM_CHECK", &net_supporting_wm_check
},
149 {"_NET_VIRTUAL_ROOTS", &net_virtual_roots
},
150 {"_NET_DESKTOP_LAYOUT", &net_desktop_layout
},
151 {"_NET_SHOWING_DESKTOP", &net_showing_desktop
},
153 {"_NET_CLOSE_WINDOW", &net_close_window
},
154 {"_NET_MOVERESIZE_WINDOW", &net_moveresize_window
},
155 {"_NET_WM_MOVERESIZE", &net_wm_moveresize
},
157 {"_NET_WM_NAME", &net_wm_name
},
158 {"_NET_WM_VISIBLE_NAME", &net_wm_visible_name
},
159 {"_NET_WM_ICON_NAME", &net_wm_icon_name
},
160 {"_NET_WM_VISIBLE_ICON_NAME", &net_wm_visible_icon_name
},
161 {"_NET_WM_DESKTOP", &net_wm_desktop
},
162 {"_NET_WM_WINDOW_TYPE", &net_wm_window_type
},
163 {"_NET_WM_WINDOW_TYPE_DESKTOP", &net_wm_window_type_desktop
},
164 {"_NET_WM_WINDOW_TYPE_DOCK", &net_wm_window_type_dock
},
165 {"_NET_WM_WINDOW_TYPE_TOOLBAR", &net_wm_window_type_toolbar
},
166 {"_NET_WM_WINDOW_TYPE_MENU", &net_wm_window_type_menu
},
167 {"_NET_WM_WINDOW_TYPE_UTILITY", &net_wm_window_type_utility
},
168 {"_NET_WM_WINDOW_TYPE_SPLASH", &net_wm_window_type_splash
},
169 {"_NET_WM_WINDOW_TYPE_DIALOG", &net_wm_window_type_dialog
},
170 {"_NET_WM_WINDOW_TYPE_NORMAL", &net_wm_window_type_normal
},
171 {"_NET_WM_STATE", &net_wm_state
},
172 {"_NET_WM_STATE_MODAL", &net_wm_state_modal
},
173 {"_NET_WM_STATE_STICKY", &net_wm_state_sticky
},
174 {"_NET_WM_STATE_MAXIMIZED_VERT", &net_wm_state_maximized_vert
},
175 {"_NET_WM_STATE_MAXIMIZED_HORZ", &net_wm_state_maximized_horz
},
176 {"_NET_WM_STATE_SHADED", &net_wm_state_shaded
},
177 {"_NET_WM_STATE_SKIP_TASKBAR", &net_wm_state_skip_taskbar
},
178 {"_NET_WM_STATE_SKIP_PAGER", &net_wm_state_skip_pager
},
179 {"_NET_WM_STATE_HIDDEN", &net_wm_state_hidden
},
180 {"_NET_WM_STATE_FULLSCREEN", &net_wm_state_fullscreen
},
181 {"_NET_WM_STATE_ABOVE", &net_wm_state_above
},
182 {"_NET_WM_STATE_BELOW", &net_wm_state_below
},
183 {"_NET_WM_ALLOWED_ACTIONS", &net_wm_allowed_actions
},
184 {"_NET_WM_ACTION_MOVE", &net_wm_action_move
},
185 {"_NET_WM_ACTION_RESIZE", &net_wm_action_resize
},
186 {"_NET_WM_ACTION_MINIMIZE", &net_wm_action_minimize
},
187 {"_NET_WM_ACTION_SHADE", &net_wm_action_shade
},
188 {"_NET_WM_ACTION_STICK", &net_wm_action_stick
},
189 {"_NET_WM_ACTION_MAXIMIZE_HORZ", &net_wm_action_maximize_horz
},
190 {"_NET_WM_ACTION_MAXIMIZE_VERT", &net_wm_action_maximize_vert
},
191 {"_NET_WM_ACTION_FULLSCREEN", &net_wm_action_fullscreen
},
192 {"_NET_WM_ACTION_CHANGE_DESKTOP", &net_wm_action_change_desktop
},
193 {"_NET_WM_ACTION_CLOSE", &net_wm_action_close
},
194 {"_NET_WM_STRUT", &net_wm_strut
},
195 {"_NET_WM_STRUT_PARTIAL", &net_wm_strut_partial
},
196 {"_NET_WM_ICON_GEOMETRY", &net_wm_icon_geometry
},
197 {"_NET_WM_ICON", &net_wm_icon
},
198 {"_NET_WM_PID", &net_wm_pid
},
199 {"_NET_WM_HANDLED_ICONS", &net_wm_handled_icons
},
201 {"_NET_WM_PING", &net_wm_ping
},
203 {"UTF8_STRING", &utf8_string
},
206 #define atomNr (sizeof(atomNames)/sizeof(atomitem_t))
208 #define _NET_WM_STATE_REMOVE 0
209 #define _NET_WM_STATE_ADD 1
210 #define _NET_WM_STATE_TOGGLE 2
212 #define _NET_WM_MOVERESIZE_SIZE_TOPLEFT 0
213 #define _NET_WM_MOVERESIZE_SIZE_TOP 1
214 #define _NET_WM_MOVERESIZE_SIZE_TOPRIGHT 2
215 #define _NET_WM_MOVERESIZE_SIZE_RIGHT 3
216 #define _NET_WM_MOVERESIZE_SIZE_BOTTOMRIGHT 4
217 #define _NET_WM_MOVERESIZE_SIZE_BOTTOM 5
218 #define _NET_WM_MOVERESIZE_SIZE_BOTTOMLEFT 6
219 #define _NET_WM_MOVERESIZE_SIZE_LEFT 7
220 #define _NET_WM_MOVERESIZE_MOVE 8 /* movement only */
221 #define _NET_WM_MOVERESIZE_SIZE_KEYBOARD 9 /* size via keyboard */
222 #define _NET_WM_MOVERESIZE_MOVE_KEYBOARD 10 /* move via keyboard */
224 static void observer(void *self
, WMNotification
* notif
);
225 static void wsobserver(void *self
, WMNotification
* notif
);
227 static void updateClientList(WScreen
* scr
);
228 static void updateClientListStacking(WScreen
* scr
, WWindow
*);
230 static void updateWorkspaceNames(WScreen
* scr
);
231 static void updateCurrentWorkspace(WScreen
* scr
);
232 static void updateWorkspaceCount(WScreen
* scr
);
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_workarea
;
257 atom
[i
++] = net_supporting_wm_check
;
258 atom
[i
++] = net_showing_desktop
;
260 atom
[i
++] = net_wm_moveresize
;
262 atom
[i
++] = net_wm_desktop
;
263 atom
[i
++] = net_wm_window_type
;
264 atom
[i
++] = net_wm_window_type_desktop
;
265 atom
[i
++] = net_wm_window_type_dock
;
266 atom
[i
++] = net_wm_window_type_toolbar
;
267 atom
[i
++] = net_wm_window_type_menu
;
268 atom
[i
++] = net_wm_window_type_utility
;
269 atom
[i
++] = net_wm_window_type_splash
;
270 atom
[i
++] = net_wm_window_type_dialog
;
271 atom
[i
++] = net_wm_window_type_normal
;
273 atom
[i
++] = net_wm_state
;
274 /* atom[i++] = net_wm_state_modal; *//* XXX: not sure where/when to use it. */
275 atom
[i
++] = net_wm_state_sticky
;
276 atom
[i
++] = net_wm_state_shaded
;
277 atom
[i
++] = net_wm_state_maximized_horz
;
278 atom
[i
++] = net_wm_state_maximized_vert
;
279 atom
[i
++] = net_wm_state_skip_taskbar
;
280 atom
[i
++] = net_wm_state_skip_pager
;
281 atom
[i
++] = net_wm_state_hidden
;
282 atom
[i
++] = net_wm_state_fullscreen
;
283 atom
[i
++] = net_wm_state_above
;
284 atom
[i
++] = net_wm_state_below
;
286 atom
[i
++] = net_wm_allowed_actions
;
287 atom
[i
++] = net_wm_action_move
;
288 atom
[i
++] = net_wm_action_resize
;
289 atom
[i
++] = net_wm_action_minimize
;
290 atom
[i
++] = net_wm_action_shade
;
291 atom
[i
++] = net_wm_action_stick
;
292 atom
[i
++] = net_wm_action_maximize_horz
;
293 atom
[i
++] = net_wm_action_maximize_vert
;
294 atom
[i
++] = net_wm_action_fullscreen
;
295 atom
[i
++] = net_wm_action_change_desktop
;
296 atom
[i
++] = net_wm_action_close
;
298 atom
[i
++] = net_wm_strut
;
299 atom
[i
++] = net_wm_icon_geometry
;
300 atom
[i
++] = net_wm_icon
;
301 atom
[i
++] = net_wm_handled_icons
;
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); */
328 #ifdef VIRTUAL_DESKTOP
329 sizes
[0] = scr
->workspaces
[scr
->current_workspace
]->width
;
330 sizes
[1] = scr
->workspaces
[scr
->current_workspace
]->height
;
332 sizes
[0] = scr
->scr_width
;
333 sizes
[1] = scr
->scr_height
;
336 for (i
= 0; i
< scr
->workspace_count
; i
++) {
337 #ifdef VIRTUAL_DESKTOP
338 views
[2 * i
+ 0] = scr
->workspaces
[i
]->view_x
;
339 views
[2 * i
+ 1] = scr
->workspaces
[i
]->view_y
;
341 views
[2 * i
+ 0] = 0;
342 views
[2 * i
+ 1] = 0;
346 XChangeProperty(dpy
, scr
->root_win
, net_desktop_geometry
, XA_CARDINAL
, 32,
347 PropModeReplace
, (unsigned char *)sizes
, 2);
349 XChangeProperty(dpy
, scr
->root_win
, net_desktop_viewport
, XA_CARDINAL
, 32,
350 PropModeReplace
, (unsigned char *)views
, count
);
355 int wNETWMGetCurrentDesktopFromHint(WScreen
* scr
)
360 prop
= PropGetCheckProperty(scr
->root_win
, net_current_desktop
, XA_CARDINAL
, 0, 1, &count
);
362 int desktop
= *(long *)prop
;
370 * Find the best icon to be used by Window Maker for appicon/miniwindows.
371 * Currently the algorithm is to take the image with the size closest
372 * to icon_size x icon_size, but never bigger than that.
374 * This algorithm is very poorly implemented and needs to be redone (it can
375 * easily select images with very large widths and very small heights over
376 * square images, if the area of the former is closer to the desired one).
378 * The logic can also be changed to accept bigger images and scale them down.
380 static unsigned long *findBestIcon(unsigned long *data
, unsigned long items
)
383 unsigned long i
, distance
;
386 /* better use only 75% of icon_size. For 64x64 this means 48x48
387 * This leaves room around the icon for the miniwindow title and
388 * results in better overall aesthetics -Dan */
389 wanted
= wPreferences
.icon_size
* wPreferences
.icon_size
;
391 for (icon
= NULL
, distance
= wanted
, i
= 0L; i
< items
- 1;) {
392 size
= data
[i
] * data
[i
+ 1];
396 if (d
>= 0 && d
<= distance
&& (i
+ size
+ 2) <= items
) {
406 static RImage
*makeRImageFromARGBData(unsigned long *data
)
408 int size
, width
, height
, i
;
410 unsigned char *imgdata
;
415 size
= width
* height
;
420 image
= RCreateImage(width
, height
, True
);
422 for (imgdata
= image
->data
, i
= 2; i
< size
+ 2; i
++, imgdata
+= 4) {
424 #if BYTE_ORDER == BIG_ENDIAN
425 imgdata
[2] = (pixel
>> 24) & 0xff; /* A */
426 imgdata
[1] = (pixel
>> 16) & 0xff; /* R */
427 imgdata
[0] = (pixel
>> 8) & 0xff; /* G */
428 imgdata
[3] = (pixel
>> 0) & 0xff; /* B */
429 #else /* Little endian */
430 imgdata
[3] = (pixel
>> 24) & 0xff; /* A */
431 imgdata
[0] = (pixel
>> 16) & 0xff; /* R */
432 imgdata
[1] = (pixel
>> 8) & 0xff; /* G */
433 imgdata
[2] = (pixel
>> 0) & 0xff; /* B */
434 #endif /* endianness */
441 static void updateIconImage(WScreen
* scr
, WWindow
* wwin
)
443 unsigned long *property
, *data
;
444 unsigned long items
, rest
;
449 if (XGetWindowProperty(dpy
, wwin
->client_win
, net_wm_icon
, 0L, LONG_MAX
,
450 False
, XA_CARDINAL
, &type
, &format
, &items
, &rest
,
451 (unsigned char **)&property
) != Success
|| !property
) {
455 if (type
!= XA_CARDINAL
|| format
!= 32 || items
< 2) {
460 data
= findBestIcon(property
, items
);
466 image
= makeRImageFromARGBData(data
);
469 if (wwin
->net_icon_image
)
470 RReleaseImage(wwin
->net_icon_image
);
471 wwin
->net_icon_image
= image
;
477 static void updateShowDesktop(WScreen
* scr
, Bool show
)
481 foo
= (show
== True
);
482 XChangeProperty(dpy
, scr
->root_win
, net_showing_desktop
, XA_CARDINAL
, 32,
483 PropModeReplace
, (unsigned char *)&foo
, 1);
486 void wNETWMShowingDesktop(WScreen
* scr
, Bool show
)
488 if (show
&& scr
->netdata
->show_desktop
== NULL
) {
489 WWindow
*tmp
, **wins
;
492 wins
= (WWindow
**) wmalloc(sizeof(WWindow
*) * (scr
->window_count
+ 1));
494 tmp
= scr
->focused_window
;
496 if (!tmp
->flags
.hidden
&& !tmp
->flags
.miniaturized
&& !WFLAGP(tmp
, skip_window_list
)) {
499 tmp
->flags
.skip_next_animation
= 1;
500 tmp
->flags
.net_show_desktop
= 1;
508 scr
->netdata
->show_desktop
= wins
;
509 updateShowDesktop(scr
, True
);
510 } else if (scr
->netdata
->show_desktop
!= NULL
) {
511 /* FIXME: get rid of workspace flashing ! */
512 int ws
= scr
->current_workspace
;
514 for (tmp
= scr
->netdata
->show_desktop
; *tmp
; ++tmp
) {
515 wDeiconifyWindow(*tmp
);
516 (*tmp
)->flags
.net_show_desktop
= 0;
518 if (ws
!= scr
->current_workspace
)
519 wWorkspaceChange(scr
, ws
);
520 wfree(scr
->netdata
->show_desktop
);
521 scr
->netdata
->show_desktop
= NULL
;
522 updateShowDesktop(scr
, False
);
526 void wNETWMInitStuff(WScreen
* scr
)
532 printf("wNETWMInitStuff\n");
535 #ifdef HAVE_XINTERNATOMS
540 for (i
= 0; i
< atomNr
; ++i
) {
541 names
[i
] = atomNames
[i
].name
;
543 XInternAtoms(dpy
, &names
[0], atomNr
, False
, atoms
);
544 for (i
= 0; i
< atomNr
; ++i
) {
545 *atomNames
[i
].atom
= atoms
[i
];
549 for (i
= 0; i
< atomNr
; i
++) {
550 *atomNames
[i
].atom
= XInternAtom(dpy
, atomNames
[i
].name
, False
);
554 data
= wmalloc(sizeof(NetData
));
557 data
->show_desktop
= NULL
;
561 setSupportedHints(scr
);
563 WMAddNotificationObserver(observer
, data
, WMNManaged
, NULL
);
564 WMAddNotificationObserver(observer
, data
, WMNUnmanaged
, NULL
);
565 WMAddNotificationObserver(observer
, data
, WMNChangedWorkspace
, NULL
);
566 WMAddNotificationObserver(observer
, data
, WMNChangedState
, NULL
);
567 WMAddNotificationObserver(observer
, data
, WMNChangedFocus
, NULL
);
568 WMAddNotificationObserver(observer
, data
, WMNChangedStacking
, NULL
);
569 WMAddNotificationObserver(observer
, data
, WMNChangedName
, NULL
);
571 WMAddNotificationObserver(wsobserver
, data
, WMNWorkspaceCreated
, NULL
);
572 WMAddNotificationObserver(wsobserver
, data
, WMNWorkspaceDestroyed
, NULL
);
573 WMAddNotificationObserver(wsobserver
, data
, WMNWorkspaceChanged
, NULL
);
574 WMAddNotificationObserver(wsobserver
, data
, WMNWorkspaceNameChanged
, NULL
);
576 updateClientList(scr
);
577 updateClientListStacking(scr
, NULL
);
578 updateWorkspaceCount(scr
);
579 updateWorkspaceNames(scr
);
580 updateShowDesktop(scr
, False
);
582 wScreenUpdateUsableArea(scr
);
585 void wNETWMCleanup(WScreen
* scr
)
589 for (i
= 0; i
< atomNr
; i
++)
590 XDeleteProperty(dpy
, scr
->root_win
, *atomNames
[i
].atom
);
593 void wNETWMUpdateActions(WWindow
* wwin
, Bool del
)
595 Atom action
[10]; /* nr of actions atoms defined */
599 XDeleteProperty(dpy
, wwin
->client_win
, net_wm_allowed_actions
);
603 if (IS_MOVABLE(wwin
))
604 action
[i
++] = net_wm_action_move
;
606 if (IS_RESIZABLE(wwin
))
607 action
[i
++] = net_wm_action_resize
;
609 if (!WFLAGP(wwin
, no_miniaturizable
))
610 action
[i
++] = net_wm_action_minimize
;
612 if (!WFLAGP(wwin
, no_shadeable
))
613 action
[i
++] = net_wm_action_shade
;
615 /* if (!WFLAGP(wwin, no_stickable)) */
616 action
[i
++] = net_wm_action_stick
;
618 /* if (!(WFLAGP(wwin, no_maximizeable) & MAX_HORIZONTAL)) */
619 if (IS_RESIZABLE(wwin
))
620 action
[i
++] = net_wm_action_maximize_horz
;
622 /* if (!(WFLAGP(wwin, no_maximizeable) & MAX_VERTICAL)) */
623 if (IS_RESIZABLE(wwin
))
624 action
[i
++] = net_wm_action_maximize_vert
;
626 /* if (!WFLAGP(wwin, no_fullscreen)) */
627 action
[i
++] = net_wm_action_fullscreen
;
629 /* if (!WFLAGP(wwin, no_change_desktop)) */
630 action
[i
++] = net_wm_action_change_desktop
;
632 if (!WFLAGP(wwin
, no_closable
))
633 action
[i
++] = net_wm_action_close
;
635 XChangeProperty(dpy
, wwin
->client_win
, net_wm_allowed_actions
,
636 XA_ATOM
, 32, PropModeReplace
, (unsigned char *)action
, i
);
639 void wNETWMUpdateWorkarea(WScreen
* scr
, WArea usableArea
)
644 /* XXX: not Xinerama compatible,
645 xinerama gets the largest available */
647 if (!scr
->netdata
|| scr
->workspace_count
== 0)
650 count
= scr
->workspace_count
* 4;
651 area
= wmalloc(sizeof(long) * count
);
652 for (i
= 0; i
< scr
->workspace_count
; i
++) {
653 area
[4 * i
+ 0] = usableArea
.x1
;
654 area
[4 * i
+ 1] = usableArea
.y1
;
655 area
[4 * i
+ 2] = usableArea
.x2
- usableArea
.x1
;
656 area
[4 * i
+ 3] = usableArea
.y2
- usableArea
.y1
;
659 XChangeProperty(dpy
, scr
->root_win
, net_workarea
, XA_CARDINAL
, 32,
660 PropModeReplace
, (unsigned char *)area
, count
);
665 Bool
wNETWMGetUsableArea(WScreen
* scr
, int head
, WArea
* area
)
670 if (!scr
->netdata
|| !scr
->netdata
->strut
)
673 area
->x1
= area
->y1
= area
->x2
= area
->y2
= 0;
675 for (cur
= scr
->netdata
->strut
; cur
; cur
= cur
->next
) {
676 WWindow
*wwin
= wWindowFor(cur
->window
);
677 if (wWindowTouchesHead(wwin
, head
)) {
678 if (cur
->area
.x1
> area
->x1
)
679 area
->x1
= cur
->area
.x1
;
680 if (cur
->area
.y1
> area
->y1
)
681 area
->y1
= cur
->area
.y1
;
682 if (cur
->area
.x2
> area
->x2
)
683 area
->x2
= cur
->area
.x2
;
684 if (cur
->area
.y2
> area
->y2
)
685 area
->y2
= cur
->area
.y2
;
689 if (area
->x1
== 0 && area
->x2
== 0 && area
->y1
== 0 && area
->y2
== 0)
692 rect
= wGetRectForHead(scr
, head
);
694 area
->x1
= rect
.pos
.x
+ area
->x1
;
695 area
->x2
= rect
.pos
.x
+ rect
.size
.width
- area
->x2
;
696 area
->y1
= rect
.pos
.y
+ area
->y1
;
697 area
->y2
= rect
.pos
.y
+ rect
.size
.height
- area
->y2
;
702 static void updateClientList(WScreen
* scr
)
708 windows
= (Window
*) wmalloc(sizeof(Window
) * (scr
->window_count
+ 1));
711 wwin
= scr
->focused_window
;
713 windows
[count
++] = wwin
->client_win
;
716 XChangeProperty(dpy
, scr
->root_win
, net_client_list
, XA_WINDOW
, 32,
717 PropModeReplace
, (unsigned char *)windows
, count
);
723 static void updateClientListStacking(WScreen
* scr
, WWindow
* wwin_excl
)
727 Window
*client_list_reverse
;
733 /* update client list */
734 i
= scr
->window_count
+ 1;
735 client_list
= (Window
*) wmalloc(sizeof(Window
) * i
);
736 client_list_reverse
= (Window
*) wmalloc(sizeof(Window
) * i
);
739 WM_ETARETI_BAG(scr
->stacking_list
, tmp
, iter
) {
741 wwin
= wWindowFor(tmp
->window
);
742 /* wwin_excl is a window to exclude from the list
743 (e.g. it's now unmanaged) */
744 if (wwin
&& (wwin
!= wwin_excl
))
745 client_list
[client_count
++] = wwin
->client_win
;
746 tmp
= tmp
->stacking
->under
;
750 for (i
= 0; i
< client_count
; i
++) {
751 Window w
= client_list
[client_count
- i
- 1];
752 client_list_reverse
[i
] = w
;
755 XChangeProperty(dpy
, scr
->root_win
, net_client_list_stacking
, XA_WINDOW
, 32,
756 PropModeReplace
, (unsigned char *)client_list_reverse
, client_count
);
759 wfree(client_list_reverse
);
764 static void updateWorkspaceCount(WScreen
* scr
)
768 count
= scr
->workspace_count
;
770 XChangeProperty(dpy
, scr
->root_win
, net_number_of_desktops
, XA_CARDINAL
,
771 32, PropModeReplace
, (unsigned char *)&count
, 1);
774 static void updateCurrentWorkspace(WScreen
* scr
)
778 count
= scr
->current_workspace
;
780 XChangeProperty(dpy
, scr
->root_win
, net_current_desktop
, XA_CARDINAL
, 32,
781 PropModeReplace
, (unsigned char *)&count
, 1);
784 static void updateWorkspaceNames(WScreen
* scr
)
786 char buf
[MAX_WORKSPACES
* (MAX_WORKSPACENAME_WIDTH
+ 1)], *pos
;
787 unsigned int i
, len
, curr_size
;
791 for (i
= 0; i
< scr
->workspace_count
; i
++) {
792 curr_size
= strlen(scr
->workspaces
[i
]->name
);
793 strcpy(pos
, scr
->workspaces
[i
]->name
);
794 pos
+= (curr_size
+ 1);
795 len
+= (curr_size
+ 1);
798 XChangeProperty(dpy
, scr
->root_win
, net_desktop_names
, utf8_string
, 8,
799 PropModeReplace
, (unsigned char *)buf
, len
);
802 static void updateFocusHint(WScreen
* scr
, WWindow
* wwin
)
806 if (!scr
->focused_window
|| !scr
->focused_window
->flags
.focused
)
809 window
= scr
->focused_window
->client_win
;
811 XChangeProperty(dpy
, scr
->root_win
, net_active_window
, XA_WINDOW
, 32,
812 PropModeReplace
, (unsigned char *)&window
, 1);
815 static void updateWorkspaceHint(WWindow
* wwin
, Bool fake
, Bool del
)
820 XDeleteProperty(dpy
, wwin
->client_win
, net_wm_desktop
);
822 l
= ((fake
|| IS_OMNIPRESENT(wwin
)) ? -1 : wwin
->frame
->workspace
);
823 XChangeProperty(dpy
, wwin
->client_win
, net_wm_desktop
, XA_CARDINAL
,
824 32, PropModeReplace
, (unsigned char *)&l
, 1);
828 static void updateStateHint(WWindow
* wwin
, Bool changedWorkspace
, Bool del
)
831 if (!wwin
->flags
.net_state_from_client
) {
832 XDeleteProperty(dpy
, wwin
->client_win
, net_wm_state
);
835 Atom state
[15]; /* nr of defined state atoms */
838 if (changedWorkspace
|| (wPreferences
.sticky_icons
&& !IS_OMNIPRESENT(wwin
)))
839 updateWorkspaceHint(wwin
, False
, False
);
841 if (IS_OMNIPRESENT(wwin
))
842 state
[i
++] = net_wm_state_sticky
;
843 if (wwin
->flags
.shaded
)
844 state
[i
++] = net_wm_state_shaded
;
845 if (wwin
->flags
.maximized
& MAX_HORIZONTAL
)
846 state
[i
++] = net_wm_state_maximized_horz
;
847 if (wwin
->flags
.maximized
& MAX_VERTICAL
)
848 state
[i
++] = net_wm_state_maximized_vert
;
849 if (WFLAGP(wwin
, skip_window_list
))
850 state
[i
++] = net_wm_state_skip_taskbar
;
851 if (wwin
->flags
.net_skip_pager
)
852 state
[i
++] = net_wm_state_skip_pager
;
853 if ((wwin
->flags
.hidden
|| wwin
->flags
.miniaturized
) && !wwin
->flags
.net_show_desktop
) {
854 state
[i
++] = net_wm_state_hidden
;
855 state
[i
++] = net_wm_state_skip_pager
;
857 if (wwin
->flags
.miniaturized
&& wPreferences
.sticky_icons
) {
858 if (!IS_OMNIPRESENT(wwin
))
859 updateWorkspaceHint(wwin
, True
, False
);
860 state
[i
++] = net_wm_state_sticky
;
863 if (WFLAGP(wwin
, sunken
))
864 state
[i
++] = net_wm_state_below
;
865 if (WFLAGP(wwin
, floating
))
866 state
[i
++] = net_wm_state_above
;
867 if (wwin
->flags
.fullscreen
)
868 state
[i
++] = net_wm_state_fullscreen
;
870 XChangeProperty(dpy
, wwin
->client_win
, net_wm_state
, XA_ATOM
, 32,
871 PropModeReplace
, (unsigned char *)state
, i
);
875 static Bool
updateStrut(WWindow
* wwin
, Bool adding
)
879 Bool hasState
= False
;
881 scr
= wwin
->screen_ptr
;
886 unsigned long nitems_ret
;
887 unsigned long bytes_after_ret
;
890 if (XGetWindowProperty(dpy
, wwin
->client_win
, net_wm_strut
, 0, 4, False
,
891 XA_CARDINAL
, &type_ret
, &fmt_ret
, &nitems_ret
,
892 &bytes_after_ret
, (unsigned char **)&data
) == Success
&& data
) {
894 area
= (WReservedArea
*) wmalloc(sizeof(WReservedArea
));
895 area
->area
.x1
= data
[0];
896 area
->area
.x2
= data
[1];
897 area
->area
.y1
= data
[2];
898 area
->area
.y2
= data
[3];
900 area
->window
= wwin
->client_win
;
902 area
->next
= scr
->netdata
->strut
;
903 scr
->netdata
->strut
= area
;
907 #ifdef VIRTUAL_DESKTOP
908 /* just in case wm_window_type didn't set it already */
909 wwin
->client_flags
.virtual_stick
= 1;
915 area
= scr
->netdata
->strut
;
918 if (area
->window
== wwin
->client_win
) {
919 scr
->netdata
->strut
= area
->next
;
923 while (area
->next
&& area
->next
->window
!= wwin
->client_win
)
929 next
= area
->next
->next
;
942 static int getWindowLayer(WWindow
* wwin
)
944 int layer
= WMNormalLevel
;
946 if (wwin
->type
== net_wm_window_type_desktop
) {
947 layer
= WMDesktopLevel
;
948 } else if (wwin
->type
== net_wm_window_type_dock
) {
950 } else if (wwin
->type
== net_wm_window_type_toolbar
) {
951 layer
= WMMainMenuLevel
;
952 } else if (wwin
->type
== net_wm_window_type_menu
) {
953 layer
= WMSubmenuLevel
;
954 } else if (wwin
->type
== net_wm_window_type_utility
) {
955 } else if (wwin
->type
== net_wm_window_type_splash
) {
956 } else if (wwin
->type
== net_wm_window_type_dialog
) {
957 if (wwin
->transient_for
) {
958 WWindow
*parent
= wWindowFor(wwin
->transient_for
);
959 if (parent
&& parent
->flags
.fullscreen
) {
960 layer
= WMFullscreenLevel
;
963 /* //layer = WMPopUpLevel; // this seems a bad idea -Dan */
964 } else if (wwin
->type
== net_wm_window_type_normal
) {
967 if (wwin
->client_flags
.sunken
&& WMSunkenLevel
< layer
)
968 layer
= WMSunkenLevel
;
969 if (wwin
->client_flags
.floating
&& WMFloatingLevel
> layer
)
970 layer
= WMFloatingLevel
;
975 static void doStateAtom(WWindow
* wwin
, Atom state
, int set
, Bool init
)
978 if (state
== net_wm_state_sticky
) {
979 if (set
== _NET_WM_STATE_TOGGLE
) {
980 set
= !IS_OMNIPRESENT(wwin
);
982 if (set
!= wwin
->flags
.omnipresent
) {
983 wWindowSetOmnipresent(wwin
, set
);
985 } else if (state
== net_wm_state_shaded
) {
986 if (set
== _NET_WM_STATE_TOGGLE
) {
987 set
= !wwin
->flags
.shaded
;
990 wwin
->flags
.shaded
= set
;
995 wUnshadeWindow(wwin
);
998 } else if (state
== net_wm_state_skip_taskbar
) {
999 if (set
== _NET_WM_STATE_TOGGLE
) {
1000 set
= !wwin
->client_flags
.skip_window_list
;
1002 wwin
->client_flags
.skip_window_list
= set
;
1003 } else if (state
== net_wm_state_skip_pager
) {
1004 if (set
== _NET_WM_STATE_TOGGLE
) {
1005 set
= !wwin
->flags
.net_skip_pager
;
1007 wwin
->flags
.net_skip_pager
= set
;
1008 } else if (state
== net_wm_state_maximized_vert
) {
1009 if (set
== _NET_WM_STATE_TOGGLE
) {
1010 set
= !(wwin
->flags
.maximized
& MAX_VERTICAL
);
1013 wwin
->flags
.maximized
|= (set
? MAX_VERTICAL
: 0);
1016 wMaximizeWindow(wwin
, wwin
->flags
.maximized
| MAX_VERTICAL
);
1018 wMaximizeWindow(wwin
, wwin
->flags
.maximized
& ~MAX_VERTICAL
);
1021 } else if (state
== net_wm_state_maximized_horz
) {
1022 if (set
== _NET_WM_STATE_TOGGLE
) {
1023 set
= !(wwin
->flags
.maximized
& MAX_HORIZONTAL
);
1026 wwin
->flags
.maximized
|= (set
? MAX_HORIZONTAL
: 0);
1029 wMaximizeWindow(wwin
, wwin
->flags
.maximized
| MAX_HORIZONTAL
);
1031 wMaximizeWindow(wwin
, wwin
->flags
.maximized
& ~MAX_HORIZONTAL
);
1034 } else if (state
== net_wm_state_hidden
) {
1035 if (set
== _NET_WM_STATE_TOGGLE
) {
1036 set
= !(wwin
->flags
.miniaturized
);
1039 wwin
->flags
.miniaturized
= set
;
1042 wIconifyWindow(wwin
);
1044 wDeiconifyWindow(wwin
);
1047 } else if (state
== net_wm_state_fullscreen
) {
1048 if (set
== _NET_WM_STATE_TOGGLE
) {
1049 set
= !(wwin
->flags
.fullscreen
);
1052 wwin
->flags
.fullscreen
= set
;
1055 wFullscreenWindow(wwin
);
1057 wUnfullscreenWindow(wwin
);
1060 } else if (state
== net_wm_state_above
) {
1061 if (set
== _NET_WM_STATE_TOGGLE
) {
1062 set
= !(wwin
->client_flags
.floating
);
1065 wwin
->client_flags
.floating
= set
;
1067 wwin
->client_flags
.floating
= set
;
1068 ChangeStackingLevel(wwin
->frame
->core
, getWindowLayer(wwin
));
1071 } else if (state
== net_wm_state_below
) {
1072 if (set
== _NET_WM_STATE_TOGGLE
) {
1073 set
= !(wwin
->client_flags
.sunken
);
1076 wwin
->client_flags
.sunken
= set
;
1078 wwin
->client_flags
.sunken
= set
;
1079 ChangeStackingLevel(wwin
->frame
->core
, getWindowLayer(wwin
));
1084 printf("doStateAtom unknown atom %s set %d\n", XGetAtomName(dpy
, state
), set
);
1089 static void removeIcon(WWindow
* wwin
)
1091 if (wwin
->icon
== NULL
)
1093 if (wwin
->flags
.miniaturized
&& wwin
->icon
->mapped
) {
1094 XUnmapWindow(dpy
, wwin
->icon
->core
->window
);
1095 RemoveFromStackList(wwin
->icon
->core
);
1096 wIconDestroy(wwin
->icon
);
1101 static Bool
handleWindowType(WWindow
* wwin
, Atom type
, int *layer
)
1105 if (type
== net_wm_window_type_desktop
) {
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_border
= 1;
1110 wwin
->client_flags
.no_resizebar
= 1;
1111 wwin
->client_flags
.no_shadeable
= 1;
1112 wwin
->client_flags
.no_movable
= 1;
1113 wwin
->client_flags
.omnipresent
= 1;
1114 wwin
->client_flags
.skip_window_list
= 1;
1115 wwin
->client_flags
.dont_move_off
= 1;
1116 wwin
->client_flags
.no_appicon
= 1;
1117 wwin
->flags
.net_skip_pager
= 1;
1120 #ifdef VIRTUAL_DESKTOP
1121 wwin
->client_flags
.virtual_stick
= 1;
1123 } else if (type
== net_wm_window_type_dock
) {
1124 wwin
->client_flags
.no_titlebar
= 1;
1125 wwin
->client_flags
.no_resizable
= 1;
1126 wwin
->client_flags
.no_miniaturizable
= 1;
1127 wwin
->client_flags
.no_border
= 1; /* XXX: really not a single decoration. */
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
.omnipresent
= 1;
1132 wwin
->client_flags
.skip_window_list
= 1;
1133 wwin
->client_flags
.dont_move_off
= 1;
1134 wwin
->flags
.net_skip_pager
= 1;
1135 #ifdef VIRTUAL_DESKTOP
1136 wwin
->client_flags
.virtual_stick
= 1;
1138 } else if (type
== net_wm_window_type_toolbar
) {
1139 wwin
->client_flags
.no_titlebar
= 1;
1140 wwin
->client_flags
.no_resizable
= 1;
1141 wwin
->client_flags
.no_miniaturizable
= 1;
1142 wwin
->client_flags
.no_resizebar
= 1;
1143 wwin
->client_flags
.no_shadeable
= 1;
1144 wwin
->client_flags
.skip_window_list
= 1;
1145 wwin
->client_flags
.dont_move_off
= 1;
1146 wwin
->client_flags
.no_appicon
= 1;
1147 } else if (type
== net_wm_window_type_menu
) {
1148 wwin
->client_flags
.no_titlebar
= 1;
1149 wwin
->client_flags
.no_resizable
= 1;
1150 wwin
->client_flags
.no_miniaturizable
= 1;
1151 wwin
->client_flags
.no_resizebar
= 1;
1152 wwin
->client_flags
.no_shadeable
= 1;
1153 wwin
->client_flags
.skip_window_list
= 1;
1154 wwin
->client_flags
.dont_move_off
= 1;
1155 wwin
->client_flags
.no_appicon
= 1;
1156 } else if (type
== net_wm_window_type_utility
) {
1157 wwin
->client_flags
.no_appicon
= 1;
1158 } else if (type
== net_wm_window_type_splash
) {
1159 wwin
->client_flags
.no_titlebar
= 1;
1160 wwin
->client_flags
.no_resizable
= 1;
1161 wwin
->client_flags
.no_miniaturizable
= 1;
1162 wwin
->client_flags
.no_resizebar
= 1;
1163 wwin
->client_flags
.no_shadeable
= 1;
1164 wwin
->client_flags
.no_movable
= 1;
1165 wwin
->client_flags
.skip_window_list
= 1;
1166 wwin
->client_flags
.dont_move_off
= 1;
1167 wwin
->client_flags
.no_appicon
= 1;
1168 wwin
->flags
.net_skip_pager
= 1;
1169 } else if (type
== net_wm_window_type_dialog
) {
1170 /* These also seem a bad idea in our context -Dan
1171 // wwin->client_flags.skip_window_list = 1;
1172 // wwin->client_flags.no_appicon = 1;
1174 } else if (type
== net_wm_window_type_normal
) {
1180 *layer
= getWindowLayer(wwin
);
1185 void wNETWMPositionSplash(WWindow
* wwin
, int *x
, int *y
, int width
, int height
)
1187 if (wwin
->type
== net_wm_window_type_splash
) {
1188 WScreen
*scr
= wwin
->screen_ptr
;
1189 WMRect rect
= wGetRectForHead(scr
, wGetHeadForPointerLocation(scr
));
1190 *x
= rect
.pos
.x
+ (rect
.size
.width
- width
) / 2;
1191 *y
= rect
.pos
.y
+ (rect
.size
.height
- height
) / 2;
1195 static void updateWindowType(WWindow
* wwin
)
1199 unsigned long nitems_ret
;
1200 unsigned long bytes_after_ret
;
1203 if (XGetWindowProperty(dpy
, wwin
->client_win
, net_wm_window_type
, 0, 1,
1204 False
, XA_ATOM
, &type_ret
, &fmt_ret
, &nitems_ret
,
1205 &bytes_after_ret
, (unsigned char **)&data
) == Success
&& data
) {
1208 Atom
*type
= (Atom
*) data
;
1209 for (i
= 0; i
< nitems_ret
; ++i
) {
1210 if (handleWindowType(wwin
, type
[i
], &layer
))
1216 if (wwin
->frame
!= NULL
) {
1217 ChangeStackingLevel(wwin
->frame
->core
, layer
);
1218 wwin
->frame
->flags
.need_texture_change
= 1;
1219 wWindowConfigureBorders(wwin
);
1220 wFrameWindowPaint(wwin
->frame
);
1221 wNETWMUpdateActions(wwin
, False
);
1225 Bool
wNETWMCheckClientHints(WWindow
* wwin
, int *layer
, int *workspace
)
1229 unsigned long nitems_ret
;
1230 unsigned long bytes_after_ret
;
1232 Bool hasState
= False
;
1235 if (XGetWindowProperty(dpy
, wwin
->client_win
, net_wm_desktop
, 0, 1, False
,
1236 XA_CARDINAL
, &type_ret
, &fmt_ret
, &nitems_ret
,
1237 &bytes_after_ret
, (unsigned char **)&data
) == Success
&& data
) {
1239 long desktop
= *data
;
1243 wwin
->client_flags
.omnipresent
= 1;
1245 *workspace
= desktop
;
1250 if (XGetWindowProperty(dpy
, wwin
->client_win
, net_wm_state
, 0, 1, False
,
1251 XA_ATOM
, &type_ret
, &fmt_ret
, &nitems_ret
,
1252 &bytes_after_ret
, (unsigned char **)&data
) == Success
&& data
) {
1254 Atom
*state
= (Atom
*) data
;
1255 for (i
= 0; i
< nitems_ret
; ++i
) {
1256 doStateAtom(wwin
, state
[i
], _NET_WM_STATE_ADD
, True
);
1262 if (XGetWindowProperty(dpy
, wwin
->client_win
, net_wm_window_type
, 0, 1, False
,
1263 XA_ATOM
, &type_ret
, &fmt_ret
, &nitems_ret
,
1264 &bytes_after_ret
, (unsigned char **)&data
) == Success
&& data
) {
1266 Atom
*type
= (Atom
*) data
;
1267 for (i
= 0; i
< nitems_ret
; ++i
) {
1268 if (handleWindowType(wwin
, type
[i
], layer
))
1275 wNETWMUpdateActions(wwin
, False
);
1276 updateStrut(wwin
, False
);
1277 if (updateStrut(wwin
, True
)) {
1280 wScreenUpdateUsableArea(wwin
->screen_ptr
);
1285 static Bool
updateNetIconInfo(WWindow
* wwin
)
1290 unsigned long nitems_ret
;
1291 unsigned long bytes_after_ret
;
1293 Bool hasState
= False
;
1294 Bool old_state
= wwin
->flags
.net_handle_icon
;
1296 if (XGetWindowProperty(dpy
, wwin
->client_win
, net_wm_handled_icons
, 0, 1, False
,
1297 XA_CARDINAL
, &type_ret
, &fmt_ret
, &nitems_ret
,
1298 &bytes_after_ret
, (unsigned char **)&data
) == Success
&& data
) {
1299 long handled
= *data
;
1300 wwin
->flags
.net_handle_icon
= (handled
!= 0);
1305 wwin
->flags
.net_handle_icon
= False
;
1307 if (XGetWindowProperty(dpy
, wwin
->client_win
, net_wm_icon_geometry
, 0, 4, False
,
1308 XA_CARDINAL
, &type_ret
, &fmt_ret
, &nitems_ret
,
1309 &bytes_after_ret
, (unsigned char **)&data
) == Success
&& data
) {
1312 if (wwin
->flags
.net_handle_icon
)
1314 wwin
->flags
.net_handle_icon
= True
;
1317 wwin
->icon_x
= data
[0];
1318 wwin
->icon_y
= data
[1];
1319 wwin
->icon_w
= data
[2];
1320 wwin
->icon_h
= data
[3];
1327 wwin
->flags
.net_handle_icon
= False
;
1329 if (wwin
->flags
.miniaturized
&& old_state
!= wwin
->flags
.net_handle_icon
) {
1330 if (wwin
->flags
.net_handle_icon
) {
1333 wwin
->flags
.miniaturized
= False
;
1334 wwin
->flags
.skip_next_animation
= True
;
1335 wIconifyWindow(wwin
);
1342 Bool
wNETWMCheckInitialClientState(WWindow
* wwin
)
1344 Bool hasState
= False
;
1347 printf("CheckInitialClientState\n");
1350 wNETWMShowingDesktop(wwin
->screen_ptr
, False
);
1352 hasState
|= updateNetIconInfo(wwin
);
1354 updateIconImage(wwin
->screen_ptr
, wwin
);
1359 static void handleDesktopNames(XClientMessageEvent
* event
, WScreen
* scr
)
1361 unsigned long nitems_ret
, bytes_after_ret
;
1362 char *data
, *names
[32];
1366 if (XGetWindowProperty(dpy
, scr
->root_win
, net_desktop_names
, 0, 1, False
,
1367 utf8_string
, &type_ret
, &fmt_ret
, &nitems_ret
,
1368 &bytes_after_ret
, (unsigned char **)&data
) != Success
) {
1375 if (type_ret
!= utf8_string
|| fmt_ret
!= 8)
1380 for (i
= 0; i
< nitems_ret
; i
++) {
1383 names
[n
] = &data
[i
];
1384 } else if (*names
[n
] == 0) {
1385 names
[n
] = &data
[i
];
1386 wWorkspaceRename(scr
, n
, names
[n
]);
1391 Bool
wNETWMProcessClientMessage(XClientMessageEvent
* event
)
1398 printf("processClientMessage type %s\n", XGetAtomName(dpy
, event
->message_type
));
1401 scr
= wScreenForWindow(event
->window
);
1403 /* generic client messages */
1404 if (event
->message_type
== net_current_desktop
) {
1405 wWorkspaceChange(scr
, event
->data
.l
[0]);
1406 } else if (event
->message_type
== net_number_of_desktops
) {
1409 value
= event
->data
.l
[0];
1410 if (value
> scr
->workspace_count
) {
1411 wWorkspaceMake(scr
, value
- scr
->workspace_count
);
1412 } else if (value
< scr
->workspace_count
) {
1414 Bool rebuild
= False
;
1416 for (i
= scr
->workspace_count
- 1; i
>= value
; i
--) {
1417 if (!wWorkspaceDelete(scr
, i
)) {
1424 updateWorkspaceCount(scr
);
1427 } else if (event
->message_type
== net_showing_desktop
) {
1428 wNETWMShowingDesktop(scr
, event
->data
.l
[0]);
1429 #ifdef VIRTUAL_DESKTOP
1430 } else if (event
->message_type
== net_desktop_viewport
) {
1431 wWorkspaceSetViewport(scr
, scr
->current_workspace
, event
->data
.l
[0], event
->data
.l
[1]);
1433 } else if (event
->message_type
== net_desktop_names
) {
1434 handleDesktopNames(event
, scr
);
1443 /* window specific client messages */
1445 wwin
= wWindowFor(event
->window
);
1449 if (event
->message_type
== net_active_window
) {
1451 * Firefox sends aditional 'net_active_window' signals on startup if
1452 * multiple tabs are open. That causes unnecessary workspace switching if
1453 * those signals come from other workspaces. Therefore we also check if
1454 * we should ignore these spurious focus across workspaces requests (but
1455 * allow the switching if it comes from a pager).
1457 if (wwin
->frame
->workspace
== wwin
->screen_ptr
->current_workspace
1458 || !WFLAGP(wwin
, dont_focus_across_wksp
) || event
->data
.l
[0] == 2) {
1459 wNETWMShowingDesktop(scr
, False
);
1460 wMakeWindowVisible(wwin
);
1462 } else if (event
->message_type
== net_close_window
) {
1463 if (!WFLAGP(wwin
, no_closable
)) {
1464 if (wwin
->protocols
.DELETE_WINDOW
)
1465 wClientSendProtocol(wwin
, _XA_WM_DELETE_WINDOW
, LastTimestamp
);
1467 } else if (event
->message_type
== net_wm_state
) {
1468 int maximized
= wwin
->flags
.maximized
;
1469 long set
= event
->data
.l
[0];
1472 printf("net_wm_state set %d a1 %s a2 %s\n", set
,
1473 XGetAtomName(dpy
, event
->data
.l
[1]), XGetAtomName(dpy
, event
->data
.l
[2]));
1476 doStateAtom(wwin
, (Atom
) event
->data
.l
[1], set
, False
);
1477 if (event
->data
.l
[2])
1478 doStateAtom(wwin
, (Atom
) event
->data
.l
[2], set
, False
);
1480 if (wwin
->flags
.maximized
!= maximized
) {
1481 if (!wwin
->flags
.maximized
) {
1482 wwin
->flags
.maximized
= maximized
;
1483 wUnmaximizeWindow(wwin
);
1485 wMaximizeWindow(wwin
, wwin
->flags
.maximized
);
1488 updateStateHint(wwin
, False
, False
);
1489 } else if (event
->message_type
== net_wm_handled_icons
|| event
->message_type
== net_wm_icon_geometry
) {
1490 updateNetIconInfo(wwin
);
1491 } else if (event
->message_type
== net_wm_desktop
) {
1492 long desktop
= event
->data
.l
[0];
1493 if (desktop
== -1) {
1494 wWindowSetOmnipresent(wwin
, True
);
1496 if (IS_OMNIPRESENT(wwin
))
1497 wWindowSetOmnipresent(wwin
, False
);
1498 wWindowChangeWorkspace(wwin
, desktop
);
1500 } else if (event
->message_type
== net_wm_icon
) {
1501 updateIconImage(scr
, wwin
);
1509 Bool
wNETWMCheckClientHintChange(WWindow
* wwin
, XPropertyEvent
* event
)
1513 if (event
->atom
== net_wm_strut
) {
1514 updateStrut(wwin
, False
);
1515 updateStrut(wwin
, True
);
1516 wScreenUpdateUsableArea(wwin
->screen_ptr
);
1517 } else if (event
->atom
== net_wm_handled_icons
|| event
->atom
== net_wm_icon_geometry
) {
1518 updateNetIconInfo(wwin
);
1519 } else if (event
->atom
== net_wm_window_type
) {
1520 updateWindowType(wwin
);
1521 } else if (event
->atom
== net_wm_name
) {
1522 char *name
= wNETWMGetWindowName(wwin
->client_win
);
1523 wWindowUpdateName(wwin
, name
);
1526 } else if (event
->atom
== net_wm_icon_name
) {
1528 char *name
= wNETWMGetIconName(wwin
->client_win
);
1529 wIconChangeTitle(wwin
->icon
, name
);
1538 int wNETWMGetPidForWindow(Window window
)
1542 unsigned long nitems_ret
;
1543 unsigned long bytes_after_ret
;
1547 if (XGetWindowProperty(dpy
, window
, net_wm_pid
, 0, 1, False
,
1548 XA_CARDINAL
, &type_ret
, &fmt_ret
, &nitems_ret
,
1549 &bytes_after_ret
, (unsigned char **)&data
) == Success
&& data
) {
1560 char *wNETWMGetWindowName(Window window
)
1566 name
= (char *)PropGetCheckProperty(window
, net_wm_name
, utf8_string
, 0, 0, &size
);
1568 ret
= wstrndup(name
, size
);
1575 char *wNETWMGetIconName(Window window
)
1581 name
= (char *)PropGetCheckProperty(window
, net_wm_icon_name
, utf8_string
, 0, 0, &size
);
1583 ret
= wstrndup(name
, size
);
1590 static void observer(void *self
, WMNotification
* notif
)
1592 WWindow
*wwin
= (WWindow
*) WMGetNotificationObject(notif
);
1593 const char *name
= WMGetNotificationName(notif
);
1594 void *data
= WMGetNotificationClientData(notif
);
1595 NetData
*ndata
= (NetData
*) self
;
1597 if (strcmp(name
, WMNManaged
) == 0 && wwin
) {
1598 updateClientList(wwin
->screen_ptr
);
1599 updateClientListStacking(wwin
->screen_ptr
, NULL
);
1600 updateStateHint(wwin
, True
, False
);
1602 updateStrut(wwin
, False
);
1603 updateStrut(wwin
, True
);
1604 wScreenUpdateUsableArea(wwin
->screen_ptr
);
1605 } else if (strcmp(name
, WMNUnmanaged
) == 0 && wwin
) {
1606 updateClientList(wwin
->screen_ptr
);
1607 updateClientListStacking(wwin
->screen_ptr
, wwin
);
1608 updateWorkspaceHint(wwin
, False
, True
);
1609 updateStateHint(wwin
, False
, True
);
1610 wNETWMUpdateActions(wwin
, True
);
1612 updateStrut(wwin
, False
);
1613 wScreenUpdateUsableArea(wwin
->screen_ptr
);
1614 } else if (strcmp(name
, WMNResetStacking
) == 0 && wwin
) {
1615 updateClientListStacking(wwin
->screen_ptr
, NULL
);
1616 updateStateHint(wwin
, False
, False
);
1617 } else if (strcmp(name
, WMNChangedStacking
) == 0 && wwin
) {
1618 updateClientListStacking(wwin
->screen_ptr
, NULL
);
1619 updateStateHint(wwin
, False
, False
);
1620 } else if (strcmp(name
, WMNChangedFocus
) == 0) {
1621 updateFocusHint(ndata
->scr
, wwin
);
1622 } else if (strcmp(name
, WMNChangedWorkspace
) == 0 && wwin
) {
1623 updateWorkspaceHint(wwin
, False
, False
);
1624 updateStateHint(wwin
, True
, False
);
1625 } else if (strcmp(name
, WMNChangedState
) == 0 && wwin
) {
1626 updateStateHint(wwin
, !strcmp(data
, "omnipresent"), False
);
1630 static void wsobserver(void *self
, WMNotification
* notif
)
1632 WScreen
*scr
= (WScreen
*) WMGetNotificationObject(notif
);
1633 const char *name
= WMGetNotificationName(notif
);
1635 if (strcmp(name
, WMNWorkspaceCreated
) == 0) {
1636 updateWorkspaceCount(scr
);
1637 updateWorkspaceNames(scr
);
1638 } else if (strcmp(name
, WMNWorkspaceDestroyed
) == 0) {
1639 updateWorkspaceCount(scr
);
1640 updateWorkspaceNames(scr
);
1641 } else if (strcmp(name
, WMNWorkspaceChanged
) == 0) {
1642 updateCurrentWorkspace(scr
);
1643 } else if (strcmp(name
, WMNWorkspaceNameChanged
) == 0) {
1644 updateWorkspaceNames(scr
);