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"
37 #include "winspector.h"
42 # include "openlook.h"
45 extern Atom _XA_WM_DELETE_WINDOW
;
46 extern Time LastTimestamp
;
47 extern int wScreenCount
;
50 static void wipeDesktop(WScreen
*scr
);
54 *----------------------------------------------------------------------
56 * Exits the window manager cleanly. If mode is WSLogoutMode,
57 * the whole X session will be closed, by killing all clients if
58 * no session manager is running or by asking a shutdown to
61 *----------------------------------------------------------------------
64 Shutdown(WShutdownMode mode
)
71 wSessionRequestShutdown();
78 /* if there is no session manager, send SAVE_YOURSELF to
82 if (!wSessionIsManaged())
84 for (i
= 0; i
< wScreenCount
; i
++) {
87 scr
= wScreenWithNumber(i
);
89 wSessionSendSaveYourself(scr
);
93 for (i
= 0; i
< wScreenCount
; i
++) {
96 scr
= wScreenWithNumber(i
);
99 kill(scr
->helper_pid
, SIGKILL
);
101 /* if the session is not being managed, save restart info */
103 if (!wSessionIsManaged())
105 wSessionSaveClients(scr
);
108 wKWMShutdown(scr
, True
);
110 wScreenSaveState(scr
);
112 if (mode
== WSKillMode
)
122 case WSRestartPreparationMode
:
123 for (i
=0; i
<wScreenCount
; i
++) {
126 scr
= wScreenWithNumber(i
);
129 kill(scr
->helper_pid
, SIGKILL
);
131 wKWMShutdown(scr
, False
);
136 wScreenSaveState(scr
);
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 *----------------------------------------------------------------------
161 RestoreDesktop(WScreen
*scr
)
165 if (scr
->helper_pid
> 0) {
166 kill(scr
->helper_pid
, SIGTERM
);
171 wDestroyInspectorPanels();
173 /* reparent windows back to the root window, keeping the stacking order */
174 for (i
=0; i
<MAX_WINDOW_LEVELS
; i
++) {
175 WCoreWindow
*core
, *next
;
178 if (!scr
->stacking_list
[i
])
181 core
= scr
->stacking_list
[i
];
182 /* go to the end of the list */
183 while (core
->stacking
->under
)
184 core
= core
->stacking
->under
;
187 next
= core
->stacking
->above
;
189 if (core
->descriptor
.parent_type
==WCLASS_WINDOW
) {
192 wwin
= core
->descriptor
.parent
;
193 window
= wwin
->client_win
;
194 wUnmanageWindow(wwin
, !wwin
->flags
.internal_window
, False
);
195 XMapWindow(dpy
, window
);
202 XSetInputFocus(dpy
, PointerRoot
, RevertToParent
, CurrentTime
);
203 wColormapInstallForWindow(scr
, NULL
);
204 PropCleanUp(scr
->root_win
);
210 *----------------------------------------------------------------------
212 * Kills all windows in a screen. Send DeleteWindow to all windows
213 * that support it and KillClient on all windows that don't.
216 * All managed windows are closed.
218 * TODO: change to XQueryTree()
219 *----------------------------------------------------------------------
222 wipeDesktop(WScreen
*scr
)
226 wwin
= scr
->focused_window
;
228 if (wwin
->protocols
.DELETE_WINDOW
)
229 wClientSendProtocol(wwin
, _XA_WM_DELETE_WINDOW
, LastTimestamp
);