Initial commit. Add poc hack script

This commit is contained in:
Kristóf Tóth 2020-08-17 12:28:52 +02:00
commit 916b3c2836

34
proof-of-concept.sh Executable file
View File

@ -0,0 +1,34 @@
#!/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