Remove XSMP_ENABLED constructs
[wmaker-crm.git] / src / shutdown.c
blobf6f6c278d1e97077c30d2ac4d6c1b7030ed338f1
1 /*
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,
19 * USA.
22 #include "wconfig.h"
24 #include <stdlib.h>
25 #include <signal.h>
26 #include <unistd.h>
28 #include <X11/Xlib.h>
29 #include <X11/Xutil.h>
31 #include "WindowMaker.h"
32 #include "window.h"
33 #include "client.h"
34 #include "funcs.h"
35 #include "properties.h"
36 #include "session.h"
37 #include "winspector.h"
38 #include "wmspec.h"
40 extern Atom _XA_WM_DELETE_WINDOW;
41 extern Time LastTimestamp;
42 extern int wScreenCount;
44 static void wipeDesktop(WScreen * scr);
47 *----------------------------------------------------------------------
48 * Shutdown-
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
52 * it if its present.
54 *----------------------------------------------------------------------
56 void Shutdown(WShutdownMode mode)
58 int i;
59 extern int inotifyFD;
61 switch (mode) {
62 case WSLogoutMode:
63 case WSKillMode:
64 case WSExitMode:
65 /* if there is no session manager, send SAVE_YOURSELF to
66 * the clients */
67 close(inotifyFD);
68 for (i = 0; i < wScreenCount; i++) {
69 WScreen *scr;
71 scr = wScreenWithNumber(i);
72 if (scr) {
73 if (scr->helper_pid)
74 kill(scr->helper_pid, SIGKILL);
76 /* if the session is not being managed, save restart info */
77 wSessionSaveClients(scr);
79 wScreenSaveState(scr);
81 if (mode == WSKillMode)
82 wipeDesktop(scr);
83 else
84 RestoreDesktop(scr);
87 ExecExitScript();
88 Exit(0);
89 break;
91 case WSRestartPreparationMode:
92 for (i = 0; i < wScreenCount; i++) {
93 WScreen *scr;
95 close(inotifyFD);
96 scr = wScreenWithNumber(i);
97 if (scr) {
98 if (scr->helper_pid)
99 kill(scr->helper_pid, SIGKILL);
100 wScreenSaveState(scr);
101 RestoreDesktop(scr);
104 break;
108 static void restoreWindows(WMBag * bag, WMBagIterator iter)
110 WCoreWindow *next;
111 WCoreWindow *core;
112 WWindow *wwin;
114 if (iter == NULL) {
115 core = WMBagFirst(bag, &iter);
116 } else {
117 core = WMBagNext(bag, &iter);
120 if (core == NULL)
121 return;
123 restoreWindows(bag, iter);
125 /* go to the end of the list */
126 while (core->stacking->under)
127 core = core->stacking->under;
129 while (core) {
130 next = core->stacking->above;
132 if (core->descriptor.parent_type == WCLASS_WINDOW) {
133 Window window;
135 wwin = core->descriptor.parent;
136 window = wwin->client_win;
137 wUnmanageWindow(wwin, !wwin->flags.internal_window, False);
138 XMapWindow(dpy, window);
140 core = next;
145 *----------------------------------------------------------------------
146 * RestoreDesktop--
147 * Puts the desktop in a usable state when exiting.
149 * Side effects:
150 * All frame windows are removed and windows are reparented
151 * back to root. Windows that are outside the screen are
152 * brought to a viable place.
154 *----------------------------------------------------------------------
156 void RestoreDesktop(WScreen * scr)
158 if (scr->helper_pid > 0) {
159 kill(scr->helper_pid, SIGTERM);
160 scr->helper_pid = 0;
163 XGrabServer(dpy);
164 wDestroyInspectorPanels();
166 /* reparent windows back to the root window, keeping the stacking order */
167 restoreWindows(scr->stacking_list, NULL);
169 XUngrabServer(dpy);
170 XSetInputFocus(dpy, PointerRoot, RevertToParent, CurrentTime);
171 wColormapInstallForWindow(scr, NULL);
172 PropCleanUp(scr->root_win);
173 wNETWMCleanup(scr);
174 XSync(dpy, 0);
178 *----------------------------------------------------------------------
179 * wipeDesktop--
180 * Kills all windows in a screen. Send DeleteWindow to all windows
181 * that support it and KillClient on all windows that don't.
183 * Side effects:
184 * All managed windows are closed.
186 * TODO: change to XQueryTree()
187 *----------------------------------------------------------------------
189 static void wipeDesktop(WScreen * scr)
191 WWindow *wwin;
193 wwin = scr->focused_window;
194 while (wwin) {
195 if (wwin->protocols.DELETE_WINDOW)
196 wClientSendProtocol(wwin, _XA_WM_DELETE_WINDOW, LastTimestamp);
197 else
198 wClientKill(wwin);
199 wwin = wwin->prev;
201 XSync(dpy, False);