-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathscreenlock.sh
executable file
·150 lines (115 loc) · 3.23 KB
/
screenlock.sh
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
#!/bin/bash
#
# Script used as main screenlock interface.
#
# I use xss-lock with i3lock
#
# Author: Xoores <whyxoores.cz>
_LOG_NAME="screenlock"
. /scripts/_common.sh
#PARAM=(-e -c 303030 -f -n)
FONT="BitstreamVeraSansMono Nerd Font"
FONT_COLOR="FFFFFFAA"
GREETERS=("What now?" "Just leave" "Have a day" "But... why?" "Don't bother" "Too late" "Try to forget")
CONNECTED_DISPLAYS="$(xrandr | grep -c " connected ")"
# Pick random greeter
GREETER=${GREETERS[RANDOM%${#GREETERS[@]}]}
PARAM=(-fe --clock --indicator --inside-color=00000099 \
--fill --image=/home/xoores/Pictures/wp_a/0ed2bfd1b896e404e23103bfc95d8cd2.jpg \
--greeter-color=ffffffff --greeteroutline-color=000000aa \
--greeteroutline-width=1 --greeter-pos="w/2:h/2-150" \
--time-size=30 --greeter-size=50 --date-str="%A" \
--noinput-text="(-_-)" \
--wrong-text='Oi!' \
--verif-text="Hmmm..." \
)
# Greeter should be displayed only if there is just the one screen
if [ "${CONNECTED_DISPLAYS}" -eq 1 ]; then
PARAM+=(--greeter-text="${GREETER}")
fi
# Fonts...
PARAM+=(--time-font="${FONT}" --date-font="${FONT}" --layout-font="${FONT}" \
--verif-font="${FONT}" --wrong-font="${FONT}" --greeter-font="${FONT}" )
# Font colors
PARAM+=(--time-color="${FONT_COLOR}" --date-color="${FONT_COLOR}" \
--modif-color="${FONT_COLOR}" --layout-color="${FONT_COLOR}")
SCREENLOCK_TIMEOUT=300
#NOTIFY_BEFORE=10
NOTIFY_BEFORE=$((SCREENLOCK_TIMEOUT/10))
NOTIFY_TIMEOUT=$((SCREENLOCK_TIMEOUT-NOTIFY_BEFORE))
function on_useractivity()
{
LOG_DBG "Dimmer killed[${PID_DIMMER}]: User activity detected..."
kill "${PID_DIMMER}"
}
function on_screenlocked()
{
LOG_DBG "Dimmer killed[${PID_DIMMER}]: Screen locked"
kill "${PID_DIMMER}"
}
function configure_x()
{
xset s "${NOTIFY_TIMEOUT}" "${NOTIFY_BEFORE}"
xset s noblank
xset +dpms
xset dpms 0 0 $((5*SCREENLOCK_TIMEOUT))
}
function lock()
{
if pgrep i3lock >/dev/null; then
#LOG_DBG "Already locked, ignoring..."
return
fi
if [ ${UID} -eq 0 ]; then
LOG_DBG "Should bootstrap ${0} to user"
su -c "${0} lock" xoores
exit
fi
dunstctl set-paused true
LOG_INFO "Locking screen as UID ${UID}"
if ! i3lock "${PARAM[@]}" >/dev/null 2>&1; then
LOG_ERR "Failed to lock screen, trying again!"
if ! i3lock -n >/dev/null 2>&1 ; then
LOG_ERR "Failed to fail! Fuck..."
fi
fi
LOG_INFO "Screen unlocked"
dunstctl set-paused false
configure_x
}
case "${1}" in
start)
LOG_DBG "Starting [SCREENLOCK=${SCREENLOCK_TIMEOUT}s NOTIFY=${NOTIFY_BEFORE}s->${NOTIFY_TIMEOUT}s]"
# Just to be sure that our config works as expected!
configure_x
exec xss-lock \
--notifier="${_THIS_SCRIPT} prepare" \
-- \
"${_THIS_SCRIPT}" activate &
;;
prepare)
if pgrep i3lock >/dev/null; then
exit 0
fi
LOG_DBG "Prepare fired..."
trap 'on_useractivity' HUP # user activity
trap 'on_screenlocked' TERM # locker started
/scripts/xss-dim --delay ${NOTIFY_BEFORE} &
PID_DIMMER="${!}"
wait
exit 0
;;
*h|*help)
echo "Usage: screenlock.sh [ACTION]"
echo ""
echo " ACTIONS:"
echo " l|lock - Lock screen"
echo ""
;;
is-locked)
pgrep i3lock >/dev/null
;;
activate) lock ;;
*l|*lock) xset s activate ;;
*) xset s activate ;;
esac