sway: improve lock, add inhibit file

This commit is contained in:
Konstantin Koslowski 2021-01-03 12:17:33 +01:00
parent ce20a704d4
commit 381755c4b8
2 changed files with 44 additions and 7 deletions

View file

@ -4,9 +4,10 @@ SCROT_APP=grim
SCROT_ARGS=" -t jpeg" SCROT_ARGS=" -t jpeg"
LOCK_APP=swaylock LOCK_APP=swaylock
LOCK_ARGS=" -f -c 000000 -i $IMAGE" LOCK_ARGS=" -f -c 000000 -i $IMAGE"
INHIBIT_FILE=$HOME/.inhibit
function _app_exists() { function _check_app() {
which $1 &> /dev/null which $1 &> /dev/null
if [ $? -ne 0 ]; then if [ $? -ne 0 ]; then
echo "ERROR: missing app \"$1\"" echo "ERROR: missing app \"$1\""
@ -14,12 +15,36 @@ function _app_exists() {
fi 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() { function _clean() {
rm -vf $IMAGE rm -vf $IMAGE
} }
function _lock() { function _lock() {
_app_exists $LOCK_APP _check_inhibit
_check_app $LOCK_APP
$LOCK_APP $LOCK_ARGS $LOCK_APP $LOCK_ARGS
} }
@ -32,24 +57,32 @@ function _on() {
} }
function _screenshot() { function _screenshot() {
_app_exists $SCROT_APP _check_app $SCROT_APP
$SCROT_APP $SCROT_ARGS $IMAGE $SCROT_APP $SCROT_ARGS $IMAGE
convert -blur 4x4 $IMAGE $IMAGE convert -blur 4x4 $IMAGE $IMAGE
} }
function _suspend() {
_check_inhibit
systemctl suspend-then-hibernate
}
mkdir -p $HOME/log mkdir -p $HOME/log
echo "lock: $(date) args: $*" >> $HOME/log/lock.log echo "lock: $(date) args: $*" >> $HOME/log/lock.log
case "$1" in case "$1" in
inhibit)
_inhibit $2
;;
lock) lock)
_on _on
_screenshot _screenshot
_lock _lock
_clean # _clean
;; ;;
lockonly) lockonly)
_lock _lock
_clean # _clean
;; ;;
off) off)
_screenshot _screenshot
@ -57,12 +90,15 @@ case "$1" in
;; ;;
on) on)
_on _on
_clean # _clean
;; ;;
screenshot) screenshot)
_on _on
_screenshot _screenshot
;; ;;
suspend)
_suspend
;;
*) *)
echo "invalid argument \"$1\"." echo "invalid argument \"$1\"."
echo "arguments: [lock|lockonly|off|on|screenshot]" echo "arguments: [lock|lockonly|off|on|screenshot]"

3
config
View file

@ -37,7 +37,7 @@ exec swayidle -w \
resume '$lock_cmd on' \ resume '$lock_cmd on' \
timeout 900 '$lock_cmd lockonly' \ timeout 900 '$lock_cmd lockonly' \
timeout 1800 '$lock_cmd suspend' \ timeout 1800 '$lock_cmd suspend' \
before-sleep 'systemctl suspend-then-hibernat' before-sleep '$lock_cmd lock'
bindsym $mod+Ctrl+Escape exec '$lock_cmd lock' bindsym $mod+Ctrl+Escape exec '$lock_cmd lock'
### Input configuration ### Input configuration
@ -56,6 +56,7 @@ bindsym $mod+Return exec $term
# Kill focused window # Kill focused window
bindsym $mod+Shift+q kill bindsym $mod+Shift+q kill
bindsym --release button2 kill
# Start your launcher # Start your launcher
bindsym $mod+p exec $menu bindsym $mod+p exec $menu