From 6764b5c28ed478e933ed0ded102f22118a585f9d Mon Sep 17 00:00:00 2001 From: Barrett Ruth Date: Fri, 6 Mar 2026 16:44:53 -0500 Subject: [PATCH] feat(waybar): fix wireplumber --- home/modules/ui.nix | 87 +++++++++++++++++++++++---------------------- 1 file changed, 44 insertions(+), 43 deletions(-) diff --git a/home/modules/ui.nix b/home/modules/ui.nix index 500d8b2..6c346e4 100644 --- a/home/modules/ui.nix +++ b/home/modules/ui.nix @@ -55,6 +55,34 @@ let foreground = "${palette.red}" frame_color = "${palette.red}" ''; + + wpSink = pkgs.writeShellScript "waybar-sink" '' + vol=$(wpctl get-volume @DEFAULT_AUDIO_SINK@ 2>/dev/null) + pct=$(printf '%s' "$vol" | awk '{printf "%d", $2 * 100}') + name=$(wpctl inspect @DEFAULT_AUDIO_SINK@ 2>/dev/null | awk -F'"' '/node\.description/{print $2; exit}') + if printf '%s' "$vol" | grep -q MUTED; then + icon="󰖁" + elif [ "$pct" -le 33 ]; then + icon="󰕿" + elif [ "$pct" -le 66 ]; then + icon="󰖀" + else + icon="󰕾" + fi + printf '{"text":"%s","tooltip":"Sink: %s\\nVolume: %d%%"}\n' "$icon" "$name" "$pct" + ''; + + wpSource = pkgs.writeShellScript "waybar-source" '' + vol=$(wpctl get-volume @DEFAULT_AUDIO_SOURCE@ 2>/dev/null) + pct=$(printf '%s' "$vol" | awk '{printf "%d", $2 * 100}') + name=$(wpctl inspect @DEFAULT_AUDIO_SOURCE@ 2>/dev/null | awk -F'"' '/node\.description/{print $2; exit}') + if printf '%s' "$vol" | grep -q MUTED; then + icon="󰍭" + else + icon="󰍬" + fi + printf '{"text":"%s","tooltip":"Source: %s\\nVolume: %d%%"}\n' "$icon" "$name" "$pct" + ''; in { home.sessionVariables = lib.mkMerge [ @@ -106,8 +134,8 @@ in "tray" "custom/keyboard" "privacy" - "wireplumber#source" - "wireplumber" + "custom/source" + "custom/sink" "network" "battery" "clock" @@ -149,54 +177,26 @@ in rewrite = { }; }; - wireplumber = { - format = "{icon}"; - format-muted = "󰖁"; - format-icons = [ - "󰖁" - "󰕿" - "󰕿" - "󰕿" - "󰖀" - "󰖀" - "󰖀" - "󰕾" - "󰕾" - "󰕾" - ]; - node-type = "Audio/Sink"; - max-volume = 100; - scroll-step = 5; + "custom/sink" = { + exec = "${wpSink}"; + return-type = "json"; + interval = 1; on-click = "ctl audio sink"; on-click-right = "ctl audio sink"; on-click-middle = "wpctl set-mute @DEFAULT_AUDIO_SINK@ toggle"; - tooltip = true; - tooltip-format = "Volume: {volume}%"; + on-scroll-up = "wpctl set-volume @DEFAULT_AUDIO_SINK@ 5%+ --limit 1.0"; + on-scroll-down = "wpctl set-volume @DEFAULT_AUDIO_SINK@ 5%-"; }; - "wireplumber#source" = { - format = "{icon}"; - format-muted = "󰍭"; - format-icons = [ - "󰍭" - "󰍬" - "󰍬" - "󰍬" - "󰍬" - "󰍬" - "󰍬" - "󰍬" - "󰍬" - "󰍬" - ]; - node-type = "Audio/Source"; - max-volume = 100; - scroll-step = 5; + "custom/source" = { + exec = "${wpSource}"; + return-type = "json"; + interval = 1; on-click = "ctl audio source"; on-click-right = "ctl audio source"; on-click-middle = "wpctl set-mute @DEFAULT_AUDIO_SOURCE@ toggle"; - tooltip = true; - tooltip-format = "Volume: {volume}%"; + on-scroll-up = "wpctl set-volume @DEFAULT_AUDIO_SOURCE@ 5%+ --limit 1.0"; + on-scroll-down = "wpctl set-volume @DEFAULT_AUDIO_SOURCE@ 5%-"; }; network = { @@ -285,7 +285,8 @@ in #custom-keyboard, #privacy, #tray, - #wireplumber, + #custom-sink, + #custom-source, #network, #battery, #clock,