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.
This commit is contained in:
Lennart Poettering 2014-02-24 16:22:23 +01:00
parent 539237644e
commit 2d62c530d2
7 changed files with 45 additions and 6 deletions

View File

@ -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)) {

View 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);
} 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;
}

View File

@ -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);

View File

@ -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;
}

View File

@ -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);

View 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);
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);

View 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_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)