~mil/sxmo-utils

ref: 1.5.2.1 sxmo-utils/scripts/core/sxmo_proximitylock.sh -rw-r--r-- 632 bytes
cdf1f8c6 — Stacy Harper fix ssh mode since we dropped xdm-config 4 years ago
                                                                                
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
#!/usr/bin/env sh

isLocked() {
	curState="$(sxmo_screenlock.sh getCurState)"
	[ "$curState" = "lock" ] || [ "$curState" = "off" ]
}

finish() {
	sxmo_screenlock.sh "$INITIALSTATE"
	exit 0
}

trap 'finish' TERM INT

proximity_raw_bus="$(find /sys/ -name 'in_proximity_raw')"
distance() {
	cat "$proximity_raw_bus"
}

TARGET=30

mainloop() {
	while true; do
		distance="$(distance)"
		if isLocked && [ "$distance" -lt "$TARGET" ]; then
			sxmo_screenlock.sh unlock
		elif ! isLocked && [ "$distance" -gt "$TARGET" ]; then
			sxmo_screenlock.sh off
		fi
		sleep 0.5
	done
}

INITIALSTATE="$(sxmo_screenlock.sh getCurState)"

mainloop