From e718a248b90c4afaebc3680813b155ef0f85ebeb Mon Sep 17 00:00:00 2001 From: Riley Apeldoorn Date: Tue, 6 Jun 2023 17:14:33 +0200 Subject: [PATCH] Add support for volume keys --- script/vol | 19 +++++++++++++++++++ shared/home/gui/default.nix | 2 ++ shared/home/gui/sway.nix | 6 ++++++ 3 files changed, 27 insertions(+) create mode 100755 script/vol diff --git a/script/vol b/script/vol new file mode 100755 index 0000000..9708615 --- /dev/null +++ b/script/vol @@ -0,0 +1,19 @@ +current=$(pactl get-sink-volume @DEFAULT_SINK@ | rg [0-9]+% -o | rg -o [0-9]+ | head -n 1) + +case "$1" in + "raise" ) { + if [ $current -ge 95 ]; + then pactl set-sink-volume @DEFAULT_SINK@ 100% + else pactl set-sink-volume @DEFAULT_SINK@ +5% + fi + };; + "lower" ) { + if [ $current -le 5 ]; + then pactl set-sink-volume @DEFAULT_SINK@ 0% + else pactl set-sink-volume @DEFAULT_SINK@ -5% + fi + };; + "toggle" ) { + pactl set-sink-mute @DEFAULT_SINK@ toggle + };; +esac diff --git a/shared/home/gui/default.nix b/shared/home/gui/default.nix index 5e5be86..03f871c 100644 --- a/shared/home/gui/default.nix +++ b/shared/home/gui/default.nix @@ -20,6 +20,8 @@ in { fira-code # GUI programs pavucontrol + # We want `pactl` from the `pulseaudio` package + pulseaudio ]; }; diff --git a/shared/home/gui/sway.nix b/shared/home/gui/sway.nix index 4fed54e..7517d21 100644 --- a/shared/home/gui/sway.nix +++ b/shared/home/gui/sway.nix @@ -18,6 +18,8 @@ let mod = "Mod4"; ${slurp}/bin/slurp | ${grim}/bin/grim -g - - | ${wl-clipboard}/bin/wl-copy -t image/png ''); + vol = ../../../script/vol; + in with lib; { options.custom.gui.wm = with types; { @@ -100,6 +102,10 @@ in with lib; { "${mod}+Alt+Tab" = "exec ${pkgs.google-chrome}/bin/google-chrome-stable --ozone-platform-hint=auto --enable-features=VaapiVideoDecoder,VaapiVideoEncoder"; "${mod}+Backspace" = "mode kill"; + + "XF86AudioRaiseVolume" = "exec ${vol} raise"; + "XF86AudioLowerVolume" = "exec ${vol} lower"; + "XF86AudioMute" = "exec ${vol} toggle"; } ];