X-Git-Url: http://www.chiark.greenend.org.uk/ucgi/~ianmdlvl/git?a=blobdiff_plain;f=src%2Flogin%2Flogind-dbus.c;h=2ef87f72aa00a60982e51103f1375c1d444127e8;hb=22fdeadcc06e95fe41ac4de872ec245c0887547f;hp=c5f9cb393075bc5de5a0aec566bcc93cada19f1b;hpb=236af516b866473c22f980b556a2d7535cef4d9b;p=elogind.git diff --git a/src/login/logind-dbus.c b/src/login/logind-dbus.c index c5f9cb393..2ef87f72a 100644 --- a/src/login/logind-dbus.c +++ b/src/login/logind-dbus.c @@ -1305,6 +1305,46 @@ static int bus_manager_log_shutdown( q, NULL); } +static int lid_switch_ignore_handler(sd_event_source *e, uint64_t usec, void *userdata) { + Manager *m = userdata; + + assert(e); + assert(m); + + m->lid_switch_ignore_event_source = sd_event_source_unref(m->lid_switch_ignore_event_source); + return 0; +} + +int manager_set_lid_switch_ignore(Manager *m, usec_t until) { + int r; + + assert(m); + + if (until <= now(CLOCK_MONOTONIC)) + return 0; + + /* We want to ignore the lid switch for a while after each + * suspend, and after boot-up. Hence let's install a timer for + * this. As long as the event source exists we ignore the lid + * switch. */ + + if (m->lid_switch_ignore_event_source) { + usec_t u; + + r = sd_event_source_get_time(m->lid_switch_ignore_event_source, &u); + if (r < 0) + return r; + + if (until <= u) + return 0; + + r = sd_event_source_set_time(m->lid_switch_ignore_event_source, until); + } else + r = sd_event_add_monotonic(m->event, &m->lid_switch_ignore_event_source, until, 0, lid_switch_ignore_handler, m); + + return r; +} + static int execute_shutdown_or_sleep( Manager *m, InhibitWhat w,