logind: split up HandleSleepKey= into HandleSuspendKey= and HandleHibernateKey=

The kernel and X11 distuingish these two, and Thinkpad keys have both,
hence we really should distinguish them too.
This commit is contained in:
Lennart Poettering 2012-09-21 15:44:14 +02:00
parent 636d30a089
commit 8e7fd6ade4
10 changed files with 93 additions and 51 deletions

View File

@ -198,7 +198,8 @@
<varlistentry>
<term><varname>HandlePowerKey=</varname></term>
<term><varname>HandleSleepKey=</varname></term>
<term><varname>HandleSuspendKey=</varname></term>
<term><varname>HandleHibernateKey=</varname></term>
<term><varname>HandleLidSwitch=</varname></term>
<listitem><para>Controls whether
@ -222,15 +223,19 @@
events. <varname>HandlePowerKey=</varname>
defaults to
<literal>poweroff</literal>.
<varname>HandleSleepKey=</varname> and
<varname>HandleSuspendKey=</varname>
and
<varname>HandleLidSwitch=</varname>
default to
<literal>suspend</literal>.</para></listitem>
default to <literal>suspend</literal>.
<varname>HandleHibernateKey=</varname>
defaults to
<literal>hibernate</literal>.</para></listitem>
</varlistentry>
<varlistentry>
<term><varname>PowerKeyIgnoreInhibited=</varname></term>
<term><varname>SleepKeyIgnoreInhibited=</varname></term>
<term><varname>SuspendKeyIgnoreInhibited=</varname></term>
<term><varname>HibernateKeyIgnoreInhibited=</varname></term>
<term><varname>LidSwitchIgnoreInhibited=</varname></term>
<listitem><para>Controls whether
@ -244,9 +249,10 @@
respected, if <literal>on</literal>
the requested operation is executed in
any
case. <varname>PowerKeyIgnoreInhibited=</varname>
case. <varname>PowerKeyIgnoreInhibited=</varname>,
<varname>SuspendKeyIgnoreInhibited=</varname>
and
<varname>SleepKeyIgnoreInhibited=</varname>
<varname>HibernateKeyIgnoreInhibited=</varname>
defaults to <literal>off</literal>,
<varname>LidSwitchIgnoreInhibited=</varname>
defaults to

View File

