From 98d59e951748a57d17e3126fbd6f7abf8b8a737d Mon Sep 17 00:00:00 2001 From: NullBite Date: Sat, 3 Feb 2024 13:33:04 +0100 Subject: [PATCH] hyprland: add volume control --- home/hyprland.nix | 15 +++++++++++++++ home/wm-helpers.nix | 22 ++++++++++++++++++++++ 2 files changed, 37 insertions(+) create mode 100644 home/wm-helpers.nix diff --git a/home/hyprland.nix b/home/hyprland.nix index a48824c..1ce4685 100644 --- a/home/hyprland.nix +++ b/home/hyprland.nix @@ -18,6 +18,9 @@ let in if hasAttr key keyNames then keyNames."${key}" else key; + wm-helpers = import ./wm-helpers.nix {inherit lib pkgs;}; + inherit (wm-helpers) keysetting; + in { home.packages = with pkgs; [ @@ -196,6 +199,18 @@ in "$mod SHIFT, 9, movetoworkspace, 9" "$mod SHIFT, 0, movetoworkspace, 10" + # Volume controls + ",XF86AudioLowerVolume, exec, ${keysetting} volumeup" + ",XF86AudioLowerVolume, exec, ${keysetting} volumedown" + ",XF86AudioMute, exec, ${keysetting} mute" + ",XF86AudioMicMute, exec, ${keysetting} micmute" + + # brightness + ",XF86KbdBrightnessDown, exec, ${keysetting} keydown" + ",XF86KbdBrightnessUp, exec, ${keysetting} keyup" + ",XF86MonBrightnessDown, exec, ${keysetting} mondown" + ",XF86MonBrightnessUp, exec, ${keysetting} monup" + # Example special workspace (scratchpad) "$mod, S, togglespecialworkspace, magic" "$mod SHIFT, S, movetoworkspace, special:magic" diff --git a/home/wm-helpers.nix b/home/wm-helpers.nix new file mode 100644 index 0000000..1520fa6 --- /dev/null +++ b/home/wm-helpers.nix @@ -0,0 +1,22 @@ +# TODO make this into a package +{ pkgs, ...}: +{ + keysetting = pkgs.writeShellScript "keysetting" '' + wpctl=${pkgs.wireplumber}/bin/wpctl + notify_send=${pkgs.libnotify}/bin/notify-send + + notifyvol () { + $notify_send "$(wpctl get-volume @DEFAULT_SINK@)" + } + + setvol () { + $wpctl set-volume @DEFAULT_SINK@ "$1" + notifyvol + } + case "$1" in + volumeup) setvol 5%+ ;; + volumedown) setvol 5%- ;; + mute) $wpctl set-mute @DEFAULT_SINK@ toggle; notifyvol;; + esac + ''; +}