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
37 #include <X11/Xatom.h>
38 #include <X11/Xarch.h>
41 #include "WindowMaker.h"
44 #include "workspace.h"
52 #include "properties.h"
58 /* Global variables */
59 extern Atom _XA_WM_DELETE_WINDOW
;
60 extern Time LastTimestamp
;
61 extern WPreferences wPreferences
;
63 /* Root Window Properties */
64 static Atom net_supported
;
65 static Atom net_client_list
;
66 static Atom net_client_list_stacking
;
67 static Atom net_number_of_desktops
;
68 static Atom net_desktop_geometry
;
69 static Atom net_desktop_viewport
;
70 static Atom net_current_desktop
;
71 static Atom net_desktop_names
;
72 static Atom net_active_window
;
73 static Atom net_workarea
; /* XXX: not xinerama compatible */
74 static Atom net_supporting_wm_check
;
75 static Atom net_virtual_roots
; /* N/A */
76 static Atom net_desktop_layout
; /* XXX */
77 static Atom net_showing_desktop
;
79 /* Other Root Window Messages */
80 static Atom net_close_window
;
81 static Atom net_moveresize_window
; /* TODO */
82 static Atom net_wm_moveresize
; /* TODO */
84 /* Application Window Properties */
85 static Atom net_wm_name
;
86 static Atom net_wm_visible_name
; /* TODO (unnecessary?) */
87 static Atom net_wm_icon_name
;
88 static Atom net_wm_visible_icon_name
; /* TODO (unnecessary?) */
89 static Atom net_wm_desktop
;
90 static Atom net_wm_window_type
;
91 static Atom net_wm_window_type_desktop
;
92 static Atom net_wm_window_type_dock
;
93 static Atom net_wm_window_type_toolbar
;
94 static Atom net_wm_window_type_menu
;
95 static Atom net_wm_window_type_utility
;
96 static Atom net_wm_window_type_splash
;
97 static Atom net_wm_window_type_dialog
;
98 static Atom net_wm_window_type_normal
;
99 static Atom net_wm_state
;
100 static Atom net_wm_state_modal
; /* XXX: what is this?!? */
101 static Atom net_wm_state_sticky
;
102 static Atom net_wm_state_maximized_vert
;
103 static Atom net_wm_state_maximized_horz
;
104 static Atom net_wm_state_shaded
;
105 static Atom net_wm_state_skip_taskbar
;
106 static Atom net_wm_state_skip_pager
;
107 static Atom net_wm_state_hidden
;
108 static Atom net_wm_state_fullscreen
;
109 static Atom net_wm_state_above
;
110 static Atom net_wm_state_below
;
111 static Atom net_wm_allowed_actions
;
112 static Atom net_wm_action_move
;
113 static Atom net_wm_action_resize
;
114 static Atom net_wm_action_minimize
;
115 static Atom net_wm_action_shade
;
116 static Atom net_wm_action_stick
;
117 static Atom net_wm_action_maximize_horz
;
118 static Atom net_wm_action_maximize_vert
;
119 static Atom net_wm_action_fullscreen
;
120 static Atom net_wm_action_change_desktop
;
121 static Atom net_wm_action_close
;
122 static Atom net_wm_strut
; /* XXX: see net_workarea */
123 static Atom net_wm_strut_partial
; /* TODO: doesn't really fit into the current strut scheme */
124 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. */
125 static Atom net_wm_icon
;
126 static Atom net_wm_pid
; /* TODO */
127 static Atom net_wm_handled_icons
; /* FIXME: see net_wm_icon_geometry */
129 /* Window Manager Protocols */
130 static Atom net_wm_ping
; /* TODO */
132 static Atom utf8_string
;
139 static atomitem_t atomNames
[] = {
140 {"_NET_SUPPORTED", &net_supported
},
141 {"_NET_CLIENT_LIST", &net_client_list
},
142 {"_NET_CLIENT_LIST_STACKING", &net_client_list_stacking
},
143 {"_NET_NUMBER_OF_DESKTOPS", &net_number_of_desktops
},
144 {"_NET_DESKTOP_GEOMETRY", &net_desktop_geometry
},
145 {"_NET_DESKTOP_VIEWPORT", &net_desktop_viewport
},
146 {"_NET_CURRENT_DESKTOP", &net_current_desktop
},
147 {"_NET_DESKTOP_NAMES", &net_desktop_names
},
148 {"_NET_ACTIVE_WINDOW", &net_active_window
},
149 {"_NET_WORKAREA", &net_workarea
},
150 {"_NET_SUPPORTING_WM_CHECK", &net_supporting_wm_check
},
151 {"_NET_VIRTUAL_ROOTS", &net_virtual_roots
},
152 {"_NET_DESKTOP_LAYOUT", &net_desktop_layout
},
153 {"_NET_SHOWING_DESKTOP", &net_showing_desktop
},
155 {"_NET_CLOSE_WINDOW", &net_close_window
},
156 {"_NET_MOVERESIZE_WINDOW", &net_moveresize_window
},
157 {"_NET_WM_MOVERESIZE", &net_wm_moveresize
},
159 {"_NET_WM_NAME", &net_wm_name
},
160 {"_NET_WM_VISIBLE_NAME", &net_wm_visible_name
},
161 {"_NET_WM_ICON_NAME", &net_wm_icon_name
},
162 {"_NET_WM_VISIBLE_ICON_NAME", &net_wm_visible_icon_name
},
163 {"_NET_WM_DESKTOP", &net_wm_desktop
},
164 {"_NET_WM_WINDOW_TYPE", &net_wm_window_type
},
165 {"_NET_WM_WINDOW_TYPE_DESKTOP", &net_wm_window_type_desktop
},
166 {"_NET_WM_WINDOW_TYPE_DOCK", &net_wm_window_type_dock
},
167 {"_NET_WM_WINDOW_TYPE_TOOLBAR", &net_wm_window_type_toolbar
},
168 {"_NET_WM_WINDOW_TYPE_MENU", &net_wm_window_type_menu
},
169 {"_NET_WM_WINDOW_TYPE_UTILITY", &net_wm_window_type_utility
},
170 {"_NET_WM_WINDOW_TYPE_SPLASH", &net_wm_window_type_splash
},
171 {"_NET_WM_WINDOW_TYPE_DIALOG", &net_wm_window_type_dialog
},
172 {"_NET_WM_WINDOW_TYPE_NORMAL", &net_wm_window_type_normal
},
173 {"_NET_WM_STATE", &net_wm_state
},
174 {"_NET_WM_STATE_MODAL", &net_wm_state_modal
},
175 {"_NET_WM_STATE_STICKY", &net_wm_state_sticky
},
176 {"_NET_WM_STATE_MAXIMIZED_VERT", &net_wm_state_maximized_vert
},
177 {"_NET_WM_STATE_MAXIMIZED_HORZ", &net_wm_state_maximized_horz
},
178 {"_NET_WM_STATE_SHADED", &net_wm_state_shaded
},
179 {"_NET_WM_STATE_SKIP_TASKBAR", &net_wm_state_skip_taskbar
},
180 {"_NET_WM_STATE_SKIP_PAGER", &net_wm_state_skip_pager
},
181 {"_NET_WM_STATE_HIDDEN", &net_wm_state_hidden
},
182 {"_NET_WM_STATE_FULLSCREEN", &net_wm_state_fullscreen
},
183 {"_NET_WM_STATE_ABOVE", &net_wm_state_above
},
184 {"_NET_WM_STATE_BELOW", &net_wm_state_below
},
185 {"_NET_WM_ALLOWED_ACTIONS", &net_wm_allowed_actions
},
186 {"_NET_WM_ACTION_MOVE", &net_wm_action_move
},
187 {"_NET_WM_ACTION_RESIZE", &net_wm_action_resize
},
188 {"_NET_WM_ACTION_MINIMIZE", &net_wm_action_minimize
},
189 {"_NET_WM_ACTION_SHADE", &net_wm_action_shade
},
190 {"_NET_WM_ACTION_STICK", &net_wm_action_stick
},
191 {"_NET_WM_ACTION_MAXIMIZE_HORZ", &net_wm_action_maximize_horz
},
192 {"_NET_WM_ACTION_MAXIMIZE_VERT", &net_wm_action_maximize_vert
},
193 {"_NET_WM_ACTION_FULLSCREEN", &net_wm_action_fullscreen
},
194 {"_NET_WM_ACTION_CHANGE_DESKTOP", &net_wm_action_change_desktop
},
195 {"_NET_WM_ACTION_CLOSE", &net_wm_action_close
},
196 {"_NET_WM_STRUT", &net_wm_strut
},
197 {"_NET_WM_STRUT_PARTIAL", &net_wm_strut_partial
},
198 {"_NET_WM_ICON_GEOMETRY", &net_wm_icon_geometry
},
199 {"_NET_WM_ICON", &net_wm_icon
},
200 {"_NET_WM_PID", &net_wm_pid
},
201 {"_NET_WM_HANDLED_ICONS", &net_wm_handled_icons
},
203 {"_NET_WM_PING", &net_wm_ping
},
205 {"UTF8_STRING", &utf8_string
},
208 #define atomNr (sizeof(atomNames)/sizeof(atomitem_t))
210 #define _NET_WM_STATE_REMOVE 0
211 #define _NET_WM_STATE_ADD 1
212 #define _NET_WM_STATE_TOGGLE 2
214 #define _NET_WM_MOVERESIZE_SIZE_TOPLEFT 0
215 #define _NET_WM_MOVERESIZE_SIZE_TOP 1
216 #define _NET_WM_MOVERESIZE_SIZE_TOPRIGHT 2
217 #define _NET_WM_MOVERESIZE_SIZE_RIGHT 3
218 #define _NET_WM_MOVERESIZE_SIZE_BOTTOMRIGHT 4
219 #define _NET_WM_MOVERESIZE_SIZE_BOTTOM 5
220 #define _NET_WM_MOVERESIZE_SIZE_BOTTOMLEFT 6
221 #define _NET_WM_MOVERESIZE_SIZE_LEFT 7
222 #define _NET_WM_MOVERESIZE_MOVE 8 /* movement only */
223 #define _NET_WM_MOVERESIZE_SIZE_KEYBOARD 9 /* size via keyboard */
224 #define _NET_WM_MOVERESIZE_MOVE_KEYBOARD 10 /* move via keyboard */
226 static void observer(void *self
, WMNotification
* notif
);
227 static void wsobserver(void *self
, WMNotification
* notif
);
229 static void updateClientList(WScreen
* scr
);
230 static void updateClientListStacking(WScreen
* scr
, WWindow
*);
232 static void updateWorkspaceNames(WScreen
* scr
);
233 static void updateCurrentWorkspace(WScreen
* scr
);
234 static void updateWorkspaceCount(WScreen
* scr
);
236 typedef struct NetData
{
238 WReservedArea
*strut
;
239 WWindow
**show_desktop
;
242 static void setSupportedHints(WScreen
* scr
)
247 /* set supported hints list */
248 /* XXX: extend this !!! */
250 atom
[i
++] = net_client_list
;
251 atom
[i
++] = net_client_list_stacking
;
252 atom
[i
++] = net_number_of_desktops
;
253 atom
[i
++] = net_desktop_geometry
;
254 atom
[i
++] = net_desktop_viewport
;
255 atom
[i
++] = net_current_desktop
;
256 atom
[i
++] = net_desktop_names
;
257 atom
[i
++] = net_active_window
;
258 atom
[i
++] = net_workarea
;
259 atom
[i
++] = net_supporting_wm_check
;
260 atom
[i
++] = net_showing_desktop
;
262 atom
[i
++] = net_wm_moveresize
;
264 atom
[i
++] = net_wm_desktop
;
265 atom
[i
++] = net_wm_window_type
;
266 atom
[i
++] = net_wm_window_type_desktop
;
267 atom
[i
++] = net_wm_window_type_dock
;
268 atom
[i
++] = net_wm_window_type_toolbar
;
269 atom
[i
++] = net_wm_window_type_menu
;
270 atom
[i
++] = net_wm_window_type_utility
;
271 atom
[i
++] = net_wm_window_type_splash
;
272 atom
[i
++] = net_wm_window_type_dialog
;
273 atom
[i
++] = net_wm_window_type_normal
;
275 atom
[i
++] = net_wm_state
;
276 /* atom[i++] = net_wm_state_modal; *//* XXX: not sure where/when to use it. */
277 atom
[i
++] = net_wm_state_sticky
;
278 atom
[i
++] = net_wm_state_shaded
;
279 atom
[i
++] = net_wm_state_maximized_horz
;
280 atom
[i
++] = net_wm_state_maximized_vert
;
281 atom
[i
++] = net_wm_state_skip_taskbar
;
282 atom
[i
++] = net_wm_state_skip_pager
;
283 atom
[i
++] = net_wm_state_hidden
;
284 atom
[i
++] = net_wm_state_fullscreen
;
285 atom
[i
++] = net_wm_state_above
;
286 atom
[i
++] = net_wm_state_below
;
288 atom
[i
++] = net_wm_allowed_actions
;
289 atom
[i
++] = net_wm_action_move
;
290 atom
[i
++] = net_wm_action_resize
;
291 atom
[i
++] = net_wm_action_minimize
;
292 atom
[i
++] = net_wm_action_shade
;
293 atom
[i
++] = net_wm_action_stick
;
294 atom
[i
++] = net_wm_action_maximize_horz
;
295 atom
[i
++] = net_wm_action_maximize_vert
;
296 atom
[i
++] = net_wm_action_fullscreen
;
297 atom
[i
++] = net_wm_action_change_desktop
;
298 atom
[i
++] = net_wm_action_close
;
300 atom
[i
++] = net_wm_strut
;
301 atom
[i
++] = net_wm_icon_geometry
;
302 atom
[i
++] = net_wm_icon
;
303 atom
[i
++] = net_wm_handled_icons
;
305 atom
[i
++] = net_wm_name
;
306 atom
[i
++] = net_wm_icon_name
;
308 XChangeProperty(dpy
, scr
->root_win
, net_supported
, XA_ATOM
, 32, PropModeReplace
, (unsigned char *)atom
, i
);
310 /* set supporting wm hint */
311 XChangeProperty(dpy
, scr
->root_win
, net_supporting_wm_check
, XA_WINDOW
, 32,
312 PropModeReplace
, (unsigned char *)&scr
->info_window
, 1);
314 XChangeProperty(dpy
, scr
->info_window
, net_supporting_wm_check
, XA_WINDOW
,
315 32, PropModeReplace
, (unsigned char *)&scr
->info_window
, 1);
318 void wNETWMUpdateDesktop(WScreen
* scr
)
320 long *views
, sizes
[2];
323 if (scr
->workspace_count
== 0)
326 count
= scr
->workspace_count
* 2;
327 views
= wmalloc(sizeof(long) * count
);
328 /*memset(views, 0, sizeof(long) * count); */
330 #ifdef VIRTUAL_DESKTOP
331 sizes
[0] = scr
->workspaces
[scr
->current_workspace
]->width
;
332 sizes
[1] = scr
->workspaces
[scr
->current_workspace
]->height
;
334 sizes
[0] = scr
->scr_width
;
335 sizes
[1] = scr
->scr_height
;
338 for (i
= 0; i
< scr
->workspace_count
; i
++) {
339 #ifdef VIRTUAL_DESKTOP
340 views
[2 * i
+ 0] = scr
->workspaces
[i
]->view_x
;
341 views
[2 * i
+ 1] = scr
->workspaces
[i
]->view_y
;
343 views
[2 * i
+ 0] = 0;
344 views
[2 * i
+ 1] = 0;
348 XChangeProperty(dpy
, scr
->root_win
, net_desktop_geometry
, XA_CARDINAL
, 32,
349 PropModeReplace
, (unsigned char *)sizes
, 2);
351 XChangeProperty(dpy
, scr
->root_win
, net_desktop_viewport
, XA_CARDINAL
, 32,
352 PropModeReplace
, (unsigned char *)views
, count
);
357 int wNETWMGetCurrentDesktopFromHint(WScreen
* scr
)
362 prop
= PropGetCheckProperty(scr
->root_win
, net_current_desktop
, XA_CARDINAL
, 0, 1, &count
);
364 int desktop
= *(long *)prop
;
372 * Find the best icon to be used by Window Maker for appicon/miniwindows.
373 * Currently the algorithm is to take the image with the size closest
374 * to icon_size x icon_size, but never bigger than that.
376 * This algorithm is very poorly implemented and needs to be redone (it can
377 * easily select images with very large widths and very small heights over
378 * square images, if the area of the former is closer to the desired one).
380 * The logic can also be changed to accept bigger images and scale them down.
382 static unsigned long *findBestIcon(unsigned long *data
, unsigned long items
)
385 unsigned long i
, distance
;
388 /* better use only 75% of icon_size. For 64x64 this means 48x48
389 * This leaves room around the icon for the miniwindow title and
390 * results in better overall aesthetics -Dan */
391 wanted
= wPreferences
.icon_size
* wPreferences
.icon_size
;
393 for (icon
= NULL
, distance
= wanted
, i
= 0L; i
< items
- 1;) {
394 size
= data
[i
] * data
[i
+ 1];
398 if (d
>= 0 && d
<= distance
&& (i
+ size
+ 2) <= items
) {
408 static RImage
*makeRImageFromARGBData(unsigned long *data
)
410 int size
, width
, height
, i
;
412 unsigned char *imgdata
;
417 size
= width
* height
;
422 image
= RCreateImage(width
, height
, True
);
424 for (imgdata
= image
->data
, i
= 2; i
< size
+ 2; i
++, imgdata
+= 4) {
426 #if BYTE_ORDER == BIG_ENDIAN
427 imgdata
[2] = (pixel
>> 24) & 0xff; /* A */
428 imgdata
[1] = (pixel
>> 16) & 0xff; /* R */
429 imgdata
[0] = (pixel
>> 8) & 0xff; /* G */
430 imgdata
[3] = (pixel
>> 0) & 0xff; /* B */
431 #else /* Little endian */
432 imgdata
[3] = (pixel
>> 24) & 0xff; /* A */
433 imgdata
[0] = (pixel
>> 16) & 0xff; /* R */
434 imgdata
[1] = (pixel
>> 8) & 0xff; /* G */
435 imgdata
[2] = (pixel
>> 0) & 0xff; /* B */
436 #endif /* endianness */
443 static void updateIconImage(WScreen
* scr
, WWindow
* wwin
)
445 unsigned long *property
, *data
;
446 unsigned long items
, rest
;
451 if (XGetWindowProperty(dpy
, wwin
->client_win
, net_wm_icon
, 0L, LONG_MAX
,
452 False
, XA_CARDINAL
, &type
, &format
, &items
, &rest
,
453 (unsigned char **)&property
) != Success
|| !property
) {
457 if (type
!= XA_CARDINAL
|| format
!= 32 || items
< 2) {
462 data
= findBestIcon(property
, items
);
468 image
= makeRImageFromARGBData(data
);
471 if (wwin
->net_icon_image
)
472 RReleaseImage(wwin
->net_icon_image
);
473 wwin
->net_icon_image
= image
;
479 static void updateShowDesktop(WScreen
* scr
, Bool show
)
483 foo
= (show
== True
);
484 XChangeProperty(dpy
, scr
->root_win
, net_showing_desktop
, XA_CARDINAL
, 32,
485 PropModeReplace
, (unsigned char *)&foo
, 1);
488 void wNETWMShowingDesktop(WScreen
* scr
, Bool show
)
490 if (show
&& scr
->netdata
->show_desktop
== NULL
) {
491 WWindow
*tmp
, **wins
;
494 wins
= (WWindow
**) wmalloc(sizeof(WWindow
*) * (scr
->window_count
+ 1));
496 tmp
= scr
->focused_window
;
498 if (!tmp
->flags
.hidden
&& !tmp
->flags
.miniaturized
&& !WFLAGP(tmp
, skip_window_list
)) {
501 tmp
->flags
.skip_next_animation
= 1;
502 tmp
->flags
.net_show_desktop
= 1;
510 scr
->netdata
->show_desktop
= wins
;
511 updateShowDesktop(scr
, True
);
512 } else if (scr
->netdata
->show_desktop
!= NULL
) {
513 /* FIXME: get rid of workspace flashing ! */
514 int ws
= scr
->current_workspace
;
516 for (tmp
= scr
->netdata
->show_desktop
; *tmp
; ++tmp
) {
517 wDeiconifyWindow(*tmp
);
518 (*tmp
)->flags
.net_show_desktop
= 0;
520 if (ws
!= scr
->current_workspace
)
521 wWorkspaceChange(scr
, ws
);
522 wfree(scr
->netdata
->show_desktop
);
523 scr
->netdata
->show_desktop
= NULL
;
524 updateShowDesktop(scr
, False
);
528 void wNETWMInitStuff(WScreen
* scr
)
534 printf("wNETWMInitStuff\n");
537 #ifdef HAVE_XINTERNATOMS
542 for (i
= 0; i
< atomNr
; ++i
) {
543 names
[i
] = atomNames
[i
].name
;
545 XInternAtoms(dpy
, &names
[0], atomNr
, False
, atoms
);
546 for (i
= 0; i
< atomNr
; ++i
) {
547 *atomNames
[i
].atom
= atoms
[i
];
551 for (i
= 0; i
< atomNr
; i
++) {
552 *atomNames
[i
].atom
= XInternAtom(dpy
, atomNames
[i
].name
, False
);
556 data
= wmalloc(sizeof(NetData
));
559 data
->show_desktop
= NULL
;
563 setSupportedHints(scr
);
565 WMAddNotificationObserver(observer
, data
, WMNManaged
, NULL
);
566 WMAddNotificationObserver(observer
, data
, WMNUnmanaged
, NULL
);
567 WMAddNotificationObserver(observer
, data
, WMNChangedWorkspace
, NULL
);
568 WMAddNotificationObserver(observer
, data
, WMNChangedState
, NULL
);
569 WMAddNotificationObserver(observer
, data
, WMNChangedFocus
, NULL
);
570 WMAddNotificationObserver(observer
, data
, WMNChangedStacking
, NULL
);
571 WMAddNotificationObserver(observer
, data
, WMNChangedName
, NULL
);
573 WMAddNotificationObserver(wsobserver
, data
, WMNWorkspaceCreated
, NULL
);
574 WMAddNotificationObserver(wsobserver
, data
, WMNWorkspaceDestroyed
, NULL
);
575 WMAddNotificationObserver(wsobserver
, data
, WMNWorkspaceChanged
, NULL
);
576 WMAddNotificationObserver(wsobserver
, data
, WMNWorkspaceNameChanged
, NULL
);
578 updateClientList(scr
);
579 updateClientListStacking(scr
, NULL
);
580 updateWorkspaceCount(scr
);
581 updateWorkspaceNames(scr
);
582 updateShowDesktop(scr
, False
);
584 wScreenUpdateUsableArea(scr
);
587 void wNETWMCleanup(WScreen
* scr
)
591 for (i
= 0; i
< atomNr
; i
++)
592 XDeleteProperty(dpy
, scr
->root_win
, *atomNames
[i
].atom
);
595 void wNETWMUpdateActions(WWindow
* wwin
, Bool del
)
597 Atom action
[10]; /* nr of actions atoms defined */
601 XDeleteProperty(dpy
, wwin
->client_win
, net_wm_allowed_actions
);
605 if (IS_MOVABLE(wwin
))
606 action
[i
++] = net_wm_action_move
;
608 if (IS_RESIZABLE(wwin
))
609 action
[i
++] = net_wm_action_resize
;
611 if (!WFLAGP(wwin
, no_miniaturizable
))
612 action
[i
++] = net_wm_action_minimize
;
614 if (!WFLAGP(wwin
, no_shadeable
))
615 action
[i
++] = net_wm_action_shade
;
617 /* if (!WFLAGP(wwin, no_stickable)) */
618 action
[i
++] = net_wm_action_stick
;
620 /* if (!(WFLAGP(wwin, no_maximizeable) & MAX_HORIZONTAL)) */
621 if (IS_RESIZABLE(wwin
))
622 action
[i
++] = net_wm_action_maximize_horz
;
624 /* if (!(WFLAGP(wwin, no_maximizeable) & MAX_VERTICAL)) */
625 if (IS_RESIZABLE(wwin
))
626 action
[i
++] = net_wm_action_maximize_vert
;
628 /* if (!WFLAGP(wwin, no_fullscreen)) */
629 action
[i
++] = net_wm_action_fullscreen
;
631 /* if (!WFLAGP(wwin, no_change_desktop)) */
632 action
[i
++] = net_wm_action_change_desktop
;
634 if (!WFLAGP(wwin
, no_closable
))
635 action
[i
++] = net_wm_action_close
;
637 XChangeProperty(dpy
, wwin
->client_win
, net_wm_allowed_actions
,
638 XA_ATOM
, 32, PropModeReplace
, (unsigned char *)action
, i
);
641 void wNETWMUpdateWorkarea(WScreen
* scr
, WArea usableArea
)
646 /* XXX: not Xinerama compatible,
647 xinerama gets the largest available */
649 if (!scr
->netdata
|| scr
->workspace_count
== 0)
652 count
= scr
->workspace_count
* 4;
653 area
= wmalloc(sizeof(long) * count
);
654 for (i
= 0; i
< scr
->workspace_count
; i
++) {
655 area
[4 * i
+ 0] = usableArea
.x1
;
656 area
[4 * i
+ 1] = usableArea
.y1
;
657 area
[4 * i
+ 2] = usableArea
.x2
- usableArea
.x1
;
658 area
[4 * i
+ 3] = usableArea
.y2
- usableArea
.y1
;
661 XChangeProperty(dpy
, scr
->root_win
, net_workarea
, XA_CARDINAL
, 32,
662 PropModeReplace
, (unsigned char *)area
, count
);
667 Bool
wNETWMGetUsableArea(WScreen
* scr
, int head
, WArea
* area
)
672 if (!scr
->netdata
|| !scr
->netdata
->strut
)
675 area
->x1
= area
->y1
= area
->x2
= area
->y2
= 0;
677 for (cur
= scr
->netdata
->strut
; cur
; cur
= cur
->next
) {
678 WWindow
*wwin
= wWindowFor(cur
->window
);
679 if (wWindowTouchesHead(wwin
, head
)) {
680 if (cur
->area
.x1
> area
->x1
)
681 area
->x1
= cur
->area
.x1
;
682 if (cur
->area
.y1
> area
->y1
)
683 area
->y1
= cur
->area
.y1
;
684 if (cur
->area
.x2
> area
->x2
)
685 area
->x2
= cur
->area
.x2
;
686 if (cur
->area
.y2
> area
->y2
)
687 area
->y2
= cur
->area
.y2
;
691 if (area
->x1
== 0 && area
->x2
== 0 && area
->y1
== 0 && area
->y2
== 0)
694 rect
= wGetRectForHead(scr
, head
);
696 area
->x1
= rect
.pos
.x
+ area
->x1
;
697 area
->x2
= rect
.pos
.x
+ rect
.size
.width
- area
->x2
;
698 area
->y1
= rect
.pos
.y
+ area
->y1
;
699 area
->y2
= rect
.pos
.y
+ rect
.size
.height
- area
->y2
;
704 static void updateClientList(WScreen
* scr
)
710 windows
= (Window
*) wmalloc(sizeof(Window
) * (scr
->window_count
+ 1));
713 wwin
= scr
->focused_window
;
715 windows
[count
++] = wwin
->client_win
;
718 XChangeProperty(dpy
, scr
->root_win
, net_client_list
, XA_WINDOW
, 32,
719 PropModeReplace
, (unsigned char *)windows
, count
);
725 static void updateClientListStacking(WScreen
* scr
, WWindow
* wwin_excl
)
729 Window
*client_list_reverse
;
735 /* update client list */
736 i
= scr
->window_count
+ 1;
737 client_list
= (Window
*) wmalloc(sizeof(Window
) * i
);
738 client_list_reverse
= (Window
*) wmalloc(sizeof(Window
) * i
);
741 WM_ETARETI_BAG(scr
->stacking_list
, tmp
, iter
) {
743 wwin
= wWindowFor(tmp
->window
);
744 /* wwin_excl is a window to exclude from the list
745 (e.g. it's now unmanaged) */
746 if (wwin
&& (wwin
!= wwin_excl
))
747 client_list
[client_count
++] = wwin
->client_win
;
748 tmp
= tmp
->stacking
->under
;
752 for (i
= 0; i
< client_count
; i
++) {
753 Window w
= client_list
[client_count
- i
- 1];
754 client_list_reverse
[i
] = w
;
757 XChangeProperty(dpy
, scr
->root_win
, net_client_list_stacking
, XA_WINDOW
, 32,
758 PropModeReplace
, (unsigned char *)client_list_reverse
, client_count
);
761 wfree(client_list_reverse
);
766 static void updateWorkspaceCount(WScreen
* scr
)
770 count
= scr
->workspace_count
;
772 XChangeProperty(dpy
, scr
->root_win
, net_number_of_desktops
, XA_CARDINAL
,
773 32, PropModeReplace
, (unsigned char *)&count
, 1);
776 static void updateCurrentWorkspace(WScreen
* scr
)
780 count
= scr
->current_workspace
;
782 XChangeProperty(dpy
, scr
->root_win
, net_current_desktop
, XA_CARDINAL
, 32,
783 PropModeReplace
, (unsigned char *)&count
, 1);
786 static void updateWorkspaceNames(WScreen
* scr
)
788 char buf
[MAX_WORKSPACES
* (MAX_WORKSPACENAME_WIDTH
+ 1)], *pos
;
789 unsigned int i
, len
, curr_size
;
793 for (i
= 0; i
< scr
->workspace_count
; i
++) {
794 curr_size
= strlen(scr
->workspaces
[i
]->name
);
795 strcpy(pos
, scr
->workspaces
[i
]->name
);
796 pos
+= (curr_size
+ 1);
797 len
+= (curr_size
+ 1);
800 XChangeProperty(dpy
, scr
->root_win
, net_desktop_names
, utf8_string
, 8,
801 PropModeReplace
, (unsigned char *)buf
, len
);
804 static void updateFocusHint(WScreen
* scr
, WWindow
* wwin
)
808 if (!scr
->focused_window
|| !scr
->focused_window
->flags
.focused
)
811 window
= scr
->focused_window
->client_win
;
813 XChangeProperty(dpy
, scr
->root_win
, net_active_window
, XA_WINDOW
, 32,
814 PropModeReplace
, (unsigned char *)&window
, 1);
817 static void updateWorkspaceHint(WWindow
* wwin
, Bool fake
, Bool del
)
822 XDeleteProperty(dpy
, wwin
->client_win
, net_wm_desktop
);
824 l
= ((fake
|| IS_OMNIPRESENT(wwin
)) ? -1 : wwin
->frame
->workspace
);
825 XChangeProperty(dpy
, wwin
->client_win
, net_wm_desktop
, XA_CARDINAL
,
826 32, PropModeReplace
, (unsigned char *)&l
, 1);
830 static void updateStateHint(WWindow
* wwin
, Bool changedWorkspace
, Bool del
)
833 if (!wwin
->flags
.net_state_from_client
) {
834 XDeleteProperty(dpy
, wwin
->client_win
, net_wm_state
);
837 Atom state
[15]; /* nr of defined state atoms */
840 if (changedWorkspace
|| (wPreferences
.sticky_icons
&& !IS_OMNIPRESENT(wwin
)))
841 updateWorkspaceHint(wwin
, False
, False
);
843 if (IS_OMNIPRESENT(wwin
))
844 state
[i
++] = net_wm_state_sticky
;
845 if (wwin
->flags
.shaded
)
846 state
[i
++] = net_wm_state_shaded
;
847 if (wwin
->flags
.maximized
& MAX_HORIZONTAL
)
848 state
[i
++] = net_wm_state_maximized_horz
;
849 if (wwin
->flags
.maximized
& MAX_VERTICAL
)
850 state
[i
++] = net_wm_state_maximized_vert
;
851 if (WFLAGP(wwin
, skip_window_list
))
852 state
[i
++] = net_wm_state_skip_taskbar
;
853 if (wwin
->flags
.net_skip_pager
)
854 state
[i
++] = net_wm_state_skip_pager
;
855 if ((wwin
->flags
.hidden
|| wwin
->flags
.miniaturized
) && !wwin
->flags
.net_show_desktop
) {
856 state
[i
++] = net_wm_state_hidden
;
857 state
[i
++] = net_wm_state_skip_pager
;
859 if (wwin
->flags
.miniaturized
&& wPreferences
.sticky_icons
) {
860 if (!IS_OMNIPRESENT(wwin
))
861 updateWorkspaceHint(wwin
, True
, False
);
862 state
[i
++] = net_wm_state_sticky
;
865 if (WFLAGP(wwin
, sunken
))
866 state
[i
++] = net_wm_state_below
;
867 if (WFLAGP(wwin
, floating
))
868 state
[i
++] = net_wm_state_above
;
869 if (wwin
->flags
.fullscreen
)
870 state
[i
++] = net_wm_state_fullscreen
;
872 XChangeProperty(dpy
, wwin
->client_win
, net_wm_state
, XA_ATOM
, 32,
873 PropModeReplace
, (unsigned char *)state
, i
);
877 static Bool
updateStrut(WWindow
* wwin
, Bool adding
)
881 Bool hasState
= False
;
883 scr
= wwin
->screen_ptr
;
888 unsigned long nitems_ret
;
889 unsigned long bytes_after_ret
;
892 if (XGetWindowProperty(dpy
, wwin
->client_win
, net_wm_strut
, 0, 4, False
,
893 XA_CARDINAL
, &type_ret
, &fmt_ret
, &nitems_ret
,
894 &bytes_after_ret
, (unsigned char **)&data
) == Success
&& data
) {
896 area
= (WReservedArea
*) wmalloc(sizeof(WReservedArea
));
897 area
->area
.x1
= data
[0];
898 area
->area
.x2
= data
[1];
899 area
->area
.y1
= data
[2];
900 area
->area
.y2
= data
[3];
902 area
->window
= wwin
->client_win
;
904 area
->next
= scr
->netdata
->strut
;
905 scr
->netdata
->strut
= area
;
909 #ifdef VIRTUAL_DESKTOP
910 /* just in case wm_window_type didn't set it already */
911 wwin
->client_flags
.virtual_stick
= 1;
917 area
= scr
->netdata
->strut
;
920 if (area
->window
== wwin
->client_win
) {
921 scr
->netdata
->strut
= area
->next
;
925 while (area
->next
&& area
->next
->window
!= wwin
->client_win
)
931 next
= area
->next
->next
;
944 static int getWindowLayer(WWindow
* wwin
)
946 int layer
= WMNormalLevel
;
948 if (wwin
->type
== net_wm_window_type_desktop
) {
949 layer
= WMDesktopLevel
;
950 } else if (wwin
->type
== net_wm_window_type_dock
) {
952 } else if (wwin
->type
== net_wm_window_type_toolbar
) {
953 layer
= WMMainMenuLevel
;
954 } else if (wwin
->type
== net_wm_window_type_menu
) {
955 layer
= WMSubmenuLevel
;
956 } else if (wwin
->type
== net_wm_window_type_utility
) {
957 } else if (wwin
->type
== net_wm_window_type_splash
) {
958 } else if (wwin
->type
== net_wm_window_type_dialog
) {
959 if (wwin
->transient_for
) {
960 WWindow
*parent
= wWindowFor(wwin
->transient_for
);
961 if (parent
&& parent
->flags
.fullscreen
) {
962 layer
= WMFullscreenLevel
;
965 /* //layer = WMPopUpLevel; // this seems a bad idea -Dan */
966 } else if (wwin
->type
== net_wm_window_type_normal
) {
969 if (wwin
->client_flags
.sunken
&& WMSunkenLevel
< layer
)
970 layer
= WMSunkenLevel
;
971 if (wwin
->client_flags
.floating
&& WMFloatingLevel
> layer
)
972 layer
= WMFloatingLevel
;
977 static void doStateAtom(WWindow
* wwin
, Atom state
, int set
, Bool init
)
980 if (state
== net_wm_state_sticky
) {
981 if (set
== _NET_WM_STATE_TOGGLE
) {
982 set
= !IS_OMNIPRESENT(wwin
);
984 if (set
!= wwin
->flags
.omnipresent
) {
985 wWindowSetOmnipresent(wwin
, set
);
987 } else if (state
== net_wm_state_shaded
) {
988 if (set
== _NET_WM_STATE_TOGGLE
) {
989 set
= !wwin
->flags
.shaded
;
992 wwin
->flags
.shaded
= set
;
997 wUnshadeWindow(wwin
);
1000 } else if (state
== net_wm_state_skip_taskbar
) {
1001 if (set
== _NET_WM_STATE_TOGGLE
) {
1002 set
= !wwin
->client_flags
.skip_window_list
;
1004 wwin
->client_flags
.skip_window_list
= set
;
1005 } else if (state
== net_wm_state_skip_pager
) {
1006 if (set
== _NET_WM_STATE_TOGGLE
) {
1007 set
= !wwin
->flags
.net_skip_pager
;
1009 wwin
->flags
.net_skip_pager
= set
;
1010 } else if (state
== net_wm_state_maximized_vert
) {
1011 if (set
== _NET_WM_STATE_TOGGLE
) {
1012 set
= !(wwin
->flags
.maximized
& MAX_VERTICAL
);
1015 wwin
->flags
.maximized
|= (set
? MAX_VERTICAL
: 0);
1018 wMaximizeWindow(wwin
, wwin
->flags
.maximized
| MAX_VERTICAL
);
1020 wMaximizeWindow(wwin
, wwin
->flags
.maximized
& ~MAX_VERTICAL
);
1023 } else if (state
== net_wm_state_maximized_horz
) {
1024 if (set
== _NET_WM_STATE_TOGGLE
) {
1025 set
= !(wwin
->flags
.maximized
& MAX_HORIZONTAL
);
1028 wwin
->flags
.maximized
|= (set
? MAX_HORIZONTAL
: 0);
1031 wMaximizeWindow(wwin
, wwin
->flags
.maximized
| MAX_HORIZONTAL
);
1033 wMaximizeWindow(wwin
, wwin
->flags
.maximized
& ~MAX_HORIZONTAL
);
1036 } else if (state
== net_wm_state_hidden
) {
1037 if (set
== _NET_WM_STATE_TOGGLE
) {
1038 set
= !(wwin
->flags
.miniaturized
);
1041 wwin
->flags
.miniaturized
= set
;
1044 wIconifyWindow(wwin
);
1046 wDeiconifyWindow(wwin
);
1049 } else if (state
== net_wm_state_fullscreen
) {
1050 if (set
== _NET_WM_STATE_TOGGLE
) {
1051 set
= !(wwin
->flags
.fullscreen
);
1054 wwin
->flags
.fullscreen
= set
;
1057 wFullscreenWindow(wwin
);
1059 wUnfullscreenWindow(wwin
);
1062 } else if (state
== net_wm_state_above
) {
1063 if (set
== _NET_WM_STATE_TOGGLE
) {
1064 set
= !(wwin
->client_flags
.floating
);
1067 wwin
->client_flags
.floating
= set
;
1069 wwin
->client_flags
.floating
= set
;
1070 ChangeStackingLevel(wwin
->frame
->core
, getWindowLayer(wwin
));
1073 } else if (state
== net_wm_state_below
) {
1074 if (set
== _NET_WM_STATE_TOGGLE
) {
1075 set
= !(wwin
->client_flags
.sunken
);
1078 wwin
->client_flags
.sunken
= set
;
1080 wwin
->client_flags
.sunken
= set
;
1081 ChangeStackingLevel(wwin
->frame
->core
, getWindowLayer(wwin
));
1086 printf("doStateAtom unknown atom %s set %d\n", XGetAtomName(dpy
, state
), set
);
1091 static void removeIcon(WWindow
* wwin
)
1093 if (wwin
->icon
== NULL
)
1095 if (wwin
->flags
.miniaturized
&& wwin
->icon
->mapped
) {
1096 XUnmapWindow(dpy
, wwin
->icon
->core
->window
);
1097 RemoveFromStackList(wwin
->icon
->core
);
1098 wIconDestroy(wwin
->icon
);
1103 static Bool
handleWindowType(WWindow
* wwin
, Atom type
, int *layer
)
1107 if (type
== net_wm_window_type_desktop
) {
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_border
= 1;
1112 wwin
->client_flags
.no_resizebar
= 1;
1113 wwin
->client_flags
.no_shadeable
= 1;
1114 wwin
->client_flags
.no_movable
= 1;
1115 wwin
->client_flags
.omnipresent
= 1;
1116 wwin
->client_flags
.skip_window_list
= 1;
1117 wwin
->client_flags
.dont_move_off
= 1;
1118 wwin
->client_flags
.no_appicon
= 1;
1119 wwin
->flags
.net_skip_pager
= 1;
1122 #ifdef VIRTUAL_DESKTOP
1123 wwin
->client_flags
.virtual_stick
= 1;
1125 } else if (type
== net_wm_window_type_dock
) {
1126 wwin
->client_flags
.no_titlebar
= 1;
1127 wwin
->client_flags
.no_resizable
= 1;
1128 wwin
->client_flags
.no_miniaturizable
= 1;
1129 wwin
->client_flags
.no_border
= 1; /* XXX: really not a single decoration. */
1130 wwin
->client_flags
.no_resizebar
= 1;
1131 wwin
->client_flags
.no_shadeable
= 1;
1132 wwin
->client_flags
.no_movable
= 1;
1133 wwin
->client_flags
.omnipresent
= 1;
1134 wwin
->client_flags
.skip_window_list
= 1;
1135 wwin
->client_flags
.dont_move_off
= 1;
1136 wwin
->flags
.net_skip_pager
= 1;
1137 #ifdef VIRTUAL_DESKTOP
1138 wwin
->client_flags
.virtual_stick
= 1;
1140 } else if (type
== net_wm_window_type_toolbar
) {
1141 wwin
->client_flags
.no_titlebar
= 1;
1142 wwin
->client_flags
.no_resizable
= 1;
1143 wwin
->client_flags
.no_miniaturizable
= 1;
1144 wwin
->client_flags
.no_resizebar
= 1;
1145 wwin
->client_flags
.no_shadeable
= 1;
1146 wwin
->client_flags
.skip_window_list
= 1;
1147 wwin
->client_flags
.dont_move_off
= 1;
1148 wwin
->client_flags
.no_appicon
= 1;
1149 } else if (type
== net_wm_window_type_menu
) {
1150 wwin
->client_flags
.no_titlebar
= 1;
1151 wwin
->client_flags
.no_resizable
= 1;
1152 wwin
->client_flags
.no_miniaturizable
= 1;
1153 wwin
->client_flags
.no_resizebar
= 1;
1154 wwin
->client_flags
.no_shadeable
= 1;
1155 wwin
->client_flags
.skip_window_list
= 1;
1156 wwin
->client_flags
.dont_move_off
= 1;
1157 wwin
->client_flags
.no_appicon
= 1;
1158 } else if (type
== net_wm_window_type_utility
) {
1159 wwin
->client_flags
.no_appicon
= 1;
1160 } else if (type
== net_wm_window_type_splash
) {
1161 wwin
->client_flags
.no_titlebar
= 1;
1162 wwin
->client_flags
.no_resizable
= 1;
1163 wwin
->client_flags
.no_miniaturizable
= 1;
1164 wwin
->client_flags
.no_resizebar
= 1;
1165 wwin
->client_flags
.no_shadeable
= 1;
1166 wwin
->client_flags
.no_movable
= 1;
1167 wwin
->client_flags
.skip_window_list
= 1;
1168 wwin
->client_flags
.dont_move_off
= 1;
1169 wwin
->client_flags
.no_appicon
= 1;
1170 wwin
->flags
.net_skip_pager
= 1;
1171 } else if (type
== net_wm_window_type_dialog
) {
1172 /* These also seem a bad idea in our context -Dan
1173 // wwin->client_flags.skip_window_list = 1;
1174 // wwin->client_flags.no_appicon = 1;
1176 } else if (type
== net_wm_window_type_normal
) {
1182 *layer
= getWindowLayer(wwin
);
1187 void wNETWMPositionSplash(WWindow
* wwin
, int *x
, int *y
, int width
, int height
)
1189 if (wwin
->type
== net_wm_window_type_splash
) {
1190 WScreen
*scr
= wwin
->screen_ptr
;
1191 WMRect rect
= wGetRectForHead(scr
, wGetHeadForPointerLocation(scr
));
1192 *x
= rect
.pos
.x
+ (rect
.size
.width
- width
) / 2;
1193 *y
= rect
.pos
.y
+ (rect
.size
.height
- height
) / 2;
1197 static void updateWindowType(WWindow
* wwin
)
1201 unsigned long nitems_ret
;
1202 unsigned long bytes_after_ret
;
1205 if (XGetWindowProperty(dpy
, wwin
->client_win
, net_wm_window_type
, 0, 1,
1206 False
, XA_ATOM
, &type_ret
, &fmt_ret
, &nitems_ret
,
1207 &bytes_after_ret
, (unsigned char **)&data
) == Success
&& data
) {
1210 Atom
*type
= (Atom
*) data
;
1211 for (i
= 0; i
< nitems_ret
; ++i
) {
1212 if (handleWindowType(wwin
, type
[i
], &layer
))
1218 ChangeStackingLevel(wwin
->frame
->core
, layer
);
1219 wwin
->frame
->flags
.need_texture_change
= 1;
1220 wWindowConfigureBorders(wwin
);
1221 wFrameWindowPaint(wwin
->frame
);
1222 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
);
1450 * Firefox with multiple tabs sends aditional 'net_active_window'
1451 * signals on startup, which causes unnecessary workspace switching
1452 * if its initial workspace is different from the current
1454 if (event
->message_type
== net_active_window
&&
1455 wwin
->frame
->workspace
== wwin
->screen_ptr
->current_workspace
) {
1456 wNETWMShowingDesktop(scr
, False
);
1457 wMakeWindowVisible(wwin
);
1458 } else if (event
->message_type
== net_close_window
) {
1459 if (!WFLAGP(wwin
, no_closable
)) {
1460 if (wwin
->protocols
.DELETE_WINDOW
)
1461 wClientSendProtocol(wwin
, _XA_WM_DELETE_WINDOW
, LastTimestamp
);
1463 } else if (event
->message_type
== net_wm_state
) {
1464 int maximized
= wwin
->flags
.maximized
;
1465 long set
= event
->data
.l
[0];
1468 printf("net_wm_state set %d a1 %s a2 %s\n", set
,
1469 XGetAtomName(dpy
, event
->data
.l
[1]), XGetAtomName(dpy
, event
->data
.l
[2]));
1472 doStateAtom(wwin
, (Atom
) event
->data
.l
[1], set
, False
);
1473 if (event
->data
.l
[2])
1474 doStateAtom(wwin
, (Atom
) event
->data
.l
[2], set
, False
);
1476 if (wwin
->flags
.maximized
!= maximized
) {
1477 if (!wwin
->flags
.maximized
) {
1478 wwin
->flags
.maximized
= maximized
;
1479 wUnmaximizeWindow(wwin
);
1481 wMaximizeWindow(wwin
, wwin
->flags
.maximized
);
1484 updateStateHint(wwin
, False
, False
);
1485 } else if (event
->message_type
== net_wm_handled_icons
|| event
->message_type
== net_wm_icon_geometry
) {
1486 updateNetIconInfo(wwin
);
1487 } else if (event
->message_type
== net_wm_desktop
) {
1488 long desktop
= event
->data
.l
[0];
1489 if (desktop
== -1) {
1490 wWindowSetOmnipresent(wwin
, True
);
1492 if (IS_OMNIPRESENT(wwin
))
1493 wWindowSetOmnipresent(wwin
, False
);
1494 wWindowChangeWorkspace(wwin
, desktop
);
1496 } else if (event
->message_type
== net_wm_icon
) {
1497 updateIconImage(scr
, wwin
);
1505 Bool
wNETWMCheckClientHintChange(WWindow
* wwin
, XPropertyEvent
* event
)
1509 if (event
->atom
== net_wm_strut
) {
1510 updateStrut(wwin
, False
);
1511 updateStrut(wwin
, True
);
1512 wScreenUpdateUsableArea(wwin
->screen_ptr
);
1513 } else if (event
->atom
== net_wm_handled_icons
|| event
->atom
== net_wm_icon_geometry
) {
1514 updateNetIconInfo(wwin
);
1515 } else if (event
->atom
== net_wm_window_type
) {
1516 updateWindowType(wwin
);
1517 } else if (event
->atom
== net_wm_name
) {
1518 char *name
= wNETWMGetWindowName(wwin
->client_win
);
1519 wWindowUpdateName(wwin
, name
);
1522 } else if (event
->atom
== net_wm_icon_name
) {
1524 char *name
= wNETWMGetIconName(wwin
->client_win
);
1525 wIconChangeTitle(wwin
->icon
, name
);
1534 int wNETWMGetPidForWindow(Window window
)
1538 unsigned long nitems_ret
;
1539 unsigned long bytes_after_ret
;
1543 if (XGetWindowProperty(dpy
, window
, net_wm_pid
, 0, 1, False
,
1544 XA_CARDINAL
, &type_ret
, &fmt_ret
, &nitems_ret
,
1545 &bytes_after_ret
, (unsigned char **)&data
) == Success
&& data
) {
1556 char *wNETWMGetWindowName(Window window
)
1562 name
= (char *)PropGetCheckProperty(window
, net_wm_name
, utf8_string
, 0, 0, &size
);
1564 ret
= wstrndup(name
, size
);
1571 char *wNETWMGetIconName(Window window
)
1577 name
= (char *)PropGetCheckProperty(window
, net_wm_icon_name
, utf8_string
, 0, 0, &size
);
1579 ret
= wstrndup(name
, size
);
1586 static void observer(void *self
, WMNotification
* notif
)
1588 WWindow
*wwin
= (WWindow
*) WMGetNotificationObject(notif
);
1589 const char *name
= WMGetNotificationName(notif
);
1590 void *data
= WMGetNotificationClientData(notif
);
1591 NetData
*ndata
= (NetData
*) self
;
1593 if (strcmp(name
, WMNManaged
) == 0 && wwin
) {
1594 updateClientList(wwin
->screen_ptr
);
1595 updateClientListStacking(wwin
->screen_ptr
, NULL
);
1596 updateStateHint(wwin
, True
, False
);
1598 updateStrut(wwin
, False
);
1599 updateStrut(wwin
, True
);
1600 wScreenUpdateUsableArea(wwin
->screen_ptr
);
1601 } else if (strcmp(name
, WMNUnmanaged
) == 0 && wwin
) {
1602 updateClientList(wwin
->screen_ptr
);
1603 updateClientListStacking(wwin
->screen_ptr
, wwin
);
1604 updateWorkspaceHint(wwin
, False
, True
);
1605 updateStateHint(wwin
, False
, True
);
1606 wNETWMUpdateActions(wwin
, True
);
1608 updateStrut(wwin
, False
);
1609 wScreenUpdateUsableArea(wwin
->screen_ptr
);
1610 } else if (strcmp(name
, WMNResetStacking
) == 0 && wwin
) {
1611 updateClientListStacking(wwin
->screen_ptr
, NULL
);
1612 updateStateHint(wwin
, False
, False
);
1613 } else if (strcmp(name
, WMNChangedStacking
) == 0 && wwin
) {
1614 updateClientListStacking(wwin
->screen_ptr
, NULL
);
1615 updateStateHint(wwin
, False
, False
);
1616 } else if (strcmp(name
, WMNChangedFocus
) == 0) {
1617 updateFocusHint(ndata
->scr
, wwin
);
1618 } else if (strcmp(name
, WMNChangedWorkspace
) == 0 && wwin
) {
1619 updateWorkspaceHint(wwin
, False
, False
);
1620 updateStateHint(wwin
, True
, False
);
1621 } else if (strcmp(name
, WMNChangedState
) == 0 && wwin
) {
1622 updateStateHint(wwin
, !strcmp(data
, "omnipresent"), False
);
1626 static void wsobserver(void *self
, WMNotification
* notif
)
1628 WScreen
*scr
= (WScreen
*) WMGetNotificationObject(notif
);
1629 const char *name
= WMGetNotificationName(notif
);
1631 if (strcmp(name
, WMNWorkspaceCreated
) == 0) {
1632 updateWorkspaceCount(scr
);
1633 updateWorkspaceNames(scr
);
1634 } else if (strcmp(name
, WMNWorkspaceDestroyed
) == 0) {
1635 updateWorkspaceCount(scr
);
1636 updateWorkspaceNames(scr
);
1637 } else if (strcmp(name
, WMNWorkspaceChanged
) == 0) {
1638 updateCurrentWorkspace(scr
);
1639 } else if (strcmp(name
, WMNWorkspaceNameChanged
) == 0) {
1640 updateWorkspaceNames(scr
);
1644 #endif /* NETWM_HINTS */