@ -249,12 +249,21 @@ int button_process(Button *b) {
log_info("Power key pressed.");
return button_handle(b, INHIBIT_HANDLE_POWER_KEY, b->manager->handle_power_key, b->manager->power_key_ignore_inhibited, true);
case KEY_SLEEP:
case KEY_SUSPEND:
log_info("Sleep key pressed.");
return button_handle(b, INHIBIT_HANDLE_SLEEP_KEY, b->manager->handle_sleep_key, b->manager->sleep_key_ignore_inhibited, true);
/* The kernel is a bit confused here:
KEY_SLEEP = suspend-to-ram, which everybody else calls "suspend"
KEY_SUSPEND = suspend-to-disk, which everybody else calls "hibernate"
*/
case KEY_SLEEP:
log_info("Suspend key pressed.");
return button_handle(b, INHIBIT_HANDLE_SUSPEND_KEY, b->manager->handle_suspend_key, b->manager->suspend_key_ignore_inhibited, true);
case KEY_SUSPEND:
log_info("Hibernate key pressed.");
return button_handle(b, INHIBIT_HANDLE_HIBERNATE_KEY, b->manager->handle_hibernate_key, b->manager->hibernate_key_ignore_inhibited, true);
}
} else if (ev.type == EV_SW && ev.value > 0) {
switch (ev.code) {

View File

@ -210,7 +210,8 @@
" <property name=\"DelayInhibited\" type=\"s\" access=\"read\"/>\n" \
" <property name=\"InhibitDelayMaxUSec\" type=\"t\" access=\"read\"/>\n" \
" <property name=\"HandlePowerKey\" type=\"s\" access=\"read\"/>\n" \
" <property name=\"HandleSleepKey\" type=\"s\" access=\"read\"/>\n" \
" <property name=\"HandleSuspendKey\" type=\"s\" access=\"read\"/>\n" \
" <property name=\"HandleHibernateKey\" type=\"s\" access=\"read\"/>\n" \
" <property name=\"HandleLidSwitch\" type=\"s\" access=\"read\"/>\n" \
" <property name=\"PreparingForShutdown\" type=\"b\" access=\"read\"/>\n" \
" <property name=\"PreparingForSleep\" type=\"b\" access=\"read\"/>\n" \
@ -729,12 +730,13 @@ static int bus_manager_inhibit(Manager *m, DBusConnection *connection, DBusMessa
}
r = verify_polkit(connection, message,
w == INHIBIT_SHUTDOWN ? (mm == INHIBIT_BLOCK ? "org.freedesktop.login1.inhibit-block-shutdown" : "org.freedesktop.login1.inhibit-delay-shutdown") :
w == INHIBIT_SLEEP ? (mm == INHIBIT_BLOCK ? "org.freedesktop.login1.inhibit-block-sleep" : "org.freedesktop.login1.inhibit-delay-sleep") :
w == INHIBIT_IDLE ? "org.freedesktop.login1.inhibit-block-idle" :
w == INHIBIT_HANDLE_POWER_KEY ? "org.freedesktop.login1.inhibit-handle-power-key" :
w == INHIBIT_HANDLE_SLEEP_KEY ? "org.freedesktop.login1.inhibit-handle-sleep-key" :
"org.freedesktop.login1.inhibit-handle-lid-switch",
w == INHIBIT_SHUTDOWN ? (mm == INHIBIT_BLOCK ? "org.freedesktop.login1.inhibit-block-shutdown" : "org.freedesktop.login1.inhibit-delay-shutdown") :
w == INHIBIT_SLEEP ? (mm == INHIBIT_BLOCK ? "org.freedesktop.login1.inhibit-block-sleep" : "org.freedesktop.login1.inhibit-delay-sleep") :
w == INHIBIT_IDLE ? "org.freedesktop.login1.inhibit-block-idle" :
w == INHIBIT_HANDLE_POWER_KEY ? "org.freedesktop.login1.inhibit-handle-power-key" :
w == INHIBIT_HANDLE_SUSPEND_KEY ? "org.freedesktop.login1.inhibit-handle-suspend-key" :
w == INHIBIT_HANDLE_HIBERNATE_KEY ? "org.freedesktop.login1.inhibit-handle-hibernate-key" :
"org.freedesktop.login1.inhibit-handle-lid-switch",
false, NULL, error);
if (r < 0)
goto fail;
@ -1322,7 +1324,8 @@ static const BusProperty bus_login_manager_properties[] = {
{ "DelayInhibited", bus_manager_append_inhibited, "s", 0 },
{ "InhibitDelayMaxUSec", bus_property_append_usec, "t", offsetof(Manager, inhibit_delay_max) },
{ "HandlePowerKey", bus_manager_append_handle_button, "s", offsetof(Manager, handle_power_key) },
{ "HandleSleepKey", bus_manager_append_handle_button, "s", offsetof(Manager, handle_sleep_key) },
{ "HandleSuspendKey", bus_manager_append_handle_button, "s", offsetof(Manager, handle_suspend_key) },
{ "HandleHibernateKey", bus_manager_append_handle_button, "s", offsetof(Manager, handle_hibernate_key)},
{ "HandleLidSwitch", bus_manager_append_handle_button, "s", offsetof(Manager, handle_lid_switch) },
{ "PreparingForShutdown", bus_manager_append_preparing, "b", 0 },
{ "PreparingForSleep", bus_manager_append_preparing, "b", 0 },

View File

@ -14,17 +14,19 @@ struct ConfigPerfItem;
%struct-type
%includes
%%
Login.NAutoVTs, config_parse_unsigned, 0, offsetof(Manager, n_autovts)
Login.ReserveVT, config_parse_unsigned, 0, offsetof(Manager, reserve_vt)
Login.KillUserProcesses, config_parse_bool, 0, offsetof(Manager, kill_user_processes)
Login.KillOnlyUsers, config_parse_strv, 0, offsetof(Manager, kill_only_users)
Login.KillExcludeUsers, config_parse_strv, 0, offsetof(Manager, kill_exclude_users)
Login.Controllers, config_parse_strv, 0, offsetof(Manager, controllers)
Login.ResetControllers, config_parse_strv, 0, offsetof(Manager, reset_controllers)
Login.InhibitDelayMaxSec, config_parse_usec, 0, offsetof(Manager, inhibit_delay_max)
Login.HandlePowerKey, config_parse_handle_button, 0, offsetof(Manager, handle_power_key)
Login.HandleSleepKey, config_parse_handle_button, 0, offsetof(Manager, handle_sleep_key)
Login.HandleLidSwitch, config_parse_handle_button, 0, offsetof(Manager, handle_lid_switch)
Login.PowerKeyIgnoreInhibited, config_parse_bool, 0, offsetof(Manager, power_key_ignore_inhibited)
Login.SleepKeyIgnoreInhibited, config_parse_bool, 0, offsetof(Manager, sleep_key_ignore_inhibited)
Login.LidSwitchIgnoreInhibited, config_parse_bool, 0, offsetof(Manager, lid_switch_ignore_inhibited)
Login.NAutoVTs, config_parse_unsigned, 0, offsetof(Manager, n_autovts)
Login.ReserveVT, config_parse_unsigned, 0, offsetof(Manager, reserve_vt)
Login.KillUserProcesses, config_parse_bool, 0, offsetof(Manager, kill_user_processes)
Login.KillOnlyUsers, config_parse_strv, 0, offsetof(Manager, kill_only_users)
Login.KillExcludeUsers, config_parse_strv, 0, offsetof(Manager, kill_exclude_users)
Login.Controllers, config_parse_strv, 0, offsetof(Manager, controllers)
Login.ResetControllers, config_parse_strv, 0, offsetof(Manager, reset_controllers)
Login.InhibitDelayMaxSec, config_parse_usec, 0, offsetof(Manager, inhibit_delay_max)
Login.HandlePowerKey, config_parse_handle_button, 0, offsetof(Manager, handle_power_key)
Login.HandleSuspendKey, config_parse_handle_button, 0, offsetof(Manager, handle_suspend_key)
Login.HandleHibernateKey, config_parse_handle_button, 0, offsetof(Manager, handle_hibernate_key)
Login.HandleLidSwitch, config_parse_handle_button, 0, offsetof(Manager, handle_lid_switch)
Login.PowerKeyIgnoreInhibited, config_parse_bool, 0, offsetof(Manager, power_key_ignore_inhibited)
Login.SuspendKeyIgnoreInhibited, config_parse_bool, 0, offsetof(Manager, suspend_key_ignore_inhibited)
Login.HibernateKeyIgnoreInhibited, config_parse_bool, 0, offsetof(Manager, hibernate_key_ignore_inhibited)
Login.LidSwitchIgnoreInhibited, config_parse_bool, 0, offsetof(Manager, lid_switch_ignore_inhibited)

View File

@ -403,7 +403,7 @@ bool manager_is_inhibited(
}
const char *inhibit_what_to_string(InhibitWhat w) {
static __thread char buffer[73];
static __thread char buffer[97];
char *p;
if (w < 0 || w >= _INHIBIT_WHAT_MAX)
@ -418,8 +418,10 @@ const char *inhibit_what_to_string(InhibitWhat w) {
p = stpcpy(p, "idle:");
if (w & INHIBIT_HANDLE_POWER_KEY)
p = stpcpy(p, "handle-power-key:");
if (w & INHIBIT_HANDLE_SLEEP_KEY)
p = stpcpy(p, "handle-sleep-key:");
if (w & INHIBIT_HANDLE_SUSPEND_KEY)
p = stpcpy(p, "handle-suspend-key:");
if (w & INHIBIT_HANDLE_HIBERNATE_KEY)
p = stpcpy(p, "handle-hibernate-key:");
if (w & INHIBIT_HANDLE_LID_SWITCH)
p = stpcpy(p, "handle-lid-switch:");
@ -445,8 +447,10 @@ InhibitWhat inhibit_what_from_string(const char *s) {
what |= INHIBIT_IDLE;
else if (l == 16 && strncmp(w, "handle-power-key", l) == 0)
what |= INHIBIT_HANDLE_POWER_KEY;
else if (l == 16 && strncmp(w, "handle-sleep-key", l) == 0)
what |= INHIBIT_HANDLE_SLEEP_KEY;
else if (l == 18 && strncmp(w, "handle-suspend-key", l) == 0)
what |= INHIBIT_HANDLE_SUSPEND_KEY;
else if (l == 20 && strncmp(w, "handle-hibernate-key", l) == 0)
what |= INHIBIT_HANDLE_HIBERNATE_KEY;
else if (l == 17 && strncmp(w, "handle-lid-switch", l) == 0)
what |= INHIBIT_HANDLE_LID_SWITCH;
else

View File

@ -32,9 +32,10 @@ typedef enum InhibitWhat {
INHIBIT_SLEEP = 2,
INHIBIT_IDLE = 4,
INHIBIT_HANDLE_POWER_KEY = 8,
INHIBIT_HANDLE_SLEEP_KEY = 16,
INHIBIT_HANDLE_LID_SWITCH = 32,
_INHIBIT_WHAT_MAX = 64,
INHIBIT_HANDLE_SUSPEND_KEY = 16,
INHIBIT_HANDLE_HIBERNATE_KEY = 32,
INHIBIT_HANDLE_LID_SWITCH = 64,
_INHIBIT_WHAT_MAX = 128,
_INHIBIT_WHAT_INVALID = -1
} InhibitWhat;

View File

@ -56,7 +56,8 @@ Manager *manager_new(void) {
m->reserve_vt = 6;
m->inhibit_delay_max = 5 * USEC_PER_SEC;
m->handle_power_key = HANDLE_POWEROFF;
m->handle_sleep_key = HANDLE_SUSPEND;
m->handle_suspend_key = HANDLE_SUSPEND;
m->handle_hibernate_key = HANDLE_HIBERNATE;
m->handle_lid_switch = HANDLE_SUSPEND;
m->lid_switch_ignore_inhibited = true;
@ -496,7 +497,8 @@ int manager_enumerate_buttons(Manager *m) {
/* Loads buttons from udev */
if (m->handle_power_key == HANDLE_IGNORE &&
m->handle_sleep_key == HANDLE_IGNORE &&
m->handle_suspend_key == HANDLE_IGNORE &&
m->handle_hibernate_key == HANDLE_IGNORE &&
m->handle_lid_switch == HANDLE_IGNORE)
return 0;
@ -1306,7 +1308,8 @@ static int manager_connect_udev(Manager *m) {
/* Don't watch keys if nobody cares */
if (m->handle_power_key != HANDLE_IGNORE ||
m->handle_sleep_key != HANDLE_IGNORE ||
m->handle_suspend_key != HANDLE_IGNORE ||
m->handle_hibernate_key != HANDLE_IGNORE ||
m->handle_lid_switch != HANDLE_IGNORE) {
m->udev_button_monitor = udev_monitor_new_from_netlink(m->udev, "udev");

View File

@ -17,8 +17,10 @@
#ResetControllers=cpu
#InhibitDelayMaxSec=5
#HandlePowerKey=poweroff
#HandleSleepKey=suspend
#HandleSuspendKey=suspend
#HandleHibernateKey=hibernate
#HandleLidSwitch=suspend
#PowerKeyIgnoreInhibited=no
#SleepKeyIgnoreInhibited=no
#SuspendKeyIgnoreInhibited=no
#HibernateKeyIgnoreInhibited=no
#LidSwitchIgnoreInhibited=yes

View File

@ -100,11 +100,13 @@ struct Manager {
usec_t inhibit_delay_max;
HandleButton handle_power_key;
HandleButton handle_sleep_key;
HandleButton handle_suspend_key;
HandleButton handle_hibernate_key;
HandleButton handle_lid_switch;
bool power_key_ignore_inhibited;
bool sleep_key_ignore_inhibited;
bool suspend_key_ignore_inhibited;
bool hibernate_key_ignore_inhibited;
bool lid_switch_ignore_inhibited;
};

View File

@ -76,9 +76,19 @@
</defaults>
</action>
<action id="org.freedesktop.login1.inhibit-handle-sleep-key">
<_description>Allow applications to inhibit system handling of the sleep key</_description>
<_message>Authentication is required to allow an application to inhibit system handling of the sleep key.</_message>
<action id="org.freedesktop.login1.inhibit-handle-suspend-key">
<_description>Allow applications to inhibit system handling of the suspend key</_description>
<_message>Authentication is required to allow an application to inhibit system handling of the suspend key.</_message>
<defaults>
<allow_any>no</allow_any>
<allow_inactive>yes</allow_inactive>
<allow_active>yes</allow_active>
</defaults>
</action>
<action id="org.freedesktop.login1.inhibit-handle-hibernate-key">
<_description>Allow applications to inhibit system handling of the hibernate key</_description>
<_message>Authentication is required to allow an application to inhibit system handling of the hibernate key.</_message>
<defaults>
<allow_any>no</allow_any>
<allow_inactive>yes</allow_inactive>