1999-10-04 15:06:00 -07:00
|
|
|
/*
|
2007-01-13 11:14:29 -08:00
|
|
|
* Copyright (C) 2000-2007 Carsten Haitzler, Geoff Harrison and various contributors
|
2009-12-03 11:29:30 -08:00
|
|
|
* Copyright (C) 2004-2014 Kim Woelders
|
2000-04-05 16:22:56 -07:00
|
|
|
*
|
1999-10-04 15:06:00 -07:00
|
|
|
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
|
|
* of this software and associated documentation files (the "Software"), to
|
|
|
|
* deal in the Software without restriction, including without limitation the
|
|
|
|
* rights to use, copy, modify, merge, publish, distribute, sublicense, and/or
|
|
|
|
* sell copies of the Software, and to permit persons to whom the Software is
|
|
|
|
* furnished to do so, subject to the following conditions:
|
2000-04-05 16:22:56 -07:00
|
|
|
*
|
1999-10-04 15:06:00 -07:00
|
|
|
* The above copyright notice and this permission notice shall be included in
|
|
|
|
* all copies of the Software, its documentation and marketing & publicity
|
|
|
|
* materials, and acknowledgment shall be given in the documentation, materials
|
|
|
|
* and software packages that this Software was used.
|
2000-04-05 16:22:56 -07:00
|
|
|
*
|
1999-10-04 15:06:00 -07:00
|
|
|
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
|
|
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
|
|
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
|
|
|
|
* THE AUTHORS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER
|
|
|
|
* IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
|
|
|
|
* CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
|
|
|
*/
|
1999-08-17 15:56:46 -07:00
|
|
|
#include "E.h"
|
2005-10-29 01:48:40 -07:00
|
|
|
#include "dialog.h"
|
2005-07-16 09:57:45 -07:00
|
|
|
#include "emodule.h"
|
2007-12-02 10:39:17 -08:00
|
|
|
#include "events.h"
|
2005-07-16 09:57:45 -07:00
|
|
|
#include "ewins.h"
|
2007-04-16 13:31:33 -07:00
|
|
|
#include "hints.h"
|
2006-04-19 12:13:46 -07:00
|
|
|
#include "session.h"
|
2007-01-16 17:10:44 -08:00
|
|
|
#include "settings.h"
|
2005-09-23 09:12:13 -07:00
|
|
|
#include "snaps.h"
|
2006-07-24 14:10:59 -07:00
|
|
|
#include "user.h"
|
2013-04-07 03:04:35 -07:00
|
|
|
#if 0 /* Unused */
|
2013-04-07 04:06:58 -07:00
|
|
|
#include "xprop.h"
|
2013-04-07 03:04:35 -07:00
|
|
|
#endif
|
2005-07-16 09:57:45 -07:00
|
|
|
#include "xwin.h"
|
1999-08-17 15:56:46 -07:00
|
|
|
|
2004-12-28 15:46:49 -08:00
|
|
|
#ifdef USE_EXT_INIT_WIN
|
2009-12-03 11:29:30 -08:00
|
|
|
static EX_Window new_init_win_ext = NoXID;
|
2004-12-28 15:46:49 -08:00
|
|
|
#endif
|
|
|
|
|
2005-01-02 01:42:35 -08:00
|
|
|
/* True if we are saving state for a doExit("restart") */
|
2013-12-28 03:29:26 -08:00
|
|
|
static char restarting = 0;
|
1999-08-17 15:56:46 -07:00
|
|
|
|
2007-07-18 04:18:50 -07:00
|
|
|
#if USE_SM
|
2003-08-18 15:23:22 -07:00
|
|
|
|
2011-01-05 10:05:45 -08:00
|
|
|
#include <fcntl.h>
|
1999-08-17 15:56:46 -07:00
|
|
|
#include <X11/SM/SMlib.h>
|
|
|
|
|
2003-08-18 15:23:22 -07:00
|
|
|
/*
|
|
|
|
* NB! If the discard property is revived, the dual use of buf must be fixed.
|
|
|
|
*/
|
|
|
|
#define USE_DISCARD_PROPERTY 0
|
|
|
|
|
1999-08-17 15:56:46 -07:00
|
|
|
static char *sm_client_id = NULL;
|
|
|
|
static SmcConn sm_conn = NULL;
|
|
|
|
|
2007-12-02 10:39:17 -08:00
|
|
|
static EventFdDesc *sm_efd = NULL;
|
|
|
|
|
1999-11-05 04:58:05 -08:00
|
|
|
static void
|
1999-08-17 15:56:46 -07:00
|
|
|
set_save_props(SmcConn smc_conn, int master_flag)
|
|
|
|
{
|
2005-04-07 09:38:57 -07:00
|
|
|
const char *s;
|
2012-02-26 12:15:52 -08:00
|
|
|
const char *user;
|
2005-04-07 09:38:57 -07:00
|
|
|
const char *program;
|
1999-08-17 15:56:46 -07:00
|
|
|
char priority = 10;
|
|
|
|
char style;
|
2005-04-07 09:38:57 -07:00
|
|
|
int i, n;
|
|
|
|
SmPropValue programVal;
|
|
|
|
SmPropValue userIDVal;
|
|
|
|
|
2003-08-18 15:23:22 -07:00
|
|
|
#if USE_DISCARD_PROPERTY
|
2005-04-07 09:38:57 -07:00
|
|
|
const char *sh = "sh";
|
|
|
|
const char *c = "-c";
|
|
|
|
const char *sm_file;
|
|
|
|
SmPropValue discardVal[3];
|
2003-08-18 15:23:22 -07:00
|
|
|
SmProp discardProp;
|
2009-01-18 07:35:35 -08:00
|
|
|
#endif
|
|
|
|
#ifdef USE_EXT_INIT_WIN
|
|
|
|
char bufx[32];
|
2003-08-18 15:23:22 -07:00
|
|
|
#endif
|
2005-04-07 09:38:57 -07:00
|
|
|
SmPropValue restartVal[32];
|
|
|
|
SmPropValue styleVal;
|
|
|
|
SmPropValue priorityVal;
|
1999-08-17 15:56:46 -07:00
|
|
|
SmProp programProp;
|
|
|
|
SmProp userIDProp;
|
|
|
|
SmProp restartProp;
|
|
|
|
SmProp cloneProp;
|
|
|
|
SmProp styleProp;
|
|
|
|
SmProp priorityProp;
|
|
|
|
SmProp *props[7];
|
2008-06-28 11:54:59 -07:00
|
|
|
char bufs[32], bufm[32];
|
1999-08-17 15:56:46 -07:00
|
|
|
|
2006-11-19 13:55:52 -08:00
|
|
|
if (EDebug(EDBUG_TYPE_SESSION))
|
2004-12-28 15:46:49 -08:00
|
|
|
Eprintf("set_save_props\n");
|
|
|
|
|
1999-08-17 15:56:46 -07:00
|
|
|
programProp.name = (char *)SmProgram;
|
2004-11-23 11:19:44 -08:00
|
|
|
programProp.type = (char *)SmARRAY8;
|
1999-08-17 15:56:46 -07:00
|
|
|
programProp.num_vals = 1;
|
|
|
|
programProp.vals = &programVal;
|
|
|
|
|
|
|
|
userIDProp.name = (char *)SmUserID;
|
2004-11-23 11:19:44 -08:00
|
|
|
userIDProp.type = (char *)SmARRAY8;
|
1999-08-17 15:56:46 -07:00
|
|
|
userIDProp.num_vals = 1;
|
|
|
|
userIDProp.vals = &userIDVal;
|
|
|
|
|
2003-08-18 15:23:22 -07:00
|
|
|
#if USE_DISCARD_PROPERTY
|
1999-08-17 15:56:46 -07:00
|
|
|
discardProp.name = (char *)SmDiscardCommand;
|
|
|
|
discardProp.type = (char *)SmLISTofARRAY8;
|
|
|
|
discardProp.num_vals = 3;
|
2005-10-30 11:40:49 -08:00
|
|
|
discardProp.vals = discardVal;
|
2003-08-18 15:23:22 -07:00
|
|
|
#endif
|
1999-08-17 15:56:46 -07:00
|
|
|
|
|
|
|
restartProp.name = (char *)SmRestartCommand;
|
|
|
|
restartProp.type = (char *)SmLISTofARRAY8;
|
2005-10-30 11:40:49 -08:00
|
|
|
restartProp.vals = restartVal;
|
1999-08-17 15:56:46 -07:00
|
|
|
|
|
|
|
cloneProp.name = (char *)SmCloneCommand;
|
|
|
|
cloneProp.type = (char *)SmLISTofARRAY8;
|
2005-10-30 11:40:49 -08:00
|
|
|
cloneProp.vals = restartVal;
|
1999-08-17 15:56:46 -07:00
|
|
|
|
|
|
|
styleProp.name = (char *)SmRestartStyleHint;
|
|
|
|
styleProp.type = (char *)SmCARD8;
|
|
|
|
styleProp.num_vals = 1;
|
2005-10-30 11:40:49 -08:00
|
|
|
styleProp.vals = &styleVal;
|
1999-08-17 15:56:46 -07:00
|
|
|
|
2005-04-07 09:38:57 -07:00
|
|
|
priorityProp.name = (char *)"_GSM_Priority";
|
1999-08-17 15:56:46 -07:00
|
|
|
priorityProp.type = (char *)SmCARD8;
|
|
|
|
priorityProp.num_vals = 1;
|
2005-10-30 11:40:49 -08:00
|
|
|
priorityProp.vals = &priorityVal;
|
1999-08-17 15:56:46 -07:00
|
|
|
|
|
|
|
if (master_flag)
|
|
|
|
/* Master WM restarts immediately for a doExit("restart") */
|
|
|
|
style = restarting ? SmRestartImmediately : SmRestartIfRunning;
|
|
|
|
else
|
|
|
|
/* Slave WMs never restart */
|
|
|
|
style = SmRestartNever;
|
|
|
|
|
2012-02-26 12:15:52 -08:00
|
|
|
user = username();
|
1999-08-17 15:56:46 -07:00
|
|
|
/* The SM specs state that the SmProgram should be the argument passed
|
|
|
|
* to execve. Passing argv[0] is close enough. */
|
2004-12-28 15:46:49 -08:00
|
|
|
program = Mode.wm.exec_name;
|
1999-08-17 15:56:46 -07:00
|
|
|
|
2005-10-30 11:40:49 -08:00
|
|
|
userIDVal.length = (user) ? strlen(user) : 0;
|
2012-02-26 12:15:52 -08:00
|
|
|
userIDVal.value = (char *)user;
|
1999-08-17 15:56:46 -07:00
|
|
|
programVal.length = strlen(program);
|
2004-12-28 15:46:49 -08:00
|
|
|
programVal.value = (char *)program;
|
1999-08-17 15:56:46 -07:00
|
|
|
styleVal.length = 1;
|
|
|
|
styleVal.value = &style;
|
|
|
|
priorityVal.length = 1;
|
|
|
|
priorityVal.value = &priority;
|
|
|
|
|
2003-08-18 15:23:22 -07:00
|
|
|
#if USE_DISCARD_PROPERTY
|
1999-08-17 15:56:46 -07:00
|
|
|
/* Tell session manager how to clean up our old data */
|
2005-04-07 09:38:57 -07:00
|
|
|
sm_file = EGetSavePrefix();
|
2003-12-09 12:25:17 -08:00
|
|
|
Esnprintf(buf, sizeof(buf), "rm %s*.clients.*", sm_file);
|
1999-08-17 15:56:46 -07:00
|
|
|
|
|
|
|
discardVal[0].length = strlen(sh);
|
|
|
|
discardVal[0].value = sh;
|
|
|
|
discardVal[1].length = strlen(c);
|
|
|
|
discardVal[1].value = c;
|
|
|
|
discardVal[2].length = strlen(buf);
|
2003-08-18 15:23:22 -07:00
|
|
|
discardVal[2].value = buf; /* ??? Also used in restartVal ??? */
|
|
|
|
#endif
|
1999-08-17 15:56:46 -07:00
|
|
|
|
2003-08-18 15:23:22 -07:00
|
|
|
n = 0;
|
2004-12-28 15:46:49 -08:00
|
|
|
restartVal[n++].value = (char *)program;
|
2004-04-07 07:32:36 -07:00
|
|
|
if (Mode.wm.single)
|
2000-07-26 11:00:47 -07:00
|
|
|
{
|
2005-04-07 09:38:57 -07:00
|
|
|
Esnprintf(bufs, sizeof(bufs), "%i", Mode.wm.master_screen);
|
|
|
|
restartVal[n++].value = (char *)"-s";
|
|
|
|
restartVal[n++].value = (char *)bufs;
|
|
|
|
}
|
|
|
|
else if (restarting && !Mode.wm.master)
|
|
|
|
{
|
|
|
|
Esnprintf(bufm, sizeof(bufm), "%i", Mode.wm.master_screen);
|
|
|
|
restartVal[n++].value = (char *)"-m";
|
|
|
|
restartVal[n++].value = bufm;
|
2000-07-26 11:00:47 -07:00
|
|
|
}
|
2004-12-28 15:46:49 -08:00
|
|
|
#ifdef USE_EXT_INIT_WIN
|
1999-08-17 15:56:46 -07:00
|
|
|
if (restarting)
|
2000-07-26 11:00:47 -07:00
|
|
|
{
|
2009-12-03 11:29:30 -08:00
|
|
|
Esnprintf(bufx, sizeof(bufx), "%#x", new_init_win_ext);
|
2005-04-07 09:38:57 -07:00
|
|
|
restartVal[n++].value = (char *)"-X";
|
|
|
|
restartVal[n++].value = bufx;
|
2000-07-26 11:00:47 -07:00
|
|
|
}
|
2004-12-28 15:46:49 -08:00
|
|
|
#endif
|
|
|
|
#if 0
|
2004-03-20 17:39:40 -08:00
|
|
|
restartVal[n++].value = (char *)smfile;
|
2004-12-28 15:46:49 -08:00
|
|
|
restartVal[n++].value = (char *)sm_file;
|
|
|
|
#endif
|
2005-04-07 09:38:57 -07:00
|
|
|
s = Mode.conf.name;
|
|
|
|
if (s)
|
|
|
|
{
|
|
|
|
restartVal[n++].value = (char *)"-p";
|
|
|
|
restartVal[n++].value = (char *)s;
|
|
|
|
}
|
|
|
|
s = Mode.conf.dir;
|
|
|
|
if (s)
|
|
|
|
{
|
|
|
|
restartVal[n++].value = (char *)"-P";
|
|
|
|
restartVal[n++].value = (char *)s;
|
|
|
|
}
|
|
|
|
s = Mode.conf.cache_dir;
|
|
|
|
if (s)
|
|
|
|
{
|
|
|
|
restartVal[n++].value = (char *)"-Q";
|
|
|
|
restartVal[n++].value = (char *)s;
|
|
|
|
}
|
|
|
|
s = sm_client_id;
|
|
|
|
restartVal[n++].value = (char *)"-S";
|
|
|
|
restartVal[n++].value = (char *)s;
|
|
|
|
|
|
|
|
for (i = 0; i < n; i++)
|
2007-01-16 17:10:44 -08:00
|
|
|
restartVal[i].length = strlen((const char *)restartVal[i].value);
|
1999-08-17 15:56:46 -07:00
|
|
|
|
|
|
|
restartProp.num_vals = n;
|
|
|
|
|
2005-04-07 09:38:57 -07:00
|
|
|
/* SM specs require SmCloneCommand excludes "--sm-client-id" option */
|
1999-08-17 15:56:46 -07:00
|
|
|
cloneProp.num_vals = restartProp.num_vals - 2;
|
|
|
|
|
2006-11-19 13:55:52 -08:00
|
|
|
if (EDebug(EDBUG_TYPE_SESSION))
|
2005-04-07 09:38:57 -07:00
|
|
|
for (i = 0; i < restartProp.num_vals; i++)
|
|
|
|
Eprintf("restartVal[i]: %2d: %s\n", restartVal[i].length,
|
|
|
|
(char *)restartVal[i].value);
|
2004-12-28 15:46:49 -08:00
|
|
|
|
2003-08-18 15:23:22 -07:00
|
|
|
n = 0;
|
|
|
|
props[n++] = &programProp;
|
|
|
|
props[n++] = &userIDProp;
|
|
|
|
#if USE_DISCARD_PROPERTY
|
|
|
|
props[n++] = &discardProp;
|
|
|
|
#endif
|
|
|
|
props[n++] = &restartProp;
|
|
|
|
props[n++] = &cloneProp;
|
|
|
|
props[n++] = &styleProp;
|
|
|
|
props[n++] = &priorityProp;
|
|
|
|
|
|
|
|
SmcSetProperties(smc_conn, n, props);
|
1999-08-17 15:56:46 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
/* This function is usually exclusively devoted to saving data.
|
|
|
|
* However, E sometimes wants to save state and exit immediately afterwards
|
|
|
|
* so that the SM will restart it in a different theme. Therefore, we include
|
|
|
|
* a suicide clause at the end.
|
|
|
|
*/
|
1999-11-05 04:58:05 -08:00
|
|
|
static void
|
2005-01-28 23:11:59 -08:00
|
|
|
callback_save_yourself2(SmcConn smc_conn, SmPointer client_data __UNUSED__)
|
1999-08-17 15:56:46 -07:00
|
|
|
{
|
2006-11-19 13:55:52 -08:00
|
|
|
if (EDebug(EDBUG_TYPE_SESSION))
|
2004-12-28 15:46:49 -08:00
|
|
|
Eprintf("callback_save_yourself2\n");
|
|
|
|
|
2004-04-07 07:32:36 -07:00
|
|
|
set_save_props(smc_conn, Mode.wm.master);
|
1999-08-17 15:56:46 -07:00
|
|
|
SmcSaveYourselfDone(smc_conn, True);
|
|
|
|
if (restarting)
|
|
|
|
EExit(0);
|
|
|
|
}
|
|
|
|
|
1999-11-05 04:58:05 -08:00
|
|
|
static void
|
2005-01-28 23:11:59 -08:00
|
|
|
callback_save_yourself(SmcConn smc_conn, SmPointer client_data __UNUSED__,
|
|
|
|
int save_style __UNUSED__, Bool shutdown __UNUSED__,
|
|
|
|
int interact_style __UNUSED__, Bool fast __UNUSED__)
|
1999-08-17 15:56:46 -07:00
|
|
|
{
|
2006-11-19 13:55:52 -08:00
|
|
|
if (EDebug(EDBUG_TYPE_SESSION))
|
2004-12-28 15:46:49 -08:00
|
|
|
Eprintf("callback_save_yourself\n");
|
|
|
|
|
1999-08-17 15:56:46 -07:00
|
|
|
SmcRequestSaveYourselfPhase2(smc_conn, callback_save_yourself2, NULL);
|
|
|
|
}
|
|
|
|
|
1999-11-05 04:58:05 -08:00
|
|
|
static void
|
2005-01-28 23:11:59 -08:00
|
|
|
callback_die(SmcConn smc_conn __UNUSED__, SmPointer client_data __UNUSED__)
|
1999-08-17 15:56:46 -07:00
|
|
|
{
|
2006-11-19 13:55:52 -08:00
|
|
|
if (EDebug(EDBUG_TYPE_SESSION))
|
2004-12-28 15:46:49 -08:00
|
|
|
Eprintf("callback_die\n");
|
|
|
|
|
2006-06-03 16:23:43 -07:00
|
|
|
SessionExit(EEXIT_EXIT, NULL);
|
1999-08-17 15:56:46 -07:00
|
|
|
}
|
|
|
|
|
1999-11-05 04:58:05 -08:00
|
|
|
static void
|
2005-01-28 23:11:59 -08:00
|
|
|
callback_save_complete(SmcConn smc_conn __UNUSED__,
|
|
|
|
SmPointer client_data __UNUSED__)
|
1999-08-17 15:56:46 -07:00
|
|
|
{
|
2006-11-19 13:55:52 -08:00
|
|
|
if (EDebug(EDBUG_TYPE_SESSION))
|
2004-12-28 15:46:49 -08:00
|
|
|
Eprintf("callback_save_complete\n");
|
1999-08-17 15:56:46 -07:00
|
|
|
}
|
|
|
|
|
1999-11-05 04:58:05 -08:00
|
|
|
static void
|
2005-01-28 23:11:59 -08:00
|
|
|
callback_shutdown_cancelled(SmcConn smc_conn, SmPointer client_data __UNUSED__)
|
1999-08-17 15:56:46 -07:00
|
|
|
{
|
2006-11-19 13:55:52 -08:00
|
|
|
if (EDebug(EDBUG_TYPE_SESSION))
|
2004-12-28 15:46:49 -08:00
|
|
|
Eprintf("callback_shutdown_cancelled\n");
|
|
|
|
|
1999-08-17 15:56:46 -07:00
|
|
|
SmcSaveYourselfDone(smc_conn, False);
|
|
|
|
}
|
|
|
|
|
2007-05-20 05:46:24 -07:00
|
|
|
#if 0 /* Unused */
|
2013-04-07 03:04:35 -07:00
|
|
|
static EX_Atom atom_sm_client_id;
|
2007-05-20 05:46:24 -07:00
|
|
|
#endif
|
1999-08-17 15:56:46 -07:00
|
|
|
|
|
|
|
static IceConn ice_conn;
|
|
|
|
|
1999-11-05 04:58:05 -08:00
|
|
|
static void
|
2005-10-30 11:40:49 -08:00
|
|
|
ice_io_error_handler(IceConn connection __UNUSED__)
|
1999-08-17 15:56:46 -07:00
|
|
|
{
|
2006-11-19 13:55:52 -08:00
|
|
|
if (EDebug(EDBUG_TYPE_SESSION))
|
2004-12-28 15:46:49 -08:00
|
|
|
Eprintf("ice_io_error_handler\n");
|
|
|
|
|
1999-08-17 15:56:46 -07:00
|
|
|
/* The less we do here the better - the default handler does an
|
|
|
|
* exit(1) instead of closing the losing connection. */
|
|
|
|
}
|
|
|
|
|
2007-12-02 10:39:17 -08:00
|
|
|
static void
|
|
|
|
ice_exit(void)
|
|
|
|
{
|
|
|
|
SmcCloseConnection(sm_conn, 0, NULL);
|
|
|
|
sm_conn = NULL;
|
|
|
|
EventFdUnregister(sm_efd);
|
|
|
|
}
|
2004-01-03 04:55:08 -08:00
|
|
|
|
2007-12-02 10:39:17 -08:00
|
|
|
static void
|
|
|
|
ice_msgs_process(void)
|
|
|
|
{
|
|
|
|
IceProcessMessagesStatus status;
|
|
|
|
|
|
|
|
status = IceProcessMessages(ice_conn, NULL, NULL);
|
|
|
|
if (status == IceProcessMessagesIOError)
|
|
|
|
{
|
|
|
|
/* Less of the hope.... E survives */
|
2008-10-18 12:05:18 -07:00
|
|
|
Alert(_("ERROR!\n" "\n"
|
|
|
|
"Lost the Session Manager that was there?\n"
|
|
|
|
"Here here session manager... come here... want a bone?\n"
|
|
|
|
"Oh come now! Stop sulking! Bugger. Oh well. "
|
|
|
|
"Will continue without\n" "a session manager.\n" "\n"
|
|
|
|
"I'll survive somehow.\n" "\n" "\n" "... I hope.\n"));
|
2007-12-02 10:39:17 -08:00
|
|
|
ice_exit();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
ice_init(void)
|
1999-08-17 15:56:46 -07:00
|
|
|
{
|
|
|
|
static SmPointer context;
|
|
|
|
SmcCallbacks callbacks;
|
2007-12-02 10:39:17 -08:00
|
|
|
char error_string_ret[4096];
|
|
|
|
char *client_id;
|
|
|
|
char style[2];
|
|
|
|
SmPropValue styleVal;
|
|
|
|
SmProp styleProp;
|
|
|
|
SmProp *props[1];
|
|
|
|
int sm_fd;
|
2006-05-14 09:17:32 -07:00
|
|
|
|
2007-12-02 10:39:17 -08:00
|
|
|
if (!getenv("SESSION_MANAGER"))
|
2006-05-14 09:17:32 -07:00
|
|
|
return;
|
1999-08-17 15:56:46 -07:00
|
|
|
|
|
|
|
IceSetIOErrorHandler(ice_io_error_handler);
|
|
|
|
|
|
|
|
callbacks.save_yourself.callback = callback_save_yourself;
|
|
|
|
callbacks.die.callback = callback_die;
|
|
|
|
callbacks.save_complete.callback = callback_save_complete;
|
|
|
|
callbacks.shutdown_cancelled.callback = callback_shutdown_cancelled;
|
|
|
|
|
2000-06-04 12:45:55 -07:00
|
|
|
callbacks.save_yourself.client_data = callbacks.die.client_data =
|
2003-05-22 12:15:03 -07:00
|
|
|
callbacks.save_complete.client_data =
|
|
|
|
callbacks.shutdown_cancelled.client_data = (SmPointer) NULL;
|
2000-07-26 11:00:47 -07:00
|
|
|
|
2007-12-02 10:39:17 -08:00
|
|
|
client_id = Estrdup(sm_client_id);
|
2000-07-26 11:00:47 -07:00
|
|
|
|
2007-12-02 10:39:17 -08:00
|
|
|
error_string_ret[0] = '\0';
|
2000-07-26 11:00:47 -07:00
|
|
|
|
2007-12-02 10:39:17 -08:00
|
|
|
sm_conn =
|
|
|
|
SmcOpenConnection(NULL, &context, SmProtoMajor, SmProtoMinor,
|
|
|
|
SmcSaveYourselfProcMask | SmcDieProcMask |
|
|
|
|
SmcSaveCompleteProcMask |
|
|
|
|
SmcShutdownCancelledProcMask, &callbacks,
|
|
|
|
client_id, &sm_client_id, 4096, error_string_ret);
|
2008-02-23 04:09:38 -08:00
|
|
|
Efree(client_id);
|
2000-07-26 11:00:47 -07:00
|
|
|
|
2007-12-02 10:39:17 -08:00
|
|
|
if (error_string_ret[0])
|
|
|
|
Eprintf("While connecting to session manager: %s.", error_string_ret);
|
|
|
|
|
|
|
|
if (!sm_conn)
|
|
|
|
return;
|
|
|
|
|
|
|
|
style[0] = SmRestartIfRunning;
|
|
|
|
style[1] = 0;
|
|
|
|
|
|
|
|
styleVal.length = 1;
|
|
|
|
styleVal.value = style;
|
|
|
|
|
|
|
|
styleProp.name = (char *)SmRestartStyleHint;
|
|
|
|
styleProp.type = (char *)SmCARD8;
|
|
|
|
styleProp.num_vals = 1;
|
|
|
|
styleProp.vals = &styleVal;
|
|
|
|
|
|
|
|
props[0] = &styleProp;
|
|
|
|
|
|
|
|
ice_conn = SmcGetIceConnection(sm_conn);
|
|
|
|
sm_fd = IceConnectionNumber(ice_conn);
|
|
|
|
/* Just in case we are a copy of E created by a doExit("restart") */
|
|
|
|
SmcSetProperties(sm_conn, 1, props);
|
|
|
|
fcntl(sm_fd, F_SETFD, fcntl(sm_fd, F_GETFD, 0) | FD_CLOEXEC);
|
|
|
|
|
|
|
|
sm_efd = EventFdRegister(sm_fd, ice_msgs_process);
|
|
|
|
}
|
2000-07-26 11:00:47 -07:00
|
|
|
|
2007-07-18 04:18:50 -07:00
|
|
|
#endif /* USE_SM */
|
2004-01-03 04:55:08 -08:00
|
|
|
|
2007-12-02 10:39:17 -08:00
|
|
|
void
|
|
|
|
SessionInit(void)
|
|
|
|
{
|
|
|
|
if (Mode.wm.window)
|
|
|
|
return;
|
|
|
|
|
|
|
|
#if 0 /* Unused */
|
2013-04-07 03:04:35 -07:00
|
|
|
atom_sm_client_id = ex_atom_get("SM_CLIENT_ID");
|
2007-12-02 10:39:17 -08:00
|
|
|
#endif
|
|
|
|
|
|
|
|
#if USE_SM
|
|
|
|
ice_init();
|
|
|
|
#endif
|
|
|
|
|
2005-11-09 12:36:35 -08:00
|
|
|
if (!Conf.session.script)
|
|
|
|
Conf.session.script = Estrdup("$EROOT/scripts/session.sh");
|
2005-01-28 23:11:59 -08:00
|
|
|
if (!Conf.session.cmd_reboot)
|
|
|
|
Conf.session.cmd_reboot = Estrdup("reboot");
|
|
|
|
if (!Conf.session.cmd_halt)
|
|
|
|
Conf.session.cmd_halt = Estrdup("poweroff");
|
1999-08-17 15:56:46 -07:00
|
|
|
}
|
|
|
|
|
1999-11-05 04:58:05 -08:00
|
|
|
void
|
2008-05-10 16:29:01 -07:00
|
|
|
SessionGetInfo(EWin * ewin __UNUSED__)
|
1999-08-17 15:56:46 -07:00
|
|
|
{
|
2007-04-16 13:31:33 -07:00
|
|
|
#if 0 /* Unused */
|
2007-07-18 04:18:50 -07:00
|
|
|
#if USE_SM
|
2013-12-28 09:59:09 -08:00
|
|
|
if (atom_sm_client_id == NoXID)
|
2006-10-20 13:09:29 -07:00
|
|
|
return;
|
2007-04-16 13:31:33 -07:00
|
|
|
_EFREE(ewin->session_id);
|
2013-12-28 09:59:09 -08:00
|
|
|
if (ewin->icccm.client_leader != NoXID)
|
2007-04-16 13:31:33 -07:00
|
|
|
ewin->session_id =
|
2013-04-07 04:06:58 -07:00
|
|
|
ex_window_prop_string_get(ewin->icccm.client_leader,
|
|
|
|
atom_sm_client_id);
|
2005-01-02 01:42:35 -08:00
|
|
|
#else
|
|
|
|
ewin = NULL;
|
2007-07-18 04:18:50 -07:00
|
|
|
#endif /* USE_SM */
|
2007-04-16 13:31:33 -07:00
|
|
|
#endif
|
1999-08-17 15:56:46 -07:00
|
|
|
}
|
|
|
|
|
2011-02-12 08:43:52 -08:00
|
|
|
#if USE_SM
|
1999-11-05 04:58:05 -08:00
|
|
|
void
|
2004-03-20 17:39:40 -08:00
|
|
|
SetSMID(const char *smid)
|
1999-08-17 15:56:46 -07:00
|
|
|
{
|
2004-03-20 17:41:00 -08:00
|
|
|
sm_client_id = Estrdup(smid);
|
2011-02-12 08:43:52 -08:00
|
|
|
}
|
2005-01-02 01:42:35 -08:00
|
|
|
#else
|
2011-02-12 08:43:52 -08:00
|
|
|
void
|
|
|
|
SetSMID(const char *smid __UNUSED__)
|
|
|
|
{
|
1999-08-17 15:56:46 -07:00
|
|
|
}
|
2011-02-12 08:43:52 -08:00
|
|
|
#endif /* USE_SM */
|
1999-08-17 15:56:46 -07:00
|
|
|
|
2007-12-02 10:39:17 -08:00
|
|
|
static void
|
2004-12-28 15:46:49 -08:00
|
|
|
SessionSave(int shutdown)
|
1999-08-17 15:56:46 -07:00
|
|
|
{
|
2006-11-19 13:55:52 -08:00
|
|
|
if (EDebug(EDBUG_TYPE_SESSION))
|
2004-12-28 15:46:49 -08:00
|
|
|
Eprintf("SessionSave(%d)\n", shutdown);
|
2004-06-02 15:44:33 -07:00
|
|
|
|
2012-04-22 10:39:51 -07:00
|
|
|
SnapshotsSaveReal();
|
2007-12-02 10:39:17 -08:00
|
|
|
|
2007-07-18 04:18:50 -07:00
|
|
|
#if USE_SM
|
1999-08-17 15:56:46 -07:00
|
|
|
if (shutdown && sm_conn)
|
2007-12-02 10:39:17 -08:00
|
|
|
ice_exit();
|
2007-07-18 04:18:50 -07:00
|
|
|
#endif /* USE_SM */
|
1999-08-17 15:56:46 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Normally, the SM will throw away all the session data for a client
|
|
|
|
* that breaks its connection unexpectedly. In order to avoid this we
|
|
|
|
* have to let the SM handle the restart (by setting a SmRestartStyleHint
|
|
|
|
* of SmRestartImmediately). Rather than forcing all SM clients to do a
|
|
|
|
* checkpoint (which would be a bit cleaner) we just save our own state
|
|
|
|
* and then restore it on restart. We grab X input via the ext_init_win
|
|
|
|
* so the our clients remain frozen while we are down.
|
|
|
|
*/
|
2008-10-18 14:20:53 -07:00
|
|
|
__NORETURN__ static void
|
2005-01-28 23:11:59 -08:00
|
|
|
doSMExit(int mode, const char *params)
|
1999-08-17 15:56:46 -07:00
|
|
|
{
|
2004-12-28 15:46:49 -08:00
|
|
|
int l;
|
2005-01-28 23:11:59 -08:00
|
|
|
char s[1024];
|
|
|
|
const char *ss;
|
2004-06-02 15:44:33 -07:00
|
|
|
|
2006-11-19 13:55:52 -08:00
|
|
|
if (EDebug(EDBUG_TYPE_SESSION))
|
2005-01-28 23:11:59 -08:00
|
|
|
Eprintf("doSMExit: mode=%d prm=%p\n", mode, params);
|
1999-08-17 15:56:46 -07:00
|
|
|
|
2013-12-28 03:29:26 -08:00
|
|
|
restarting = 1;
|
1999-08-17 15:56:46 -07:00
|
|
|
|
2007-12-02 10:39:17 -08:00
|
|
|
SessionSave(1);
|
2004-05-07 08:18:07 -07:00
|
|
|
|
2005-11-06 10:12:12 -08:00
|
|
|
if (mode != EEXIT_THEME && mode != EEXIT_RESTART)
|
|
|
|
SessionHelper(ESESSION_STOP);
|
|
|
|
|
2006-04-21 16:47:30 -07:00
|
|
|
LangExit();
|
|
|
|
|
2004-05-07 08:18:07 -07:00
|
|
|
if (disp)
|
2004-06-19 14:31:40 -07:00
|
|
|
{
|
2005-04-29 09:33:35 -07:00
|
|
|
/* We may get here from HandleXIOError */
|
|
|
|
EwinsSetFree();
|
2008-03-30 05:13:16 -07:00
|
|
|
ESelectInput(VROOT, 0);
|
2005-04-23 06:35:37 -07:00
|
|
|
ExtInitWinKill();
|
2008-02-13 13:31:29 -08:00
|
|
|
ESync(0);
|
2004-05-07 08:18:07 -07:00
|
|
|
|
2005-05-29 16:48:08 -07:00
|
|
|
/* Forget about cleaning up if no disp */
|
|
|
|
ModulesSignal(ESIGNAL_EXIT, NULL);
|
|
|
|
}
|
2005-04-29 09:33:35 -07:00
|
|
|
|
2005-01-28 23:11:59 -08:00
|
|
|
ss = NULL;
|
|
|
|
switch (mode)
|
2000-07-26 11:00:47 -07:00
|
|
|
{
|
2005-01-28 23:11:59 -08:00
|
|
|
case EEXIT_EXEC:
|
2008-12-14 08:44:45 -08:00
|
|
|
SoundPlay(SOUND_EXIT);
|
2004-12-28 15:46:49 -08:00
|
|
|
EDisplayClose();
|
|
|
|
|
2006-11-19 13:55:52 -08:00
|
|
|
if (EDebug(EDBUG_TYPE_SESSION))
|
2012-02-26 12:15:50 -08:00
|
|
|
Eprintf("doSMExit: exec %s\n", params);
|
2013-04-03 12:54:05 -07:00
|
|
|
Eexec(params);
|
2005-01-28 23:11:59 -08:00
|
|
|
break;
|
|
|
|
|
|
|
|
case EEXIT_THEME:
|
|
|
|
ss = params;
|
2010-06-06 03:05:53 -07:00
|
|
|
/* FALLTHROUGH */
|
2005-01-28 23:11:59 -08:00
|
|
|
case EEXIT_RESTART:
|
2008-12-14 08:44:45 -08:00
|
|
|
SoundPlay(SOUND_WAIT);
|
2004-12-28 15:46:49 -08:00
|
|
|
#ifdef USE_EXT_INIT_WIN
|
2007-12-08 06:01:27 -08:00
|
|
|
if (disp && !Mode.wm.window)
|
2005-03-04 09:59:27 -08:00
|
|
|
new_init_win_ext = ExtInitWinCreate();
|
2004-12-28 15:46:49 -08:00
|
|
|
#endif
|
|
|
|
EDisplayClose();
|
2003-05-22 12:15:03 -07:00
|
|
|
|
2004-12-28 15:46:49 -08:00
|
|
|
l = 0;
|
2012-02-26 12:15:50 -08:00
|
|
|
l += Esnprintf(s + l, sizeof(s) - l, "%s -f", Mode.wm.exec_name);
|
2005-04-07 09:38:57 -07:00
|
|
|
if (Mode.wm.single)
|
2008-03-29 10:18:58 -07:00
|
|
|
l += Esnprintf(s + l, sizeof(s) - l, " -s %d", Dpy.screen);
|
2005-04-07 09:38:57 -07:00
|
|
|
else if (!Mode.wm.master)
|
|
|
|
l +=
|
|
|
|
Esnprintf(s + l, sizeof(s) - l, " -m %d", Mode.wm.master_screen);
|
2007-12-08 06:01:27 -08:00
|
|
|
if (Mode.wm.window)
|
2008-03-24 04:12:40 -07:00
|
|
|
l += Esnprintf(s + l, sizeof(s) - l, " -w %dx%d",
|
|
|
|
WinGetW(VROOT), WinGetH(VROOT));
|
2007-07-18 04:18:50 -07:00
|
|
|
#if USE_SM
|
2003-05-22 12:15:03 -07:00
|
|
|
if (sm_client_id)
|
2005-04-07 09:38:57 -07:00
|
|
|
l += Esnprintf(s + l, sizeof(s) - l, " -S %s", sm_client_id);
|
2005-01-02 01:42:35 -08:00
|
|
|
#endif
|
2005-03-04 09:59:27 -08:00
|
|
|
#ifdef USE_EXT_INIT_WIN
|
2013-12-28 09:59:09 -08:00
|
|
|
if (new_init_win_ext != NoXID)
|
2009-12-03 11:29:30 -08:00
|
|
|
l += Esnprintf(s + l, sizeof(s) - l, " -X %#x", new_init_win_ext);
|
2005-03-04 09:59:27 -08:00
|
|
|
#endif
|
2005-01-28 23:11:59 -08:00
|
|
|
if (ss)
|
|
|
|
l += Esnprintf(s + l, sizeof(s) - l, " -t %s", ss);
|
1999-09-30 23:08:25 -07:00
|
|
|
|
2006-11-19 13:55:52 -08:00
|
|
|
if (EDebug(EDBUG_TYPE_SESSION))
|
2012-02-26 12:15:50 -08:00
|
|
|
Eprintf("doSMExit: exec %s\n", s);
|
2004-01-03 04:55:08 -08:00
|
|
|
|
2013-04-03 12:54:05 -07:00
|
|
|
Eexec(s);
|
2005-01-28 23:11:59 -08:00
|
|
|
break;
|
2004-01-03 04:55:08 -08:00
|
|
|
}
|
|
|
|
|
2013-12-28 03:29:26 -08:00
|
|
|
restarting = 0;
|
2008-12-14 08:44:45 -08:00
|
|
|
SoundPlay(SOUND_EXIT);
|
2004-01-03 04:55:08 -08:00
|
|
|
EExit(0);
|
|
|
|
}
|
|
|
|
|
2005-01-28 23:11:59 -08:00
|
|
|
static void
|
|
|
|
SessionLogout(void)
|
|
|
|
{
|
2007-07-18 04:18:50 -07:00
|
|
|
#if USE_SM
|
2005-01-28 23:11:59 -08:00
|
|
|
if (sm_conn)
|
|
|
|
{
|
|
|
|
SmcRequestSaveYourself(sm_conn, SmSaveBoth, True, SmInteractStyleAny,
|
|
|
|
False, True);
|
|
|
|
}
|
|
|
|
else
|
2007-07-18 04:18:50 -07:00
|
|
|
#endif /* USE_SM */
|
2005-01-28 23:11:59 -08:00
|
|
|
{
|
2006-05-12 06:10:16 -07:00
|
|
|
SessionExit(EEXIT_EXIT, NULL);
|
2005-01-28 23:11:59 -08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2009-01-24 00:31:50 -08:00
|
|
|
#if ENABLE_DIALOGS
|
2005-01-28 23:11:59 -08:00
|
|
|
static void
|
2006-07-24 13:53:49 -07:00
|
|
|
LogoutCB(Dialog * d, int val, void *data __UNUSED__)
|
2005-01-28 23:11:59 -08:00
|
|
|
{
|
2007-07-18 04:18:50 -07:00
|
|
|
#if USE_SM
|
2005-01-28 23:11:59 -08:00
|
|
|
if (sm_conn)
|
|
|
|
{
|
|
|
|
SessionLogout();
|
|
|
|
}
|
|
|
|
else
|
2007-07-18 04:18:50 -07:00
|
|
|
#endif /* USE_SM */
|
2005-01-28 23:11:59 -08:00
|
|
|
{
|
2005-02-06 00:02:11 -08:00
|
|
|
/* 0:LogOut -: No -or- */
|
|
|
|
/* 0:Halt 1:Reboot 2:LogOut -:No */
|
|
|
|
switch (val)
|
|
|
|
{
|
2006-08-22 12:23:36 -07:00
|
|
|
default:
|
2005-02-06 00:02:11 -08:00
|
|
|
break;
|
|
|
|
case 1:
|
2006-08-22 12:23:36 -07:00
|
|
|
SessionExit(EEXIT_EXIT, NULL);
|
2005-02-06 00:02:11 -08:00
|
|
|
break;
|
|
|
|
case 2:
|
2006-08-22 12:23:36 -07:00
|
|
|
SessionExit(EEXIT_EXEC, Conf.session.cmd_reboot);
|
|
|
|
break;
|
|
|
|
case 3:
|
|
|
|
SessionExit(EEXIT_EXEC, Conf.session.cmd_halt);
|
2005-02-06 00:02:11 -08:00
|
|
|
break;
|
|
|
|
}
|
2005-01-28 23:11:59 -08:00
|
|
|
}
|
2006-07-24 13:53:49 -07:00
|
|
|
|
|
|
|
DialogClose(d);
|
2005-01-28 23:11:59 -08:00
|
|
|
}
|
|
|
|
|
2004-05-31 15:54:12 -07:00
|
|
|
static void
|
|
|
|
SessionLogoutConfirm(void)
|
|
|
|
{
|
|
|
|
Dialog *d;
|
2006-08-22 12:23:36 -07:00
|
|
|
DItem *table, *di;
|
2004-05-31 15:54:12 -07:00
|
|
|
|
2006-02-18 00:30:09 -08:00
|
|
|
d = DialogFind("LOGOUT_DIALOG");
|
2004-05-31 15:54:12 -07:00
|
|
|
if (!d)
|
|
|
|
{
|
2008-12-14 08:44:45 -08:00
|
|
|
SoundPlay(SOUND_LOGOUT);
|
2004-05-31 15:54:12 -07:00
|
|
|
d = DialogCreate("LOGOUT_DIALOG");
|
2006-08-22 12:23:36 -07:00
|
|
|
table = DialogInitItem(d);
|
2004-05-31 15:54:12 -07:00
|
|
|
DialogSetTitle(d, _("Are you sure?"));
|
2006-08-22 12:23:36 -07:00
|
|
|
di = DialogAddItem(table, DITEM_TEXT);
|
2010-05-09 12:03:19 -07:00
|
|
|
DialogItemSetText(di, _("Are you sure you wish to log out ?"));
|
2006-08-22 12:23:36 -07:00
|
|
|
table = DialogAddItem(table, DITEM_TABLE);
|
2006-08-24 13:32:20 -07:00
|
|
|
DialogItemSetAlign(table, 512, 0);
|
|
|
|
DialogItemSetFill(table, 0, 0);
|
2006-08-22 12:23:36 -07:00
|
|
|
DialogItemTableSetOptions(table, 2, 0, 1, 0);
|
2005-01-28 23:11:59 -08:00
|
|
|
if (Conf.session.enable_reboot_halt)
|
|
|
|
{
|
2006-08-22 12:23:36 -07:00
|
|
|
DialogItemTableSetOptions(table, 4, 0, 1, 0);
|
2010-05-09 12:03:19 -07:00
|
|
|
DialogItemAddButton(table, _("Yes, Shut Down"), LogoutCB, 3,
|
2006-08-22 12:23:36 -07:00
|
|
|
1, DLG_BUTTON_OK);
|
2010-05-09 12:03:19 -07:00
|
|
|
DialogItemAddButton(table, _("Yes, Reboot"), LogoutCB, 2,
|
2006-08-22 12:23:36 -07:00
|
|
|
1, DLG_BUTTON_OK);
|
2005-01-28 23:11:59 -08:00
|
|
|
}
|
2010-05-09 12:03:19 -07:00
|
|
|
DialogItemAddButton(table, _("Yes, Log Out"), LogoutCB, 1,
|
2006-08-22 12:23:36 -07:00
|
|
|
1, DLG_BUTTON_OK);
|
2010-05-09 12:03:19 -07:00
|
|
|
DialogItemAddButton(table, _("No"), NULL, 0, 1, DLG_BUTTON_CANCEL);
|
2006-08-22 12:23:36 -07:00
|
|
|
DialogBindKey(d, "Escape", DialogCallbackClose, 0, NULL);
|
|
|
|
DialogBindKey(d, "Return", LogoutCB, 1, NULL);
|
2004-05-31 15:54:12 -07:00
|
|
|
}
|
|
|
|
|
2006-04-26 16:43:07 -07:00
|
|
|
DialogShowCentered(d);
|
2004-05-31 15:54:12 -07:00
|
|
|
}
|
2009-01-24 00:31:50 -08:00
|
|
|
#endif /* ENABLE_DIALOGS */
|
2004-05-31 15:54:12 -07:00
|
|
|
|
2005-01-28 23:11:59 -08:00
|
|
|
void
|
|
|
|
SessionExit(int mode, const char *param)
|
2004-01-03 04:55:08 -08:00
|
|
|
{
|
2006-04-19 12:13:46 -07:00
|
|
|
/* We do not want to be exited by children. */
|
|
|
|
if (getpid() != Mode.wm.pid)
|
|
|
|
return;
|
|
|
|
|
2006-11-19 13:55:52 -08:00
|
|
|
if (EDebug(EDBUG_TYPE_SESSION))
|
2006-05-12 06:10:16 -07:00
|
|
|
Eprintf("SessionExit: mode=%d(%d) prm=%s\n", mode, Mode.wm.exit_mode,
|
|
|
|
param);
|
|
|
|
|
2007-12-08 06:01:27 -08:00
|
|
|
if (Mode.wm.exiting)
|
|
|
|
return;
|
|
|
|
|
2007-12-30 12:55:20 -08:00
|
|
|
if (Mode.wm.startup || Mode.wm.exit_now)
|
2006-05-12 06:10:16 -07:00
|
|
|
goto done;
|
|
|
|
|
|
|
|
switch (mode)
|
2004-05-31 15:54:12 -07:00
|
|
|
{
|
2006-05-12 06:10:16 -07:00
|
|
|
default:
|
|
|
|
/* In event loop - Set exit mode */
|
|
|
|
Mode.wm.exit_mode = mode;
|
|
|
|
Mode.wm.exit_param = Estrdup(param);
|
2005-01-28 23:11:59 -08:00
|
|
|
return;
|
2004-05-31 15:54:12 -07:00
|
|
|
|
2006-05-12 06:10:16 -07:00
|
|
|
case EEXIT_QUIT:
|
|
|
|
mode = Mode.wm.exit_mode;
|
|
|
|
param = Mode.wm.exit_param;
|
|
|
|
break;
|
|
|
|
|
|
|
|
case EEXIT_ERROR:
|
|
|
|
if (!Mode.wm.exiting)
|
|
|
|
break;
|
2004-05-07 08:18:07 -07:00
|
|
|
/* This may be possible during nested signal handling */
|
|
|
|
Eprintf("SessionExit already in progress ... now exiting\n");
|
|
|
|
exit(1);
|
2006-05-12 06:10:16 -07:00
|
|
|
break;
|
|
|
|
|
|
|
|
case EEXIT_LOGOUT:
|
2009-01-24 00:31:50 -08:00
|
|
|
#if ENABLE_DIALOGS
|
2006-05-12 06:10:16 -07:00
|
|
|
if (Conf.session.enable_logout_dialog)
|
|
|
|
SessionLogoutConfirm();
|
|
|
|
else
|
2009-01-24 00:31:50 -08:00
|
|
|
#endif
|
2006-05-12 06:10:16 -07:00
|
|
|
SessionLogout();
|
|
|
|
return;
|
2004-05-07 08:18:07 -07:00
|
|
|
}
|
|
|
|
|
2006-05-12 06:10:16 -07:00
|
|
|
done:
|
|
|
|
Mode.wm.exiting++;
|
2005-01-28 23:11:59 -08:00
|
|
|
doSMExit(mode, param);
|
2004-01-03 04:55:08 -08:00
|
|
|
}
|
2005-11-06 10:12:12 -08:00
|
|
|
|
|
|
|
static void
|
|
|
|
SessionRunProg(const char *prog, const char *params)
|
|
|
|
{
|
|
|
|
char buf[4096];
|
|
|
|
const char *s;
|
|
|
|
|
|
|
|
if (params)
|
|
|
|
{
|
|
|
|
Esnprintf(buf, sizeof(buf), "%s %s", prog, params);
|
|
|
|
s = buf;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
s = prog;
|
|
|
|
}
|
2006-11-19 13:55:52 -08:00
|
|
|
if (EDebug(EDBUG_TYPE_SESSION))
|
2005-11-06 10:12:12 -08:00
|
|
|
Eprintf("SessionRunProg: %s\n", s);
|
2009-06-10 10:45:10 -07:00
|
|
|
Esystem(s);
|
2005-11-06 10:12:12 -08:00
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
SessionHelper(int when)
|
|
|
|
{
|
|
|
|
switch (when)
|
|
|
|
{
|
|
|
|
case ESESSION_INIT:
|
2005-11-09 12:36:35 -08:00
|
|
|
if (Conf.session.enable_script && Conf.session.script)
|
|
|
|
SessionRunProg(Conf.session.script, "init");
|
2005-11-06 10:12:12 -08:00
|
|
|
break;
|
|
|
|
case ESESSION_START:
|
2005-11-09 12:36:35 -08:00
|
|
|
if (Conf.session.enable_script && Conf.session.script)
|
|
|
|
SessionRunProg(Conf.session.script, "start");
|
2005-11-06 10:12:12 -08:00
|
|
|
break;
|
|
|
|
case ESESSION_STOP:
|
2005-11-09 12:36:35 -08:00
|
|
|
if (Conf.session.enable_script && Conf.session.script)
|
|
|
|
SessionRunProg(Conf.session.script, "stop");
|
2005-11-06 10:12:12 -08:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
2005-11-10 13:39:29 -08:00
|
|
|
|
2009-01-24 00:31:50 -08:00
|
|
|
#if ENABLE_DIALOGS
|
2005-11-10 13:39:29 -08:00
|
|
|
/*
|
|
|
|
* Session dialog
|
|
|
|
*/
|
|
|
|
static char tmp_session_script;
|
|
|
|
static char tmp_logout_dialog;
|
|
|
|
static char tmp_reboot_halt;
|
|
|
|
|
|
|
|
static void
|
2014-04-25 11:20:20 -07:00
|
|
|
_DlgApplySession(Dialog * d __UNUSED__, int val __UNUSED__,
|
|
|
|
void *data __UNUSED__)
|
2005-11-10 13:39:29 -08:00
|
|
|
{
|
2014-04-25 11:20:20 -07:00
|
|
|
Conf.session.enable_script = tmp_session_script;
|
|
|
|
Conf.session.enable_logout_dialog = tmp_logout_dialog;
|
|
|
|
Conf.session.enable_reboot_halt = tmp_reboot_halt;
|
2005-11-10 13:39:29 -08:00
|
|
|
autosave();
|
|
|
|
}
|
|
|
|
|
2006-07-20 20:17:18 -07:00
|
|
|
static void
|
2006-08-07 20:58:42 -07:00
|
|
|
_DlgFillSession(Dialog * d __UNUSED__, DItem * table, void *data __UNUSED__)
|
2005-11-10 13:39:29 -08:00
|
|
|
{
|
2006-07-20 20:17:18 -07:00
|
|
|
DItem *di;
|
2005-11-10 13:39:29 -08:00
|
|
|
|
|
|
|
tmp_session_script = Conf.session.enable_script;
|
|
|
|
tmp_logout_dialog = Conf.session.enable_logout_dialog;
|
|
|
|
tmp_reboot_halt = Conf.session.enable_reboot_halt;
|
|
|
|
|
|
|
|
DialogItemTableSetOptions(table, 2, 0, 0, 0);
|
|
|
|
|
|
|
|
di = DialogAddItem(table, DITEM_CHECKBUTTON);
|
|
|
|
DialogItemSetColSpan(di, 2);
|
|
|
|
DialogItemSetText(di, _("Enable Session Script"));
|
|
|
|
DialogItemCheckButtonSetPtr(di, &tmp_session_script);
|
|
|
|
|
|
|
|
di = DialogAddItem(table, DITEM_CHECKBUTTON);
|
|
|
|
DialogItemSetColSpan(di, 2);
|
|
|
|
DialogItemSetText(di, _("Enable Logout Dialog"));
|
|
|
|
DialogItemCheckButtonSetPtr(di, &tmp_logout_dialog);
|
|
|
|
|
|
|
|
di = DialogAddItem(table, DITEM_CHECKBUTTON);
|
|
|
|
DialogItemSetColSpan(di, 2);
|
|
|
|
DialogItemSetText(di, _("Enable Reboot/Halt on Logout"));
|
|
|
|
DialogItemCheckButtonSetPtr(di, &tmp_reboot_halt);
|
|
|
|
}
|
2006-07-20 20:17:18 -07:00
|
|
|
|
|
|
|
const DialogDef DlgSession = {
|
|
|
|
"CONFIGURE_SESSION",
|
2014-04-25 14:07:58 -07:00
|
|
|
N_("Session"), N_("Session Settings"),
|
|
|
|
0,
|
2008-12-14 08:44:45 -08:00
|
|
|
SOUND_SETTINGS_SESSION,
|
2006-07-26 21:52:50 -07:00
|
|
|
"pix/miscellaneous.png",
|
2010-05-09 12:03:19 -07:00
|
|
|
N_("Enlightenment Session\n" "Settings Dialog"),
|
2006-08-07 20:58:42 -07:00
|
|
|
_DlgFillSession,
|
2014-04-25 11:20:20 -07:00
|
|
|
DLG_OAC, _DlgApplySession, NULL
|
2006-07-20 20:17:18 -07:00
|
|
|
};
|
2009-01-24 00:31:50 -08:00
|
|
|
#endif /* ENABLE_DIALOGS */
|