Waybar : Cycle output devices on sound click.
This commit is contained in:
parent
e4070818aa
commit
984f217835
|
@ -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}]}
|
||||
}
|
||||
'';
|
||||
}
|
||||
|
|
|
@ -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" ]]
|
||||
|
|
|
@ -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"
|
||||
}
|
||||
}
|
||||
'';
|
||||
|
|
Loading…
Reference in a new issue