diff --git a/dotfiles/config/hypr/hyprland/binds.lua b/dotfiles/config/hypr/hyprland/binds.lua index 9365448f..ce6bae3a 100644 --- a/dotfiles/config/hypr/hyprland/binds.lua +++ b/dotfiles/config/hypr/hyprland/binds.lua @@ -256,7 +256,7 @@ function M.setup(ctx) bind(hyper .. " + I", exec("rofi_select_input.hs")) bind(hyper .. " + backslash", exec("/home/imalison/dotfiles/dotfiles/lib/functions/mpg341cx_input toggle")) bind(hyper .. " + SHIFT + backslash", workspacehistory("debug")) - bind(hyper .. " + O", exec("rofi_paswitch")) + bind(hyper .. " + O", exec("/home/imalison/dotfiles/dotfiles/lib/functions/rofi_paswitch")) bind(hyper .. " + comma", exec("rofi_wallpaper.sh")) bind(hyper .. " + SHIFT + comma", exec("/home/imalison/dotfiles/dotfiles/lib/bin/neowall-wallpaper toggle")) bind(hyper .. " + Y", exec("rofi_agentic_skill")) diff --git a/dotfiles/lib/functions/pahelper b/dotfiles/lib/functions/pahelper index 141b617c..80dbcb30 100755 --- a/dotfiles/lib/functions/pahelper +++ b/dotfiles/lib/functions/pahelper @@ -4,21 +4,32 @@ function list_sinks() { - pacmd list-sinks | grep -E 'index:|name:' + local default_sink + default_sink="$(pactl get-default-sink 2>/dev/null || true)" + + pactl list short sinks | + while IFS=$'\t' read -r id name _; do + if [ "$name" = "$default_sink" ]; then + printf ' * index: %s\n' "$id" + else + printf ' index: %s\n' "$id" + fi + printf '\tname: <%s>\n' "$name" + done } function switch_sink_default() { echo switching default - pacmd set-default-sink $1 || echo failed + pactl set-default-sink "$1" || echo failed } function switch_sink_applications() { echo switching applications - pacmd list-sink-inputs | - awk '/index:/{print $2}' | - xargs -r -I{} pacmd move-sink-input {} $1 || + pactl list short sink-inputs | + awk '{print $1}' | + xargs -r -I{} pactl move-sink-input {} "$1" || echo failed } @@ -29,11 +40,7 @@ function switch_sink_kmix_master() typeset name mixer # get the device name in pulseaudio name="$( - pacmd list-sinks | awk -v search=$1 ' - /index:/{found=$2} - /* index:/{found=$3} - /name:/&&found==search{print $2} - ' + pactl list short sinks | awk -v search="$1" '$1 == search {print $2}' )" # format device name to a name in kmix name="${name#<}" @@ -61,9 +68,10 @@ function switch_sink() function switch_gui() { # get current output id, all output ids and the sink names - current_id=$(pacmd list-sinks | egrep '\* index:' | egrep -o '[0-9]+$') - ids=( $(pacmd list-sinks | egrep 'index:' | egrep -o '[0-9]+$' | tr '\n' ' ') ) - names=( $(pacmd list-sinks | egrep 'name:' | egrep -o '\..*>$' | tr -d '>' | tr '\n' ' ') ) + current_name="$(pactl get-default-sink)" + current_id="$(pactl list short sinks | awk -v name="$current_name" '$2 == name {print $1}')" + ids=( $(pactl list short sinks | awk '{print $1}' | tr '\n' ' ') ) + names=( $(pactl list short sinks | awk '{print $2}' | tr '\n' ' ') ) zen_pars="--list --radiolist --column '' --column 'ID' --column 'Sink_name'" diff --git a/dotfiles/lib/functions/pasink b/dotfiles/lib/functions/pasink index ef652e63..cb519fcb 100755 --- a/dotfiles/lib/functions/pasink +++ b/dotfiles/lib/functions/pasink @@ -1,7 +1,7 @@ #!/usr/bin/env sh function pasink { - pacmd stat | awk -F": " '/^Default sink name: /{print $2}' + pactl get-default-sink } pasink "$@" diff --git a/dotfiles/lib/functions/rofi_paswitch b/dotfiles/lib/functions/rofi_paswitch index dd24a0eb..4d6706e9 100755 --- a/dotfiles/lib/functions/rofi_paswitch +++ b/dotfiles/lib/functions/rofi_paswitch @@ -1,7 +1,23 @@ -#!/usr/bin/env sh +#!/usr/bin/env bash function rofi_paswitch { - pahelper | tr -d '\n' | tr '>' '|' | rofi -i -dmenu -sep '|' | grep -Eo ' [0-9]*' | xargs pahelper + local default_sink entries choice sink_id script_dir + + script_dir="$(cd -- "$(dirname -- "${BASH_SOURCE[0]}")" && pwd)" + default_sink="$(pactl get-default-sink 2>/dev/null || true)" + entries="$( + pactl list short sinks | while IFS=$'\t' read -r id name _; do + if [ "$name" = "$default_sink" ]; then + printf '* %s %s\n' "$id" "$name" + else + printf '%s %s %s\n' '-' "$id" "$name" + fi + done + )" + + choice="$(printf '%s\n' "$entries" | rofi -i -dmenu -p "Audio output")" || return + sink_id="$(awk '{print $2}' <<<"$choice")" + [ -n "$sink_id" ] && "$script_dir/pahelper" "$sink_id" } rofi_paswitch diff --git a/nixos/base.nix b/nixos/base.nix index 6a9aca6d..c6bf8345 100644 --- a/nixos/base.nix +++ b/nixos/base.nix @@ -47,6 +47,7 @@ makeEnable config "myModules.base" true { # Audio + hardware.alsa.enablePersistence = true; security.rtkit.enable = true; services.pulseaudio.enable = false; services.pipewire = {