From 47bea9b784cb2c182784f885b737cfd642afb1c1 Mon Sep 17 00:00:00 2001 From: Liam Malone Date: Thu, 12 Dec 2024 23:09:12 +0100 Subject: [PATCH] Add Volume/Brightness Increase/Decrease Notifications --- modules/desktop/hyprland.nix | 11 ++-- modules/desktop/waybar.nix | 6 +-- modules/home-manager/dunst.nix | 35 +++++++++---- modules/scripts/progress-notify.sh | 83 ++++++++++++++++++++++++++++++ 4 files changed, 117 insertions(+), 18 deletions(-) create mode 100755 modules/scripts/progress-notify.sh diff --git a/modules/desktop/hyprland.nix b/modules/desktop/hyprland.nix index 356334e..492036f 100644 --- a/modules/desktop/hyprland.nix +++ b/modules/desktop/hyprland.nix @@ -22,6 +22,7 @@ imports = [ ./waybar.nix ]; + wayland.windowManager.hyprland = { package = inputs.hyprland.packages.${pkgs.system}.hyprland; enable = true; @@ -273,14 +274,14 @@ ]; bindel = [ - ", XF86AudioRaiseVolume, exec, pamixer -i 5" - ", XF86AudioLowerVolume, exec, pamixer -d 5" - ", XF86AudioMute, exec, pamixer -t" + ", XF86AudioRaiseVolume, exec, pamixer -i 5 && ${../scripts/progress-notify.sh} audio" + ", XF86AudioLowerVolume, exec, pamixer -d 5 && ${../scripts/progress-notify.sh} audio" + ", XF86AudioMute, exec, pamixer -t && ${../scripts/progress-notify.sh} mute" ]; binde = [ - ", XF86MonBrightnessDown, exec, brightnessctl set 10%-" - ", XF86MonBrightnessUp, exec, brightnessctl set 10%+" + ", XF86MonBrightnessDown, exec, brightnessctl set 10%- && ${../scripts/progress-notify.sh} brightness" + ", XF86MonBrightnessUp, exec, brightnessctl set 10%+ && ${../scripts/progress-notify.sh} brightness" ]; # Move/resize windows with mainMod + LMB/RMB and dragging diff --git a/modules/desktop/waybar.nix b/modules/desktop/waybar.nix index fc8a564..379485f 100644 --- a/modules/desktop/waybar.nix +++ b/modules/desktop/waybar.nix @@ -139,10 +139,10 @@ "󰕾" ]; }; - on-click = "pamixer -t"; + on-click = "pamixer -t && exec ${../scripts/progress-notify.sh} mute"; on-click-right = "pavucontrol"; - on-scroll-down = "pamixer -d 5"; - on-scroll-up = "pamixer -i 5"; + on-scroll-down = "pamixer -d 5 && exec ${../scripts/progress-notify.sh} audio"; + on-scroll-up = "pamixer -i 5 && exec ${../scripts/progress-notify.sh} audio"; tooltip = true; tooltip-format = "{icon} {desc} {volume}%"; }; diff --git a/modules/home-manager/dunst.nix b/modules/home-manager/dunst.nix index 9c2edb0..8f4062f 100644 --- a/modules/home-manager/dunst.nix +++ b/modules/home-manager/dunst.nix @@ -5,29 +5,44 @@ enable = true; settings = { global = { - width = 300; - height = 300; - offset = "top-right"; - transparency = 10; - frame_color = "#22bbff"; + offset = "4x4"; + frame_color = "#881798"; + gap_size = 2; + corner_radius = 10; + frame_width = 2; font = "FiraCodeNerdFont"; + enable_recursive_icon_lookup = true; + icon_theme = "Arc"; }; urgency_low = { - background = "#37474f"; - foreground = "#ecefff"; + background = "#050D0E"; + foreground = "#ecefee"; timeout = 5; }; urgency_normal = { - background = "#37474f"; - foreground = "#ecefff"; + background = "#050D0E"; + foreground = "#ecefee"; timeout = 5; }; urgency_high = { background = "#cc474f"; - foreground = "#ecefff"; + foreground = "#eceffe"; timeout = 5; }; + + volume_rule = { + appname = "volume_indicator"; + background = "#050D0E88"; + foreground = "#ecefee"; + timeout = 1; + }; + brightness_rule = { + appname = "brightness_indicator"; + background = "#050D0E88"; + foreground = "#ecefee"; + timeout = 1; + }; }; }; } diff --git a/modules/scripts/progress-notify.sh b/modules/scripts/progress-notify.sh new file mode 100755 index 0000000..4378c25 --- /dev/null +++ b/modules/scripts/progress-notify.sh @@ -0,0 +1,83 @@ +#!/usr/bin/env bash + +notify='dunstify' + +muteToggleNotify() { + volume=$(pamixer --get-volume) + muted=$(pamixer --get-mute) + + icon="" + + if [ $muted == "true" ]; then + str="Muted" + icon="audio-volume-muted" + else + if [ $volume -eq 0 ]; then + icon="audio-volume-low" + elif [ $volume -le 30 ]; then + icon="audio-volume-medium" + elif [ $volume -le 70 ]; then + icon="audio-volume-high" + else + icon="audio-volume-muted" + fi + str="Unmuted" + fi + + $notify -a volume_indicator -h string:x-canonical-private-synchronous:audio "$str" -h int:value:"$volume" -t 1500 --icon $icon +} + +notifyMuted() { + volume=$(pamixer --get-volume) + muted=$(pamixer --get-mute) + $notify -a volume_indicator -h string:x-canonical-private-synchronous:audio "Muted" -h int:value:"$volume" -t 1500 --icon audio-volume-muted +} + +notifyAudio() { + volume=$(pamixer --get-volume) + muted=$(pamixer --get-mute) + + $muted && notifyMuted "$volume" && return + + if [ $volume -eq 0 ]; then + notifyMuted "$volume" + elif [ $volume -le 30 ]; then + $notify --appname=volume_indicator -h string:x-canonical-private-synchronous:audio "Volume: " -h int:value:"$volume" -t 1500 --icon audio-volume-low + elif [ $volume -le 70 ]; then + $notify --appname=volume_indicator -h string:x-canonical-private-synchronous:audio "Volume: " -h int:value:"$volume" -t 1500 --icon audio-volume-medium + else + $notify --appname=volume_indicator -h string:x-canonical-private-synchronous:audio "Volume: " -h int:value:"$volume" -t 1500 --icon audio-volume-high + fi +} + +notifyBrightness() { + base_brightness=$(brightnessctl g) + brightness=$(( $(( $base_brightness * 5 )) + 5 )) + if [ $brightness -eq 0 ]; then + $notify --appname=brightness_indicator -h string:x-canonical-private-synchronous:brightness "Brightness: " -h int:value:"$brightness" -t 1500 --icon display-brightness-symbolic + elif [ $brightness -le 30 ]; then + $notify --appname=brightness_indicator -h string:x-canonical-private-synchronous:brightness "Brightness: " -h int:value:"$brightness" -t 1500 --icon display-brightness-symbolic + elif [ $brightness -le 70 ]; then + $notify --appname=brightness_indicator -h string:x-canonical-private-synchronous:brightness "Brightness: " -h int:value:"$brightness" -t 1500 --icon display-brightness-symbolic + else + $notify --appname=brightness_indicator -h string:x-canonical-private-synchronous:brightness "Brightness: " -h int:value:"$brightness" -t 1500 --icon display-brightness-symbolic + fi +} + + +case "$1" in + mute) + muteToggleNotify + ;; + audio) + notifyAudio + ;; + brightness) + notifyBrightness + ;; + + *) + echo "Invalid Arguments:" + echo "$1" + exit 2 +esac