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"
59 /* Global variables */
60 extern Atom _XA_WM_DELETE_WINDOW
;
61 extern Time LastTimestamp
;
62 extern WPreferences wPreferences
;
64 /* Root Window Properties */
65 static Atom net_supported
;
66 static Atom net_client_list
;
67 static Atom net_client_list_stacking
;
68 static Atom net_number_of_desktops
;
69 static Atom net_desktop_geometry
;
70 static Atom net_desktop_viewport
;
71 static Atom net_current_desktop
;
72 static Atom net_desktop_names
;
73 static Atom net_active_window
;
74 static Atom net_workarea
; /* XXX: not xinerama compatible */
75 static Atom net_supporting_wm_check
;
76 static Atom net_virtual_roots
; /* N/A */
77 static Atom net_desktop_layout
; /* XXX */
78 static Atom net_showing_desktop
;
80 /* Other Root Window Messages */
81 static Atom net_close_window
;
82 static Atom net_moveresize_window
; /* TODO */
83 static Atom net_wm_moveresize
; /* TODO */
85 /* Application Window Properties */
86 static Atom net_wm_name
;
87 static Atom net_wm_visible_name
; /* TODO (unnecessary?) */
88 static Atom net_wm_icon_name
;
89 static Atom net_wm_visible_icon_name
; /* TODO (unnecessary?) */
90 static Atom net_wm_desktop
;
91 static Atom net_wm_window_type
;
92 static Atom net_wm_window_type_desktop
;
93 static Atom net_wm_window_type_dock
;
94 static Atom net_wm_window_type_toolbar
;
95 static Atom net_wm_window_type_menu
;
96 static Atom net_wm_window_type_utility
;
97 static Atom net_wm_window_type_splash
;
98 static Atom net_wm_window_type_dialog
;
99 static Atom net_wm_window_type_normal
;
100 static Atom net_wm_state
;
101 static Atom net_wm_state_modal
; /* XXX: what is this?!? */
102 static Atom net_wm_state_sticky
;
103 static Atom net_wm_state_maximized_vert
;
104 static Atom net_wm_state_maximized_horz
;
105 static Atom net_wm_state_shaded
;
106 static Atom net_wm_state_skip_taskbar
;
107 static Atom net_wm_state_skip_pager
;
108 static Atom net_wm_state_hidden
;
109 static Atom net_wm_state_fullscreen
;
110 static Atom net_wm_state_above
;
111 static Atom net_wm_state_below
;
112 static Atom net_wm_allowed_actions
;
113 static Atom net_wm_action_move
;
114 static Atom net_wm_action_resize
;
115 static Atom net_wm_action_minimize
;
116 static Atom net_wm_action_shade
;
117 static Atom net_wm_action_stick
;
118 static Atom net_wm_action_maximize_horz
;
119 static Atom net_wm_action_maximize_vert
;
120 static Atom net_wm_action_fullscreen
;
121 static Atom net_wm_action_change_desktop
;
122 static Atom net_wm_action_close
;
123 static Atom net_wm_strut
; /* XXX: see net_workarea */
124 static Atom net_wm_strut_partial
; /* TODO: doesn't really fit into the current strut scheme */
125 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. */
126 static Atom net_wm_icon
;
127 static Atom net_wm_pid
; /* TODO */
128 static Atom net_wm_handled_icons
; /* FIXME: see net_wm_icon_geometry */
130 /* Window Manager Protocols */
131 static Atom net_wm_ping
; /* TODO */
133 static Atom utf8_string
;
140 static atomitem_t atomNames
[] = {
141 { "_NET_SUPPORTED", &net_supported
},
142 { "_NET_CLIENT_LIST", &net_client_list
},
143 { "_NET_CLIENT_LIST_STACKING", &net_client_list_stacking
},
144 { "_NET_NUMBER_OF_DESKTOPS", &net_number_of_desktops
},
145 { "_NET_DESKTOP_GEOMETRY", &net_desktop_geometry
},
146 { "_NET_DESKTOP_VIEWPORT", &net_desktop_viewport
},
147 { "_NET_CURRENT_DESKTOP", &net_current_desktop
},
148 { "_NET_DESKTOP_NAMES", &net_desktop_names
},
149 { "_NET_ACTIVE_WINDOW", &net_active_window
},
150 { "_NET_WORKAREA", &net_workarea
},
151 { "_NET_SUPPORTING_WM_CHECK", &net_supporting_wm_check
},
152 { "_NET_VIRTUAL_ROOTS", &net_virtual_roots
},
153 { "_NET_DESKTOP_LAYOUT", &net_desktop_layout
},
154 { "_NET_SHOWING_DESKTOP", &net_showing_desktop
},
156 { "_NET_CLOSE_WINDOW", &net_close_window
},
157 { "_NET_MOVERESIZE_WINDOW", &net_moveresize_window
},
158 { "_NET_WM_MOVERESIZE", &net_wm_moveresize
},
160 { "_NET_WM_NAME", &net_wm_name
},
161 { "_NET_WM_VISIBLE_NAME", &net_wm_visible_name
},
162 { "_NET_WM_ICON_NAME", &net_wm_icon_name
},
163 { "_NET_WM_VISIBLE_ICON_NAME", &net_wm_visible_icon_name
},
164 { "_NET_WM_DESKTOP", &net_wm_desktop
},
165 { "_NET_WM_WINDOW_TYPE", &net_wm_window_type
},
166 { "_NET_WM_WINDOW_TYPE_DESKTOP", &net_wm_window_type_desktop
},
167 { "_NET_WM_WINDOW_TYPE_DOCK", &net_wm_window_type_dock
},
168 { "_NET_WM_WINDOW_TYPE_TOOLBAR", &net_wm_window_type_toolbar
},
169 { "_NET_WM_WINDOW_TYPE_MENU", &net_wm_window_type_menu
},
170 { "_NET_WM_WINDOW_TYPE_UTILITY", &net_wm_window_type_utility
},
171 { "_NET_WM_WINDOW_TYPE_SPLASH", &net_wm_window_type_splash
},
172 { "_NET_WM_WINDOW_TYPE_DIALOG", &net_wm_window_type_dialog
},
173 { "_NET_WM_WINDOW_TYPE_NORMAL", &net_wm_window_type_normal
},
174 { "_NET_WM_STATE", &net_wm_state
},
175 { "_NET_WM_STATE_MODAL", &net_wm_state_modal
},
176 { "_NET_WM_STATE_STICKY", &net_wm_state_sticky
},
177 { "_NET_WM_STATE_MAXIMIZED_VERT", &net_wm_state_maximized_vert
},
178 { "_NET_WM_STATE_MAXIMIZED_HORZ", &net_wm_state_maximized_horz
},
179 { "_NET_WM_STATE_SHADED", &net_wm_state_shaded
},
180 { "_NET_WM_STATE_SKIP_TASKBAR", &net_wm_state_skip_taskbar
},
181 { "_NET_WM_STATE_SKIP_PAGER", &net_wm_state_skip_pager
},
182 { "_NET_WM_STATE_HIDDEN", &net_wm_state_hidden
},
183 { "_NET_WM_STATE_FULLSCREEN", &net_wm_state_fullscreen
},
184 { "_NET_WM_STATE_ABOVE", &net_wm_state_above
},
185 { "_NET_WM_STATE_BELOW", &net_wm_state_below
},
186 { "_NET_WM_ALLOWED_ACTIONS", &net_wm_allowed_actions
},
187 { "_NET_WM_ACTION_MOVE", &net_wm_action_move
},
188 { "_NET_WM_ACTION_RESIZE", &net_wm_action_resize
},
189 { "_NET_WM_ACTION_MINIMIZE", &net_wm_action_minimize
},
190 { "_NET_WM_ACTION_SHADE", &net_wm_action_shade
},
191 { "_NET_WM_ACTION_STICK", &net_wm_action_stick
},
192 { "_NET_WM_ACTION_MAXIMIZE_HORZ", &net_wm_action_maximize_horz
},
193 { "_NET_WM_ACTION_MAXIMIZE_VERT", &net_wm_action_maximize_vert
},
194 { "_NET_WM_ACTION_FULLSCREEN", &net_wm_action_fullscreen
},
195 { "_NET_WM_ACTION_CHANGE_DESKTOP", &net_wm_action_change_desktop
},
196 { "_NET_WM_ACTION_CLOSE", &net_wm_action_close
},
197 { "_NET_WM_STRUT", &net_wm_strut
},
198 { "_NET_WM_STRUT_PARTIAL", &net_wm_strut_partial
},
199 { "_NET_WM_ICON_GEOMETRY", &net_wm_icon_geometry
},
200 { "_NET_WM_ICON", &net_wm_icon
},
201 { "_NET_WM_PID", &net_wm_pid
},
202 { "_NET_WM_HANDLED_ICONS", &net_wm_handled_icons
},
204 { "_NET_WM_PING", &net_wm_ping
},
206 { "UTF8_STRING", &utf8_string
},
209 #define atomNr (sizeof(atomNames)/sizeof(atomitem_t))
211 #define _NET_WM_STATE_REMOVE 0
212 #define _NET_WM_STATE_ADD 1
213 #define _NET_WM_STATE_TOGGLE 2
215 #define _NET_WM_MOVERESIZE_SIZE_TOPLEFT 0
216 #define _NET_WM_MOVERESIZE_SIZE_TOP 1
217 #define _NET_WM_MOVERESIZE_SIZE_TOPRIGHT 2
218 #define _NET_WM_MOVERESIZE_SIZE_RIGHT 3
219 #define _NET_WM_MOVERESIZE_SIZE_BOTTOMRIGHT 4
220 #define _NET_WM_MOVERESIZE_SIZE_BOTTOM 5
221 #define _NET_WM_MOVERESIZE_SIZE_BOTTOMLEFT 6
222 #define _NET_WM_MOVERESIZE_SIZE_LEFT 7
223 #define _NET_WM_MOVERESIZE_MOVE 8 /* movement only */
224 #define _NET_WM_MOVERESIZE_SIZE_KEYBOARD 9 /* size via keyboard */
225 #define _NET_WM_MOVERESIZE_MOVE_KEYBOARD 10 /* move via keyboard */
227 static void observer(void *self
, WMNotification
*notif
);
228 static void wsobserver(void *self
, WMNotification
*notif
);
230 static void updateClientList(WScreen
*scr
);
231 static void updateClientListStacking(WScreen
*scr
, WWindow
*);
233 static void updateWorkspaceNames(WScreen
*scr
);
234 static void updateCurrentWorkspace(WScreen
*scr
);
235 static void updateWorkspaceCount(WScreen
*scr
);
237 typedef struct NetData
{
239 WReservedArea
*strut
;
240 WWindow
**show_desktop
;
245 setSupportedHints(WScreen
*scr
)
250 /* set supported hints list */
251 /* XXX: extend this !!! */
253 atom
[i
++] = net_client_list
;
254 atom
[i
++] = net_client_list_stacking
;
255 atom
[i
++] = net_number_of_desktops
;
256 atom
[i
++] = net_desktop_geometry
;
257 atom
[i
++] = net_desktop_viewport
;
258 atom
[i
++] = net_current_desktop
;
259 atom
[i
++] = net_desktop_names
;
260 atom
[i
++] = net_active_window
;
261 atom
[i
++] = net_workarea
;
262 atom
[i
++] = net_supporting_wm_check
;
263 atom
[i
++] = net_showing_desktop
;
265 atom
[i
++] = net_wm_moveresize
;
267 atom
[i
++] = net_wm_desktop
;
268 atom
[i
++] = net_wm_window_type
;
269 atom
[i
++] = net_wm_window_type_desktop
;
270 atom
[i
++] = net_wm_window_type_dock
;
271 atom
[i
++] = net_wm_window_type_toolbar
;
272 atom
[i
++] = net_wm_window_type_menu
;
273 atom
[i
++] = net_wm_window_type_utility
;
274 atom
[i
++] = net_wm_window_type_splash
;
275 atom
[i
++] = net_wm_window_type_dialog
;
276 atom
[i
++] = net_wm_window_type_normal
;
278 atom
[i
++] = net_wm_state
;
279 /* atom[i++] = net_wm_state_modal; */ /* XXX: not sure where/when to use it. */
280 atom
[i
++] = net_wm_state_sticky
;
281 atom
[i
++] = net_wm_state_shaded
;
282 atom
[i
++] = net_wm_state_maximized_horz
;
283 atom
[i
++] = net_wm_state_maximized_vert
;
284 atom
[i
++] = net_wm_state_skip_taskbar
;
285 atom
[i
++] = net_wm_state_skip_pager
;
286 atom
[i
++] = net_wm_state_hidden
;
287 atom
[i
++] = net_wm_state_fullscreen
;
288 atom
[i
++] = net_wm_state_above
;
289 atom
[i
++] = net_wm_state_below
;
291 atom
[i
++] = net_wm_allowed_actions
;
292 atom
[i
++] = net_wm_action_move
;
293 atom
[i
++] = net_wm_action_resize
;
294 atom
[i
++] = net_wm_action_minimize
;
295 atom
[i
++] = net_wm_action_shade
;
296 atom
[i
++] = net_wm_action_stick
;
297 atom
[i
++] = net_wm_action_maximize_horz
;
298 atom
[i
++] = net_wm_action_maximize_vert
;
299 atom
[i
++] = net_wm_action_fullscreen
;
300 atom
[i
++] = net_wm_action_change_desktop
;
301 atom
[i
++] = net_wm_action_close
;
303 atom
[i
++] = net_wm_strut
;
304 atom
[i
++] = net_wm_icon_geometry
;
305 atom
[i
++] = net_wm_icon
;
306 atom
[i
++] = net_wm_handled_icons
;
308 atom
[i
++] = net_wm_name
;
309 atom
[i
++] = net_wm_icon_name
;
311 XChangeProperty(dpy
, scr
->root_win
, net_supported
, XA_ATOM
, 32,
312 PropModeReplace
, (unsigned char*)atom
, i
);
314 /* set supporting wm hint */
315 XChangeProperty(dpy
, scr
->root_win
, net_supporting_wm_check
, XA_WINDOW
, 32,
316 PropModeReplace
, (unsigned char*)&scr
->info_window
, 1);
318 XChangeProperty(dpy
, scr
->info_window
, net_supporting_wm_check
, XA_WINDOW
,
319 32, PropModeReplace
, (unsigned char*)&scr
->info_window
, 1);
324 wNETWMUpdateDesktop(WScreen
*scr
)
326 long *views
, sizes
[2];
329 if (scr
->workspace_count
==0)
332 count
= scr
->workspace_count
* 2;
333 views
= wmalloc(sizeof(long) * count
);
334 /*memset(views, 0, sizeof(long) * count);*/
336 #ifdef VIRTUAL_DESKTOP
337 sizes
[0] = scr
->workspaces
[scr
->current_workspace
]->width
;
338 sizes
[1] = scr
->workspaces
[scr
->current_workspace
]->height
;
340 sizes
[0] = scr
->scr_width
;
341 sizes
[1] = scr
->scr_height
;
344 for (i
=0; i
<scr
->workspace_count
; i
++) {
345 #ifdef VIRTUAL_DESKTOP
346 views
[2*i
+ 0] = scr
->workspaces
[i
]->view_x
;
347 views
[2*i
+ 1] = scr
->workspaces
[i
]->view_y
;
354 XChangeProperty(dpy
, scr
->root_win
, net_desktop_geometry
, XA_CARDINAL
, 32,
355 PropModeReplace
, (unsigned char*)sizes
, 2);
357 XChangeProperty(dpy
, scr
->root_win
, net_desktop_viewport
, XA_CARDINAL
, 32,
358 PropModeReplace
, (unsigned char*)views
, count
);
365 wNETWMGetCurrentDesktopFromHint(WScreen
*scr
)
370 prop
= PropGetCheckProperty(scr
->root_win
, net_current_desktop
, XA_CARDINAL
,
374 int desktop
= *(long*)prop
;
383 * Find the best icon to be used by Window Maker for appicon/miniwindows.
384 * Currently the algorithm is to take the image with the size closest
385 * to icon_size x icon_size, but never bigger than that.
387 * This algorithm is very poorly implemented and needs to be redone (it can
388 * easily select images with very large widths and very small heights over
389 * square images, if the area of the former is closer to the desired one).
391 * The logic can also be changed to accept bigger images and scale them down.
393 static unsigned long*
394 findBestIcon(unsigned long *data
, unsigned long items
)
396 int size
, wanted
, d
, distance
;
400 /* better use only 75% of icon_size. For 64x64 this means 48x48
401 * This leaves room around the icon for the miniwindow title and
402 * results in better overall aesthetics -Dan */
403 wanted
= wPreferences
.icon_size
* wPreferences
.icon_size
;
405 for (icon
=NULL
, distance
=LONG_MAX
, i
=0L; i
<items
-1; ) {
406 size
= data
[i
] * data
[i
+1];
410 if (d
>=0 && d
<=distance
&& (i
+size
+2)<=items
) {
422 makeRImageFromARGBData(unsigned long *data
)
424 int size
, width
, height
, i
;
426 unsigned char *imgdata
;
431 size
= width
* height
;
436 image
= RCreateImage(width
, height
, True
);
438 for (imgdata
=image
->data
, i
=2; i
<size
+2; i
++, imgdata
+=4) {
440 #if BYTE_ORDER == BIG_ENDIAN
441 imgdata
[2] = (pixel
>> 24) & 0xff; /* A */
442 imgdata
[1] = (pixel
>> 16) & 0xff; /* R */
443 imgdata
[0] = (pixel
>> 8) & 0xff; /* G */
444 imgdata
[3] = (pixel
>> 0) & 0xff; /* B */
445 #else /* Little endian */
446 imgdata
[3] = (pixel
>> 24) & 0xff; /* A */
447 imgdata
[0] = (pixel
>> 16) & 0xff; /* R */
448 imgdata
[1] = (pixel
>> 8) & 0xff; /* G */
449 imgdata
[2] = (pixel
>> 0) & 0xff; /* B */
450 #endif /* endianness */
459 updateIconImage(WScreen
*scr
, WWindow
*wwin
)
461 unsigned long *property
, *data
;
462 unsigned long items
, rest
;
467 if (XGetWindowProperty(dpy
, wwin
->client_win
, net_wm_icon
, 0L, LONG_MAX
,
468 False
, XA_CARDINAL
, &type
, &format
, &items
, &rest
,
469 (unsigned char**)&property
)!=Success
|| !property
) {
473 if (type
!=XA_CARDINAL
|| format
!=32 || items
<2) {
478 data
= findBestIcon(property
, items
);
484 image
= makeRImageFromARGBData(data
);
487 if (wwin
->net_icon_image
)
488 RReleaseImage(wwin
->net_icon_image
);
489 wwin
->net_icon_image
= image
;
497 updateShowDesktop(WScreen
* scr
, Bool show
)
501 foo
= (show
== True
);
502 XChangeProperty(dpy
, scr
->root_win
, net_showing_desktop
, XA_CARDINAL
, 32,
503 PropModeReplace
, (unsigned char *)&foo
, 1);
508 wNETWMShowingDesktop(WScreen
*scr
, Bool show
)
510 if (show
&& scr
->netdata
->show_desktop
== NULL
) {
511 WWindow
*tmp
, **wins
;
514 wins
= (WWindow
**)wmalloc(sizeof(WWindow
*)*(scr
->window_count
+1));
516 tmp
= scr
->focused_window
;
518 if (!tmp
->flags
.hidden
&& !tmp
->flags
.miniaturized
&&
519 !WFLAGP(tmp
, skip_window_list
)) {
522 tmp
->flags
.skip_next_animation
= 1;
523 tmp
->flags
.net_show_desktop
= 1;
531 scr
->netdata
->show_desktop
= wins
;
532 updateShowDesktop(scr
, True
);
533 } else if (scr
->netdata
->show_desktop
!= NULL
) {
534 /* FIXME: get rid of workspace flashing ! */
535 int ws
= scr
->current_workspace
;
537 for (tmp
= scr
->netdata
->show_desktop
; *tmp
; ++tmp
) {
538 wDeiconifyWindow(*tmp
);
539 (*tmp
)->flags
.net_show_desktop
= 0;
541 if (ws
!= scr
->current_workspace
)
542 wWorkspaceChange(scr
, ws
);
543 wfree(scr
->netdata
->show_desktop
);
544 scr
->netdata
->show_desktop
= NULL
;
545 updateShowDesktop(scr
, False
);
551 wNETWMInitStuff(WScreen
*scr
)
557 printf( "wNETWMInitStuff\n");
560 #ifdef HAVE_XINTERNATOMS
563 char * names
[atomNr
];
565 for (i
= 0; i
< atomNr
; ++i
) {
566 names
[i
] = atomNames
[i
].name
;
568 XInternAtoms(dpy
, &names
[0], atomNr
, False
, atoms
);
569 for (i
= 0; i
< atomNr
; ++i
) {
570 *atomNames
[i
].atom
= atoms
[i
];
574 for (i
= 0; i
< atomNr
; i
++) {
575 *atomNames
[i
].atom
= XInternAtom(dpy
, atomNames
[i
].name
, False
);
579 data
= wmalloc(sizeof(NetData
));
582 data
->show_desktop
= NULL
;
586 setSupportedHints(scr
);
588 WMAddNotificationObserver(observer
, data
, WMNManaged
, NULL
);
589 WMAddNotificationObserver(observer
, data
, WMNUnmanaged
, NULL
);
590 WMAddNotificationObserver(observer
, data
, WMNChangedWorkspace
, NULL
);
591 WMAddNotificationObserver(observer
, data
, WMNChangedState
, NULL
);
592 WMAddNotificationObserver(observer
, data
, WMNChangedFocus
, NULL
);
593 WMAddNotificationObserver(observer
, data
, WMNChangedStacking
, NULL
);
594 WMAddNotificationObserver(observer
, data
, WMNChangedName
, NULL
);
596 WMAddNotificationObserver(wsobserver
, data
, WMNWorkspaceCreated
, NULL
);
597 WMAddNotificationObserver(wsobserver
, data
, WMNWorkspaceDestroyed
, NULL
);
598 WMAddNotificationObserver(wsobserver
, data
, WMNWorkspaceChanged
, NULL
);
599 WMAddNotificationObserver(wsobserver
, data
, WMNWorkspaceNameChanged
, NULL
);
601 updateClientList(scr
);
602 updateClientListStacking(scr
, NULL
);
603 updateWorkspaceCount(scr
);
604 updateWorkspaceNames(scr
);
605 updateShowDesktop(scr
, False
);
607 wScreenUpdateUsableArea(scr
);
612 wNETWMCleanup(WScreen
*scr
)
616 for (i
= 0; i
< atomNr
; i
++)
617 XDeleteProperty(dpy
, scr
->root_win
, *atomNames
[i
].atom
);
622 wNETWMUpdateActions(WWindow
*wwin
, Bool del
)
624 Atom action
[10]; /* nr of actions atoms defined */
628 XDeleteProperty(dpy
, wwin
->client_win
, net_wm_allowed_actions
);
632 if (IS_MOVABLE(wwin
))
633 action
[i
++] = net_wm_action_move
;
635 if (IS_RESIZABLE(wwin
))
636 action
[i
++] = net_wm_action_resize
;
638 if (!WFLAGP(wwin
, no_miniaturizable
))
639 action
[i
++] = net_wm_action_minimize
;
641 if (!WFLAGP(wwin
, no_shadeable
))
642 action
[i
++] = net_wm_action_shade
;
644 /* if (!WFLAGP(wwin, no_stickable)) */
645 action
[i
++] = net_wm_action_stick
;
647 /* if (!(WFLAGP(wwin, no_maximizeable) & MAX_HORIZONTAL)) */
648 if (IS_RESIZABLE(wwin
))
649 action
[i
++] = net_wm_action_maximize_horz
;
651 /* if (!(WFLAGP(wwin, no_maximizeable) & MAX_VERTICAL)) */
652 if (IS_RESIZABLE(wwin
))
653 action
[i
++] = net_wm_action_maximize_vert
;
655 /* if (!WFLAGP(wwin, no_fullscreen)) */
656 action
[i
++] = net_wm_action_fullscreen
;
658 /* if (!WFLAGP(wwin, no_change_desktop)) */
659 action
[i
++] = net_wm_action_change_desktop
;
661 if (!WFLAGP(wwin
, no_closable
))
662 action
[i
++] = net_wm_action_close
;
664 XChangeProperty(dpy
, wwin
->client_win
, net_wm_allowed_actions
,
665 XA_ATOM
, 32, PropModeReplace
, (unsigned char *)action
, i
);
670 wNETWMUpdateWorkarea(WScreen
*scr
, WArea usableArea
)
675 /* XXX: not Xinerama compatible,
676 xinerama gets the largest available */
678 if(!scr
->netdata
|| scr
->workspace_count
==0)
681 count
= scr
->workspace_count
* 4;
682 area
= wmalloc(sizeof(long) * count
);
683 for (i
=0; i
<scr
->workspace_count
; i
++) {
684 area
[4*i
+ 0] = usableArea
.x1
;
685 area
[4*i
+ 1] = usableArea
.y1
;
686 area
[4*i
+ 2] = usableArea
.x2
- usableArea
.x1
;
687 area
[4*i
+ 3] = usableArea
.y2
- usableArea
.y1
;
690 XChangeProperty(dpy
, scr
->root_win
, net_workarea
, XA_CARDINAL
, 32,
691 PropModeReplace
, (unsigned char*)area
, count
);
698 wNETWMGetUsableArea(WScreen
*scr
, int head
, WArea
*area
)
703 if(!scr
->netdata
|| !scr
->netdata
->strut
)
706 area
->x1
= area
->y1
= area
->x2
= area
->y2
= 0;
708 for(cur
= scr
->netdata
->strut
; cur
; cur
= cur
->next
) {
709 WWindow
* wwin
= wWindowFor(cur
->window
);
710 if (wWindowTouchesHead(wwin
, head
)) {
711 if(cur
->area
.x1
> area
->x1
)
712 area
->x1
= cur
->area
.x1
;
713 if(cur
->area
.y1
> area
->y1
)
714 area
->y1
= cur
->area
.y1
;
715 if(cur
->area
.x2
> area
->x2
)
716 area
->x2
= cur
->area
.x2
;
717 if(cur
->area
.y2
> area
->y2
)
718 area
->y2
= cur
->area
.y2
;
722 if (area
->x1
==0 && area
->x2
==0 &&
723 area
->y1
==0 && area
->y2
==0) return False
;
725 rect
= wGetRectForHead(scr
, head
);
727 area
->x1
= rect
.pos
.x
+ area
->x1
;
728 area
->x2
= rect
.pos
.x
+ rect
.size
.width
- area
->x2
;
729 area
->y1
= rect
.pos
.y
+ area
->y1
;
730 area
->y2
= rect
.pos
.y
+ rect
.size
.height
- area
->y2
;
737 updateClientList(WScreen
*scr
)
743 windows
= (Window
*)wmalloc(sizeof(Window
)*(scr
->window_count
+1));
746 wwin
= scr
->focused_window
;
748 windows
[count
++] = wwin
->client_win
;
751 XChangeProperty(dpy
, scr
->root_win
, net_client_list
, XA_WINDOW
, 32,
752 PropModeReplace
, (unsigned char*)windows
, count
);
760 updateClientListStacking(WScreen
*scr
, WWindow
*wwin_excl
)
764 Window
*client_list_reverse
;
770 /* update client list */
771 i
= scr
->window_count
+ 1;
772 client_list
= (Window
*)wmalloc(sizeof(Window
) * i
);
773 client_list_reverse
= (Window
*)wmalloc(sizeof(Window
) * i
);
776 WM_ETARETI_BAG(scr
->stacking_list
, tmp
, iter
) {
778 wwin
= wWindowFor(tmp
->window
);
779 /* wwin_excl is a window to exclude from the list
780 (e.g. it's now unmanaged) */
781 if(wwin
&& (wwin
!= wwin_excl
))
782 client_list
[client_count
++] = wwin
->client_win
;
783 tmp
= tmp
->stacking
->under
;
787 for(i
= 0; i
< client_count
; i
++) {
788 Window w
= client_list
[client_count
- i
- 1];
789 client_list_reverse
[i
] = w
;
792 XChangeProperty(dpy
, scr
->root_win
, net_client_list_stacking
, XA_WINDOW
, 32,
793 PropModeReplace
, (unsigned char *)client_list_reverse
, client_count
);
796 wfree(client_list_reverse
);
803 updateWorkspaceCount(WScreen
*scr
) /* changeable */
807 count
= scr
->workspace_count
;
809 XChangeProperty(dpy
, scr
->root_win
, net_number_of_desktops
, XA_CARDINAL
,
810 32, PropModeReplace
, (unsigned char*)&count
, 1);
815 updateCurrentWorkspace(WScreen
*scr
) /* changeable */
819 count
= scr
->current_workspace
;
821 XChangeProperty(dpy
, scr
->root_win
, net_current_desktop
, XA_CARDINAL
, 32,
822 PropModeReplace
, (unsigned char*)&count
, 1);
827 updateWorkspaceNames(WScreen
*scr
)
829 char buf
[1024], *pos
;
830 unsigned int i
, len
, curr_size
;
834 for(i
= 0; i
< scr
->workspace_count
; i
++) {
835 curr_size
= strlen(scr
->workspaces
[i
]->name
);
836 strcpy(pos
, scr
->workspaces
[i
]->name
);
837 pos
+= (curr_size
+1);
838 len
+= (curr_size
+1);
841 XChangeProperty(dpy
, scr
->root_win
, net_desktop_names
, utf8_string
, 8,
842 PropModeReplace
, (unsigned char *)buf
, len
);
847 updateFocusHint(WScreen
*scr
, WWindow
*wwin
) /* changeable */
851 if (!scr
->focused_window
|| !scr
->focused_window
->flags
.focused
)
854 window
= scr
->focused_window
->client_win
;
856 XChangeProperty(dpy
, scr
->root_win
, net_active_window
, XA_WINDOW
, 32,
857 PropModeReplace
, (unsigned char*)&window
, 1);
862 updateWorkspaceHint(WWindow
*wwin
, Bool fake
, Bool del
)
867 XDeleteProperty(dpy
, wwin
->client_win
, net_wm_desktop
);
869 l
= ((fake
|| IS_OMNIPRESENT(wwin
)) ? -1 : wwin
->frame
->workspace
);
870 XChangeProperty(dpy
, wwin
->client_win
, net_wm_desktop
, XA_CARDINAL
,
871 32, PropModeReplace
, (unsigned char*)&l
, 1);
877 updateStateHint(WWindow
*wwin
, Bool changedWorkspace
, Bool del
) /* changeable */
880 if (!wwin
->flags
.net_state_from_client
) {
881 XDeleteProperty(dpy
, wwin
->client_win
, net_wm_state
);
884 Atom state
[15]; /* nr of defined state atoms */
887 if(changedWorkspace
|| (wPreferences
.sticky_icons
&& !IS_OMNIPRESENT(wwin
)))
888 updateWorkspaceHint(wwin
, False
, False
);
890 if (IS_OMNIPRESENT(wwin
))
891 state
[i
++] = net_wm_state_sticky
;
892 if (wwin
->flags
.shaded
)
893 state
[i
++] = net_wm_state_shaded
;
894 if (wwin
->flags
.maximized
& MAX_HORIZONTAL
)
895 state
[i
++] = net_wm_state_maximized_horz
;
896 if (wwin
->flags
.maximized
& MAX_VERTICAL
)
897 state
[i
++] = net_wm_state_maximized_vert
;
898 if (WFLAGP(wwin
, skip_window_list
))
899 state
[i
++] = net_wm_state_skip_taskbar
;
900 if (wwin
->flags
.net_skip_pager
)
901 state
[i
++] = net_wm_state_skip_pager
;
902 if ((wwin
->flags
.hidden
|| wwin
->flags
.miniaturized
) && !wwin
->flags
.net_show_desktop
){
903 state
[i
++] = net_wm_state_hidden
;
904 state
[i
++] = net_wm_state_skip_pager
;
906 if (wwin
->flags
.miniaturized
&& wPreferences
.sticky_icons
) {
907 if (!IS_OMNIPRESENT(wwin
))
908 updateWorkspaceHint(wwin
, True
, False
);
909 state
[i
++] = net_wm_state_sticky
;
912 if (WFLAGP(wwin
, sunken
))
913 state
[i
++] = net_wm_state_below
;
914 if (WFLAGP(wwin
, floating
))
915 state
[i
++] = net_wm_state_above
;
916 if (wwin
->flags
.fullscreen
)
917 state
[i
++] = net_wm_state_fullscreen
;
919 XChangeProperty(dpy
, wwin
->client_win
, net_wm_state
, XA_ATOM
, 32,
920 PropModeReplace
, (unsigned char *)state
, i
);
926 updateStrut(WWindow
*wwin
, Bool adding
)
930 Bool hasState
= False
;
932 scr
= wwin
->screen_ptr
;
937 unsigned long nitems_ret
;
938 unsigned long bytes_after_ret
;
941 if (XGetWindowProperty(dpy
, wwin
->client_win
, net_wm_strut
, 0, 4, False
,
942 XA_CARDINAL
, &type_ret
, &fmt_ret
, &nitems_ret
,
944 (unsigned char**)&data
)==Success
&& data
) {
946 area
= (WReservedArea
*)wmalloc(sizeof(WReservedArea
));
947 area
->area
.x1
= data
[0];
948 area
->area
.x2
= data
[1];
949 area
->area
.y1
= data
[2];
950 area
->area
.y2
= data
[3];
952 area
->window
= wwin
->client_win
;
954 area
->next
= scr
->netdata
->strut
;
955 scr
->netdata
->strut
= area
;
959 #ifdef VIRTUAL_DESKTOP
960 /* just in case wm_window_type didn't set it already */
961 wwin
->client_flags
.virtual_stick
= 1;
967 area
= scr
->netdata
->strut
;
970 if(area
->window
== wwin
->client_win
) {
971 scr
->netdata
->strut
= area
->next
;
975 while(area
->next
&& area
->next
->window
!= wwin
->client_win
)
981 next
= area
->next
->next
;
996 getWindowLayer(WWindow
* wwin
)
998 int layer
= WMNormalLevel
;
1000 if (wwin
->type
== net_wm_window_type_desktop
) {
1001 layer
= WMDesktopLevel
;
1002 } else if (wwin
->type
== net_wm_window_type_dock
) {
1003 layer
= WMDockLevel
;
1004 } else if (wwin
->type
== net_wm_window_type_toolbar
) {
1005 layer
= WMMainMenuLevel
;
1006 } else if (wwin
->type
== net_wm_window_type_menu
) {
1007 layer
= WMSubmenuLevel
;
1008 } else if (wwin
->type
== net_wm_window_type_utility
) {
1009 } else if (wwin
->type
== net_wm_window_type_splash
) {
1010 } else if (wwin
->type
== net_wm_window_type_dialog
) {
1011 if (wwin
->transient_for
) {
1012 WWindow
*parent
= wWindowFor(wwin
->transient_for
);
1013 if (parent
&& parent
->flags
.fullscreen
) {
1014 layer
= WMFullscreenLevel
;
1017 /* //layer = WMPopUpLevel; // this seems a bad idea -Dan */
1018 } else if (wwin
->type
== net_wm_window_type_normal
) {
1021 if (wwin
->client_flags
.sunken
&& WMSunkenLevel
< layer
)
1022 layer
= WMSunkenLevel
;
1023 if (wwin
->client_flags
.floating
&& WMFloatingLevel
> layer
)
1024 layer
= WMFloatingLevel
;
1031 doStateAtom(WWindow
*wwin
, Atom state
, int set
, Bool init
)
1034 if (state
== net_wm_state_sticky
) {
1035 if (set
== _NET_WM_STATE_TOGGLE
) {
1036 set
= !IS_OMNIPRESENT(wwin
);
1038 if (set
!= wwin
->flags
.omnipresent
) {
1039 wWindowSetOmnipresent(wwin
, set
);
1041 } else if (state
== net_wm_state_shaded
) {
1042 if (set
== _NET_WM_STATE_TOGGLE
) {
1043 set
= !wwin
->flags
.shaded
;
1046 wwin
->flags
.shaded
= set
;
1051 wUnshadeWindow(wwin
);
1054 } else if (state
== net_wm_state_skip_taskbar
) {
1055 if (set
== _NET_WM_STATE_TOGGLE
) {
1056 set
= !wwin
->client_flags
.skip_window_list
;
1058 wwin
->client_flags
.skip_window_list
= set
;
1059 } else if (state
== net_wm_state_skip_pager
) {
1060 if (set
== _NET_WM_STATE_TOGGLE
) {
1061 set
= !wwin
->flags
.net_skip_pager
;
1063 wwin
->flags
.net_skip_pager
= set
;
1064 } else if (state
== net_wm_state_maximized_vert
) {
1065 if (set
== _NET_WM_STATE_TOGGLE
) {
1066 set
= !(wwin
->flags
.maximized
& MAX_VERTICAL
);
1069 wwin
->flags
.maximized
|= (set
? MAX_VERTICAL
: 0);
1072 wMaximizeWindow(wwin
, wwin
->flags
.maximized
| MAX_VERTICAL
);
1074 wMaximizeWindow(wwin
, wwin
->flags
.maximized
& ~MAX_VERTICAL
);
1077 } else if (state
== net_wm_state_maximized_horz
) {
1078 if (set
== _NET_WM_STATE_TOGGLE
) {
1079 set
= !(wwin
->flags
.maximized
& MAX_HORIZONTAL
);
1082 wwin
->flags
.maximized
|= (set
? MAX_HORIZONTAL
: 0);
1085 wMaximizeWindow(wwin
, wwin
->flags
.maximized
| MAX_HORIZONTAL
);
1087 wMaximizeWindow(wwin
, wwin
->flags
.maximized
& ~MAX_HORIZONTAL
);
1090 } else if (state
== net_wm_state_hidden
) {
1091 if (set
== _NET_WM_STATE_TOGGLE
) {
1092 set
= !(wwin
->flags
.miniaturized
);
1095 wwin
->flags
.miniaturized
= set
;
1098 wIconifyWindow(wwin
);
1100 wDeiconifyWindow(wwin
);
1103 } else if (state
== net_wm_state_fullscreen
) {
1104 if (set
== _NET_WM_STATE_TOGGLE
) {
1105 set
= !(wwin
->flags
.fullscreen
);
1108 wwin
->flags
.fullscreen
= set
;
1111 wFullscreenWindow(wwin
);
1113 wUnfullscreenWindow(wwin
);
1116 } else if (state
== net_wm_state_above
) {
1117 if (set
== _NET_WM_STATE_TOGGLE
) {
1118 set
= !(wwin
->client_flags
.floating
);
1121 wwin
->client_flags
.floating
= set
;
1123 wwin
->client_flags
.floating
= set
;
1124 ChangeStackingLevel(wwin
->frame
->core
, getWindowLayer(wwin
));
1127 } else if (state
== net_wm_state_below
) {
1128 if (set
== _NET_WM_STATE_TOGGLE
) {
1129 set
= !(wwin
->client_flags
.sunken
);
1132 wwin
->client_flags
.sunken
= set
;
1134 wwin
->client_flags
.sunken
= set
;
1135 ChangeStackingLevel(wwin
->frame
->core
, getWindowLayer(wwin
));
1140 printf("doStateAtom unknown atom %s set %d\n", XGetAtomName(dpy
, state
), set
);
1147 removeIcon( WWindow
* wwin
)
1149 if (wwin
->icon
== NULL
)
1151 if (wwin
->flags
.miniaturized
&& wwin
->icon
->mapped
) {
1152 XUnmapWindow(dpy
, wwin
->icon
->core
->window
);
1153 RemoveFromStackList(wwin
->icon
->core
);
1154 wIconDestroy(wwin
->icon
);
1161 handleWindowType(WWindow
* wwin
, Atom type
, int *layer
)
1165 if (type
== net_wm_window_type_desktop
) {
1166 wwin
->client_flags
.no_titlebar
= 1;
1167 wwin
->client_flags
.no_resizable
= 1;
1168 wwin
->client_flags
.no_miniaturizable
= 1;
1169 wwin
->client_flags
.no_border
= 1;
1170 wwin
->client_flags
.no_resizebar
= 1;
1171 wwin
->client_flags
.no_shadeable
= 1;
1172 wwin
->client_flags
.no_movable
= 1;
1173 wwin
->client_flags
.omnipresent
= 1;
1174 wwin
->client_flags
.skip_window_list
= 1;
1175 wwin
->client_flags
.dont_move_off
= 1;
1176 wwin
->client_flags
.no_appicon
= 1;
1177 wwin
->flags
.net_skip_pager
= 1;
1180 #ifdef VIRTUAL_DESKTOP
1181 wwin
->client_flags
.virtual_stick
= 1;
1183 } else if (type
== net_wm_window_type_dock
) {
1184 wwin
->client_flags
.no_titlebar
= 1;
1185 wwin
->client_flags
.no_resizable
= 1;
1186 wwin
->client_flags
.no_miniaturizable
= 1;
1187 wwin
->client_flags
.no_border
= 1; /* XXX: really not a single decoration. */
1188 wwin
->client_flags
.no_resizebar
= 1;
1189 wwin
->client_flags
.no_shadeable
= 1;
1190 wwin
->client_flags
.no_movable
= 1;
1191 wwin
->client_flags
.omnipresent
= 1;
1192 wwin
->client_flags
.skip_window_list
= 1;
1193 wwin
->client_flags
.dont_move_off
= 1;
1194 wwin
->flags
.net_skip_pager
= 1;
1195 #ifdef VIRTUAL_DESKTOP
1196 wwin
->client_flags
.virtual_stick
= 1;
1198 } else if (type
== net_wm_window_type_toolbar
) {
1199 wwin
->client_flags
.no_titlebar
= 1;
1200 wwin
->client_flags
.no_resizable
= 1;
1201 wwin
->client_flags
.no_miniaturizable
= 1;
1202 wwin
->client_flags
.no_resizebar
= 1;
1203 wwin
->client_flags
.no_shadeable
= 1;
1204 wwin
->client_flags
.skip_window_list
= 1;
1205 wwin
->client_flags
.dont_move_off
= 1;
1206 wwin
->client_flags
.no_appicon
= 1;
1207 } else if (type
== net_wm_window_type_menu
) {
1208 wwin
->client_flags
.no_titlebar
= 1;
1209 wwin
->client_flags
.no_resizable
= 1;
1210 wwin
->client_flags
.no_miniaturizable
= 1;
1211 wwin
->client_flags
.no_resizebar
= 1;
1212 wwin
->client_flags
.no_shadeable
= 1;
1213 wwin
->client_flags
.skip_window_list
= 1;
1214 wwin
->client_flags
.dont_move_off
= 1;
1215 wwin
->client_flags
.no_appicon
= 1;
1216 } else if (type
== net_wm_window_type_utility
) {
1217 wwin
->client_flags
.no_appicon
= 1;
1218 } else if (type
== net_wm_window_type_splash
) {
1219 wwin
->client_flags
.no_titlebar
= 1;
1220 wwin
->client_flags
.no_resizable
= 1;
1221 wwin
->client_flags
.no_miniaturizable
= 1;
1222 wwin
->client_flags
.no_resizebar
= 1;
1223 wwin
->client_flags
.no_shadeable
= 1;
1224 wwin
->client_flags
.no_movable
= 1;
1225 wwin
->client_flags
.skip_window_list
= 1;
1226 wwin
->client_flags
.dont_move_off
= 1;
1227 wwin
->client_flags
.no_appicon
= 1;
1228 wwin
->flags
.net_skip_pager
= 1;
1229 } else if (type
== net_wm_window_type_dialog
) {
1230 /* These also seem a bad idea in our context -Dan
1231 // wwin->client_flags.skip_window_list = 1;
1232 // wwin->client_flags.no_appicon = 1;
1234 } else if (type
== net_wm_window_type_normal
) {
1240 *layer
= getWindowLayer(wwin
);
1247 wNETWMPositionSplash(WWindow
*wwin
, int *x
, int *y
, int width
, int height
)
1249 if (wwin
->type
== net_wm_window_type_splash
) {
1250 WScreen
* scr
= wwin
->screen_ptr
;
1251 WMRect rect
= wGetRectForHead(scr
, wGetHeadForPointerLocation(scr
));
1252 *x
= rect
.pos
.x
+ (rect
.size
.width
- width
)/2;
1253 *y
= rect
.pos
.y
+ (rect
.size
.height
- height
)/2;
1259 updateWindowType(WWindow
* wwin
)
1263 unsigned long nitems_ret
;
1264 unsigned long bytes_after_ret
;
1267 if (XGetWindowProperty(dpy
, wwin
->client_win
, net_wm_window_type
, 0, 1,
1268 False
, XA_ATOM
, &type_ret
, &fmt_ret
, &nitems_ret
,
1269 &bytes_after_ret
, (unsigned char **)&data
)==Success
1273 Atom
* type
= (Atom
*)data
;
1274 for (i
=0; i
<nitems_ret
; ++i
) {
1275 if (handleWindowType(wwin
, type
[i
], &layer
)) break;
1280 ChangeStackingLevel(wwin
->frame
->core
, layer
);
1281 wwin
->frame
->flags
.need_texture_change
= 1;
1282 wWindowConfigureBorders(wwin
);
1283 wFrameWindowPaint(wwin
->frame
);
1284 wNETWMUpdateActions(wwin
, False
);
1289 wNETWMCheckClientHints(WWindow
*wwin
, int *layer
, int *workspace
)
1293 unsigned long nitems_ret
;
1294 unsigned long bytes_after_ret
;
1296 Bool hasState
= False
;
1299 if (XGetWindowProperty(dpy
, wwin
->client_win
, net_wm_desktop
, 0, 1, False
,
1300 XA_CARDINAL
, &type_ret
, &fmt_ret
, &nitems_ret
,
1302 (unsigned char**)&data
)==Success
&& data
) {
1304 long desktop
= *data
;
1308 wwin
->client_flags
.omnipresent
= 1;
1310 *workspace
= desktop
;
1315 if (XGetWindowProperty(dpy
, wwin
->client_win
, net_wm_state
, 0, 1, False
,
1316 XA_ATOM
, &type_ret
, &fmt_ret
, &nitems_ret
,
1318 (unsigned char**)&data
)==Success
&& data
) {
1320 Atom
* state
= (Atom
*)data
;
1321 for(i
=0; i
<nitems_ret
; ++i
) {
1322 doStateAtom(wwin
, state
[i
], _NET_WM_STATE_ADD
, True
);
1328 if (XGetWindowProperty(dpy
, wwin
->client_win
, net_wm_window_type
, 0, 1, False
,
1329 XA_ATOM
, &type_ret
, &fmt_ret
, &nitems_ret
,
1331 (unsigned char **)&data
) == Success
&& data
) {
1333 Atom
* type
= (Atom
*)data
;
1334 for (i
=0; i
<nitems_ret
; ++i
) {
1335 if (handleWindowType(wwin
, type
[i
], layer
)) break;
1341 wNETWMUpdateActions(wwin
, False
);
1342 updateStrut(wwin
, False
);
1343 if (updateStrut(wwin
, True
)) {
1346 wScreenUpdateUsableArea(wwin
->screen_ptr
);
1353 updateNetIconInfo(WWindow
*wwin
) {
1357 unsigned long nitems_ret
;
1358 unsigned long bytes_after_ret
;
1360 Bool hasState
= False
;
1361 Bool old_state
= wwin
->flags
.net_handle_icon
;
1363 if (XGetWindowProperty(dpy
, wwin
->client_win
, net_wm_handled_icons
, 0, 1, False
,
1364 XA_CARDINAL
, &type_ret
, &fmt_ret
, &nitems_ret
,
1365 &bytes_after_ret
, (unsigned char **)&data
) == Success
&& data
) {
1366 long handled
= *data
;
1367 wwin
->flags
.net_handle_icon
= (handled
!= 0);
1371 } else wwin
->flags
.net_handle_icon
= False
;
1373 if ( XGetWindowProperty(dpy
, wwin
->client_win
, net_wm_icon_geometry
, 0, 4, False
,
1374 XA_CARDINAL
, &type_ret
, &fmt_ret
, &nitems_ret
,
1375 &bytes_after_ret
, (unsigned char **)&data
) == Success
&& data
) {
1378 if (wwin
->flags
.net_handle_icon
)
1380 wwin
->flags
.net_handle_icon
= True
;
1383 wwin
->icon_x
= data
[0];
1384 wwin
->icon_y
= data
[1];
1385 wwin
->icon_w
= data
[2];
1386 wwin
->icon_h
= data
[3];
1392 } else wwin
->flags
.net_handle_icon
= False
;
1394 if (wwin
->flags
.miniaturized
&&
1395 old_state
!= wwin
->flags
.net_handle_icon
) {
1396 if (wwin
->flags
.net_handle_icon
) {
1399 wwin
->flags
.miniaturized
= False
;
1400 wwin
->flags
.skip_next_animation
= True
;
1401 wIconifyWindow(wwin
);
1410 wNETWMCheckInitialClientState(WWindow
*wwin
)
1412 Bool hasState
= False
;
1415 printf("CheckInitialClientState\n");
1418 wNETWMShowingDesktop(wwin
->screen_ptr
, False
);
1420 hasState
|= updateNetIconInfo(wwin
);
1422 updateIconImage(wwin
->screen_ptr
, wwin
);
1429 handleDesktopNames(XClientMessageEvent
*event
, WScreen
*scr
)
1431 unsigned long nitems_ret
, bytes_after_ret
;
1432 char *data
, *names
[32];
1436 if (XGetWindowProperty(dpy
, scr
->root_win
, net_desktop_names
, 0, 1, False
,
1437 utf8_string
, &type_ret
, &fmt_ret
, &nitems_ret
,
1439 (unsigned char**)&data
)!=Success
) {
1446 if (type_ret
!= utf8_string
|| fmt_ret
!= 8)
1451 for (i
= 0; i
< nitems_ret
; i
++) {
1454 names
[n
] = &data
[i
];
1455 } else if (*names
[n
] == 0) {
1456 names
[n
] = &data
[i
];
1457 wWorkspaceRename(scr
, n
, names
[n
]);
1464 wNETWMProcessClientMessage(XClientMessageEvent
*event
)
1471 printf("processClientMessage type %s\n", XGetAtomName(dpy
, event
->message_type
));
1474 scr
= wScreenForWindow(event
->window
);
1476 /* generic client messages */
1477 if (event
->message_type
== net_current_desktop
) {
1478 wWorkspaceChange(scr
, event
->data
.l
[0]);
1479 } else if(event
->message_type
== net_number_of_desktops
) {
1482 value
= event
->data
.l
[0];
1483 if(value
> scr
->workspace_count
) {
1484 wWorkspaceMake(scr
, value
- scr
->workspace_count
);
1485 } else if(value
< scr
->workspace_count
) {
1487 Bool rebuild
= False
;
1489 for (i
= scr
->workspace_count
-1; i
>= value
; i
--) {
1490 if (!wWorkspaceDelete(scr
, i
)) {
1497 updateWorkspaceCount(scr
);
1500 } else if (event
->message_type
== net_showing_desktop
) {
1501 wNETWMShowingDesktop(scr
, event
->data
.l
[0]);
1502 #ifdef VIRTUAL_DESKTOP
1503 } else if (event
->message_type
== net_desktop_viewport
) {
1504 wWorkspaceSetViewport(scr
, scr
->current_workspace
,
1505 event
->data
.l
[0], event
->data
.l
[1]);
1507 } else if (event
->message_type
== net_desktop_names
) {
1508 handleDesktopNames(event
, scr
);
1517 /* window specific client messages */
1519 wwin
= wWindowFor(event
->window
);
1523 if (event
->message_type
== net_active_window
) {
1524 wNETWMShowingDesktop(scr
, False
);
1525 wMakeWindowVisible(wwin
);
1526 } else if (event
->message_type
== net_close_window
) {
1527 if (!WFLAGP(wwin
, no_closable
)) {
1528 if (wwin
->protocols
.DELETE_WINDOW
)
1529 wClientSendProtocol(wwin
, _XA_WM_DELETE_WINDOW
, LastTimestamp
);
1531 } else if (event
->message_type
== net_wm_state
) {
1532 int maximized
= wwin
->flags
.maximized
;
1533 long set
= event
->data
.l
[0];
1536 printf("net_wm_state set %d a1 %s a2 %s\n", set
,
1537 XGetAtomName(dpy
, event
->data
.l
[1]),
1538 XGetAtomName(dpy
, event
->data
.l
[2]));
1541 doStateAtom(wwin
, (Atom
)event
->data
.l
[1], set
, False
);
1542 if(event
->data
.l
[2])
1543 doStateAtom(wwin
, (Atom
)event
->data
.l
[2], set
, False
);
1545 if(wwin
->flags
.maximized
!= maximized
) {
1546 if(!wwin
->flags
.maximized
) {
1547 wwin
->flags
.maximized
= maximized
;
1548 wUnmaximizeWindow(wwin
);
1550 wMaximizeWindow(wwin
, wwin
->flags
.maximized
);
1553 updateStateHint(wwin
, False
, False
);
1554 } else if (event
->message_type
== net_wm_handled_icons
||
1555 event
->message_type
== net_wm_icon_geometry
) {
1556 updateNetIconInfo(wwin
);
1557 } else if (event
->message_type
== net_wm_desktop
) {
1558 long desktop
= event
->data
.l
[0];
1559 if (desktop
== -1) {
1560 wWindowSetOmnipresent(wwin
, True
);
1562 if (IS_OMNIPRESENT(wwin
))
1563 wWindowSetOmnipresent(wwin
, False
);
1564 wWindowChangeWorkspace(wwin
, desktop
);
1566 } else if (event
->message_type
== net_wm_icon
) {
1567 updateIconImage(scr
, wwin
);
1577 wNETWMCheckClientHintChange(WWindow
*wwin
, XPropertyEvent
*event
)
1581 if(event
->atom
== net_wm_strut
) {
1582 updateStrut(wwin
, False
);
1583 updateStrut(wwin
, True
);
1584 wScreenUpdateUsableArea(wwin
->screen_ptr
);
1585 } else if (event
->atom
== net_wm_handled_icons
||
1586 event
->atom
== net_wm_icon_geometry
) {
1587 updateNetIconInfo(wwin
);
1588 } else if (event
->atom
== net_wm_window_type
) {
1589 updateWindowType(wwin
);
1590 } else if (event
->atom
== net_wm_name
) {
1591 char *name
= wNETWMGetWindowName(wwin
->client_win
);
1592 wWindowUpdateName(wwin
, name
);
1593 if (name
) wfree(name
);
1594 } else if (event
->atom
== net_wm_icon_name
) {
1596 char *name
= wNETWMGetIconName(wwin
->client_win
);
1597 wIconChangeTitle(wwin
->icon
, name
);
1608 wNETWMGetPidForWindow(Window window
)
1612 unsigned long nitems_ret
;
1613 unsigned long bytes_after_ret
;
1617 if (XGetWindowProperty(dpy
, window
, net_wm_pid
, 0, 1, False
,
1618 XA_CARDINAL
, &type_ret
, &fmt_ret
, &nitems_ret
,
1620 (unsigned char**)&data
)==Success
&& data
) {
1633 wNETWMGetWindowName(Window window
)
1639 name
= (char*)PropGetCheckProperty(window
,
1640 net_wm_name
, utf8_string
, 0,
1643 ret
= wstrndup(name
, size
);
1653 wNETWMGetIconName(Window window
)
1659 name
= (char*)PropGetCheckProperty(window
,
1660 net_wm_icon_name
, utf8_string
, 0,
1663 ret
= wstrndup(name
, size
);
1673 observer(void *self
, WMNotification
*notif
)
1675 WWindow
*wwin
= (WWindow
*)WMGetNotificationObject(notif
);
1676 const char *name
= WMGetNotificationName(notif
);
1677 void *data
= WMGetNotificationClientData(notif
);
1678 NetData
*ndata
= (NetData
*)self
;
1681 if (strcmp(name
, WMNManaged
) == 0 && wwin
) {
1682 updateClientList(wwin
->screen_ptr
);
1683 updateClientListStacking(wwin
->screen_ptr
, NULL
);
1684 updateStateHint(wwin
, True
, False
);
1686 updateStrut(wwin
, False
);
1687 updateStrut(wwin
, True
);
1688 wScreenUpdateUsableArea(wwin
->screen_ptr
);
1689 } else if (strcmp(name
, WMNUnmanaged
) == 0 && wwin
) {
1690 updateClientList(wwin
->screen_ptr
);
1691 updateClientListStacking(wwin
->screen_ptr
, wwin
);
1692 updateWorkspaceHint(wwin
, False
, True
);
1693 updateStateHint(wwin
, False
, True
);
1694 wNETWMUpdateActions(wwin
, True
);
1696 updateStrut(wwin
, False
);
1697 wScreenUpdateUsableArea(wwin
->screen_ptr
);
1698 } else if (strcmp(name
, WMNResetStacking
) == 0 && wwin
) {
1699 updateClientListStacking(wwin
->screen_ptr
, NULL
);
1700 updateStateHint(wwin
, False
, False
);
1701 } else if (strcmp(name
, WMNChangedStacking
) == 0 && wwin
) {
1702 updateClientListStacking(wwin
->screen_ptr
, NULL
);
1703 updateStateHint(wwin
, False
, False
);
1704 } else if (strcmp(name
, WMNChangedFocus
) == 0) {
1705 updateFocusHint(ndata
->scr
, wwin
);
1706 } else if (strcmp(name
, WMNChangedWorkspace
) == 0 && wwin
) {
1707 updateWorkspaceHint(wwin
, False
, False
);
1708 updateStateHint(wwin
, True
, False
);
1709 } else if (strcmp(name
, WMNChangedState
) == 0 && wwin
) {
1710 updateStateHint(wwin
, !strcmp(data
, "omnipresent"), False
);
1716 wsobserver(void *self
, WMNotification
*notif
)
1718 WScreen
*scr
= (WScreen
*)WMGetNotificationObject(notif
);
1719 const char *name
= WMGetNotificationName(notif
);
1721 if (strcmp(name
, WMNWorkspaceCreated
) == 0) {
1722 updateWorkspaceCount(scr
);
1723 updateWorkspaceNames(scr
);
1724 } else if (strcmp(name
, WMNWorkspaceDestroyed
) == 0) {
1725 updateWorkspaceCount(scr
);
1726 updateWorkspaceNames(scr
);
1727 } else if (strcmp(name
, WMNWorkspaceChanged
) == 0) {
1728 updateCurrentWorkspace(scr
);
1729 } else if (strcmp(name
, WMNWorkspaceNameChanged
) == 0) {
1730 updateWorkspaceNames(scr
);
1734 #endif /* NETWM_HINTS */