scripts reorganize
This commit is contained in:
73
scripts/WMScripts/mute_active.sh
Executable file
73
scripts/WMScripts/mute_active.sh
Executable file
@@ -0,0 +1,73 @@
|
||||
#!/usr/bin/env bash
|
||||
|
||||
# mutes the pipewire sink of the active window, if we can find it.
|
||||
# $1: if non-empty, applies the specified shader
|
||||
|
||||
# 1: get activewindow pid
|
||||
# 2 match to pactl source
|
||||
# 2a: try directly against pid
|
||||
# 2b: if fails: run through fallbacks for specific windows
|
||||
# 3 toggle pactl source mute
|
||||
# 4 set window tag for custom shading
|
||||
|
||||
|
||||
# Toggle mute a pactl sink
|
||||
# $1 int: id of sink to toggle
|
||||
function toggle_sink {
|
||||
pactl set-sink-input-mute "$1" toggle
|
||||
}
|
||||
|
||||
# Toggle mute for an array of pactl sinks
|
||||
# $1 string: space separated list of sink ids
|
||||
function toggle_multiple {
|
||||
for i in $1; do
|
||||
toggle_sink "$i"
|
||||
done
|
||||
}
|
||||
|
||||
|
||||
case "$XDG_CURRENT_DESKTOP" in
|
||||
"Hyprland")
|
||||
activePid=$(hyprctl activewindow -j | jq ".pid")
|
||||
tagCmd="hyprctl dispatch 'hl.dsp.window.tag({ tag = \"shader/$1\" })'"
|
||||
class=$(hyprctl activewindow -j | jq ".class")
|
||||
;;
|
||||
*)
|
||||
dunstify -u low -t 2000 -i ~/.icons/candy-icons/apps/scalable/yast-sound.svg "muteActive does not support the current desktop."
|
||||
exit
|
||||
;;
|
||||
esac
|
||||
|
||||
|
||||
sinks=$(pactl -f json list sink-inputs)
|
||||
binary=$(ps -q "$activePid" -o comm=)
|
||||
|
||||
mutableSinks=$(printf "%s" "$sinks" | jq -r ".[] | select(.properties.\"application.process.id\" == \"$activePid\") | .index")
|
||||
|
||||
# fallbacks
|
||||
[[ -z "$mutableSinks" ]] && mutableSinks=$(printf "%s" "$sinks" | jq -r ".[] | select(.properties.\"application.process.binary\" == \"$binary\") | .index") # Feishin
|
||||
[[ -z "$mutableSinks" ]] && mutableSinks=$(printf "%s" "$sinks" | jq -r ".[] | select(.properties.\"application.id\" == \"$binary\") | .index") # mpv
|
||||
[[ -z "$mutableSinks" && "$class" = \"tf_linux64\" ]] && mutableSinks=$(printf "%s" "$sinks" | jq -r ".[] | select(.properties.\"application.name\" == \"tf_linux64\" ) .index") # tf2
|
||||
|
||||
|
||||
|
||||
if [[ -z "$mutableSinks" ]]; then
|
||||
# still no matched sink; give up
|
||||
printf "Couldn't match activeWindow to any pipewire sinks!\n"
|
||||
dunstify -u low \
|
||||
-a Mute \
|
||||
-r 35 \
|
||||
-i ~/.icons/candy-icons/apps/scalable/yast-sound.svg \
|
||||
"Could not match active window to pipewire input"
|
||||
exit 1
|
||||
else
|
||||
printf "Matched activeWindow | class | %s\n |binary| %s\n | sink | %s | to pipewire sink" "$class" "$binary" "$mutableSinks" | column -ts '|'
|
||||
dunstify -u low \
|
||||
-a Mute \
|
||||
-r 35 \
|
||||
-i ~/.icons/candy-icons/apps/scalable/yast-sound.svg \
|
||||
"Toggled mute on active window"
|
||||
fi
|
||||
|
||||
toggle_multiple "$mutableSinks"
|
||||
[ -n "$1" ] && eval "$tagCmd"
|
||||
Reference in New Issue
Block a user