Remove unused functions
[wmaker-crm.git] / src / shutdown.c
blob0cf9ab708b3a86a10ea7e8947d6c97bafced28e3
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 along
17 * with this program; if not, write to the Free Software Foundation, Inc.,
18 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
21 #include "wconfig.h"
23 #include <stdlib.h>
24 #include <signal.h>
25 #include <unistd.h>
27 #include <X11/Xlib.h>
28 #include <X11/Xutil.h>
30 #include "WindowMaker.h"
31 #include "window.h"
32 #include "client.h"
33 #include "funcs.h"
34 #include "properties.h"
35 #include "session.h"
36 #include "winspector.h"
37 #include "wmspec.h"
39 extern Atom _XA_WM_DELETE_WINDOW;
40 extern Time LastTimestamp;
41 extern int wScreenCount;
43 static void wipeDesktop(WScreen * scr);
46 *----------------------------------------------------------------------
47 * Shutdown-
48 * Exits the window manager cleanly. If mode is WSLogoutMode,
49 * the whole X session will be closed, by killing all clients if
50 * no session manager is running or by asking a shutdown to
51 * it if its present.
53 *----------------------------------------------------------------------
55 void Shutdown(WShutdownMode mode)
57 int i;
58 #ifdef HAVE_INOTIFY
59 extern int inotifyFD;
60 #endif
62 switch (mode) {
63 case WSLogoutMode:
64 case WSKillMode:
65 case WSExitMode:
66 /* if there is no session manager, send SAVE_YOURSELF to
67 * the clients */
68 #ifdef HAVE_INOTIFY
69 close(inotifyFD);
70 #endif
71 for (i = 0; i < wScreenCount; i++) {
72 WScreen *scr;
74 scr = wScreenWithNumber(i);
75 if (scr) {
76 if (scr->helper_pid)
77 kill(scr->helper_pid, SIGKILL);
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 #ifdef HAVE_INOTIFY
96 close(inotifyFD);
97 #endif
98 scr = wScreenWithNumber(i);
99 if (scr) {
100 if (scr->helper_pid)
101 kill(scr->helper_pid, SIGKILL);
102 wScreenSaveState(scr);
103 RestoreDesktop(scr);
106 break;
110 static void restoreWindows(WMBag * bag, WMBagIterator iter)
112 WCoreWindow *next;
113 WCoreWindow *core;
114 WWindow *wwin;
116 if (iter == NULL) {
117 core = WMBagFirst(bag, &iter);
118 } else {
119 core = WMBagNext(bag, &iter);
122 if (core == NULL)
123 return;
125 restoreWindows(bag, iter);
127 /* go to the end of the list */
128 while (core->stacking->under)
129 core = core->stacking->under;
131 while (core) {
132 next = core->stacking->above;
134 if (core->descriptor.parent_type == WCLASS_WINDOW) {
135 Window window;
137 wwin = core->descriptor.parent;
138 window = wwin->client_win;
139 wUnmanageWindow(wwin, !wwin->flags.internal_window, False);
140 XMapWindow(dpy, window);
142 core = next;
147 *----------------------------------------------------------------------
148 * RestoreDesktop--
149 * Puts the desktop in a usable state when exiting.
151 * Side effects:
152 * All frame windows are removed and windows are reparented
153 * back to root. Windows that are outside the screen are
154 * brought to a viable place.
156 *----------------------------------------------------------------------
158 void RestoreDesktop(WScreen * scr)
160 if (scr->helper_pid > 0) {
161 kill(scr->helper_pid, SIGTERM);
162 scr->helper_pid = 0;
165 XGrabServer(dpy);
166 wDestroyInspectorPanels();
168 /* reparent windows back to the root window, keeping the stacking order */
169 restoreWindows(scr->stacking_list, NULL);
171 XUngrabServer(dpy);
172 XSetInputFocus(dpy, PointerRoot, RevertToParent, CurrentTime);
173 wColormapInstallForWindow(scr, NULL);
174 PropCleanUp(scr->root_win);
175 wNETWMCleanup(scr);
176 XSync(dpy, 0);
180 *----------------------------------------------------------------------
181 * wipeDesktop--
182 * Kills all windows in a screen. Send DeleteWindow to all windows
183 * that support it and KillClient on all windows that don't.
185 * Side effects:
186 * All managed windows are closed.
188 * TODO: change to XQueryTree()
189 *----------------------------------------------------------------------
191 static void wipeDesktop(WScreen * scr)
193 WWindow *wwin;
195 wwin = scr->focused_window;
196 while (wwin) {
197 if (wwin->protocols.DELETE_WINDOW)
198 wClientSendProtocol(wwin, _XA_WM_DELETE_WINDOW, LastTimestamp);
199 else
200 wClientKill(wwin);
201 wwin = wwin->prev;
203 XSync(dpy, False);