chiark / gitweb /
logind: add HandleLidSwitchDocked= option to logind.conf + documentation
authorBen Wolsieffer <benwolsieffer@gmail.com>
Tue, 26 Aug 2014 20:08:02 +0000 (22:08 +0200)
committerLennart Poettering <lennart@poettering.net>
Tue, 26 Aug 2014 20:08:02 +0000 (22:08 +0200)
https://bugs.freedesktop.org/show_bug.cgi?id=82485

man/logind.conf.xml
src/login/logind-action.c
src/login/logind-button.c
src/login/logind-core.c
src/login/logind-dbus.c
src/login/logind-gperf.gperf
src/login/logind.c
src/login/logind.conf
src/login/logind.h

index f037da259b1ab30ab54c1a1665d4efdff7bcfe0e..8ba95230bee63a3af4dad1e168574dbd603424a2 100644 (file)
                                 <term><varname>HandleSuspendKey=</varname></term>
                                 <term><varname>HandleHibernateKey=</varname></term>
                                 <term><varname>HandleLidSwitch=</varname></term>
+                                <term><varname>HandleLidSwitchDocked=</varname></term>
 
                                 <listitem><para>Controls whether
                                 logind shall handle the system power
                                 and
                                 <varname>HandleLidSwitch=</varname>
                                 default to <literal>suspend</literal>.
+                                <varname>HandleLidSwitchDocked=</varname>
+                                defaults to <literal>ignore</literal>.
                                 <varname>HandleHibernateKey=</varname>
                                 defaults to
-                                <literal>hibernate</literal>. Note
-                                that the lid switch is ignored if the
-                                system is inserted in a docking
-                                station, or if more than one display
-                                is connected.</para></listitem>
+                                <literal>hibernate</literal>. If the
+                                system is inserted in a docking station,
+                                or if more than one display is connected,
+                                the action specified by
+                                <varname>HandleLidSwitchDocked=</varname>
+                                occurs; otherwise the
+                                <varname>HandleLidSwitch=</varname>
+                                action occurs.</para></listitem>
                         </varlistentry>
 
                         <varlistentry>
index 36ee4418b8bc6f85a3ecd47223d3dc2c5644c081..0844df20a9762ec3b0197c9346dec28d54617989 100644 (file)
@@ -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
index 2561d13c673f55c7ab807369d01a28bbe4621316..57e619efe690b801e80fa65cb5115afcb58a48ae 100644 (file)
@@ -97,13 +97,27 @@ int button_set_seat(Button *b, const char *sn) {
         return 0;
 }
 
+static void button_lid_switch_handle_action(Manager *manager, bool is_edge) {
+        HandleAction handle_action;
+
+        assert(manager);
+
+        /* If we are docked, handle the lid switch differently */
+        if (manager_is_docked_or_multiple_displays(manager))
+                handle_action = manager->handle_lid_switch_docked;
+        else
+                handle_action = manager->handle_lid_switch;
+
+        manager_handle_action(manager, INHIBIT_HANDLE_LID_SWITCH, handle_action, manager->lid_switch_ignore_inhibited, is_edge);
+}
+
 static int button_recheck(sd_event_source *e, void *userdata) {
         Button *b = userdata;
 
         assert(b);
         assert(b->lid_closed);
 
-        manager_handle_action(b->manager, INHIBIT_HANDLE_LID_SWITCH, b->manager->handle_lid_switch, b->manager->lid_switch_ignore_inhibited, false);
+        button_lid_switch_handle_action(b->manager, false);
         return 1;
 }
 
@@ -186,7 +200,7 @@ static int button_dispatch(sd_event_source *s, int fd, uint32_t revents, void *u
                                    NULL);
 
                         b->lid_closed = true;
-                        manager_handle_action(b->manager, INHIBIT_HANDLE_LID_SWITCH, b->manager->handle_lid_switch, b->manager->lid_switch_ignore_inhibited, true);
+                        button_lid_switch_handle_action(b->manager, true);
                         button_install_check_event_source(b);
 
                 } else if (ev.code == SW_DOCK) {
index 053d2ed63e189df1cfec0c53e8d3093deb672ca7..ed7ea5da31cd9ba45aaeb6838e6b78824cd186cb 100644 (file)
@@ -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;
+}
index acef5119b16b590b2998fcf8d8fd06daaac792a0..0b2b7b5afeea56208587a7c07fddfb44ef4dd77d 100644 (file)
@@ -1919,6 +1919,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),
index 006f7286c5d1db0a6bba1ebfe2e6ec0761b100c9..62460673b9bd4e78eb5098f899f26c85af766699 100644 (file)
@@ -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)
index 52e1c43a472289be13910c6e824cbc4fa111bca7..1f94a97bd0500bc17c5db2934c6e873067a5a560 100644 (file)
@@ -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)
index 79f96ec05bb366dd3fd89a723ba393032ef491f8..4608a2c0e2477a30c0300437fd0ed5edbbb57575 100644 (file)
@@ -18,6 +18,7 @@
 #HandleSuspendKey=suspend
 #HandleHibernateKey=hibernate
 #HandleLidSwitch=suspend
+#HandleLidSwitchDocked=ignore
 #PowerKeyIgnoreInhibited=no
 #SuspendKeyIgnoreInhibited=no
 #HibernateKeyIgnoreInhibited=no
index 31353eff028154697f5bd7b3df43831e48615d73..2f76572580bf24273635e6474dd01172fda7ae7b 100644 (file)
@@ -114,6 +114,7 @@ struct Manager {
         HandleAction handle_suspend_key;
         HandleAction handle_hibernate_key;
         HandleAction handle_lid_switch;
+        HandleAction handle_lid_switch_docked;
 
         bool power_key_ignore_inhibited;
         bool suspend_key_ignore_inhibited;
@@ -159,6 +160,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[];