2 * Window Maker window manager
4 * Copyright (c) 1997, 1998 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>
30 #include <X11/Intrinsic.h>
32 #include "WindowMaker.h"
36 #include "properties.h"
38 #include "winspector.h"
43 # include "openlook.h"
46 extern Atom _XA_WM_DELETE_WINDOW
;
47 extern Time LastTimestamp
;
48 extern int wScreenCount
;
51 static void wipeDesktop(WScreen
*scr
);
55 *----------------------------------------------------------------------
57 * Exits the window manager cleanly. If mode is WSLogoutMode,
58 * the whole X session will be closed, by killing all clients if
59 * no session manager is running or by asking a shutdown to
62 *----------------------------------------------------------------------
65 Shutdown(WShutdownMode mode
)
72 wSessionRequestShutdown();
79 /* if there is no session manager, send SAVE_YOURSELF to
83 if (!wSessionIsManaged())
85 for (i
= 0; i
< wScreenCount
; i
++) {
88 scr
= wScreenWithNumber(i
);
90 wSessionSendSaveYourself(scr
);
94 for (i
= 0; i
< wScreenCount
; i
++) {
97 scr
= wScreenWithNumber(i
);
100 kill(scr
->helper_pid
, SIGKILL
);
102 /* if the session is not being managed, save restart info */
104 if (!wSessionIsManaged())
106 wSessionSaveClients(scr
);
109 wKWMShutdown(scr
, True
);
111 wScreenSaveState(scr
);
113 if (mode
== WSKillMode
)
123 case WSRestartPreparationMode
:
124 for (i
=0; i
<wScreenCount
; i
++) {
127 scr
= wScreenWithNumber(i
);
130 kill(scr
->helper_pid
, SIGKILL
);
132 wKWMShutdown(scr
, False
);
137 wScreenSaveState(scr
);
150 *----------------------------------------------------------------------
152 * Puts the desktop in a usable state when exiting.
155 * All frame windows are removed and windows are reparented
156 * back to root. Windows that are outside the screen are
157 * brought to a viable place.
159 *----------------------------------------------------------------------
162 RestoreDesktop(WScreen
*scr
)
166 if (scr
->helper_pid
> 0) {
167 kill(scr
->helper_pid
, SIGTERM
);
172 wDestroyInspectorPanels();
174 /* reparent windows back to the root window, keeping the stacking order */
175 for (i
=0; i
<MAX_WINDOW_LEVELS
; i
++) {
176 WCoreWindow
*core
, *next
;
179 if (!scr
->stacking_list
[i
])
182 core
= scr
->stacking_list
[i
];
183 /* go to the end of the list */
184 while (core
->stacking
->under
)
185 core
= core
->stacking
->under
;
188 next
= core
->stacking
->above
;
190 if (core
->descriptor
.parent_type
==WCLASS_WINDOW
) {
193 wwin
= core
->descriptor
.parent
;
194 window
= wwin
->client_win
;
195 wUnmanageWindow(wwin
, !wwin
->flags
.internal_window
, False
);
196 XMapWindow(dpy
, window
);
203 XSetInputFocus(dpy
, PointerRoot
, RevertToParent
, CurrentTime
);
204 wColormapInstallForWindow(scr
, NULL
);
205 PropCleanUp(scr
->root_win
);
211 *----------------------------------------------------------------------
213 * Kills all windows in a screen. Send DeleteWindow to all windows
214 * that support it and KillClient on all windows that don't.
217 * All managed windows are closed.
219 * TODO: change to XQueryTree()
220 *----------------------------------------------------------------------
223 wipeDesktop(WScreen
*scr
)
227 wwin
= scr
->focused_window
;
229 if (wwin
->protocols
.DELETE_WINDOW
)
230 wClientSendProtocol(wwin
, _XA_WM_DELETE_WINDOW
, LastTimestamp
);