aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorXavier Del Campo Romero <xavi.dcr@tutanota.com>2022-03-04 22:31:09 +0100
committerXavier Del Campo Romero <xavi.dcr@tutanota.com>2022-03-04 22:31:09 +0100
commit312bc6955ac36197c9069d28dbfe234bae76e39d (patch)
tree3ddd76db1478313ec3bb3a1d98a2648129108907
parentb24bfb10c7cb50386bff19e699d5bc0e44382770 (diff)
Do not suspend on active inhibitors
-rw-r--r--sleepwalk16
1 files changed, 12 insertions, 4 deletions
diff --git a/sleepwalk b/sleepwalk
index 2abacc0..eb4071c 100644
--- a/sleepwalk
+++ b/sleepwalk
@@ -23,7 +23,7 @@ wait_for_notifications() {
is_led_on=0
fi
- if is_screen_on; then
+ if is_screen_on_or_inhibitor_active; then
break
fi
secs=$(($secs-1))
@@ -40,7 +40,15 @@ reset_wake_time() {
> /sys/class/rtc/rtc0/wakealarm
}
-is_screen_on() {
+is_screen_on_or_inhibitor_active() {
+ INHIBITORS=$(systemd-inhibit --list --no-legend \
+ | grep -e '[[:space:]]sleep[[:space:]]' \
+ | grep -e 'lock$')
+
+ if [ "$INHIBITORS" != "" ]; then
+ return 0
+ fi
+
return "$(cat /sys/class/backlight/backlight/bl_power)"
}
@@ -85,7 +93,7 @@ if [ "$1" == "start" ]; then
trap "$0 stop" EXIT
while [ -d "$LOCK_DIR" ]; do
- while is_screen_on; do
+ while is_screen_on_or_inhibitor_active; do
sleep 60
done
@@ -97,7 +105,7 @@ if [ "$1" == "start" ]; then
echo "Failed going to sleep, try again in $WAKE_SECS seconds ..." >&2
wait_for_notifications
schedule_wake_time
- if is_screen_on; then
+ if is_screen_on_or_inhibitor_active; then
break
fi
done