From 381755c4b803d94e9bc2dc5d632223118f7ce884 Mon Sep 17 00:00:00 2001 From: Konstantin Koslowski Date: Sun, 3 Jan 2021 12:17:33 +0100 Subject: [PATCH] sway: improve lock, add inhibit file --- bin/lock | 48 ++++++++++++++++++++++++++++++++++++++++++------ config | 3 ++- 2 files changed, 44 insertions(+), 7 deletions(-) diff --git a/bin/lock b/bin/lock index 98e28c2..c24648a 100755 --- a/bin/lock +++ b/bin/lock @@ -4,9 +4,10 @@ SCROT_APP=grim SCROT_ARGS=" -t jpeg" LOCK_APP=swaylock LOCK_ARGS=" -f -c 000000 -i $IMAGE" +INHIBIT_FILE=$HOME/.inhibit -function _app_exists() { +function _check_app() { which $1 &> /dev/null if [ $? -ne 0 ]; then echo "ERROR: missing app \"$1\"" @@ -14,12 +15,36 @@ function _app_exists() { fi } +function _check_inhibit() { + if [ -e $INHIBIT_FILE ]; then + echo "ERROR: found inhibit file $INHIBIT_FILE" + exit 1 + fi +} + +function _inhibit() { + case "$1" in + 0|off) + rm -f $INHIBIT_FILE + echo "inhibit disabled" + ;; + 1|on) + touch $INHIBIT_FILE + echo "inhibit enabled" + ;; + *) + echo "ERROR: unknown argument: $1" + ;; + esac +} + function _clean() { rm -vf $IMAGE } function _lock() { - _app_exists $LOCK_APP + _check_inhibit + _check_app $LOCK_APP $LOCK_APP $LOCK_ARGS } @@ -32,24 +57,32 @@ function _on() { } function _screenshot() { - _app_exists $SCROT_APP + _check_app $SCROT_APP $SCROT_APP $SCROT_ARGS $IMAGE convert -blur 4x4 $IMAGE $IMAGE } +function _suspend() { + _check_inhibit + systemctl suspend-then-hibernate +} + mkdir -p $HOME/log echo "lock: $(date) args: $*" >> $HOME/log/lock.log case "$1" in + inhibit) + _inhibit $2 + ;; lock) _on _screenshot _lock - _clean + # _clean ;; lockonly) _lock - _clean + # _clean ;; off) _screenshot @@ -57,12 +90,15 @@ case "$1" in ;; on) _on - _clean + # _clean ;; screenshot) _on _screenshot ;; + suspend) + _suspend + ;; *) echo "invalid argument \"$1\"." echo "arguments: [lock|lockonly|off|on|screenshot]" diff --git a/config b/config index 34a0930..836bfb9 100644 --- a/config +++ b/config @@ -37,7 +37,7 @@ exec swayidle -w \ resume '$lock_cmd on' \ timeout 900 '$lock_cmd lockonly' \ timeout 1800 '$lock_cmd suspend' \ - before-sleep 'systemctl suspend-then-hibernat' + before-sleep '$lock_cmd lock' bindsym $mod+Ctrl+Escape exec '$lock_cmd lock' ### Input configuration @@ -56,6 +56,7 @@ bindsym $mod+Return exec $term # Kill focused window bindsym $mod+Shift+q kill +bindsym --release button2 kill # Start your launcher bindsym $mod+p exec $menu