This update includes the 0.20.3pre3 code
[wmaker-crm.git] / src / shutdown.c
blob760943a91dc9d1a42bc22bdb1cea25b4355d880e
1 /*
2 * Window Maker window manager
3 *
4 * Copyright (c) 1997, 1998 Alfredo K. Kojima
5 *
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>
26 #include <X11/Xlib.h>
27 #include <X11/Xutil.h>
28 #include <X11/Intrinsic.h>
30 #include "WindowMaker.h"
31 #include "window.h"
32 #include "client.h"
33 #include "funcs.h"
34 #include "properties.h"
35 #include "winspector.h"
38 extern Atom _XA_WM_DELETE_WINDOW;
39 extern Time LastTimestamp;
40 extern int wScreenCount;
43 *----------------------------------------------------------------------
44 * RestoreDesktop--
45 * Puts the desktop in a usable state when exiting.
47 * Side effects:
48 * All frame windows are removed and windows are reparented
49 * back to root. Windows that are outside the screen are
50 * brought to a viable place.
52 *----------------------------------------------------------------------
54 void
55 RestoreDesktop(WScreen *scr)
57 int i;
59 if (!scr) {
60 int j;
61 for (j=0; j<wScreenCount; j++) {
62 WScreen *scr;
63 scr = wScreenWithNumber(j);
64 if (scr) {
65 RestoreDesktop(scr);
68 return;
71 XGrabServer(dpy);
72 wDestroyInspectorPanels();
74 /* reparent windows back to the root window, keeping the stacking order */
75 for (i=0; i<MAX_WINDOW_LEVELS; i++) {
76 WCoreWindow *core, *next;
77 WWindow *wwin;
79 if (!scr->stacking_list[i])
80 continue;
82 core = scr->stacking_list[i];
83 /* go to the end of the list */
84 while (core->stacking->under)
85 core = core->stacking->under;
87 while (core) {
88 next = core->stacking->above;
90 if (core->descriptor.parent_type==WCLASS_WINDOW) {
91 wwin = core->descriptor.parent;
92 wwin->flags.mapped=1;
93 wUnmanageWindow(wwin, !wwin->flags.internal_window);
95 core = next;
99 XUngrabServer(dpy);
100 XSetInputFocus(dpy, PointerRoot, RevertToParent, CurrentTime);
101 wColormapInstallForWindow(scr, NULL);
102 PropCleanUp(scr->root_win);
103 XSync(dpy, 0);
108 *----------------------------------------------------------------------
109 * WipeDesktop--
110 * Kills all windows in a screen. Send DeleteWindow to all windows
111 * that support it and KillClient on all windows that don't.
113 * Side effects:
114 * All managed windows are closed.
116 * TODO: change to XQueryTree()
117 *----------------------------------------------------------------------
119 void
120 WipeDesktop(WScreen *scr)
122 WWindow *wwin;
124 if (!scr) {
125 int j;
126 for (j=0; j<wScreenCount; j++) {
127 WScreen *scr;
128 scr = wScreenWithNumber(j);
129 if (scr) {
130 WipeDesktop(scr);
133 return;
136 wwin = scr->focused_window;
137 while (wwin) {
138 if (wwin->protocols.DELETE_WINDOW)
139 wClientSendProtocol(wwin, _XA_WM_DELETE_WINDOW, LastTimestamp);
140 else
141 wClientKill(wwin);
142 wwin = wwin->prev;
144 XSync(dpy, False);