session: Enable setting suspend and hibernate actions

If set the options are presented in the logout dialog.

Suggestion from Milan Maljković.
This commit is contained in:
Kim Woelders 2023-10-12 09:01:12 +02:00
parent b0f3dd2c2c
commit 91ef25bb42
4 changed files with 30 additions and 0 deletions

View File

@ -1083,6 +1083,10 @@ misc.session.enable_reboot_halt = 0
misc.session.cmd_reboot = reboot
# [string] Halt command
misc.session.cmd_halt = poweroff
# [string] Suspend command (if set, option is shown in logout dialog)
misc.session.cmd_suspend =
# [string] Hibernate command (if set, option is shown in logout dialog)
misc.session.cmd_hibernate =
# [bool] Enable animation of window shading
misc.shading.animate = 1

View File

@ -265,6 +265,8 @@ typedef struct {
char enable_reboot_halt;
char *cmd_reboot;
char *cmd_halt;
char *cmd_suspend;
char *cmd_hibernate;
} session;
struct {
char animate;

View File

@ -196,6 +196,8 @@ static const CfgItem MiscCfgItems[] = {
CFG_ITEM_BOOL(Conf, session.enable_reboot_halt, 0),
CFG_ITEM_STR(Conf, session.cmd_reboot),
CFG_ITEM_STR(Conf, session.cmd_halt),
CFG_ITEM_STR(Conf, session.cmd_suspend),
CFG_ITEM_STR(Conf, session.cmd_hibernate),
CFG_ITEM_BOOL(Conf, shading.animate, 1),
CFG_ITEM_INT(Conf, shading.speed, 8000),

View File

@ -561,6 +561,8 @@ SessionLogout(void)
#define LOGOUT_EXIT 1
#define LOGOUT_REBOOT 2
#define LOGOUT_HALT 3
#define LOGOUT_SUSPEND 4
#define LOGOUT_HIBERNATE 5
static void
LogoutCB(Dialog * d, int val, void *data __UNUSED__)
@ -588,12 +590,20 @@ LogoutCB(Dialog * d, int val, void *data __UNUSED__)
case LOGOUT_HALT:
SessionExit(EEXIT_EXEC, Conf.session.cmd_halt);
break;
case LOGOUT_SUSPEND:
SessionExit(EEXIT_EXEC, Conf.session.cmd_suspend);
break;
case LOGOUT_HIBERNATE:
SessionExit(EEXIT_EXEC, Conf.session.cmd_hibernate);
break;
}
}
DialogClose(d);
}
#define ISSET(s) (s && *s != '\0')
static void
SessionLogoutConfirm(void)
{
@ -615,6 +625,18 @@ SessionLogoutConfirm(void)
DialogItemSetAlign(table, 512, 0);
DialogItemSetFill(table, 0, 0);
tcols = 0;
if (ISSET(Conf.session.cmd_hibernate))
{
tcols += 1;
DialogItemAddButton(table, _("Yes, Hibernate"), LogoutCB,
LOGOUT_HIBERNATE, 1, DLG_BUTTON_OK);
}
if (ISSET(Conf.session.cmd_suspend))
{
tcols += 1;
DialogItemAddButton(table, _("Yes, Suspend"), LogoutCB,
LOGOUT_SUSPEND, 1, DLG_BUTTON_OK);
}
if (Conf.session.enable_reboot_halt)
{