dotfiles/home/.local/bin/scripts/lockscreen

45 lines
1.2 KiB
Bash
Executable file

#!/bin/sh
if [ "$1" = "start" ]; then
MODE="start"
elif [ "$1" = "stop" ]; then
MODE="stop"
elif [ "$1" = "toggle" ]; then
if pidof -s xss-lock > /dev/null 2>&1; then
MODE="stop"
else
MODE="start"
fi
elif [ "$1" = "lock" ]; then
MODE="lock"
else
echo "Invalid command usage, use: lockscreen [start/stop/toggle/lock]"
exit 1
fi
if [ "$MODE" = "start" ]; then
echo "Starting xss-lock"
# Set X11 lockscreen delays (DPMS)
xset s on
xset s 600 10 # Dim screen after 10 minutes, lock 10s later
# XSS lock with xsecurelock
xss-lock -n /usr/lib/xsecurelock/dimmer -l -- xsecurelock &
elif [ "$MODE" = "stop" ]; then
echo "Stopping xss-lock"
# Remove X11 lockscreen delays (DPMS)
xset s off
# Stop XSS lock
killall xss-lock
elif [ "$MODE" = "lock" ]; then
# Send a DPMS trigger if xss-lock is running to inform it
# about the lockstate, if it's not running, run xsecurelock directly
if pidof -s xss-lock > /dev/null 2>&1; then
echo "Locking screen - using DPMS (xss-lock active)"
xset s activate
else
echo "Locking screen - running xsecurelock directly (xss-lock isn't running)"
xsecurelock
fi
fi