Trivial session cleanups.

SVN revision: 8265
This commit is contained in:
Kim Woelders 2004-01-03 12:55:08 +00:00
parent e117fe4368
commit 5c66882c39
9 changed files with 192 additions and 226 deletions

View File

@ -2406,9 +2406,10 @@ void ArrangeEwinCentered(EWin * ewin, int focus);
void ArrangeEwinXY(EWin * ewin, int *px, int *py);
void ArrangeEwinCenteredXY(EWin * ewin, int *px, int *py);
/* session.c */
void SessionInit(void);
void SessionSave(int shutdown);
void doSMExit(void *params);
int SessionExit(void *params);
void ProcessICEMSGS(void);
int GetSMfd(void);
void SessionGetInfo(EWin * ewin, Atom atom_change);

View File

@ -845,7 +845,7 @@ doExit(void *params)
/* This function is now handled in session.c */
if (InZoom())
Zoom(NULL);
doSMExit(params);
SessionExit(params);
EDBUG_RETURN(0);
}

View File

@ -441,7 +441,7 @@ HandleComms(XClientMessageEvent * ev)
{
SetDefaultTheme(buf);
Esnprintf(sss, sizeof(sss), "restart_theme %s", buf);
doExit(sss);
SessionExit(sss);
}
}
else if (!strcmp(w, "list_bg"))

View File

@ -3250,7 +3250,7 @@ OpenConfigFileForReading(char *path, char preprocess)
"This is a FATAL ERROR.\n"
"This is probably due to either the program not existing or\n"
"it not being able to be executed by you.\n"), epp_path);
doExit(_("error"));
SessionExit("error");
}
else
have_epp = 1;
@ -3401,7 +3401,7 @@ LoadOpenConfigFile(FILE * ConfigFile)
"features in Enlightenment in new versions.\n"),
e_cfg_ver, min_e_cfg_ver);
RESET_ALERT;
doExit("restart_theme DEFAULT");
SessionExit("restart_theme DEFAULT");
}
else
{
@ -3423,7 +3423,7 @@ LoadOpenConfigFile(FILE * ConfigFile)
"your liking again safely.\n"), e_cfg_ver,
min_e_cfg_ver);
RESET_ALERT;
doExit("restart");
SessionExit("restart");
}
}
else
@ -4229,6 +4229,6 @@ RecoverUserConfig(void)
XKillClient(disp, init_win_ext);
init_win_ext = 0;
}
doExit("restart");
SessionExit("restart");
}
}

View File

@ -2128,7 +2128,7 @@ DialogOKstr(const char *title, const char *txt)
void
DialogRestart(int val, void *data)
{
doExit("restart");
SessionExit("restart");
val = 0;
data = NULL;
}
@ -2136,7 +2136,7 @@ DialogRestart(int val, void *data)
void
DialogQuit(int val, void *data)
{
doExit("error");
SessionExit("error");
val = 0;
data = NULL;
}

View File

@ -33,7 +33,7 @@ SignalHandler(int sig)
switch (sig)
{
case SIGHUP:
doExit("restart");
SessionExit("restart");
break;
default:
@ -41,7 +41,7 @@ SignalHandler(int sig)
case SIGQUIT:
case SIGABRT:
case SIGTERM:
doExit("error");
SessionExit("error");
break;
case SIGPIPE:
@ -61,7 +61,7 @@ SignalHandler(int sig)
"either obtain the correct package for your system, or\n"
"re-compile Enlightenment and possibly any support libraries\n"
"that you got in binary format to run Enlightenment.\n"));
doExit("error");
SessionExit("error");
break;
case SIGFPE:
@ -77,7 +77,7 @@ SignalHandler(int sig)
"Enlightenment under gdb so you can backtrace for where it died and\n"
"send in a useful bug report with backtrace information and variable\n"
"dumps etc.\n"));
doExit("error");
SessionExit("error");
break;
case SIGSEGV:
@ -225,7 +225,7 @@ HandleXIOError(Display * d)
{
EDBUG(7, "HandleXIOError");
disp = NULL;
doExit("error");
SessionExit("error");
EDBUG_RETURN_;
d = NULL;
}

View File

