dotfiles/dot_config/i3/scripts/autolock.sh

22 lines
769 B
Bash

#!/usr/bin/sh
# Only exported variables can be used within the timer's command.
export PRIMARY_DISPLAY="$(xrandr | awk '/ primary/{print $1}')"
# Run xidlehook
xidlehook \
`# Don't lock when there's a fullscreen application` \
--not-when-fullscreen \
`# Don't lock when there's audio playing` \
--not-when-audio \
`# Dim the screen after 1 minute and 20 seconds, undim if user becomes active` \
--timer 80 \
'xrandr --output "$PRIMARY_DISPLAY" --brightness .1' \
'xrandr --output "$PRIMARY_DISPLAY" --brightness 1' \
`# Undim & lock after 10 more seconds` \
--timer 10 \
'xrandr --output "$PRIMARY_DISPLAY" --brightness 1; i3lock' \
'' \
`# Finally, suspend an hour after it locks` \
--timer 3600 \
'systemctl suspend' \
''