diff --git a/src/login/logind-action.c b/src/login/logind-action.c index 36ee441..0844df2 100644 --- a/src/login/logind-action.c +++ b/src/login/logind-action.c @@ -71,24 +71,6 @@ int manager_handle_action( } if (inhibit_key == INHIBIT_HANDLE_LID_SWITCH) { - int n; - - /* If we are docked don't react to lid closing */ - if (manager_is_docked(m)) { - log_debug("Ignoring lid switch request, system is docked."); - return 0; - } - - /* If we have more than one display connected, - * don't react to lid closing. */ - n = manager_count_displays(m); - if (n < 0) - log_warning("Display counting failed: %s", strerror(-n)); - else if (n > 1) { - log_debug("Ignoring lid switch request, %i displays connected.", n); - return 0; - } - /* If the last system suspend or startup is too close, * let's not suspend for now, to give USB docking * stations some time to settle so that we can diff --git a/src/login/logind-core.c b/src/login/logind-core.c index 053d2ed..ed7ea5d 100644 --- a/src/login/logind-core.c +++ b/src/login/logind-core.c @@ -537,3 +537,25 @@ int manager_count_displays(Manager *m) { return n; } + +bool manager_is_docked_or_multiple_displays(Manager *m) { + int n; + + /* If we are docked don't react to lid closing */ + if (manager_is_docked(m)) { + log_debug("System is docked."); + return true; + } + + /* If we have more than one display connected, + * assume that we are docked. */ + n = manager_count_displays(m); + if (n < 0) + log_warning("Display counting failed: %s", strerror(-n)); + else if (n > 1) { + log_debug("Multiple (%i) displays connected.", n); + return true; + } + + return false; +} diff --git a/src/login/logind-dbus.c b/src/login/logind-dbus.c index bcfcba2..2a58489 100644 --- a/src/login/logind-dbus.c +++ b/src/login/logind-dbus.c @@ -1925,6 +1925,7 @@ const sd_bus_vtable manager_vtable[] = { SD_BUS_PROPERTY("HandleSuspendKey", "s", property_get_handle_action, offsetof(Manager, handle_suspend_key), SD_BUS_VTABLE_PROPERTY_CONST), SD_BUS_PROPERTY("HandleHibernateKey", "s", property_get_handle_action, offsetof(Manager, handle_hibernate_key), SD_BUS_VTABLE_PROPERTY_CONST), SD_BUS_PROPERTY("HandleLidSwitch", "s", property_get_handle_action, offsetof(Manager, handle_lid_switch), SD_BUS_VTABLE_PROPERTY_CONST), + SD_BUS_PROPERTY("HandleLidSwitchDocked", "s", property_get_handle_action, offsetof(Manager, handle_lid_switch_docked), SD_BUS_VTABLE_PROPERTY_CONST), SD_BUS_PROPERTY("IdleAction", "s", property_get_handle_action, offsetof(Manager, idle_action), SD_BUS_VTABLE_PROPERTY_CONST), SD_BUS_PROPERTY("IdleActionUSec", "t", NULL, offsetof(Manager, idle_action_usec), SD_BUS_VTABLE_PROPERTY_CONST), SD_BUS_PROPERTY("PreparingForShutdown", "b", property_get_preparing, 0, 0), diff --git a/src/login/logind-gperf.gperf b/src/login/logind-gperf.gperf index 006f728..6246067 100644 --- a/src/login/logind-gperf.gperf +++ b/src/login/logind-gperf.gperf @@ -24,6 +24,7 @@ Login.HandlePowerKey, config_parse_handle_action, 0, offsetof(Manag Login.HandleSuspendKey, config_parse_handle_action, 0, offsetof(Manager, handle_suspend_key) Login.HandleHibernateKey, config_parse_handle_action, 0, offsetof(Manager, handle_hibernate_key) Login.HandleLidSwitch, config_parse_handle_action, 0, offsetof(Manager, handle_lid_switch) +Login.HandleLidSwitchDocked, config_parse_handle_action, 0, offsetof(Manager, handle_lid_switch_docked) 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) diff --git a/src/login/logind.c b/src/login/logind.c index 8ec8105..e31b128 100644 --- a/src/login/logind.c +++ b/src/login/logind.c @@ -55,6 +55,7 @@ Manager *manager_new(void) { m->handle_suspend_key = HANDLE_SUSPEND; m->handle_hibernate_key = HANDLE_HIBERNATE; m->handle_lid_switch = HANDLE_SUSPEND; + m->handle_lid_switch_docked = HANDLE_IGNORE; m->lid_switch_ignore_inhibited = true; m->idle_action_usec = 30 * USEC_PER_MINUTE; @@ -232,7 +233,8 @@ static int manager_enumerate_buttons(Manager *m) { if (m->handle_power_key == HANDLE_IGNORE && m->handle_suspend_key == HANDLE_IGNORE && m->handle_hibernate_key == HANDLE_IGNORE && - m->handle_lid_switch == HANDLE_IGNORE) + m->handle_lid_switch == HANDLE_IGNORE && + m->handle_lid_switch_docked == HANDLE_IGNORE) return 0; e = udev_enumerate_new(m->udev); @@ -875,7 +877,8 @@ static int manager_connect_udev(Manager *m) { if (m->handle_power_key != HANDLE_IGNORE || m->handle_suspend_key != HANDLE_IGNORE || m->handle_hibernate_key != HANDLE_IGNORE || - m->handle_lid_switch != HANDLE_IGNORE) { + m->handle_lid_switch != HANDLE_IGNORE || + m->handle_lid_switch_docked != HANDLE_IGNORE) { m->udev_button_monitor = udev_monitor_new_from_netlink(m->udev, "udev"); if (!m->udev_button_monitor) diff --git a/src/login/logind.conf b/src/login/logind.conf index 79f96ec..4608a2c 100644 --- a/src/login/logind.conf +++ b/src/login/logind.conf @@ -18,6 +18,7 @@ #HandleSuspendKey=suspend #HandleHibernateKey=hibernate #HandleLidSwitch=suspend +#HandleLidSwitchDocked=ignore #PowerKeyIgnoreInhibited=no #SuspendKeyIgnoreInhibited=no #HibernateKeyIgnoreInhibited=no diff --git a/src/login/logind.h b/src/login/logind.h index 31353ef..f7e49e5 100644 --- a/src/login/logind.h +++ b/src/login/logind.h @@ -114,6 +114,9 @@ struct Manager { HandleAction handle_suspend_key; HandleAction handle_hibernate_key; HandleAction handle_lid_switch; + HandleAction handle_lid_switch_docked; + + bool lid_switch_suspend_if_docked; bool power_key_ignore_inhibited; bool suspend_key_ignore_inhibited; @@ -159,6 +162,7 @@ int manager_get_session_by_pid(Manager *m, pid_t pid, Session **session); bool manager_is_docked(Manager *m); int manager_count_displays(Manager *m); +bool manager_is_docked_or_multiple_displays(Manager *m); extern const sd_bus_vtable manager_vtable[];