fix(hyprland): show the mic level in the mute OSD

The wpctl-based mic toggle lost the volume bar the native swayosd input OSD
used to draw -- it only showed an icon + text. swayosd 0.3.x exposes
--custom-progress (0.0-1.0), so read the level back from wpctl after the
toggle and render icon + bar (muted/active glyph via --custom-icon),
matching the output-volume OSD. Parsing is pure bash builtins so the script
needs no PATH beyond the two pinned tools.

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
This commit is contained in:
Bernardo Magri
2026-06-14 12:51:01 +01:00
parent 7da6bb979e
commit 58096c09ed

View File

@@ -8,22 +8,23 @@ let
c = t.colors;
inherit (config.nomarchy.lib) rgb rgba;
# swayosd 0.2.1's `--input-volume mute-toggle` draws the OSD but never
# flips the source mute (verified on hardware: wpctl toggles the state,
# swayosd's input-mute path is a no-op — unlike its working output-mute
# path). Do the real toggle with wpctl, then show an OSD reflecting the
# resulting state via swayosd's --custom-icon/--custom-message.
# swayosd's `--input-volume mute-toggle` draws the OSD but never flips the
# source mute (verified on hardware: wpctl toggles the state, swayosd's
# input-mute path is a no-op — unlike its working output-mute path). Do the
# real toggle with wpctl, then re-render the same icon + volume-bar OSD the
# native input path would, reading the resulting state back from wpctl:
# --custom-progress is the mic level (0.0-1.0), --custom-icon the
# muted/active glyph. Pure bash builtins for parsing so the script needs no
# PATH beyond the two pinned tools.
micMute = pkgs.writeShellScript "nomarchy-mic-mute" ''
${pkgs.wireplumber}/bin/wpctl set-mute @DEFAULT_SOURCE@ toggle
if ${pkgs.wireplumber}/bin/wpctl get-volume @DEFAULT_SOURCE@ | grep -q MUTED; then
${pkgs.swayosd}/bin/swayosd-client \
--custom-icon microphone-sensitivity-muted-symbolic \
--custom-message "Microphone muted"
else
${pkgs.swayosd}/bin/swayosd-client \
--custom-icon microphone-sensitivity-high-symbolic \
--custom-message "Microphone unmuted"
fi
out=$(${pkgs.wireplumber}/bin/wpctl get-volume @DEFAULT_SOURCE@)
set -- $out # "Volume: 0.85 [MUTED]" -> $2 is the level
case "$out" in
*MUTED*) icon=microphone-sensitivity-muted-symbolic ;;
*) icon=microphone-sensitivity-high-symbolic ;;
esac
${pkgs.swayosd}/bin/swayosd-client --custom-icon "$icon" --custom-progress "$2"
'';
# SUPER+1..9 / SUPER+SHIFT+1..9 workspace binds, generated.