From ca25ef4696e020a65a0b5c5b869fe74801d23301 Mon Sep 17 00:00:00 2001 From: Christian Ott Date: Sat, 1 Jun 2024 17:34:26 +0200 Subject: [PATCH] show dunst notifications on sound change --- hyperland/default.nix | 33 ++++++++++++++++++++++++++++++--- 1 file changed, 30 insertions(+), 3 deletions(-) diff --git a/hyperland/default.nix b/hyperland/default.nix index 3504762..1907d9b 100644 --- a/hyperland/default.nix +++ b/hyperland/default.nix @@ -1,11 +1,34 @@ { config, pkgs, username, ... }: +let + volumeChange = pkgs.writeShellScript "volume-change" '' + # FROM: https://github.com/jsimonrichard/nix-config/blob/master/modules/my-config/desktop/hyprland/home-manager/desktop/hyprland/keybinds.nix + # Arbitrary but unique message tag + msgTag="dunst-sound" + + # Change the volume using alsa(might differ if you use pulseaudio) + wpctl $@ > /dev/null + + # Query wpctl for the current volume and whether or not the speaker is muted + volume="$(wpctl get-volume $2 | awk '{print $2 * 100}')" + mute="$(wpctl get-volume $2 | awk '{print $3}')" + if [[ $volume == 0 || "$mute" == "[MUTED]" ]]; then + # Show the sound muted notification + dunstify -a "volumeChange" -u low -i audio-volume-muted -h string:x-dunst-stack-tag:$msgTag "Volume muted" + else + # Show the volume notification + dunstify -a "volumeChange" -u low -i audio-volume-high -h string:x-dunst-stack-tag:$msgTag \ + -h int:value:"$volume" "Volume: $volume%" + fi + ''; +in { home.packages = with pkgs; [ dunst waybar swww rofi + brightnessctl # (pkgs.waybar.overrideAttrs (oldAttrs: { # mesonFlags = oldAttrs.mesonFlags ++ [ "-Dexperimental=true" ]; # })) @@ -104,6 +127,8 @@ "$mod, l, exec, hyprlock" # Add a keybinding to lock the screen "$mod, C, exec, codium" "$mod, E, exec, hyprctl dispatch exit" + ",XF86MonBrightnessDown, exec, brightnessctl s 5%-" + ",XF86MonBrightnessUp, exec, brightnessctl s +5%" ] ++ ( # workspaces @@ -130,13 +155,15 @@ # t -> transparent, cannot be shadowed by other binds. # i -> ignore mods, will ignore modifiers. binde = [ - ", XF86AudioRaiseVolume, exec, wpctl set-volume @DEFAULT_AUDIO_SINK@ 5%+ --limit 1.3" + ", XF86AudioRaiseVolume, exec, ${volumeChange} set-volume @DEFAULT_AUDIO_SINK@ 5%+ --limit 1.3" + "CTRL, XF86AudioRaiseVolume, exec, ${volumeChange} set-volume @DEFAULT_AUDIO_SOURCE@ 5%+ --limit 1" ]; bindle = [ - ", XF86AudioLowerVolume, exec, wpctl set-volume @DEFAULT_AUDIO_SINK@ 5%-" + ", XF86AudioLowerVolume, exec, ${volumeChange} set-volume @DEFAULT_AUDIO_SINK@ 5%-" + "CTRL, XF86AudioLowerVolume, exec, ${volumeChange} set-volume @DEFAULT_AUDIO_SOURCE@ 5%-" ]; bindl = [ - ", XF86AudioMute, exec, wpctl set-mute @DEFAULT_AUDIO_SINK@ toggle" + ", XF86AudioMute, exec, ${volumeChange} set-mute @DEFAULT_AUDIO_SINK@ toggle" ]; }; } \ No newline at end of file