Make the indicator update nearly immediately from sway keybindings being pressed.
This commit is contained in:
parent
8ea4ca15d8
commit
7039857b95
@ -6,11 +6,31 @@ IFS=$'\n\t'
|
|||||||
DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )"
|
DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )"
|
||||||
|
|
||||||
SLEEP_INTERVAL=${SLEEP_INTERVAL:-10}
|
SLEEP_INTERVAL=${SLEEP_INTERVAL:-10}
|
||||||
|
DELAY_ACTION=${DELAY_ACTION:-2}
|
||||||
|
|
||||||
function main {
|
function main {
|
||||||
local previous_reported="-1"
|
local previous_reported="-1"
|
||||||
|
local now=$(date +%s)
|
||||||
|
local check_again_at=$((now + SLEEP_INTERVAL))
|
||||||
|
local next_sleep_interval=$SLEEP_INTERVAL
|
||||||
|
|
||||||
|
stream_key_binding_activations | while true; do
|
||||||
|
if read -t "$next_sleep_interval" event; then
|
||||||
|
now=$(date +%s)
|
||||||
|
latest_allowed_check=$((now + DELAY_ACTION))
|
||||||
|
if [ "$latest_allowed_check" -lt "$check_again_at" ]; then
|
||||||
|
# Scheduling a debounced action
|
||||||
|
check_again_at=$latest_allowed_check
|
||||||
|
next_sleep_interval=$DELAY_ACTION
|
||||||
|
else
|
||||||
|
# New debounced event would trigger after a check is already scheduled
|
||||||
|
next_sleep_interval=$((check_again_at - now))
|
||||||
|
fi
|
||||||
|
if [ "$now" -lt "$check_again_at" ]; then
|
||||||
|
continue
|
||||||
|
fi
|
||||||
|
fi
|
||||||
|
|
||||||
stream_key_binding_activations | while read -t "$SLEEP_INTERVAL" event; do
|
|
||||||
if pgrep -q wf-recorder; then
|
if pgrep -q wf-recorder; then
|
||||||
local is_running=1
|
local is_running=1
|
||||||
else
|
else
|
||||||
@ -20,14 +40,15 @@ function main {
|
|||||||
previous_reported="$is_running"
|
previous_reported="$is_running"
|
||||||
report "$is_running"
|
report "$is_running"
|
||||||
fi
|
fi
|
||||||
done
|
|
||||||
|
|
||||||
while true; do
|
now=$(date +%s)
|
||||||
sleep $SLEEP_INTERVAL
|
check_again_at=$((now + SLEEP_INTERVAL))
|
||||||
|
next_sleep_interval=$SLEEP_INTERVAL
|
||||||
done
|
done
|
||||||
}
|
}
|
||||||
|
|
||||||
function stream_key_binding_activations {
|
function stream_key_binding_activations {
|
||||||
|
echo "{}"
|
||||||
swaymsg --raw --monitor --type subscribe '[ "binding" ]'
|
swaymsg --raw --monitor --type subscribe '[ "binding" ]'
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user