summaryrefslogtreecommitdiff
path: root/src/login/logind-core.c
diff options
context:
space:
mode:
authorSimon Fowler <simon.fowler@anu.edu.au>2018-02-10 02:37:39 +1000
committerZbigniew Jędrzejewski-Szmek <zbyszek@in.waw.pl>2018-02-09 17:37:39 +0100
commite25937a3ed740ed0618a8943dee32e8966541cdf (patch)
tree42d9943892d70e5eda8a1f745b6b3940961d6f06 /src/login/logind-core.c
parent9e42c9373c10f3287ffdd3ecd677e4b5ed0ccf42 (diff)
downloadsystemd-e25937a3ed740ed0618a8943dee32e8966541cdf.tar.gz
Suspend on lid close based on power status. (#8016)
This change adds support for controlling the suspend-on-lid-close behaviour based on the power status as well as whether the machine is docked or has an external monitor. For backwards compatibility the new configuration file variable is ignored completely by default, and must be set explicitly before being considered in any decisions.
Diffstat (limited to 'src/login/logind-core.c')
-rw-r--r--src/login/logind-core.c31
1 files changed, 31 insertions, 0 deletions
diff --git a/src/login/logind-core.c b/src/login/logind-core.c
index e338682f41..cd10536ce5 100644
--- a/src/login/logind-core.c
+++ b/src/login/logind-core.c
@@ -602,3 +602,34 @@ bool manager_is_docked_or_external_displays(Manager *m) {
return false;
}
+
+bool manager_is_on_external_power(void) {
+ int r;
+
+ /* For now we only check for AC power, but 'external power' can apply
+ * to anything that isn't an internal battery */
+ r = on_ac_power();
+ if (r < 0)
+ log_warning_errno(r, "Failed to read AC power status: %m");
+ else if (r > 0)
+ return true;
+
+ return false;
+}
+
+bool manager_all_buttons_ignored(Manager *m) {
+ if (m->handle_power_key != HANDLE_IGNORE)
+ return false;
+ if (m->handle_suspend_key != HANDLE_IGNORE)
+ return false;
+ if (m->handle_hibernate_key != HANDLE_IGNORE)
+ return false;
+ if (m->handle_lid_switch != HANDLE_IGNORE)
+ return false;
+ if (m->handle_lid_switch_ep != _HANDLE_ACTION_INVALID &&
+ m->handle_lid_switch_ep != HANDLE_IGNORE)
+ return false;
+ if (m->handle_lid_switch_docked != HANDLE_IGNORE)
+ return false;
+ return true;
+}