chiark / gitweb /
logind: detect whether the system is docked, and if it is inhibit lid switch processing
authorLennart Poettering <lennart@poettering.net>
Mon, 24 Feb 2014 15:22:23 +0000 (16:22 +0100)
committerLennart Poettering <lennart@poettering.net>
Mon, 24 Feb 2014 15:22:23 +0000 (16:22 +0100)
This should make operation nicer with docking stations, but will not
cover anything that does not implement SW_DOCK.

src/login/logind-action.c
src/login/logind-button.c
src/login/logind-button.h
src/login/logind-core.c
src/login/logind.c
src/login/logind.h
src/systemd/sd-messages.h

index 3bad92271349bbfc072ba1940d3d53b571ab2fbd..c04f2107d1787d6f861c21a2568f383d88b157eb 100644 (file)
@@ -70,6 +70,14 @@ int manager_handle_action(
                 return 0;
         }
 
                 return 0;
         }
 
+        /* If we are docked don't react to lid closing */
+        if (inhibit_key == INHIBIT_HANDLE_LID_SWITCH) {
+                if (manager_is_docked(m)) {
+                        log_debug("Ignoring lid switch request, system is docked.");
+                        return 0;
+                }
+        }
+
         /* If the key handling is inhibited, don't do anything */
         if (inhibit_key > 0) {
                 if (manager_is_inhibited(m, inhibit_key, INHIBIT_BLOCK, NULL, true, false, 0, NULL)) {
         /* If the key handling is inhibited, don't do anything */
         if (inhibit_key > 0) {
                 if (manager_is_inhibited(m, inhibit_key, INHIBIT_BLOCK, NULL, true, false, 0, NULL)) {
index 720071a2a846faeb8cd9b0b9e51ba0c32bdc8a62..060978dd349ac8b6be5df5386c9366e3745a8136 100644 (file)
@@ -188,6 +188,14 @@ static int button_dispatch(sd_event_source *s, int fd, uint32_t revents, void *u
                         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_install_check_event_source(b);
                         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_install_check_event_source(b);
+
+                } else if (ev.code == SW_DOCK) {
+                        log_struct(LOG_INFO,
+                                   "MESSAGE=System docked.",
+                                   MESSAGE_ID(SD_MESSAGE_SYSTEM_DOCKED),
+                                   NULL);
+
+                        b->docked = true;
                 }
 
         } else if (ev.type == EV_SW && ev.value == 0) {
                 }
 
         } else if (ev.type == EV_SW && ev.value == 0) {
@@ -200,6 +208,14 @@ static int button_dispatch(sd_event_source *s, int fd, uint32_t revents, void *u
 
                         b->lid_closed = false;
                         b->check_event_source = sd_event_source_unref(b->check_event_source);
 
                         b->lid_closed = false;
                         b->check_event_source = sd_event_source_unref(b->check_event_source);
+
+                } else if (ev.code == SW_DOCK) {
+                        log_struct(LOG_INFO,
+                                   "MESSAGE=System undocked.",
+                                   MESSAGE_ID(SD_MESSAGE_SYSTEM_UNDOCKED),
+                                   NULL);
+
+                        b->docked = false;
                 }
         }
 
                 }
         }
 
@@ -247,7 +263,7 @@ fail:
         return r;
 }
 
         return r;
 }
 
-int button_check_lid(Button *b) {
+int button_check_switches(Button *b) {
         uint8_t switches[SW_MAX/8+1] = {};
         assert(b);
 
         uint8_t switches[SW_MAX/8+1] = {};
         assert(b);
 
@@ -258,11 +274,10 @@ int button_check_lid(Button *b) {
                 return -errno;
 
         b->lid_closed = (switches[SW_LID/8] >> (SW_LID % 8)) & 1;
                 return -errno;
 
         b->lid_closed = (switches[SW_LID/8] >> (SW_LID % 8)) & 1;
+        b->docked = (switches[SW_DOCK/8] >> (SW_DOCK % 8)) & 1;
 
 
-        if (b->lid_closed) {
-                manager_handle_action(b->manager, INHIBIT_HANDLE_LID_SWITCH, b->manager->handle_lid_switch, b->manager->lid_switch_ignore_inhibited, true);
+        if (b->lid_closed)
                 button_install_check_event_source(b);
                 button_install_check_event_source(b);
-        }
 
         return 0;
 }
 
         return 0;
 }
index e85aa81d0a8e75b5fc6ad310111a43c8918e5343..72a612e9148acedf6d71607dd1756074333c4ab5 100644 (file)
@@ -38,10 +38,11 @@ struct Button {
         int fd;
 
         bool lid_closed;
         int fd;
 
         bool lid_closed;
+        bool docked;
 };
 
 Button* button_new(Manager *m, const char *name);
 void button_free(Button*b);
 int button_open(Button *b);
 int button_set_seat(Button *b, const char *sn);
 };
 
 Button* button_new(Manager *m, const char *name);
 void button_free(Button*b);
 int button_open(Button *b);
 int button_set_seat(Button *b, const char *sn);
