Waybar : Cycle output devices on sound click.

This commit is contained in:
Dmitry Voronin 2024-05-04 13:54:42 +03:00
parent e4070818aa
commit 984f217835
Signed by: voronind
SSH key fingerprint: SHA256:3kBb4iV2ahufEBNq+vFbUe4QYfHt98DHQjN7QaptY9k
3 changed files with 37 additions and 3 deletions

View file

@ -4,5 +4,19 @@
function sound() {
pavucontrol
}
# Cycle output devices.
function sound_output_cycle() {
local IFS=$'\n'
local current=$(pactl get-default-sink)
local all=($(pactl list short sinks | cut -f2))
local i_current=$(_index_of ''${current} ''${all})
local i_total=''${#all[@]}; ((i_total--))
local i_target=0
[[ "''${i_current}" -lt "''${i_total}" ]] && i_target=$((i_current+1))
pactl set-default-sink ''${all[''${i_target}]}
}
'';
}

View file

@ -119,6 +119,21 @@
return 1
}
# Find an index of an element in array.
# Usage: _index_of <ELEMENT> <ARRAY>
function _index_of() {
local element="''${1}"
local array="''${@:2}"
local index=0
for item in ''${array[@]}; do
[[ "''${item}" = "''${element}" ]] && break
((index++))
done
echo "''${index}"
}
# Check if inside Tmux.
function _is_tmux() {
[[ "''${TERM_PROGRAM}" = "tmux" ]]

View file

@ -61,7 +61,8 @@
"format-icons": {
"default": ["", "", ""]
},
"on-click": "pavucontrol"
"on-click": "sound_output_cycle",
"on-click-right": "pavucontrol"
},
"mpris": {
"format": "{player_icon} {artist} - {title}",
@ -74,18 +75,22 @@
"status-icons": {
"paused": ""
},
"on-click-middle": "playerctl stop"
// "ignored-players": ["firefox"]
},
"cpu": {
"format": "{usage}% ({load})",
"tooltip": false
"tooltip": false,
"on-click": "btop"
},
"memory": {
"format": "{percentage}%"
"format": "{percentage}%",
"on-click": "btop"
},
"temperature": {
"hwmon-path": "/sys/class/hwmon/hwmon1/temp1_input",
"format": "{temperatureC}°C",
"on-click": "btop"
}
}
'';