2 * Window Maker window manager
4 * Copyright (c) 1997-2003 Alfredo K. Kojima
6 * This program is free software; you can redistribute it and/or modify
7 * it under the terms of the GNU General Public License as published by
8 * the Free Software Foundation; either version 2 of the License, or
9 * (at your option) any later version.
11 * This program is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 * GNU General Public License for more details.
16 * You should have received a copy of the GNU General Public License along
17 * with this program; if not, write to the Free Software Foundation, Inc.,
18 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
28 #include <X11/Xutil.h>
30 #include "WindowMaker.h"
34 #include "properties.h"
36 #include "winspector.h"
42 static void wipeDesktop(WScreen
* scr
);
45 *----------------------------------------------------------------------
47 * Exits the window manager cleanly. If mode is WSLogoutMode,
48 * the whole X session will be closed, by killing all clients if
49 * no session manager is running or by asking a shutdown to
52 *----------------------------------------------------------------------
54 void Shutdown(WShutdownMode mode
)
62 /* if there is no session manager, send SAVE_YOURSELF to
65 if (w_global
.inotify
.fd_event_queue
>= 0) {
66 close(w_global
.inotify
.fd_event_queue
);
67 w_global
.inotify
.fd_event_queue
= -1;
70 for (i
= 0; i
< w_global
.screen_count
; i
++) {
73 scr
= wScreenWithNumber(i
);
76 kill(scr
->helper_pid
, SIGKILL
);
78 wScreenSaveState(scr
);
80 if (mode
== WSKillMode
)
90 case WSRestartPreparationMode
:
91 for (i
= 0; i
< w_global
.screen_count
; i
++) {
95 if (w_global
.inotify
.fd_event_queue
>= 0) {
96 close(w_global
.inotify
.fd_event_queue
);
97 w_global
.inotify
.fd_event_queue
= -1;
100 scr
= wScreenWithNumber(i
);
103 kill(scr
->helper_pid
, SIGKILL
);
104 wScreenSaveState(scr
);
112 static void restoreWindows(WMBag
* bag
, WMBagIterator iter
)
119 core
= WMBagFirst(bag
, &iter
);
121 core
= WMBagNext(bag
, &iter
);
127 restoreWindows(bag
, iter
);
129 /* go to the end of the list */
130 while (core
->stacking
->under
)
131 core
= core
->stacking
->under
;
134 next
= core
->stacking
->above
;
136 if (core
->descriptor
.parent_type
== WCLASS_WINDOW
) {
139 wwin
= core
->descriptor
.parent
;
140 window
= wwin
->client_win
;
141 wUnmanageWindow(wwin
, !wwin
->flags
.internal_window
, False
);
142 XMapWindow(dpy
, window
);
149 *----------------------------------------------------------------------
151 * Puts the desktop in a usable state when exiting.
154 * All frame windows are removed and windows are reparented
155 * back to root. Windows that are outside the screen are
156 * brought to a viable place.
158 *----------------------------------------------------------------------
160 void RestoreDesktop(WScreen
* scr
)
162 if (scr
->helper_pid
> 0) {
163 kill(scr
->helper_pid
, SIGTERM
);
168 wDestroyInspectorPanels();
170 /* reparent windows back to the root window, keeping the stacking order */
171 restoreWindows(scr
->stacking_list
, NULL
);
174 XSetInputFocus(dpy
, PointerRoot
, RevertToParent
, CurrentTime
);
175 wColormapInstallForWindow(scr
, NULL
);
176 PropCleanUp(scr
->root_win
);
182 *----------------------------------------------------------------------
184 * Kills all windows in a screen. Send DeleteWindow to all windows
185 * that support it and KillClient on all windows that don't.
188 * All managed windows are closed.
190 * TODO: change to XQueryTree()
191 *----------------------------------------------------------------------
193 static void wipeDesktop(WScreen
* scr
)
197 wwin
= scr
->focused_window
;
199 if (wwin
->protocols
.DELETE_WINDOW
)
200 wClientSendProtocol(wwin
, w_global
.atom
.wm
.delete_window
,
201 w_global
.timestamp
.last_event
);