Skip to content

Commit cd64135

Browse files
Add --listen-timeout-secs
1 parent 0221de3 commit cd64135

File tree

1 file changed

+17
-1
lines changed

1 file changed

+17
-1
lines changed

pulseaudio-control.bash

+17-1
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@ OSD="no"
2222
NODE_NICKNAMES_PROP=
2323
VOLUME_STEP=2
2424
VOLUME_MAX=130
25+
LISTEN_TIMEOUT=0.1
2526
# shellcheck disable=SC2016
2627
FORMAT='$VOL_ICON ${VOL_LEVEL}% $ICON_NODE $NODE_NICKNAME'
2728
declare -A NODE_NICKNAMES
@@ -348,7 +349,7 @@ function listen() {
348349
# Read all stdin to flush unwanted pending events, i.e. if there are
349350
# 15 events at the same time (100ms window), output is only called
350351
# twice.
351-
read -r -d '' -t 0.1 -n 10000
352+
read -r -d '' -t "$LISTEN_TIMEOUT" -n 10000
352353

353354
# After the 100ms waiting time, output again the state, as it may
354355
# have changed if the user did an action during the 100ms window.
@@ -466,6 +467,17 @@ Options:
466467
Exact matches are prioritized. Don't forget to quote the string when
467468
using globs, to avoid unwanted shell glob extension.
468469
Default: none
470+
--listen-timeout-secs
471+
The listen command updates the output as soon as it receives an event
472+
from PulseAudio. However, events are often accompanied by many other
473+
useless ones, which may result in unnecessary consecutive output
474+
updates. This script buffers the following events until a timeout is
475+
reached to avoid this scenario, which lessens the CPU load on events.
476+
However, this may result in noticeable latency when performing many
477+
actions quickly (e.g., updating the volume with the mouse wheel). You
478+
can specify what timeout to use to control the responsiveness, in
479+
seconds.
480+
Default: \"$LISTEN_TIMEOUT\"
469481
470482
Actions:
471483
help display this message and exit
@@ -570,6 +582,10 @@ while [[ "$1" = --* ]]; do
570582
NODE_TYPE="$val"
571583
SINK_OR_SOURCE=$([ "$NODE_TYPE" == "output" ] && echo "ink" || echo "ource")
572584
;;
585+
--listen-timeout-secs)
586+
if getOptVal "$@"; then shift; fi
587+
LISTEN_TIMEOUT="$val"
588+
;;
573589
# Deprecated options, to be removed in a next release
574590
--icon-sink)
575591
echo "Replaced by --icon-node, see https://github.com/marioortizmanero/polybar-pulseaudio-control/releases/tag/v3.0.0" >&2

0 commit comments

Comments
 (0)