Unify sxmo state switch and ensure consistency
If two power handler trigger at the same time, the current behavior is that we switch two time to the same target state. This move the flock to a central script that make sure only one switch is ocurring at the same time. Concurrent switch will wait for the previous one to finish before guessing the new target state. This also refactorise the sxmo_proximitylock.sh to make it simple, stripping the two related proximitylock and proximityunlock states. Signed-off-by: Willow Barraco <contact@willowbarraco.fr> Signed-off-by: Anjandev Momi <anjan@momi.ca>
This commit is contained in:

committed by
Anjandev Momi

parent
ee180f6e51
commit
ef8254681c
@@ -15,4 +15,4 @@ case "$SXMO_WM" in
|
||||
;;
|
||||
esac
|
||||
|
||||
sxmo_hook_unlock.sh
|
||||
sxmo_state_switch.sh set unlock
|
||||
|
@@ -8,9 +8,6 @@
|
||||
# shellcheck source=scripts/core/sxmo_common.sh
|
||||
. sxmo_common.sh
|
||||
|
||||
sxmo_log "transitioning to stage unlock"
|
||||
printf unlock > "$SXMO_STATE"
|
||||
|
||||
sxmo_wakelock.sh lock sxmo_stay_awake "${SXMO_UNLOCK_IDLE_TIME:-120}s"
|
||||
|
||||
sxmo_hook_statusbar.sh state_change &
|
||||
|
@@ -88,7 +88,7 @@ case "$WMCLASS" in
|
||||
) ^ 1 ^ (rm $XDG_CACHE_HOME/sxmo/sxmo.nosuspend 2>/dev/null || touch $XDG_CACHE_HOME/sxmo/sxmo.nosuspend)
|
||||
$icon_zzz Auto-screen-off $(
|
||||
[ -e "$XDG_CACHE_HOME/sxmo/sxmo.noidle" ] && printf "%s" "$icon_tof" || printf "%s" "$icon_ton"
|
||||
) ^ 1 ^ (rm $XDG_CACHE_HOME/sxmo/sxmo.noidle 2>/dev/null || touch $XDG_CACHE_HOME/sxmo/sxmo.noidle) && sxmo_hook_unlock.sh
|
||||
) ^ 1 ^ (rm $XDG_CACHE_HOME/sxmo/sxmo.noidle 2>/dev/null || touch $XDG_CACHE_HOME/sxmo/sxmo.noidle) && sxmo_state_switch.sh set unlock
|
||||
$icon_ror Autorotate $(
|
||||
sxmo_daemons.sh running autorotate -q &&
|
||||
printf "%s" "$icon_ton" || printf "%s" "$icon_tof"
|
||||
@@ -107,8 +107,8 @@ case "$WMCLASS" in
|
||||
power)
|
||||
# Power menu
|
||||
CHOICES="
|
||||
$icon_lck Lock ^ 0 ^ sxmo_hook_lock.sh
|
||||
$icon_lck Lock (Screen off) ^ 0 ^ sxmo_hook_screenoff.sh
|
||||
$icon_lck Lock ^ 0 ^ sxmo_state_switch.sh set lock
|
||||
$icon_lck Lock (Screen off) ^ 0 ^ sxmo_state_switch.sh set screenoff
|
||||
$icon_out Logout ^ 0 ^ confirm Logout && sxmo_power.sh logout
|
||||
$([ -f "$(xdg_data_path xsessions/sxmo.desktop)" ] &&
|
||||
[ -f "$(xdg_data_path wayland-sessions/swmo.desktop)" ] &&
|
||||
|
@@ -62,7 +62,7 @@ case "$SXMO_WM" in
|
||||
esac
|
||||
|
||||
# To setup initial lock state
|
||||
sxmo_hook_unlock.sh
|
||||
sxmo_state_switch.sh set unlock
|
||||
|
||||
# Turn on auto-suspend
|
||||
if [ -w "/sys/power/wakeup_count" ] && [ -f "/sys/power/wake_lock" ]; then
|
||||
|
@@ -27,11 +27,13 @@ set_state() {
|
||||
return
|
||||
fi
|
||||
|
||||
if sxmo_daemons.sh running proximity_lock; then
|
||||
sxmobar -a -e bold -f orange state 90 "$icon_state_proximity" # circle with dot
|
||||
return
|
||||
fi
|
||||
|
||||
STATE_LABEL="$(cat "$SXMO_STATE")"
|
||||
case "$STATE_LABEL" in
|
||||
proximity*)
|
||||
sxmobar -a -e bold -f orange state 90 "$icon_state_proximity" # circle with dot
|
||||
;;
|
||||
screenoff)
|
||||
sxmobar -a -e bold -f red state 90 "$icon_state_screenoff" # filled circle
|
||||
;;
|
||||
|
@@ -15,29 +15,6 @@ stop_proximity_lock() {
|
||||
sxmo_daemons.sh stop proximity_lock
|
||||
}
|
||||
|
||||
# this action will move the lock state $1 levels higher
|
||||
lock_screen_action() {
|
||||
count="${1:-1}"
|
||||
|
||||
state="$(cat "$SXMO_STATE")"
|
||||
while [ "$count" -gt 0 ]; do
|
||||
case "$state" in
|
||||
unlock)
|
||||
state=screenoff
|
||||
;;
|
||||
screenoff)
|
||||
state=lock
|
||||
;;
|
||||
lock)
|
||||
state=unlock
|
||||
;;
|
||||
esac
|
||||
count=$((count-1))
|
||||
done
|
||||
|
||||
sxmo_hook_"$state".sh
|
||||
}
|
||||
|
||||
XPROPOUT="$(sxmo_wm.sh focusedwindow)"
|
||||
WMCLASS="$(printf %s "$XPROPOUT" | grep app: | cut -d" " -f2- | tr '[:upper:]' '[:lower:]')"
|
||||
WMNAME="$(printf %s "$XPROPOUT" | grep title: | cut -d" " -f2- | tr '[:upper:]' '[:lower:]')"
|
||||
@@ -61,16 +38,16 @@ if ! grep -q unlock "$SXMO_STATE"; then
|
||||
esac
|
||||
case "$ACTION" in
|
||||
"powerbutton_one")
|
||||
lock_screen_action
|
||||
sxmo_state_switch.sh up
|
||||
;;
|
||||
"powerbutton_two")
|
||||
lock_screen_action 2
|
||||
sxmo_state_switch.sh up 2
|
||||
;;
|
||||
"powerbutton_three")
|
||||
if grep -q proximity "$SXMO_STATE"; then
|
||||
stop_proximity_lock
|
||||
else
|
||||
lock_screen_action 2
|
||||
sxmo_state_switch.sh up 2
|
||||
fi
|
||||
;;
|
||||
"voldown_one")
|
||||
@@ -332,12 +309,12 @@ case "$ACTION" in
|
||||
if echo "$WMCLASS" | grep -i "megapixels"; then
|
||||
sxmo_type.sh -k space
|
||||
else
|
||||
lock_screen_action
|
||||
sxmo_state_switch.sh up
|
||||
fi
|
||||
exit 0
|
||||
;;
|
||||
"powerbutton_two")
|
||||
lock_screen_action 2
|
||||
sxmo_state_switch.sh up 2
|
||||
exit 0
|
||||
;;
|
||||
"powerbutton_three")
|
||||
@@ -472,9 +449,9 @@ case "$ACTION" in
|
||||
sxmo_dmenu.sh close
|
||||
sxmo_keyboard.sh close
|
||||
if [ -n "$WMCLASS" ]; then
|
||||
sxmo_hook_lock.sh
|
||||
sxmo_state_switch.sh set lock
|
||||
else
|
||||
sxmo_hook_screenoff.sh
|
||||
sxmo_state_switch.sh set screenoff
|
||||
fi
|
||||
exit 0
|
||||
;;
|
||||
|
@@ -14,18 +14,11 @@
|
||||
# shellcheck source=scripts/core/sxmo_common.sh
|
||||
. sxmo_common.sh
|
||||
|
||||
exec 3<> "$SXMO_STATE.lock"
|
||||
flock -x 3
|
||||
|
||||
sxmo_log "transitioning to stage lock"
|
||||
printf lock > "$SXMO_STATE"
|
||||
|
||||
sxmo_wakelock.sh lock sxmo_not_screenoff infinite
|
||||
|
||||
# This hook is called when the system reaches a locked state
|
||||
|
||||
sxmo_led.sh blink blue &
|
||||
sxmo_hook_statusbar.sh state_change &
|
||||
|
||||
[ "$SXMO_WM" = "sway" ] && swaymsg mode default
|
||||
sxmo_wm.sh dpms off
|
||||
@@ -37,7 +30,7 @@ sxmo_daemons.sh stop periodic_wakelock_check
|
||||
# Go to screenoff after 8 seconds of inactivity
|
||||
if ! [ -e "$XDG_CACHE_HOME/sxmo/sxmo.noidle" ]; then
|
||||
sxmo_daemons.sh start idle_locker sxmo_idle.sh -w \
|
||||
timeout "${SXMO_LOCK_IDLE_TIME:-8}" "sxmo_hook_screenoff.sh"
|
||||
timeout "${SXMO_LOCK_IDLE_TIME:-8}" "sxmo_state_switch.sh set screenoff"
|
||||
fi
|
||||
|
||||
wait
|
||||
|
@@ -16,13 +16,6 @@
|
||||
|
||||
# This hook is called when the system reaches a off state (screen off)
|
||||
|
||||
exec 3<> "$SXMO_STATE.lock"
|
||||
flock -x 3
|
||||
|
||||
sxmo_log "transitioning to stage off"
|
||||
printf screenoff > "$SXMO_STATE"
|
||||
sxmo_hook_statusbar.sh state_change &
|
||||
|
||||
[ "$SXMO_WM" = "sway" ] && swaymsg mode default
|
||||
sxmo_wm.sh dpms on
|
||||
sxmo_wm.sh inputevent touchscreen off
|
||||
|
@@ -8,16 +8,9 @@
|
||||
|
||||
# This hook is called when the system becomes unlocked again
|
||||
|
||||
exec 3<> "$SXMO_STATE.lock"
|
||||
flock -x 3
|
||||
|
||||
sxmo_log "transitioning to stage unlock"
|
||||
printf unlock > "$SXMO_STATE"
|
||||
|
||||
sxmo_wakelock.sh lock sxmo_not_screenoff infinite
|
||||
|
||||
sxmo_led.sh blink red green &
|
||||
sxmo_hook_statusbar.sh state_change &
|
||||
|
||||
sxmo_wm.sh dpms off
|
||||
sxmo_wm.sh inputevent touchscreen on
|
||||
@@ -34,12 +27,12 @@ else
|
||||
sxmo_daemons.sh start idle_locker sxmo_idle.sh -w \
|
||||
timeout "${SXMO_UNLOCK_IDLE_TIME:-120}" 'sh -c "
|
||||
swaymsg mode default;
|
||||
exec sxmo_hook_lock.sh
|
||||
exec sxmo_state_switch.sh set lock
|
||||
"'
|
||||
;;
|
||||
dwm)
|
||||
sxmo_daemons.sh start idle_locker sxmo_idle.sh -w \
|
||||
timeout "${SXMO_UNLOCK_IDLE_TIME:-120}" "sxmo_hook_lock.sh"
|
||||
timeout "${SXMO_UNLOCK_IDLE_TIME:-120}" "sxmo_state_switch.sh set lock"
|
||||
;;
|
||||
esac
|
||||
fi
|
||||
|
@@ -20,38 +20,35 @@ finish() {
|
||||
printf 6553 > "$prox_path/events/in_proximity_thresh_rising_value"
|
||||
|
||||
sxmo_wakelock.sh unlock sxmo_proximity_lock_running
|
||||
sxmo_daemons.sh start state_change_bar sxmo_hook_statusbar.sh state_change
|
||||
|
||||
exec sxmo_hook_"$INITIALSTATE".sh
|
||||
if [ -n "$INITIALSTATE" ]; then
|
||||
sxmo_state_switch.sh set "$INITIALSTATE"
|
||||
fi
|
||||
|
||||
exit
|
||||
}
|
||||
|
||||
near() {
|
||||
if [ -z "$INITIALSTATE" ]; then
|
||||
INITIALSTATE="$(cat "$SXMO_STATE")"
|
||||
fi
|
||||
|
||||
sxmo_debug "near"
|
||||
sxmo_wm.sh dpms on
|
||||
sxmo_wm.sh inputevent touchscreen off
|
||||
printf proximitylock > "$SXMO_STATE"
|
||||
sxmo_state_switch.sh set screenoff
|
||||
}
|
||||
|
||||
far() {
|
||||
sxmo_debug "far"
|
||||
sxmo_wm.sh dpms off
|
||||
sxmo_wm.sh inputevent touchscreen on
|
||||
printf proximityunlock > "$SXMO_STATE"
|
||||
}
|
||||
|
||||
exec 3<> "$SXMO_STATE.lock"
|
||||
flock -x 3
|
||||
|
||||
sxmo_log "transitioning to stage proximitylock"
|
||||
if [ -z "$INITIALSTATE" ]; then
|
||||
INITIALSTATE="$(cat "$SXMO_STATE")"
|
||||
printf proximitylock > "$SXMO_STATE"
|
||||
fi
|
||||
|
||||
sxmo_debug "far"
|
||||
sxmo_state_switch.sh set unlock
|
||||
}
|
||||
|
||||
trap 'finish' TERM INT
|
||||
|
||||
sxmo_daemons.sh stop idle_locker
|
||||
|
||||
sxmo_wakelock.sh lock sxmo_proximity_lock_running infinite
|
||||
sxmo_daemons.sh start state_change_bar sxmo_hook_statusbar.sh state_change
|
||||
|
||||
# find the device
|
||||
if [ -z "$SXMO_PROX_RAW_BUS" ]; then
|
||||
|
76
scripts/core/sxmo_state_switch.sh
Normal file
76
scripts/core/sxmo_state_switch.sh
Normal file
@@ -0,0 +1,76 @@
|
||||
#!/bin/sh
|
||||
|
||||
# include common definitions
|
||||
# shellcheck source=scripts/core/sxmo_common.sh
|
||||
. sxmo_common.sh
|
||||
|
||||
transition() {
|
||||
sxmo_log "transitioning to stage $state"
|
||||
printf %s "$state" > "$SXMO_STATE"
|
||||
|
||||
sxmo_hook_"$state".sh &
|
||||
sxmo_hook_statusbar.sh state_change &
|
||||
wait
|
||||
}
|
||||
|
||||
up() {
|
||||
count="${1:-1}"
|
||||
while [ "$count" -gt 0 ]; do
|
||||
case "$state" in
|
||||
unlock)
|
||||
state=screenoff
|
||||
;;
|
||||
screenoff)
|
||||
state=lock
|
||||
;;
|
||||
lock)
|
||||
state=unlock
|
||||
;;
|
||||
esac
|
||||
count=$((count-1))
|
||||
done
|
||||
transition
|
||||
}
|
||||
|
||||
down() {
|
||||
count="${1:-1}"
|
||||
while [ "$count" -gt 0 ]; do
|
||||
case "$state" in
|
||||
unlock)
|
||||
state=lock
|
||||
;;
|
||||
screenoff)
|
||||
state=unlock
|
||||
;;
|
||||
lock)
|
||||
state=screenoff
|
||||
;;
|
||||
esac
|
||||
count=$((count-1))
|
||||
done
|
||||
transition
|
||||
}
|
||||
|
||||
exec 3<> "$SXMO_STATE.lock"
|
||||
flock -x 3
|
||||
|
||||
state="$(cat "$SXMO_STATE")"
|
||||
|
||||
action="$1"
|
||||
shift
|
||||
case "$action" in
|
||||
up)
|
||||
up "$@"
|
||||
;;
|
||||
down)
|
||||
down "$@"
|
||||
;;
|
||||
set)
|
||||
case "$1" in
|
||||
lock|unlock|screenoff)
|
||||
state="$1"
|
||||
transition
|
||||
;;
|
||||
esac
|
||||
;;
|
||||
esac
|
@@ -199,7 +199,7 @@ processmms() {
|
||||
fi
|
||||
|
||||
if grep -q screenoff "$SXMO_STATE"; then
|
||||
sxmo_hook_lock.sh
|
||||
sxmo_state_switch.sh set lock
|
||||
fi
|
||||
|
||||
if [ "$NUM_RECIPIENTS" -gt 1 ]; then
|
||||
|
@@ -266,7 +266,7 @@ checkfornewtexts() {
|
||||
fi
|
||||
|
||||
if grep -q screenoff "$SXMO_STATE"; then
|
||||
sxmo_hook_lock.sh
|
||||
sxmo_state_switch.sh set lock
|
||||
fi
|
||||
|
||||
sxmo_hook_sms.sh "$CONTACTNAME" "$TEXT"
|
||||
|
@@ -44,7 +44,7 @@ processvvm() {
|
||||
fi
|
||||
|
||||
if grep -q screenoff "$SXMO_STATE"; then
|
||||
sxmo_hook_lock.sh
|
||||
sxmo_state_switch.sh set lock
|
||||
fi
|
||||
|
||||
sxmo_hook_sms.sh "$VVM_SENDER" "VVM" "$VVM_ID"
|
||||
|
Reference in New Issue
Block a user