state: rename down to idle and up to click

These match what the states are used for. These actions aren't the exact
inverse of each other, and with more states could even take different
routes through the available states.

For example if we were to dim the screen before entering lock, the idle
states would be: unlock, dim, lock, screenoff, and the click states
would be unlock, screenoff, lock. Logic would be needed to handle states
not in the click list.

Signed-off-by: Willow Barraco <contact@willowbarraco.fr>
This commit is contained in:
Aren Moynihan
2023-12-16 19:07:35 -05:00
committed by Willow Barraco
parent 61aa02754f
commit 853690a704
4 changed files with 14 additions and 19 deletions

View File

@@ -38,16 +38,16 @@ if ! grep -q unlock "$SXMO_STATE"; then
esac
case "$ACTION" in
"powerbutton_one")
sxmo_state.sh up
sxmo_state.sh click
;;
"powerbutton_two")
sxmo_state.sh up 2
sxmo_state.sh click 2
;;
"powerbutton_three")
if grep -q proximity "$SXMO_STATE"; then
stop_proximity_lock
else
sxmo_state.sh up 2
sxmo_state.sh click 2
fi
;;
"voldown_one")
@@ -309,12 +309,12 @@ case "$ACTION" in
if echo "$WMCLASS" | grep -i "megapixels"; then
sxmo_type.sh -k space
else
sxmo_state.sh up
sxmo_state.sh click
fi
exit 0
;;
"powerbutton_two")
sxmo_state.sh up 2
sxmo_state.sh click 2
exit 0
;;
"powerbutton_three")

View File

@@ -30,7 +30,7 @@ if [ -e "$XDG_CACHE_HOME/sxmo/sxmo.noidle" ]; then
sxmo_jobs.sh stop idle_locker
else
sxmo_jobs.sh start idle_locker sxmo_idle.sh -w \
timeout "${SXMO_LOCK_IDLE_TIME:-8}" "sxmo_state.sh down"
timeout "${SXMO_LOCK_IDLE_TIME:-8}" "sxmo_state.sh idle"
fi
wait

View File

@@ -16,7 +16,7 @@ sxmo_wm.sh inputevent touchscreen on
sxmo_jobs.sh stop periodic_blink
sxmo_jobs.sh stop periodic_wakelock_check
# Go down after 120 seconds of inactivity
# Go to the next idle state after 120 seconds of inactivity
if [ -e "$XDG_CACHE_HOME/sxmo/sxmo.noidle" ]; then
sxmo_jobs.sh stop idle_locker
else
@@ -25,12 +25,12 @@ else
sxmo_jobs.sh start idle_locker sxmo_idle.sh -w \
timeout "${SXMO_UNLOCK_IDLE_TIME:-120}" 'sh -c "
swaymsg mode default;
exec sxmo_state.sh down
exec sxmo_state.sh idle
"'
;;
dwm)
sxmo_jobs.sh start idle_locker sxmo_idle.sh -w \
timeout "${SXMO_UNLOCK_IDLE_TIME:-120}" "sxmo_state.sh down"
timeout "${SXMO_UNLOCK_IDLE_TIME:-120}" "sxmo_state.sh idle"
;;
esac
fi

View File

@@ -68,7 +68,7 @@ transition() {
)
}
up() {
click() {
count="${1:-1}"
# shellcheck disable=SC2086
set -- $SXMO_STATES
@@ -89,13 +89,13 @@ up() {
i=$((i+1))
done
if [ "$count" -gt 1 ]; then
up $((count-1))
click $((count-1))
else
transition
fi
}
down() {
idle() {
count="${1:-1}"
# shellcheck disable=SC2086
set -- $SXMO_STATES
@@ -116,7 +116,7 @@ down() {
i=$((i+1))
done
if [ "$count" -gt 1 ]; then
down $((count-1))
idle $((count-1))
else
transition
fi
@@ -130,12 +130,7 @@ state="$(cat "$SXMO_STATE")"
action="$1"
shift
case "$action" in
up)
up "$@"
;;
down)
down "$@"
;;
click|idle) "$action" "$@" ;;
set)
if printf "%b\n" "$SXMO_STATES" | tr ' ' '\n' | grep -xq "$1"; then
state="$1"