windowmaker-wl/src/shutdown.c

129 lines
3.1 KiB
C

/*
* Window Maker window manager
*
* Copyright (c) 1997-2003 Alfredo K. Kojima
*
* 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 Foundation, Inc.,
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
*/
#include "wconfig.h"
#include <stdlib.h>
#include <signal.h>
#include <unistd.h>
#include "WindowMaker.h"
#include "window.h"
#include "client.h"
#include "main.h"
#include "properties.h"
#include "session.h"
#include "winspector.h"
#include "colormap.h"
#include "shutdown.h"
/*
*----------------------------------------------------------------------
* 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.
*
*----------------------------------------------------------------------
*/
void Shutdown(WShutdownMode mode)
{
int i;
switch (mode) {
case WSLogoutMode:
case WSKillMode:
case WSExitMode:
/* if there is no session manager, send SAVE_YOURSELF to
* the clients */
#ifdef HAVE_INOTIFY
if (w_global.inotify.fd_event_queue >= 0) {
close(w_global.inotify.fd_event_queue);
w_global.inotify.fd_event_queue = -1;
}
#endif
for (i = 0; i < w_global.screen_count; i++) {
WScreen *scr;
scr = wScreenWithNumber(i);
if (scr) {
if (scr->helper_pid)
kill(scr->helper_pid, SIGKILL);
wScreenSaveState(scr);
if (mode == WSKillMode)
wm_backend->wipe_desktop(scr);
else
wm_backend->restore_desktop(scr);
}
}
ExecExitScript();
Exit(0);
break;
case WSRestartPreparationMode:
for (i = 0; i < w_global.screen_count; i++) {
WScreen *scr;
#ifdef HAVE_INOTIFY
if (w_global.inotify.fd_event_queue >= 0) {
close(w_global.inotify.fd_event_queue);
w_global.inotify.fd_event_queue = -1;
}
#endif
scr = wScreenWithNumber(i);
if (scr) {
if (scr->helper_pid)
kill(scr->helper_pid, SIGKILL);
wScreenSaveState(scr);
RestoreDesktop(scr);
}
}
break;
}
}
/*
*----------------------------------------------------------------------
* RestoreDesktop--
* Puts the desktop in a usable state when exiting.
*
* Side effects:
* All frame windows are removed and windows are reparented
* back to root. Windows that are outside the screen are
* brought to a viable place.
*
*----------------------------------------------------------------------
*/
void RestoreDesktop(WScreen * scr)
{
wm_backend->restore_desktop(scr);
}
void wWipeDesktop(WScreen * scr)
{
wm_backend->wipe_desktop(scr);
}