@ -4377,7 +4377,7 @@ IPC_Restart(char *params, Client * c)
c = NULL;
params = NULL;
doExit("restart");
SessionExit("restart");
}
@ -4390,7 +4390,7 @@ IPC_RestartWM(char *params, Client * c)
{
Esnprintf(buf, sizeof(buf), "restart_wm %s", params);
params = NULL;
doExit(buf);
SessionExit(buf);
}
else
{
@ -4408,7 +4408,7 @@ IPC_RestartTheme(char *params, Client * c)
{
Esnprintf(buf, sizeof(buf), "restart_theme %s", params);
params = NULL;
doExit(buf);
SessionExit(buf);
}
else
{
@ -4423,9 +4423,9 @@ IPC_Exit(char *params, Client * c)
c = NULL;
if (params)
doExit("quit");
SessionExit("quit");
else
doExit("logout");
SessionExit("logout");
}
static void
@ -4451,7 +4451,7 @@ IPC_DefaultTheme(char *params, Client * c)
SetDefaultTheme(params);
Esnprintf(restartcommand, sizeof(restartcommand),
"restart_theme %s", params);
doExit(restartcommand);
SessionExit(restartcommand);
}
else
{

View File

@ -90,8 +90,9 @@ main(int argc, char **argv)
AssignExitText(_("Quit Enlightenment"));
/* We'll set up what the buttons do now, too */
AssignRestartFunction(doExit, "restart");
AssignExitFunction(doExit, NULL);
AssignRestartFunction(SessionExit, "restart");
AssignExitFunction(SessionExit, NULL);
srand(time(NULL));
if (!uname(&ubuf))
@ -244,10 +245,7 @@ main(int argc, char **argv)
/* make all of our fallback classes */
SetupFallbackClasses();
UngrabX();
/* We'll set up what the buttons do now, too */
/* again? why are we doing this twice? */
AssignRestartFunction((*doExit), duplicate("restart"));
AssignExitFunction((*EExit), (void *)1);
desks.desk[0].viewable = 0;
/* now we're going to load the configuration/theme */
LoadEConfig(themepath);

View File

@ -38,6 +38,8 @@ typedef unsigned long big_type;
#endif
static int sm_fd = -1;
/* Generate a unique temporary file name from TEMPLATE.
* The last six characters of TEMPLATE must be "XXXXXX";
* they are replaced with a string that makes the filename unique.
@ -449,188 +451,7 @@ autosave(void)
}
}
#ifndef HAVE_X11_SM_SMLIB_H
void
SessionInit(void)
{
int i;
LoadWindowStates();
}
void
ProcessICEMSGS(void)
{
}
int
GetSMfd(void)
{
return -1;
}
void
SessionGetInfo(EWin * ewin, Atom atom_change)
{
}
void
SetSMID(char *smid)
{
}
void
SaveSession(int shutdown)
{
/* don't need */
/* autosave(); */
}
static void
LogoutCB(int val, void *data)
{
doSMExit(NULL);
val = 0;
data = NULL;
}
static void
CB_SettingsEscape(int val, void *data)
{
DialogClose((Dialog *) data);
val = 0;
}
/* This is the original code from actions.c(doExit). */
void
doSMExit(void *params)
{
char s[1024];
char *real_exec;
char sss[FILEPATH_LEN_MAX];
Window w;
char master_flag, do_master_kill;
master_flag = (master_pid == getpid())? 1 : 0;
do_master_kill = 1;
if (!params)
SaveSession(1);
if ((disp) && ((!params) || ((params) && strcmp((char *)params, "logout"))))
SetEInfoOnAll();
if (params)
{
SoundExit();
#ifndef __EMX__
setsid();
#endif
sscanf(params, "%1000s", s);
if (mustdel)
{
#ifndef __EMX__
Esnprintf(sss, sizeof(sss), "/bin/rm -rf %s", themepath);
#else
Esnprintf(sss, sizeof(sss), "rm.exe -rf %s", themepath);
#endif
system(sss);
}
if (!strcmp(s, "restart"))
{
SoundPlay("SOUND_WAIT");
if (sound_fd >= 0)
close(sound_fd);
w = MakeExtInitWin();
XCloseDisplay(disp);
disp = NULL;
if (themepath[0] != 0)
{
Esnprintf(sss, sizeof(sss),
"exec %s -single -ext_init_win %i -theme %s "
"-econfdir %s -ecachedir %s", command,
w, themename, UserEDir(), UserCacheDir());
execl(DEFAULT_SH_PATH, DEFAULT_SH_PATH, "-c", sss, NULL);
}
else
{
Esnprintf(sss, sizeof(sss),
"exec %s -single -ext_init_win %i "
"-econfdir %s -ecachedir %s", command,
w, UserEDir(), UserCacheDir());
execl(DEFAULT_SH_PATH, DEFAULT_SH_PATH, "-c", sss, NULL);
}
}
else if (!strcmp(s, "restart_theme"))
{
SoundPlay("SOUND_WAIT");
if (sound_fd >= 0)
close(sound_fd);
w = MakeExtInitWin();
XCloseDisplay(disp);
disp = NULL;
sscanf(params, "%*s %1000s", s);
Esnprintf(sss, sizeof(sss),
"exec %s -single -ext_init_win %i -theme %s "
"-econfdir %s -ecachedir %s", command, w, s,
UserEDir(), UserCacheDir());
execl(DEFAULT_SH_PATH, DEFAULT_SH_PATH, "-c", sss, NULL);
}
else if (!strcmp(s, "restart_wm"))
{
SoundPlay("SOUND_EXIT");
if (sound_fd >= 0)
close(sound_fd);
XCloseDisplay(disp);
disp = NULL;
if (atword(params, 2))
strncpy(s, atword(params, 2), 1000);
real_exec = (char *)Emalloc(strlen(s) + 6);
sprintf(real_exec,
"exec %s " "-econfdir %s -ecachedir %s", s,
UserEDir(), UserCacheDir());
execl(DEFAULT_SH_PATH, DEFAULT_SH_PATH, "-c", "exec", real_exec,
NULL);
}
else if (!strcmp(s, "logout"))
{
Dialog *d;
EWin *ewin;
if (!
(d =
FindItem("LOGOUT_DIALOG", 0, LIST_FINDBY_NAME,
LIST_TYPE_DIALOG)))
{
SoundPlay("SOUND_LOGOUT");
d = DialogCreate("LOGOUT_DIALOG");
DialogSetTitle(d, "Are you sure?");
DialogSetText(d,
"\n" "\n"
" Are you sure you wish to log out ? \n"
"\n" "\n");
DialogAddButton(d, " Yes, Log Out ", LogoutCB, 1);
DialogAddButton(d, " No ", NULL, 1);
DialogBindKey(d, "Escape", CB_SettingsEscape, 0, d);
DialogBindKey(d, "Return", LogoutCB, 0, d);
}
ShowDialog(d);
ewin = FindEwinByDialog(d);
if (ewin)
{
ArrangeEwinCentered(ewin, 1);
}
return;
}
}
SoundPlay("SOUND_EXIT");
EExit(0);
}
#else /* HAVE_X11_SM_SMLIB_H */
#ifdef HAVE_X11_SM_SMLIB_H
#include <X11/SM/SMlib.h>
@ -641,7 +462,6 @@ doSMExit(void *params)
static char *sm_client_id = NULL;
static SmcConn sm_conn = NULL;
static int sm_fd = -1;
/* True if we are saving state for a doExit("restart") */
static int restarting = False;
@ -778,7 +598,7 @@ set_save_props(SmcConn smc_conn, int master_flag)
}
if (restarting)
{
Esnprintf(buf, sizeof(buf), "%i", (unsigned)init_win_ext);
Esnprintf(buf, sizeof(buf), "%li", init_win_ext);
restartVal[n].length = strlen(extinitwin);
restartVal[n++].value = extinitwin;
@ -937,9 +757,12 @@ ice_io_error_handler(IceConn connection)
connection = 0;
}
#endif /* HAVE_X11_SM_SMLIB_H */
void
SessionInit(void)
{
#ifdef HAVE_X11_SM_SMLIB_H
static SmPointer context;
SmcCallbacks callbacks;
@ -1003,12 +826,15 @@ SessionInit(void)
fcntl(sm_fd, F_SETFD, fcntl(sm_fd, F_GETFD, 0) | FD_CLOEXEC);
}
stale_sm_file = 1;
#endif /* HAVE_X11_SM_SMLIB_H */
LoadWindowStates();
}
void
ProcessICEMSGS(void)
{
#ifdef HAVE_X11_SM_SMLIB_H
IceProcessMessagesStatus status;
if (sm_fd < 0)
@ -1028,6 +854,7 @@ ProcessICEMSGS(void)
sm_conn = NULL;
sm_fd = -1;
}
#endif /* HAVE_X11_SM_SMLIB_H */
}
int
@ -1039,6 +866,7 @@ GetSMfd(void)
void
SessionGetInfo(EWin * ewin, Atom atom_change)
{
#ifdef HAVE_X11_SM_SMLIB_H
char *s;
Window *w;
int size;
@ -1069,41 +897,47 @@ SessionGetInfo(EWin * ewin, Atom atom_change)
}
Efree(w);
}
#endif /* HAVE_X11_SM_SMLIB_H */
}
void
SetSMID(char *smid)
{
#ifdef HAVE_X11_SM_SMLIB_H
sm_client_id = smid;
#endif /* HAVE_X11_SM_SMLIB_H */
}
static void doSMExit(void *params);
static void
LogoutCB(int val, void *data)
{
#ifdef HAVE_X11_SM_SMLIB_H
if (sm_conn)
{
SmcRequestSaveYourself(sm_conn, SmSaveBoth, True, SmInteractStyleAny,
False, True);
}
else
#endif /* HAVE_X11_SM_SMLIB_H */
{
doSMExit(NULL);
}
val = 0;
data = NULL;
}
void
SaveSession(int shutdown)
{
/* dont' need anymore */
/* ayosave(); */
/* autosave(); */
#ifdef HAVE_X11_SM_SMLIB_H
if (shutdown && sm_conn)
{
SmcCloseConnection(sm_conn, 0, NULL);
sm_conn = NULL;
sm_fd = -1;
}
#endif /* HAVE_X11_SM_SMLIB_H */
}
static void
@ -1113,6 +947,8 @@ CB_SettingsEscape(int val, void *data)
val = 0;
}
#ifdef HAVE_X11_SM_SMLIB_H
/*
* Normally, the SM will throw away all the session data for a client
* that breaks its connection unexpectedly. In order to avoid this we
@ -1122,7 +958,7 @@ CB_SettingsEscape(int val, void *data)
* 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.
*/
void
static void
doSMExit(void *params)
{
char s[1024];
@ -1198,16 +1034,16 @@ doSMExit(void *params)
{
if (sm_client_id)
Esnprintf(s, sizeof(s),
"exec %s -single -ext_init_win %i -theme %s "
"exec %s -single -ext_init_win %li -theme %s "
"-econfdir %s -ecachedir %s "
"-smfile %s -smid %s", command,
(unsigned)init_win_ext, themename, UserEDir(),
init_win_ext, themename, UserEDir(),
UserCacheDir(), sm_file, sm_client_id);
else
Esnprintf(s, sizeof(s),
"exec %s -single -ext_init_win %i -theme %s "
"exec %s -single -ext_init_win %li -theme %s "
"-econfdir %s -ecachedir %s "
"-smfile %s", command, (unsigned)init_win_ext,
"-smfile %s", command, init_win_ext,
themename, UserEDir(), UserCacheDir(), sm_file);
execl(DEFAULT_SH_PATH, DEFAULT_SH_PATH, "-c", s, NULL);
}
@ -1215,16 +1051,16 @@ doSMExit(void *params)
{
if (sm_client_id)
Esnprintf(s, sizeof(s),
"exec %s -single -ext_init_win %i "
"exec %s -single -ext_init_win %li "
"-econfdir %s -ecachedir %s "
"-smfile %s -smid %s", command,
(unsigned)init_win_ext, UserEDir(), UserCacheDir(),
init_win_ext, UserEDir(), UserCacheDir(),
sm_file, sm_client_id);
else
Esnprintf(s, sizeof(s),
"exec %s -single -ext_init_win %i"
"exec %s -single -ext_init_win %li"
"-econfdir %s -ecachedir %s "
"-smfile %s", command, (unsigned)init_win_ext,
"-smfile %s", command, init_win_ext,
UserEDir(), UserCacheDir(), sm_file);
execl(DEFAULT_SH_PATH, DEFAULT_SH_PATH, "-c", s, NULL);
}
@ -1245,16 +1081,16 @@ doSMExit(void *params)
}
if (sm_client_id)
Esnprintf(s, sizeof(s),
"exec %s -single -ext_init_win %i -theme %s "
"exec %s -single -ext_init_win %li -theme %s "
"-econfdir %s -ecachedir %s "
"-smfile %s -smid %s", command, (unsigned)init_win_ext,
"-smfile %s -smid %s", command, init_win_ext,
userthemepath, UserEDir(), UserCacheDir(), sm_file,
sm_client_id);
else
Esnprintf(s, sizeof(s),
"exec %s -ext_init_win %i -theme %s "
"exec %s -ext_init_win %li -theme %s "
"-econfdir %s -ecachedir %s "
"-smfile %s -single", command, (unsigned)init_win_ext,
"-smfile %s -single", command, init_win_ext,
userthemepath, UserEDir(), UserCacheDir(), sm_file);
execl(DEFAULT_SH_PATH, DEFAULT_SH_PATH, "-c", s, NULL);
}
@ -1269,4 +1105,135 @@ doSMExit(void *params)
EExit(0);
}
#else /* HAVE_X11_SM_SMLIB_H */
/* This is the original code from actions.c(doExit). */
static void
doSMExit(void *params)
{
char s[1024];
char *real_exec;
char sss[FILEPATH_LEN_MAX];
Window w;
char master_flag, do_master_kill;
master_flag = (master_pid == getpid())? 1 : 0;
do_master_kill = 1;
if (!params)
SaveSession(1);
if ((disp) && ((!params) || ((params) && strcmp((char *)params, "logout"))))
SetEInfoOnAll();
if (params)
{
SoundExit();
#ifndef __EMX__
setsid();
#endif
sscanf(params, "%1000s", s);
if (mustdel)
{
#ifndef __EMX__
Esnprintf(sss, sizeof(sss), "/bin/rm -rf %s", themepath);
#else
Esnprintf(sss, sizeof(sss), "rm.exe -rf %s", themepath);
#endif
system(sss);
}
if (!strcmp(s, "restart"))
{
SoundPlay("SOUND_WAIT");
w = MakeExtInitWin();
XCloseDisplay(disp);
disp = NULL;
if (themepath[0] != 0)
{
Esnprintf(sss, sizeof(sss),
"exec %s -single -ext_init_win %li -theme %s "
"-econfdir %s -ecachedir %s", command,
w, themename, UserEDir(), UserCacheDir());
execl(DEFAULT_SH_PATH, DEFAULT_SH_PATH, "-c", sss, NULL);
}
else
{
Esnprintf(sss, sizeof(sss),
"exec %s -single -ext_init_win %li "
"-econfdir %s -ecachedir %s", command,
w, UserEDir(), UserCacheDir());
execl(DEFAULT_SH_PATH, DEFAULT_SH_PATH, "-c", sss, NULL);
}
}
else if (!strcmp(s, "restart_theme"))
{
SoundPlay("SOUND_WAIT");
w = MakeExtInitWin();
XCloseDisplay(disp);
disp = NULL;
sscanf(params, "%*s %1000s", s);
Esnprintf(sss, sizeof(sss),
"exec %s -single -ext_init_win %li -theme %s "
"-econfdir %s -ecachedir %s", command, w, s,
UserEDir(), UserCacheDir());
execl(DEFAULT_SH_PATH, DEFAULT_SH_PATH, "-c", sss, NULL);
}
else if (!strcmp(s, "restart_wm"))
{
SoundPlay("SOUND_EXIT");
XCloseDisplay(disp);
disp = NULL;
if (atword(params, 2))
strncpy(s, atword(params, 2), 1000);
real_exec = (char *)Emalloc(strlen(s) + 6);
sprintf(real_exec,
"exec %s " "-econfdir %s -ecachedir %s", s,
UserEDir(), UserCacheDir());
execl(DEFAULT_SH_PATH, DEFAULT_SH_PATH, "-c", "exec", real_exec,
NULL);
}
else if (!strcmp(s, "logout"))
{
Dialog *d;
EWin *ewin;
if (!
(d =
FindItem("LOGOUT_DIALOG", 0, LIST_FINDBY_NAME,
LIST_TYPE_DIALOG)))
{
SoundPlay("SOUND_LOGOUT");
d = DialogCreate("LOGOUT_DIALOG");
DialogSetTitle(d, "Are you sure?");
DialogSetText(d,
"\n" "\n"
" Are you sure you wish to log out ? \n"
"\n" "\n");
DialogAddButton(d, " Yes, Log Out ", LogoutCB, 1);
DialogAddButton(d, " No ", NULL, 1);
DialogBindKey(d, "Escape", CB_SettingsEscape, 0, d);
DialogBindKey(d, "Return", LogoutCB, 0, d);
}
ShowDialog(d);
ewin = FindEwinByDialog(d);
if (ewin)
{
ArrangeEwinCentered(ewin, 1);
}
return;
}
}
SoundPlay("SOUND_EXIT");
EExit(0);
}
#endif /* HAVE_X11_SM_SMLIB_H */
int
SessionExit(void *param)
{
doSMExit(param);
return 0;
}