kde-lockscreen-suspend-display/proof-of-concept.sh

35 lines
683 B
Bash
Executable File

#!/bin/bash
set -euo pipefail
LOCK=/tmp/after-lock.lock
INITIAL_DELAY=3
LOOP_DELAY=17
if ! mkdir "${LOCK}" &> /dev/null; then
exit 0
fi
cleanup() {
rmdir "${LOCK}"
}
trap cleanup INT TERM EXIT
screensaver_isactive() {
[[ $(qdbus org.kde.screensaver /ScreenSaver org.freedesktop.ScreenSaver.GetActive) = "true" ]]
}
display_shouldsleep() {
if ! xset q | grep -q Monitor; then
return 0
elif [[ "$(xset q | grep -oP '(?<=Monitor is )\w+')" = 'On' ]]; then
return 0
fi
return 1
}
sleep "${INITIAL_DELAY}"
while screensaver_isactive; do
if display_shouldsleep; then
xset dpms force suspend
fi
sleep "${LOOP_DELAY}"
done