mirror of
https://github.com/Stunkymonkey/dotfiles.git
synced 2025-05-24 19:14:39 +02:00
[i3/lockscreen] updated to socat & dbus
thanks to @bebehei
This commit is contained in:
parent
b8a2d32722
commit
35d7d39126
1 changed files with 59 additions and 15 deletions
|
@ -1,22 +1,24 @@
|
||||||
#!/usr/bin/bash
|
#!/usr/bin/bash
|
||||||
|
|
||||||
[ -f "~/.lockvars" ] && [ -r "~/.lockvars" ] && . ~/.lockvars
|
# shellcheck source=.lockvars
|
||||||
|
# shellcheck disable=SC1091
|
||||||
|
[ -f "$HOME/.lockvars" ] && [ -r "$HOME/.lockvars" ] && . ~/.lockvars
|
||||||
|
|
||||||
LOCK_TIME=${LOCK_TIME:-3}
|
LOCK_TIME=${LOCK_TIME:-3}
|
||||||
LOCK_NOTIFY_TIME=${LOCK_NOTIFY_TIME:-15}
|
LOCK_NOTIFY_TIME=${LOCK_NOTIFY_TIME:-15}
|
||||||
|
|
||||||
|
SOCK_PATH="/run/user/${UID}/i3/locksock-${XDG_SESSION_ID:-unknown}"
|
||||||
|
|
||||||
if [ -n "${WAYLAND_DISPLAY}" ]; then
|
if [ -n "${WAYLAND_DISPLAY}" ]; then
|
||||||
LOCK_CMD="swaylock"
|
LOCK_CMD="swaylock"
|
||||||
else
|
else
|
||||||
LOCK_CMD="i3lock"
|
LOCK_CMD="i3lock"
|
||||||
fi
|
fi
|
||||||
|
|
||||||
PROGNAME=$(basename $0)
|
OUTPUT_IMAGE="$HOME/.lockscreen.png"
|
||||||
|
|
||||||
OUTPUT_IMAGE="/tmp/i3lock.png"
|
|
||||||
|
|
||||||
error(){
|
error(){
|
||||||
echo -e '\e[01;31m'$*'\e[0m' >&2
|
echo -e '\e[01;31m"$*"\e[0m' >&2
|
||||||
}
|
}
|
||||||
|
|
||||||
usage(){
|
usage(){
|
||||||
|
@ -29,8 +31,10 @@ usage(){
|
||||||
-d execute the xautolock daemon
|
-d execute the xautolock daemon
|
||||||
-h help
|
-h help
|
||||||
|
|
||||||
Mind, that the options are order-sensitive. -lf != -fl && -l == -lf
|
Mind, that the options are order-sensitive:
|
||||||
(-fl is probably the thing you want)
|
-lf != -fl && -l == -lf
|
||||||
|
|
||||||
|
(-fl is probably the thing you want)
|
||||||
FIN
|
FIN
|
||||||
exit 1
|
exit 1
|
||||||
}
|
}
|
||||||
|
@ -39,13 +43,28 @@ checkfull(){
|
||||||
[ 1 -eq "$force" ] || ~/.local/bin/checknofullscreen
|
[ 1 -eq "$force" ] || ~/.local/bin/checknofullscreen
|
||||||
}
|
}
|
||||||
|
|
||||||
|
encrypt_the_chest(){
|
||||||
|
if command -v systemctl &>/dev/null; then
|
||||||
|
systemctl hibernate || shutdown now
|
||||||
|
else
|
||||||
|
shutdown now
|
||||||
|
fi
|
||||||
|
}
|
||||||
|
|
||||||
lock(){
|
lock(){
|
||||||
scrot -z $OUTPUT_IMAGE
|
socat /dev/null "UNIX-LISTEN:${SOCK_PATH}" &
|
||||||
convert $OUTPUT_IMAGE -resize 20% -level 0%,100%,0.9 -blur 0x2 -resize 500% $OUTPUT_IMAGE
|
local socat_pid=$!
|
||||||
|
|
||||||
|
scrot -z "$OUTPUT_IMAGE"
|
||||||
|
convert "$OUTPUT_IMAGE" -resize 20% -level 0%,100%,0.9 -blur 0x2 -resize 500% "$OUTPUT_IMAGE"
|
||||||
|
|
||||||
${LOCK_CMD} \
|
${LOCK_CMD} \
|
||||||
-t \
|
-t \
|
||||||
-i $OUTPUT_IMAGE
|
-n \
|
||||||
rm $OUTPUT_IMAGE
|
-i "$OUTPUT_IMAGE"
|
||||||
|
|
||||||
|
rm "$OUTPUT_IMAGE"
|
||||||
|
kill ${socat_pid}
|
||||||
}
|
}
|
||||||
|
|
||||||
notification(){
|
notification(){
|
||||||
|
@ -59,16 +78,40 @@ notification(){
|
||||||
"Will Lock Screen in 15s"
|
"Will Lock Screen in 15s"
|
||||||
}
|
}
|
||||||
|
|
||||||
daemon(){
|
daemon_signallistener(){
|
||||||
|
dbus-monitor --system --profile path=/org/freedesktop/login1 2>/dev/null \
|
||||||
|
| while read -r _ _ _ _ _ _ _ signal _; do
|
||||||
|
case "${signal}" in
|
||||||
|
PrepareForSleep) $0 -fl & ;;
|
||||||
|
*) true;;
|
||||||
|
esac
|
||||||
|
done
|
||||||
|
}
|
||||||
|
|
||||||
|
daemon_xautolock() {
|
||||||
|
# Do not use -secure option, as we have to use -locknow
|
||||||
xautolock \
|
xautolock \
|
||||||
-time $LOCK_TIME \
|
-time "$LOCK_TIME" \
|
||||||
-locker "$0 -l" \
|
-locker "$0 -l" \
|
||||||
-nowlocker "$0 -fl" \
|
-nowlocker "$0 -fl" \
|
||||||
-notify $LOCK_NOTIFY_TIME \
|
-notify "$LOCK_NOTIFY_TIME" \
|
||||||
-notifier "$0 -n" \
|
-notifier "$0 -n" \
|
||||||
-noclose
|
-noclose
|
||||||
}
|
}
|
||||||
|
|
||||||
|
# Listen for signals from the DBus Service as
|
||||||
|
# xautolock does not always catch system sleeps
|
||||||
|
daemon(){
|
||||||
|
daemon_signallistener &
|
||||||
|
local pid_signal=$!
|
||||||
|
|
||||||
|
daemon_xautolock &
|
||||||
|
local pid_xautolock=$!
|
||||||
|
|
||||||
|
trap 'kill "${pid_xautolock}" "${pid_signal}" && wait'
|
||||||
|
wait
|
||||||
|
}
|
||||||
|
|
||||||
force=0
|
force=0
|
||||||
|
|
||||||
while getopts ":hdfln" opt; do
|
while getopts ":hdfln" opt; do
|
||||||
|
@ -80,7 +123,8 @@ while getopts ":hdfln" opt; do
|
||||||
force=1
|
force=1
|
||||||
;;
|
;;
|
||||||
l)
|
l)
|
||||||
checkfull && lock
|
[ -S "${SOCK_PATH}" ] \
|
||||||
|
|| (checkfull && (lock )) #|| encrypt_the_chest))
|
||||||
;;
|
;;
|
||||||
n)
|
n)
|
||||||
checkfull && notification
|
checkfull && notification
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue