[systemd-commits] src/login src/systemd

Lennart Poettering lennart at kemper.freedesktop.org
Mon Feb 24 07:36:37 PST 2014


 src/login/logind-action.c |    8 ++++++++
 src/login/logind-button.c |   23 +++++++++++++++++++----
 src/login/logind-button.h |    3 ++-
 src/login/logind-core.c   |   11 +++++++++++
 src/login/logind.c        |    2 +-
 src/login/logind.h        |    2 ++
 src/systemd/sd-messages.h |    2 ++
 7 files changed, 45 insertions(+), 6 deletions(-)

New commits:
commit 2d62c530d2b4c2730abff715b7342f1402114513
Author: Lennart Poettering <lennart at poettering.net>
Date:   Mon Feb 24 16:22:23 2014 +0100

    logind: detect whether the system is docked, and if it is inhibit lid switch processing
    
    This should make operation nicer with docking stations, but will not
    cover anything that does not implement SW_DOCK.

diff --git a/src/login/logind-action.c b/src/login/logind-action.c
index 3bad922..c04f210 100644
--- a/src/login/logind-action.c
+++ b/src/login/logind-action.c
@@ -70,6 +70,14 @@ int manager_handle_action(
                 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)) {
diff --git a/src/login/logind-button.c b/src/login/logind-button.c
index 720071a..060978d 100644
--- a/src/login/logind-button.c
+++ b/src/login/logind-button.c
@@ -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);
+
+                } 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) {
@@ -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);
+
+                } 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;
 }
 
-int button_check_lid(Button *b) {
+int button_check_switches(Button *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;
+        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);
-        }
 
         return 0;
 }
diff --git a/src/login/logind-button.h b/src/login/logind-button.h
index e85aa81..72a612e 100644
--- a/src/login/logind-button.h
+++ b/src/login/logind-button.h
@@ -38,10 +38,11 @@ struct Button {
         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);
-int button_check_lid(Button *b);
+int button_check_switches(Button *b);
diff --git a/src/login/logind-core.c b/src/login/logind-core.c
index 3f8e813..e4e593f 100644
--- a/src/login/logind-core.c
+++ b/src/login/logind-core.c
@@ -503,3 +503,14 @@ int manager_spawn_autovt(Manager *m, unsigned int vtnr) {
 
         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;
+}
diff --git a/src/login/logind.c b/src/login/logind.c
index 9cbd9e8..3a514bb 100644
--- a/src/login/logind.c
+++ b/src/login/logind.c
@@ -1039,7 +1039,7 @@ int manager_startup(Manager *m) {
                 inhibitor_start(inhibitor);
 
         HASHMAP_FOREACH(button, m->buttons, i)
-                button_check_lid(button);
+                button_check_switches(button);
 
         manager_dispatch_idle_action(NULL, 0, m);
 
diff --git a/src/login/logind.h b/src/login/logind.h
index 0bf52da..0344acc 100644
--- a/src/login/logind.h
+++ b/src/login/logind.h
@@ -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);
 
+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);
diff --git a/src/systemd/sd-messages.h b/src/systemd/sd-messages.h
index 947bd1a..a8379e0 100644
--- a/src/systemd/sd-messages.h
+++ b/src/systemd/sd-messages.h
@@ -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_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)



More information about the systemd-commits mailing list