From 9d62acd01a6b09dda6cb810f0f9b89e34dfeb94b Mon Sep 17 00:00:00 2001 From: Jakob Odersky Date: Wed, 26 Dec 2018 10:22:33 +0100 Subject: Lock screen: use fixed script that locks screen before sleep --- home/.config/i3/config | 2 +- home/bin/lock | 55 +++++++++++++++++++++++++++++++++++++++++++++++--- 2 files changed, 53 insertions(+), 4 deletions(-) diff --git a/home/.config/i3/config b/home/.config/i3/config index 71a91ee..2908ac6 100644 --- a/home/.config/i3/config +++ b/home/.config/i3/config @@ -273,7 +273,7 @@ bindsym $mod+r mode "resize" # # Session and power management # - exec --no-startup-id xss-lock -- ~/bin/lock + exec --no-startup-id xss-lock --transfer-sleep-lock -- ~/bin/lock set $mode_system [0-3] monitor, (l) lock, (e) logout, (s) suspend, (r) reboot, (S) shutdown mode "$mode_system" { bindsym 0 exec --no-startup-id ~/bin/setup mirror, mode "default" diff --git a/home/bin/lock b/home/bin/lock index f75f4cb..8f336bd 100755 --- a/home/bin/lock +++ b/home/bin/lock @@ -1,7 +1,56 @@ #!/bin/bash +# Example locker script -- demonstrates how to use the --transfer-sleep-lock +# option with i3lock's forking mode to delay sleep until the screen is locked. + +## CONFIGURATION ############################################################## + screenshot="$XDG_RUNTIME_DIR/.screen.png" -scrot "$screenshot" \ - && convert "$screenshot" -scale 5% -scale 2000% "$screenshot" -i3lock --nofork --image="$screenshot" --ignore-empty-password +# Options to pass to i3lock +i3lock_options="--image=$screenshot --ignore-empty-password" + + +# Run before starting the locker +pre_lock() { + scrot "$screenshot" \ + && convert "$screenshot" -scale 5% -scale 2000% "$screenshot" + #mpc pause + return +} + +# Run after the locker exits +post_lock() { + return +} + +############################################################################### + +pre_lock + +# We set a trap to kill the locker if we get killed, then start the locker and +# wait for it to exit. The waiting is not that straightforward when the locker +# forks, so we use this polling only if we have a sleep lock to deal with. +if [[ -e /dev/fd/${XSS_SLEEP_LOCK_FD:--1} ]]; then + kill_i3lock() { + pkill -xu $EUID "$@" i3lock + } + + trap kill_i3lock TERM INT + + # we have to make sure the locker does not inherit a copy of the lock fd + i3lock $i3lock_options {XSS_SLEEP_LOCK_FD}<&- + + # now close our fd (only remaining copy) to indicate we're ready to sleep + exec {XSS_SLEEP_LOCK_FD}<&- + + while kill_i3lock -0; do + sleep 0.5 + done +else + trap 'kill %%' TERM INT + i3lock -n $i3lock_options & + wait +fi + +post_lock -- cgit v1.2.3