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
17 * along with this program; if not, write to the Free Software
18 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307,
29 #include <X11/Xutil.h>
31 #include "WindowMaker.h"
35 #include "properties.h"
37 #include "winspector.h"
40 extern Atom _XA_WM_DELETE_WINDOW
;
41 extern Time LastTimestamp
;
42 extern int wScreenCount
;
44 static void wipeDesktop(WScreen
* scr
);
47 *----------------------------------------------------------------------
49 * Exits the window manager cleanly. If mode is WSLogoutMode,
50 * the whole X session will be closed, by killing all clients if
51 * no session manager is running or by asking a shutdown to
54 *----------------------------------------------------------------------
56 void Shutdown(WShutdownMode mode
)
64 wSessionRequestShutdown();
71 /* if there is no session manager, send SAVE_YOURSELF to
75 if (!wSessionIsManaged())
77 for (i
= 0; i
< wScreenCount
; i
++) {
80 scr
= wScreenWithNumber(i
);
82 wSessionSendSaveYourself(scr
);
87 for (i
= 0; i
< wScreenCount
; i
++) {
90 scr
= wScreenWithNumber(i
);
93 kill(scr
->helper_pid
, SIGKILL
);
95 /* if the session is not being managed, save restart info */
97 if (!wSessionIsManaged())
99 wSessionSaveClients(scr
);
101 wScreenSaveState(scr
);
103 if (mode
== WSKillMode
)
113 case WSRestartPreparationMode
:
114 for (i
= 0; i
< wScreenCount
; i
++) {
118 scr
= wScreenWithNumber(i
);
121 kill(scr
->helper_pid
, SIGKILL
);
122 wScreenSaveState(scr
);
130 static void restoreWindows(WMBag
* bag
, WMBagIterator iter
)
137 core
= WMBagFirst(bag
, &iter
);
139 core
= WMBagNext(bag
, &iter
);
145 restoreWindows(bag
, iter
);
147 /* go to the end of the list */
148 while (core
->stacking
->under
)
149 core
= core
->stacking
->under
;
152 next
= core
->stacking
->above
;
154 if (core
->descriptor
.parent_type
== WCLASS_WINDOW
) {
157 wwin
= core
->descriptor
.parent
;
158 window
= wwin
->client_win
;
159 wUnmanageWindow(wwin
, !wwin
->flags
.internal_window
, False
);
160 XMapWindow(dpy
, window
);
167 *----------------------------------------------------------------------
169 * Puts the desktop in a usable state when exiting.
172 * All frame windows are removed and windows are reparented
173 * back to root. Windows that are outside the screen are
174 * brought to a viable place.
176 *----------------------------------------------------------------------
178 void RestoreDesktop(WScreen
* scr
)
180 if (scr
->helper_pid
> 0) {
181 kill(scr
->helper_pid
, SIGTERM
);
186 wDestroyInspectorPanels();
188 /* reparent windows back to the root window, keeping the stacking order */
189 restoreWindows(scr
->stacking_list
, NULL
);
192 XSetInputFocus(dpy
, PointerRoot
, RevertToParent
, CurrentTime
);
193 wColormapInstallForWindow(scr
, NULL
);
194 PropCleanUp(scr
->root_win
);
200 *----------------------------------------------------------------------
202 * Kills all windows in a screen. Send DeleteWindow to all windows
203 * that support it and KillClient on all windows that don't.
206 * All managed windows are closed.
208 * TODO: change to XQueryTree()
209 *----------------------------------------------------------------------
211 static void wipeDesktop(WScreen
* scr
)
215 wwin
= scr
->focused_window
;
217 if (wwin
->protocols
.DELETE_WINDOW
)
218 wClientSendProtocol(wwin
, _XA_WM_DELETE_WINDOW
, LastTimestamp
);