Compare commits

...

11 Commits

Author SHA1 Message Date
Kim Woelders e318bb07fe session: Rearrange logout functions
We can now also do shutdown when we don't have dialogs enabled.
2024-04-02 15:31:18 +02:00
Kim Woelders d73aff1391 session: Move some #defines 2024-04-02 14:44:09 +02:00
Kim Woelders f0a3f894b4 session: Introduce SessionLogout() 2024-04-02 14:40:19 +02:00
Kim Woelders af8665e634 session: Add shutdown command 2024-04-02 14:40:19 +02:00
Kim Woelders e0cd65cc10 session: Rename some macros 2024-04-02 14:40:19 +02:00
Kim Woelders 5aaa2857e6 session: Add some SM connection debug messages 2024-04-02 14:40:19 +02:00
Kim Woelders d836ee5ea1 session: Add missing newline in error message 2024-03-29 19:10:26 +01:00
Kim Woelders 8aacad3ef1 session: Mark some private functions as such 2024-03-16 08:38:55 +01:00
Kim Woelders 93f8594e4d session: Eliminate SessionSave() 2024-03-16 08:38:33 +01:00
Kim Woelders 7a6a475b20 session: Eliminate SetSMID() 2024-03-16 08:38:12 +01:00
Kim Woelders 73dade6c92 Spec file: Set high rpm release number for non-release rpms
Should normally avoid that distro rpms get installed over private build
ones.
2024-03-09 09:55:56 +01:00
8 changed files with 147 additions and 133 deletions

View File

@ -35,7 +35,7 @@ version.h: FORCE
dist-hook: $(top_builddir)/$(PACKAGE).spec
RPR_DEV = `echo -n "1.%(date '+%y%m%d').git"; git rev-parse --short=8 HEAD`
RPR_DEV = `echo -n "99.%(date '+%y%m%d').git"; git rev-parse --short=8 HEAD`
RPR_REL = 1
SED_DEV = "s/\@PACKAGE\@/@PACKAGE@/;s/\@VERSION\@/@VERSION@/;s/\@RPM_RELEASE\@/$(RPR_DEV)/"
SED_REL = "s/\@PACKAGE\@/@PACKAGE@/;s/\@VERSION\@/@VERSION@/;s/\@RPM_RELEASE\@/$(RPR_REL)/"

View File

@ -8,3 +8,4 @@
"Theme menu" NULL menu theme.menu
"Restart" NULL "exit restart"
"Log out" NULL "exit logout"
"Shut down" NULL "exit shutdown"

View File

