~mil/sxmo-utils

c769ef15182fd6092e115266754e74c39c4f7631 — Stacy Harper 23 days ago 34c2aad
Allow multikeys without bonsaictl
2 files changed, 78 insertions(+), 0 deletions(-)

A scripts/core/sxmo_multikey.sh
M scripts/core/sxmo_swayinitconf.sh
A scripts/core/sxmo_multikey.sh => scripts/core/sxmo_multikey.sh +44 -0
@@ 0,0 1,44 @@
#!/bin/sh
# SPDX-License-Identifier: AGPL-3.0-only
# Copyright 2022 Sxmo Contributors
# shellcheck source=scripts/core/sxmo_common.sh
. sxmo_common.sh

if [ "$1" = clear ]; then
	rm -f "$XDG_RUNTIME_DIR"/sxmo.multikey.count.*
	exit
fi

identifier="$1"
threshold="${SXMO_THRESHOLD:-0.30}"

count_file="$XDG_RUNTIME_DIR"/sxmo.multikey.count."$identifier"

if [ -f "$count_file" ]; then
	counter="$(($(cat "$count_file")+1))"
else
	counter=1
fi

printf %s "$counter" > "$count_file"

shift "$counter"
if [ "$#" -eq 0 ]; then
	exit
fi

sleep "$threshold"

new_counter="$(cat "$count_file")"
if [ "$counter" != "$new_counter" ] && [ "$#" -ne 1 ]; then # Only the last count can overflow
	exit
fi

eval sxmo_hook_inputhandler.sh "$1" &

if [ "$counter" != "$new_counter" ]; then # overlowed
	printf "%s * 2" "$threshold" | bc | xargs sleep
fi

rm "$count_file"


M scripts/core/sxmo_swayinitconf.sh => scripts/core/sxmo_swayinitconf.sh +34 -0
@@ 13,6 13,35 @@ pwr="${SXMO_POWER_BUTTON:-"0:0:axp20x-pek"}"
vols="${SXMO_VOLUME_BUTTON:-"1:1:1c21800.lradc"}"
scale="${SXMO_SWAY_SCALE:-2}"

# Drop this when bonsai is available on 32 bits systems
multikey_retrocompat() {
	sxmo_multikey.sh clear

	swaymsg -- bindsym --locked --input-device="$pwr" XF86PowerOff exec sxmo_multikey.sh \
		powerbutton \
		powerbutton_one \
		powerbutton_two \
		powerbutton_three

	 if ! [ "$vols" = "none" ]; then
		for vol in $vols; do
			swaymsg -- bindsym --locked --input-device="$vol" XF86AudioRaiseVolume exec \
				sxmo_multikey.sh \
				volup \
				volup_one \
				volup_two \
				volup_three

			swaymsg -- bindsym --locked --input-device="$vol" XF86AudioLowerVolume exec \
				sxmo_multikey.sh \
				voldown \
				voldown_one \
				voldown_two \
				voldown_three
		done
	 fi
}

if [ -n "$SXMO_MODEM_GPIO_KEY_RI" ]; then
	# Disable the gpio-key-ri input devive
	# It will trigger idle wakeup on modem notification which break sxmo


@@ 37,6 66,11 @@ if ! [ "$vols" = "none" ]; then
	done
fi

if ! command -v bonsaictl > /dev/null; then
	multikey_retrocompat
	exit
fi

swaymsg -- bindsym --locked --input-device="$pwr" --no-repeat XF86PowerOff exec bonsaictl -e power_pressed
swaymsg -- bindsym --locked --input-device="$pwr" --release XF86PowerOff exec bonsaictl -e power_released