From d0abfc16255818d4048fb813545243e2d05b4ac7 Mon Sep 17 00:00:00 2001 From: alexion Date: Sun, 11 Oct 2026 22:33:32 -0400 Subject: [PATCH] refactor(osd): move volume bindings to audio --- .../nixos/modules/desktop/utilities/audio.nix | 20 +++++ .../nixos/modules/desktop/utilities/osd.nix | 80 ++++++------------- 2 files changed, 45 insertions(+), 55 deletions(-) diff --git a/configs/nixos/modules/desktop/utilities/audio.nix b/configs/nixos/modules/desktop/utilities/audio.nix index 9444772..d2d9d1f 100644 --- a/configs/nixos/modules/desktop/utilities/audio.nix +++ b/configs/nixos/modules/desktop/utilities/audio.nix @@ -7,6 +7,15 @@ }: # PipeWire as the desktop audio server. let + volumeKey = keys: command: { + inherit keys; + repeating = true; + action = { + kind = "exec"; + command = "${lib.getExe' pkgs.swayosd "swayosd-client"} --output-volume ${command}"; + }; + }; + mediaKey = keys: command: { inherit keys; locked = true; @@ -30,6 +39,17 @@ in }; registry.keybind.${config.networking.hostName} = { + volume-up = volumeKey "XF86AudioRaiseVolume" "raise --max-volume 100"; + volume-down = volumeKey "XF86AudioLowerVolume" "lower"; + mute = { + keys = "XF86AudioMute"; + locked = true; + action = { + kind = "exec"; + command = "${lib.getExe' pkgs.swayosd "swayosd-client"} --output-volume mute-toggle"; + }; + }; + media-play = mediaKey "XF86AudioPlay" "play-pause"; media-next = mediaKey "XF86AudioNext" "next"; media-previous = mediaKey "XF86AudioPrev" "previous"; diff --git a/configs/nixos/modules/desktop/utilities/osd.nix b/configs/nixos/modules/desktop/utilities/osd.nix index 3c7511d..a6792b1 100644 --- a/configs/nixos/modules/desktop/utilities/osd.nix +++ b/configs/nixos/modules/desktop/utilities/osd.nix @@ -5,39 +5,41 @@ ... }: # SwayOSD: a transient on-screen popup for volume and brightness changes. -let - user = config.user.name; -in { options.modules.desktop.utilities.osd.enable = lib.mkEnableOption "the SwayOSD volume and brightness popup"; config = lib.mkIf config.modules.desktop.utilities.osd.enable { + environment.systemPackages = [ pkgs.swayosd ]; + + # The udev rule chgrps each backlight's brightness node to `video` and adds + # group write, so the server dims the panel without root. + # Membership below grants the running session that access. + services.udev.packages = [ pkgs.swayosd ]; + users.users.${config.user.name}.extraGroups = [ "video" ]; + + # The server draws the popups, so it runs for the whole graphical session. + # It binds to the target uwsm activates. + home-manager.users.${config.user.name}.systemd.user.services.swayosd = { + Unit = { + Description = "SwayOSD on-screen display server"; + PartOf = [ "graphical-session.target" ]; + After = [ "graphical-session.target" ]; + }; + Service = { + ExecStart = lib.getExe' pkgs.swayosd "swayosd-server"; + Restart = "on-failure"; + }; + Install.WantedBy = [ "graphical-session.target" ]; + }; + registry.keybind.${config.networking.hostName} = { - volume-up = { - keys = "XF86AudioRaiseVolume"; - repeating = true; - action = { - kind = "exec"; - command = "${pkgs.swayosd}/bin/swayosd-client --output-volume raise --max-volume 100"; - }; - }; - - volume-down = { - keys = "XF86AudioLowerVolume"; - repeating = true; - action = { - kind = "exec"; - command = "${pkgs.swayosd}/bin/swayosd-client --output-volume lower"; - }; - }; - brightness-up = { keys = "XF86MonBrightnessUp"; repeating = true; action = { kind = "exec"; - command = "${pkgs.swayosd}/bin/swayosd-client --brightness raise"; + command = "${lib.getExe' pkgs.swayosd "swayosd-client"} --brightness raise"; }; }; @@ -46,41 +48,9 @@ in repeating = true; action = { kind = "exec"; - command = "${pkgs.swayosd}/bin/swayosd-client --brightness lower"; + command = "${lib.getExe' pkgs.swayosd "swayosd-client"} --brightness lower"; }; }; - - mute = { - keys = "XF86AudioMute"; - locked = true; - action = { - kind = "exec"; - command = "${pkgs.swayosd}/bin/swayosd-client --output-volume mute-toggle"; - }; - }; - }; - - environment.systemPackages = [ pkgs.swayosd ]; - - # The udev rule chgrps each backlight's brightness node to `video` and adds - # group write, so the server dims the panel without root. - # Membership below grants the running session that access. - services.udev.packages = [ pkgs.swayosd ]; - users.users.${user}.extraGroups = [ "video" ]; - - # The server draws the popups, so it runs for the whole graphical session. - # It binds to the target uwsm activates. - home-manager.users.${user}.systemd.user.services.swayosd = { - Unit = { - Description = "SwayOSD on-screen display server"; - PartOf = [ "graphical-session.target" ]; - After = [ "graphical-session.target" ]; - }; - Service = { - ExecStart = "${pkgs.swayosd}/bin/swayosd-server"; - Restart = "on-failure"; - }; - Install.WantedBy = [ "graphical-session.target" ]; }; }; }