diff --git a/scripts/core/sxmo_appmenu.sh b/scripts/core/sxmo_appmenu.sh index a4edc13..0789205 100755 --- a/scripts/core/sxmo_appmenu.sh +++ b/scripts/core/sxmo_appmenu.sh @@ -136,6 +136,10 @@ programchoicesinit() { pgrep -f "$(command -v sxmo_rotateautotoggle.sh)" > /dev/null && printf %b "On → Off ^ 0 ^ sxmo_rotateautotoggle.sh &" || printf %b "Off → On ^ 0 ^ sxmo_rotateautotoggle.sh &" ) + $icon_lck Proximity Lock $( + pgrep -f "$(command -v sxmo_proximitylock.sh)" > /dev/null && + printf %b "On → Off ^ 0 ^ sxmo_proximitylocktoggle.sh &" || printf %b "Off → On ^ 0 ^ sxmo_proximitylocktoggle.sh &" + ) $icon_ror Rotate ^ 1 ^ sxmo_rotate.sh rotate $icon_upc Upgrade Pkgs ^ 0 ^ st -e sxmo_upgrade.sh $icon_cfg Edit configuration ^ 0 ^ st -e $EDITOR $XDG_CONFIG_HOME/sxmo/xinit diff --git a/scripts/core/sxmo_proximitylock.sh b/scripts/core/sxmo_proximitylock.sh index 3834873..a0505e6 100644 --- a/scripts/core/sxmo_proximitylock.sh +++ b/scripts/core/sxmo_proximitylock.sh @@ -1,7 +1,16 @@ #!/usr/bin/env sh +islocked() { + pgrep -f sxmo_lock.sh > /dev/null +} + +syncstate() { + islocked && STATE=locked || STATE=free +} + finish() { kill $(jobs -p) + syncstate [ free = "$STATE" ] && [ true = "$WASLOCKED" ] && sxmo_lock.sh & exit 0 } @@ -18,10 +27,12 @@ TARGET=30 mainloop() { while true; do distance="$(distance)" + # here we do not syncstate to allow user manual lock if [ locked = "$STATE" ] && [ "$distance" -lt "$TARGET" ]; then pkill -f sxmo_lock.sh STATE=free elif [ free = "$STATE" ] && [ "$distance" -gt "$TARGET" ]; then + islocked && pkill -f sxmo_lock.sh # we want screen-off on proximity sxmo_lock.sh --screen-off & STATE=locked fi @@ -29,7 +40,7 @@ mainloop() { done } -pgrep -f sxmo_lock.sh > /dev/null && STATE=locked || STATE=free +syncstate if [ locked = "$STATE" ]; then WASLOCKED=true diff --git a/scripts/core/sxmo_proximitylocktoggle.sh b/scripts/core/sxmo_proximitylocktoggle.sh new file mode 100644 index 0000000..c424198 --- /dev/null +++ b/scripts/core/sxmo_proximitylocktoggle.sh @@ -0,0 +1,18 @@ +#!/usr/bin/env sh + +proximitylockdisable() { + notify-send "Proximity Lock Disabled" + pkill -f "$(command -v sxmo_proximitylock.sh)" + exit 0 +} + +proximitylockenable() { + notify-send "Proximity Lock Enabled" + setsid -f sxmo_proximitylock.sh & +} + +if pgrep -f "$(command -v sxmo_proximitylock.sh)"; then + proximitylockdisable +else + proximitylockenable +fi diff --git a/scripts/modem/sxmo_modemcall.sh b/scripts/modem/sxmo_modemcall.sh index fd8e9b9..b5ac6bf 100755 --- a/scripts/modem/sxmo_modemcall.sh +++ b/scripts/modem/sxmo_modemcall.sh @@ -25,7 +25,7 @@ finish() { echo "sxmo_modemcall: $1">&2 notify-send "$1" fi - kill $LOCKPID + [ -n "$LOCKPID" ] && kill $LOCKPID pkill -9 dmenu exit 1 } @@ -257,8 +257,11 @@ incomingcallmenu() { modem_n || finish "Couldn't determine modem number - is modem online?" -sxmo_proximitylock.sh & -LOCKPID="$!" +# do not duplicate proximity lock if already running +if ! pgrep -f sxmo_proximitylock.sh > /dev/null; then + sxmo_proximitylock.sh & + LOCKPID="$!" +fi "$@" & MAINPID="$!"