-
Notifications
You must be signed in to change notification settings - Fork 0
/
lock-notify
executable file
·72 lines (59 loc) · 1.89 KB
/
lock-notify
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
#!/bin/bash
# Example notifier script -- lowers screen brightness, then waits to be killed
# and restores previous brightness on exit.
## CONFIGURATION ##############################################################
# Brightness will be lowered to this value.
min_brightness=5
# If your video driver works with xbacklight, set -time and -steps for fading
# to $min_brightness here. Setting steps to 1 disables fading.
fade_time=1000
fade_steps=50
# If you have a driver without RandR backlight property (e.g. radeon), set this
# to use the sysfs interface and create a .conf file in /etc/tmpfiles.d/
# containing the following line to make the sysfs file writable for group
# "users":
#
# m /sys/class/backlight/acpi_video0/brightness 0664 root users - -
#
#sysfs_path=/sys/class/backlight/acpi_video0/brightness
# Time to sleep (in seconds) between increments when using sysfs. If unset or
# empty, fading is disabled.
fade_step_time=0.05
# Message to show
notify_message="Locking screen ..."
###############################################################################
get_brightness() {
if [[ -z $sysfs_path ]]; then
xbacklight -get
else
cat $sysfs_path
fi
}
set_brightness() {
if [[ -z $sysfs_path ]]; then
xbacklight -steps 1 -set $1
else
echo $1 > $sysfs_path
fi
}
fade_brightness() {
if [[ -z $sysfs_path ]]; then
xbacklight -time $fade_time -steps $fade_steps -set $1
elif [[ -z $fade_step_time ]]; then
set_brightness $1
else
local level
for level in $(eval echo {$(get_brightness)..$1}); do
set_brightness $level
sleep $fade_step_time
done
fi
}
trap 'exit 0' TERM INT
trap "set_brightness $(get_brightness); kill %%" EXIT
notify-send -u low -i "system-lock-screen" "$notify_message"
fade_brightness $min_brightness
sleep 2
xset dpms force standby
sleep 2147483647 &
wait