diff --git a/dot_config/i3/config b/dot_config/i3/config index 67a3185..842de49 100644 --- a/dot_config/i3/config +++ b/dot_config/i3/config @@ -19,8 +19,8 @@ set $mod Mod4 # Display setup exec --no-startup-id xrandr --auto -# Transfer X11 lock to i3lock (locks computer before going to sleep) -exec xss-lock --transfer-sleep-lock -- i3lock --nofork +# Autolock script +exec "$HOME/.config/i3/scripts/autolock.sh" # Polybar exec_always --no-startup-id $HOME/.config/i3/scripts/polybar.sh diff --git a/dot_config/i3/scripts/autolock.sh b/dot_config/i3/scripts/autolock.sh new file mode 100644 index 0000000..55a3671 --- /dev/null +++ b/dot_config/i3/scripts/autolock.sh @@ -0,0 +1,22 @@ +#!/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' \ + ''