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
)
67 /* if there is no session manager, send SAVE_YOURSELF to
72 for (i
= 0; i
< wScreenCount
; i
++) {
75 scr
= wScreenWithNumber(i
);
78 kill(scr
->helper_pid
, SIGKILL
);
80 /* if the session is not being managed, save restart info */
81 wSessionSaveClients(scr
);
83 wScreenSaveState(scr
);
85 if (mode
== WSKillMode
)
95 case WSRestartPreparationMode
:
96 for (i
= 0; i
< wScreenCount
; i
++) {
102 scr
= wScreenWithNumber(i
);
105 kill(scr
->helper_pid
, SIGKILL
);
106 wScreenSaveState(scr
);
114 static void restoreWindows(WMBag
* bag
, WMBagIterator iter
)
121 core
= WMBagFirst(bag
, &iter
);
123 core
= WMBagNext(bag
, &iter
);
129 restoreWindows(bag
, iter
);
131 /* go to the end of the list */
132 while (core
->stacking
->under
)
133 core
= core
->stacking
->under
;
136 next
= core
->stacking
->above
;
138 if (core
->descriptor
.parent_type
== WCLASS_WINDOW
) {
141 wwin
= core
->descriptor
.parent
;
142 window
= wwin
->client_win
;
143 wUnmanageWindow(wwin
, !wwin
->flags
.internal_window
, False
);
144 XMapWindow(dpy
, window
);
151 *----------------------------------------------------------------------
153 * Puts the desktop in a usable state when exiting.
156 * All frame windows are removed and windows are reparented
157 * back to root. Windows that are outside the screen are
158 * brought to a viable place.
160 *----------------------------------------------------------------------
162 void RestoreDesktop(WScreen
* scr
)
164 if (scr
->helper_pid
> 0) {
165 kill(scr
->helper_pid
, SIGTERM
);
170 wDestroyInspectorPanels();
172 /* reparent windows back to the root window, keeping the stacking order */
173 restoreWindows(scr
->stacking_list
, NULL
);
176 XSetInputFocus(dpy
, PointerRoot
, RevertToParent
, CurrentTime
);
177 wColormapInstallForWindow(scr
, NULL
);
178 PropCleanUp(scr
->root_win
);
184 *----------------------------------------------------------------------
186 * Kills all windows in a screen. Send DeleteWindow to all windows
187 * that support it and KillClient on all windows that don't.
190 * All managed windows are closed.
192 * TODO: change to XQueryTree()
193 *----------------------------------------------------------------------
195 static void wipeDesktop(WScreen
* scr
)
199 wwin
= scr
->focused_window
;
201 if (wwin
->protocols
.DELETE_WINDOW
)
202 wClientSendProtocol(wwin
, _XA_WM_DELETE_WINDOW
, LastTimestamp
);