@ -105,6 +105,7 @@ const char *txt[] = {
_("Theme menu"),
_("Restart"),
_("Log out"),
_("Shut down"),
/* winops.menu */
_("Window Options"),
_("Close"),

View File

@ -3,7 +3,7 @@
/*****************************************************************************/
/*
* Copyright (C) 2000-2007 Carsten Haitzler, Geoff Harrison and various contributors
* Copyright (C) 2004-2023 Kim Woelders
* Copyright (C) 2004-2024 Kim Woelders
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to
@ -400,6 +400,11 @@ typedef struct {
EX_Pixmap ext_pmap;
char ext_pmap_valid;
} root;
#if USE_SM
struct {
char *sm_client_id;
} session;
#endif
struct {
bool cache_rebuild;
char *paths;

View File

@ -1,6 +1,6 @@
/*
* Copyright (C) 2000-2007 Carsten Haitzler, Geoff Harrison and various contributors
* Copyright (C) 2004-2023 Kim Woelders
* Copyright (C) 2004-2024 Kim Woelders
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to
@ -1097,14 +1097,16 @@ IPC_Exit(const char *params)
if (!param1[0])
SessionExit(EEXIT_EXIT, NULL);
else if (!strcmp(param1, "logout"))
SessionExit(EEXIT_LOGOUT, NULL);
else if (!strcmp(param1, "restart"))
SessionExit(EEXIT_RESTART, NULL);
else if (!strcmp(param1, "theme"))
SessionExit(EEXIT_THEME, p2);
else if (!strcmp(param1, "exec"))
SessionExit(EEXIT_EXEC, p2);
else if (!strcmp(param1, "logout"))
SessionLogout(ESESSION_LOGOUT);
else if (!strcmp(param1, "shutdown"))
SessionLogout(ESESSION_SHUTDOWN);
}
#if ENABLE_DIALOGS

View File

@ -1,6 +1,6 @@
/*
* Copyright (C) 2000-2007 Carsten Haitzler, Geoff Harrison and various contributors
* Copyright (C) 2004-2022 Kim Woelders
* Copyright (C) 2004-2024 Kim Woelders
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to
@ -195,7 +195,9 @@ main(int argc, char **argv)
Dpy.screen = Strtoi(eoptarg, 10);
break;
case 'S':
SetSMID(eoptarg);
#if USE_SM
Mode.session.sm_client_id = Estrdup(eoptarg);
#endif
break;
case 't':
theme = Estrdup(eoptarg);
@ -470,9 +472,9 @@ static void
RunInitPrograms(void)
{
if (Mode.wm.session_start)
SessionHelper(ESESSION_INIT);
SessionHelper(ESESSHLP_INIT);
SessionHelper(ESESSION_START);
SessionHelper(ESESSHLP_START);
if (Mode.firsttime && Mode.wm.master)
{

View File

@ -1,6 +1,6 @@
/*
* Copyright (C) 2000-2007 Carsten Haitzler, Geoff Harrison and various contributors
* Copyright (C) 2004-2023 Kim Woelders
* Copyright (C) 2004-2024 Kim Woelders
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to
@ -49,7 +49,6 @@ static char restarting = 0;
*/
#define USE_DISCARD_PROPERTY 0
static char *sm_client_id = NULL;
static SmcConn sm_conn = NULL;
static int sm_efd = 0;
@ -204,7 +203,7 @@ set_save_props(SmcConn smc_conn, int master_flag)
restartVal[n++].value = (char *)"-Q";
restartVal[n++].value = (char *)s;
}
s = sm_client_id;
s = Mode.session.sm_client_id;
restartVal[n++].value = (char *)"-S";
restartVal[n++].value = (char *)s;
@ -304,6 +303,9 @@ ice_io_error_handler(IceConn connection __UNUSED__)
static void
ice_exit(void)
{
if (EDebug(EDBUG_TYPE_SESSION))
Eprintf("%s: smc=%p\n", __func__, sm_conn);
SmcCloseConnection(sm_conn, 0, NULL);
sm_conn = NULL;
EventFdUnregister(sm_efd);
@ -342,7 +344,7 @@ ice_init(void)
int sm_fd;
if (!getenv("SESSION_MANAGER"))
return;
goto done;
IceSetIOErrorHandler(ice_io_error_handler);
@ -362,15 +364,16 @@ ice_init(void)
SmcSaveYourselfProcMask | SmcDieProcMask |
SmcSaveCompleteProcMask |
SmcShutdownCancelledProcMask, &callbacks,
sm_client_id, &client_id, 4096, error_string_ret);
Mode.session.sm_client_id, &client_id,
4096, error_string_ret);
EFREE_SET(sm_client_id, client_id);
EFREE_SET(Mode.session.sm_client_id, client_id);
if (error_string_ret[0])
Eprintf("While connecting to session manager: %s.", error_string_ret);
Eprintf("While connecting to session manager: %s\n", error_string_ret);
if (!sm_conn)
return;
goto done;
style[0] = SmRestartIfRunning;
style[1] = 0;
@ -392,6 +395,10 @@ ice_init(void)
fcntl(sm_fd, F_SETFD, fcntl(sm_fd, F_GETFD, 0) | FD_CLOEXEC);
sm_efd = EventFdRegister(sm_fd, ice_msgs_process);
done:
if (EDebug(EDBUG_TYPE_SESSION))
Eprintf("%s: smc=%p\n", __func__, sm_conn);
}
#endif /* USE_SM */
@ -414,33 +421,6 @@ SessionInit(void)
#endif
}
#if USE_SM
void
SetSMID(const char *smid)
{
sm_client_id = Estrdup(smid);
}
#else
void
SetSMID(const char *smid __UNUSED__)
{
}
#endif /* USE_SM */
static void
SessionSave(int shutdown)
{
if (EDebug(EDBUG_TYPE_SESSION))
Eprintf("%s: %d\n", __func__, shutdown);
SnapshotsSaveReal();
#if USE_SM
if (shutdown && sm_conn)
ice_exit();
#endif /* USE_SM */
}
/*
* Normally, the SM will throw away all the session data for a client
* that breaks its connection unexpectedly. In order to avoid this we
@ -462,10 +442,15 @@ doSMExit(int mode, const char *params)
restarting = 1;
SessionSave(1);
SnapshotsSaveReal();
#if USE_SM
if (sm_conn)
ice_exit();
#endif
if (mode != EEXIT_THEME && mode != EEXIT_RESTART)
SessionHelper(ESESSION_STOP);
SessionHelper(ESESSHLP_STOP);
LangExit();
@ -518,8 +503,9 @@ doSMExit(int mode, const char *params)
l += Esnprintf(s + l, sizeof(s) - l, " -w %dx%d",
WinGetW(VROOT), WinGetH(VROOT));
#if USE_SM
if (sm_client_id)
l += Esnprintf(s + l, sizeof(s) - l, " -S %s", sm_client_id);
if (Mode.session.sm_client_id)
l += Esnprintf(s + l, sizeof(s) - l, " -S %s",
Mode.session.sm_client_id);
#endif
#ifdef USE_EXT_INIT_WIN
if (new_init_win_ext != NoXID)
@ -540,24 +526,6 @@ doSMExit(int mode, const char *params)
EExit(0);
}
static void
SessionLogout(void)
{
#if USE_SM
if (sm_conn)
{
SmcRequestSaveYourself(sm_conn, SmSaveBoth, True, SmInteractStyleAny,
False, True);
}
else
#endif /* USE_SM */
{
SessionExit(EEXIT_EXIT, NULL);
}
}
#if ENABLE_DIALOGS
#define LOGOUT_EXIT 1
#define LOGOUT_REBOOT 2
#define LOGOUT_HALT 3
@ -566,48 +534,63 @@ SessionLogout(void)
#define LOGOUT_HIBERNATE 6
static void
LogoutCB(Dialog *d, int val, void *data __UNUSED__)
_SessionLogout(int how)
{
#if USE_SM
if (EDebug(EDBUG_TYPE_SESSION))
Eprintf("%s: how=%d smc=%p\n", __func__, how, sm_conn);
if (sm_conn)
{
SmcRequestSaveYourself(sm_conn, SmSaveBoth, True, SmInteractStyleAny,
False, True);
return;
}
#else
if (EDebug(EDBUG_TYPE_SESSION))
Eprintf("%s: how=%d\n", __func__, how);
#endif /* USE_SM */
switch (how)
{
default:
break;
case LOGOUT_EXIT:
SessionExit(EEXIT_EXIT, NULL);
break;
case LOGOUT_REBOOT:
SessionExit(EEXIT_EXEC, Conf.session.cmd_reboot);
break;
case LOGOUT_HALT:
SessionExit(EEXIT_EXEC, Conf.session.cmd_halt);
break;
case LOGOUT_LOCK:
Espawn("%s", Conf.session.cmd_lock);
break;
case LOGOUT_SUSPEND:
Espawn("%s", Conf.session.cmd_suspend);
break;
case LOGOUT_HIBERNATE:
Espawn("%s", Conf.session.cmd_hibernate);
break;
}
}
#if ENABLE_DIALOGS
static void
_SessionLogoutCB(Dialog *d, int val, void *data __UNUSED__)
{
DialogClose(d);
#if USE_SM
if (sm_conn)
{
SessionLogout();
}
else
#endif /* USE_SM */
{
switch (val)
{
default:
break;
case LOGOUT_EXIT:
SessionExit(EEXIT_EXIT, NULL);
break;
case LOGOUT_REBOOT:
SessionExit(EEXIT_EXEC, Conf.session.cmd_reboot);
break;
case LOGOUT_HALT:
SessionExit(EEXIT_EXEC, Conf.session.cmd_halt);
break;
case LOGOUT_LOCK:
Espawn("%s", Conf.session.cmd_lock);
break;
case LOGOUT_SUSPEND:
Espawn("%s", Conf.session.cmd_suspend);
break;
case LOGOUT_HIBERNATE:
Espawn("%s", Conf.session.cmd_hibernate);
break;
}
}
_SessionLogout(val);
}
#define ISSET(s) ((s && *s != '\0') ? 1 : 0)
static void
SessionLogoutConfirm(void)
_SessionLogoutConfirm(void)
{
Dialog *d;
DItem *table, *di;
@ -646,19 +629,19 @@ SessionLogoutConfirm(void)
if (ISSET(Conf.session.cmd_hibernate))
{
tcols += 1;
DialogItemAddButton(table, _("Hibernate"), LogoutCB,
DialogItemAddButton(table, _("Hibernate"), _SessionLogoutCB,
LOGOUT_HIBERNATE, 1, DLG_BUTTON_OK);
}
if (ISSET(Conf.session.cmd_suspend))
{
tcols += 1;
DialogItemAddButton(table, _("Suspend"), LogoutCB,
DialogItemAddButton(table, _("Suspend"), _SessionLogoutCB,
LOGOUT_SUSPEND, 1, DLG_BUTTON_OK);
}
if (ISSET(Conf.session.cmd_lock))
{
tcols += 1;
DialogItemAddButton(table, _("Lock"), LogoutCB,
DialogItemAddButton(table, _("Lock"), _SessionLogoutCB,
LOGOUT_LOCK, 1, DLG_BUTTON_OK);
}
for (; tcols < ncols; tcols++)
@ -669,13 +652,13 @@ SessionLogoutConfirm(void)
if (Conf.session.enable_reboot_halt)
{
tcols += 2;
DialogItemAddButton(table, _("Yes, Shut Down"), LogoutCB,
DialogItemAddButton(table, _("Yes, Shut Down"), _SessionLogoutCB,
LOGOUT_HALT, 1, DLG_BUTTON_OK);
DialogItemAddButton(table, _("Yes, Reboot"), LogoutCB,
DialogItemAddButton(table, _("Yes, Reboot"), _SessionLogoutCB,
LOGOUT_REBOOT, 1, DLG_BUTTON_OK);
}
tcols += 1;
DialogItemAddButton(table, _("Yes, Log Out"), LogoutCB,
DialogItemAddButton(table, _("Yes, Log Out"), _SessionLogoutCB,
LOGOUT_EXIT, 1, DLG_BUTTON_OK);
for (; tcols < ncols; tcols++)
DialogAddItem(table, DITEM_NONE);
@ -684,7 +667,7 @@ SessionLogoutConfirm(void)
DialogItemSetColSpan(di, ncols);
DialogBindKey(d, "Escape", DialogCallbackClose, 0, NULL);
DialogBindKey(d, "Return", LogoutCB, LOGOUT_EXIT, NULL);
DialogBindKey(d, "Return", _SessionLogoutCB, LOGOUT_EXIT, NULL);
}
DialogShowCentered(d);
@ -728,15 +711,6 @@ SessionExit(int mode, const char *param)
Eprintf("%s: already in progress ... now exiting\n", __func__);
exit(1);
break;
case EEXIT_LOGOUT:
#if ENABLE_DIALOGS
if (Conf.session.enable_logout_dialog)
SessionLogoutConfirm();
else
#endif
SessionLogout();
return;
}
done:
@ -744,8 +718,36 @@ SessionExit(int mode, const char *param)
doSMExit(mode, param);
}
void
SessionLogout(int mode)
{
switch (mode)
{
default: /* We should not go here - ignore */
break;
case ESESSION_LOGOUT:
#if ENABLE_DIALOGS
if (Conf.session.enable_logout_dialog)
_SessionLogoutConfirm();
else
#endif
_SessionLogout(LOGOUT_EXIT);
break;
case ESESSION_SHUTDOWN:
#if ENABLE_DIALOGS
if (Conf.session.enable_logout_dialog)
_SessionLogoutConfirm();
else
#endif
_SessionLogout(LOGOUT_HALT);
break;
}
}
static void
SessionRunProg(const char *prog, const char *params)
_SessionRunProg(const char *prog, const char *params)
{
if (EDebug(EDBUG_TYPE_SESSION))
Eprintf("%s: %s %s\n", __func__, prog, params);
@ -757,17 +759,17 @@ SessionHelper(int when)
{
switch (when)
{
case ESESSION_INIT:
case ESESSHLP_INIT:
if (Conf.session.enable_script && Conf.session.script)
SessionRunProg(Conf.session.script, "init");
_SessionRunProg(Conf.session.script, "init");
break;
case ESESSION_START:
case ESESSHLP_START:
if (Conf.session.enable_script && Conf.session.script)
SessionRunProg(Conf.session.script, "start");
_SessionRunProg(Conf.session.script, "start");
break;
case ESESSION_STOP:
case ESESSHLP_STOP:
if (Conf.session.enable_script && Conf.session.script)
SessionRunProg(Conf.session.script, "stop");
_SessionRunProg(Conf.session.script, "stop");
break;
}
}

View File

@ -1,6 +1,6 @@
/*
* Copyright (C) 2000-2007 Carsten Haitzler, Geoff Harrison and various contributors
* Copyright (C) 2004-2007 Kim Woelders
* Copyright (C) 2004-2024 Kim Woelders
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to
@ -24,22 +24,23 @@
#ifndef _SESSION_H_
#define _SESSION_H_
/* session.c */
#define EEXIT_QUIT 0
#define EEXIT_EXIT 1
#define EEXIT_ERROR 2
#define EEXIT_LOGOUT 3
#define EEXIT_RESTART 4
#define EEXIT_THEME 5
#define EEXIT_EXEC 6
#define EEXIT_RESTART 3
#define EEXIT_THEME 4
#define EEXIT_EXEC 5
#define ESESSION_INIT 0
#define ESESSION_START 1
#define ESESSION_STOP 2
#define ESESSION_LOGOUT 0
#define ESESSION_SHUTDOWN 1
#define ESESSHLP_INIT 0
#define ESESSHLP_START 1
#define ESESSHLP_STOP 2
void SessionInit(void);
void SessionExit(int mode, const char *params);
void SessionLogout(int mode);
void SessionHelper(int when);
void SetSMID(const char *smid);
#endif /* _SESSION_H_ */