-int button_check_lid(Button *b);
+int button_check_switches(Button *b);
index 3f8e8139da255f02737f95e149ba14911f65edd7..e4e593fa5b6d8ec8b9ba2233e97c9a21d294c3a7 100644 (file)
@@ -503,3 +503,14 @@ int manager_spawn_autovt(Manager *m, unsigned int vtnr) {
 
         return r;
 }
 
         return r;
 }
+
+bool manager_is_docked(Manager *m) {
+        Iterator i;
+        Button *b;
+
+        HASHMAP_FOREACH(b, m->buttons, i)
+                if (b->docked)
+                        return true;
+
+        return false;
+}
index 9cbd9e817fc2c8028e68104a1e6021cbf828e860..3a514bbf81311cca8b43978519d9e1efb3659294 100644 (file)
@@ -1039,7 +1039,7 @@ int manager_startup(Manager *m) {
                 inhibitor_start(inhibitor);
 
         HASHMAP_FOREACH(button, m->buttons, i)
                 inhibitor_start(inhibitor);
 
         HASHMAP_FOREACH(button, m->buttons, i)
-                button_check_lid(button);
+                button_check_switches(button);
 
         manager_dispatch_idle_action(NULL, 0, m);
 
 
         manager_dispatch_idle_action(NULL, 0, m);
 
index 0bf52daeb1a21cd100405ecaae3f35e40ec5d290..0344acc8bd513845b45ca6c4c4c85165178f389d 100644 (file)
@@ -148,6 +148,8 @@ int manager_get_idle_hint(Manager *m, dual_timestamp *t);
 int manager_get_user_by_pid(Manager *m, pid_t pid, User **user);
 int manager_get_session_by_pid(Manager *m, pid_t pid, Session **session);
 
 int manager_get_user_by_pid(Manager *m, pid_t pid, User **user);
 int manager_get_session_by_pid(Manager *m, pid_t pid, Session **session);
 
+bool manager_is_docked(Manager *m);
+
 extern const sd_bus_vtable manager_vtable[];
 
 int match_job_removed(sd_bus *bus, sd_bus_message *message, void *userdata, sd_bus_error *error);
 extern const sd_bus_vtable manager_vtable[];
 
 int match_job_removed(sd_bus *bus, sd_bus_message *message, void *userdata, sd_bus_error *error);
index 947bd1a9e51906b3aa997bc6356c9eb22b53fe97..a8379e098cd047f787c2c66328635e5f561966ff 100644 (file)
@@ -75,6 +75,8 @@ _SD_BEGIN_DECLARATIONS;
 
 #define SD_MESSAGE_LID_OPENED       SD_ID128_MAKE(b7,2e,a4,a2,88,15,45,a0,b5,0e,20,0e,55,b9,b0,6f)
 #define SD_MESSAGE_LID_CLOSED       SD_ID128_MAKE(b7,2e,a4,a2,88,15,45,a0,b5,0e,20,0e,55,b9,b0,70)
 
 #define SD_MESSAGE_LID_OPENED       SD_ID128_MAKE(b7,2e,a4,a2,88,15,45,a0,b5,0e,20,0e,55,b9,b0,6f)
 #define SD_MESSAGE_LID_CLOSED       SD_ID128_MAKE(b7,2e,a4,a2,88,15,45,a0,b5,0e,20,0e,55,b9,b0,70)
+#define SD_MESSAGE_SYSTEM_DOCKED    SD_ID128_MAKE(f5,f4,16,b8,62,07,4b,28,92,7a,48,c3,ba,7d,51,ff)
+#define SD_MESSAGE_SYSTEM_UNDOCKED  SD_ID128_MAKE(51,e1,71,bd,58,52,48,56,81,10,14,4c,51,7c,ca,53)
 #define SD_MESSAGE_POWER_KEY        SD_ID128_MAKE(b7,2e,a4,a2,88,15,45,a0,b5,0e,20,0e,55,b9,b0,71)
 #define SD_MESSAGE_SUSPEND_KEY      SD_ID128_MAKE(b7,2e,a4,a2,88,15,45,a0,b5,0e,20,0e,55,b9,b0,72)
 #define SD_MESSAGE_HIBERNATE_KEY    SD_ID128_MAKE(b7,2e,a4,a2,88,15,45,a0,b5,0e,20,0e,55,b9,b0,73)
 #define SD_MESSAGE_POWER_KEY        SD_ID128_MAKE(b7,2e,a4,a2,88,15,45,a0,b5,0e,20,0e,55,b9,b0,71)
 #define SD_MESSAGE_SUSPEND_KEY      SD_ID128_MAKE(b7,2e,a4,a2,88,15,45,a0,b5,0e,20,0e,55,b9,b0,72)
 #define SD_MESSAGE_HIBERNATE_KEY    SD_ID128_MAKE(b7,2e,a4,a2,88,15,45,a0,b5,0e,20,0e,55,b9,b0,73)