Files
wmaker/src/shutdown.c
T

209 lines
4.8 KiB
C
Raw Normal View History

1998-09-29 22:36:29 +00:00
/*
1998-10-21 14:43:47 +00:00
* Window Maker window manager
2004-10-12 21:28:27 +00:00
*
2003-01-16 23:30:45 +00:00
* Copyright (c) 1997-2003 Alfredo K. Kojima
2004-10-12 21:28:27 +00:00
*
1998-09-29 22:36:29 +00:00
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
2004-10-12 21:28:27 +00:00
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307,
1998-09-29 22:36:29 +00:00
* USA.
*/
#include "wconfig.h"
#include <stdlib.h>
1999-01-06 15:22:33 +00:00
#include <signal.h>
#include <unistd.h>
1998-09-29 22:36:29 +00:00
#include <X11/Xlib.h>
#include <X11/Xutil.h>
#include "WindowMaker.h"
#include "window.h"
#include "client.h"
#include "funcs.h"
#include "properties.h"
1999-04-16 20:05:26 +00:00
#include "session.h"
1998-09-29 22:36:29 +00:00
#include "winspector.h"
#include "wmspec.h"
1998-09-29 22:36:29 +00:00
extern Atom _XA_WM_DELETE_WINDOW;
extern Time LastTimestamp;
1998-11-23 11:32:19 +00:00
extern int wScreenCount;
1998-09-29 22:36:29 +00:00
2009-08-20 00:59:40 +02:00
static void wipeDesktop(WScreen * scr);
1999-01-06 15:22:33 +00:00
/*
*----------------------------------------------------------------------
* Shutdown-
* Exits the window manager cleanly. If mode is WSLogoutMode,
* the whole X session will be closed, by killing all clients if
* no session manager is running or by asking a shutdown to
* it if its present.
2004-10-12 21:28:27 +00:00
*
1999-01-06 15:22:33 +00:00
*----------------------------------------------------------------------
*/
2009-08-20 00:59:40 +02:00
void Shutdown(WShutdownMode mode)
1999-01-06 15:22:33 +00:00
{
2009-08-20 00:59:40 +02:00
int i;
2010-03-18 19:18:18 +01:00
#ifdef HAVE_INOTIFY
2009-08-20 00:59:40 +02:00
extern int inotifyFD;
2010-03-18 19:18:18 +01:00
#endif
1999-01-06 15:22:33 +00:00
2009-08-20 00:59:40 +02:00
switch (mode) {
case WSLogoutMode:
case WSKillMode:
case WSExitMode:
/* if there is no session manager, send SAVE_YOURSELF to
* the clients */
2010-03-18 19:18:18 +01:00
#ifdef HAVE_INOTIFY
2009-08-20 00:59:40 +02:00
close(inotifyFD);
2010-03-18 19:18:18 +01:00
#endif
2009-08-20 00:59:40 +02:00
for (i = 0; i < wScreenCount; i++) {
WScreen *scr;
1999-01-25 19:06:50 +00:00
2009-08-20 00:59:40 +02:00
scr = wScreenWithNumber(i);
if (scr) {
if (scr->helper_pid)
kill(scr->helper_pid, SIGKILL);
1999-01-25 19:06:50 +00:00
2009-08-20 00:59:40 +02:00
/* if the session is not being managed, save restart info */
wSessionSaveClients(scr);
wScreenSaveState(scr);
if (mode == WSKillMode)
wipeDesktop(scr);
else
RestoreDesktop(scr);
}
}
ExecExitScript();
Exit(0);
break;
case WSRestartPreparationMode:
for (i = 0; i < wScreenCount; i++) {
WScreen *scr;
2010-03-18 19:18:18 +01:00
#ifdef HAVE_INOTIFY
2009-08-20 00:59:40 +02:00
close(inotifyFD);
2010-03-18 19:18:18 +01:00
#endif
2009-08-20 00:59:40 +02:00
scr = wScreenWithNumber(i);
if (scr) {
if (scr->helper_pid)
kill(scr->helper_pid, SIGKILL);
wScreenSaveState(scr);
RestoreDesktop(scr);
}
}
break;
}
1999-01-06 15:22:33 +00:00
}
2009-08-20 00:59:40 +02:00
static void restoreWindows(WMBag * bag, WMBagIterator iter)
2000-04-08 23:53:22 +00:00
{
2009-08-20 00:59:40 +02:00
WCoreWindow *next;
WCoreWindow *core;
WWindow *wwin;
if (iter == NULL) {
core = WMBagFirst(bag, &iter);
} else {
core = WMBagNext(bag, &iter);
}
if (core == NULL)
return;
restoreWindows(bag, iter);
/* go to the end of the list */
while (core->stacking->under)
core = core->stacking->under;
while (core) {
next = core->stacking->above;
if (core->descriptor.parent_type == WCLASS_WINDOW) {
Window window;
wwin = core->descriptor.parent;
window = wwin->client_win;
wUnmanageWindow(wwin, !wwin->flags.internal_window, False);
XMapWindow(dpy, window);
}
core = next;
}
2000-04-08 23:53:22 +00:00
}
2000-09-24 02:31:58 +00:00
1998-09-29 22:36:29 +00:00
/*
*----------------------------------------------------------------------
* RestoreDesktop--
* Puts the desktop in a usable state when exiting.
1998-11-23 11:32:19 +00:00
*
1998-09-29 22:36:29 +00:00
* Side effects:
* All frame windows are removed and windows are reparented
2004-10-12 21:28:27 +00:00
* back to root. Windows that are outside the screen are
* brought to a viable place.
*
*----------------------------------------------------------------------
1998-09-29 22:36:29 +00:00
*/
2009-08-20 00:59:40 +02:00
void RestoreDesktop(WScreen * scr)
1998-09-29 22:36:29 +00:00
{
2009-08-20 00:59:40 +02:00
if (scr->helper_pid > 0) {
kill(scr->helper_pid, SIGTERM);
scr->helper_pid = 0;
}
XGrabServer(dpy);
wDestroyInspectorPanels();
/* reparent windows back to the root window, keeping the stacking order */
restoreWindows(scr->stacking_list, NULL);
XUngrabServer(dpy);
XSetInputFocus(dpy, PointerRoot, RevertToParent, CurrentTime);
wColormapInstallForWindow(scr, NULL);
PropCleanUp(scr->root_win);
wNETWMCleanup(scr);
XSync(dpy, 0);
1998-09-29 22:36:29 +00:00
}
/*
*----------------------------------------------------------------------
1999-01-06 15:22:33 +00:00
* wipeDesktop--
1998-09-29 22:36:29 +00:00
* Kills all windows in a screen. Send DeleteWindow to all windows
* that support it and KillClient on all windows that don't.
2004-10-12 21:28:27 +00:00
*
1998-09-29 22:36:29 +00:00
* Side effects:
* All managed windows are closed.
2004-10-12 21:28:27 +00:00
*
1998-09-29 22:36:29 +00:00
* TODO: change to XQueryTree()
2004-10-12 21:28:27 +00:00
*----------------------------------------------------------------------
1998-09-29 22:36:29 +00:00
*/
2009-08-20 00:59:40 +02:00
static void wipeDesktop(WScreen * scr)
1998-09-29 22:36:29 +00:00
{
2009-08-20 00:59:40 +02:00
WWindow *wwin;
wwin = scr->focused_window;
while (wwin) {
if (wwin->protocols.DELETE_WINDOW)
wClientSendProtocol(wwin, _XA_WM_DELETE_WINDOW, LastTimestamp);
else
wClientKill(wwin);
wwin = wwin->prev;
}
XSync(dpy, False);
1998-09-29 22:36:29 +00:00
}