From 4360f4863b7fac14a5684c25e653ab0accff3807 Mon Sep 17 00:00:00 2001 From: alexion Date: Sun, 11 Oct 2026 16:40:07 -0400 Subject: [PATCH] feat(hyprland): migrate hardware key bindings --- .../desktop/session/hyprland/default.nix | 3 ++ .../nixos/modules/desktop/utilities/audio.nix | 36 +++++++++++++- .../nixos/modules/desktop/utilities/osd.nix | 47 +++++++++++++++++++ configs/nixos/registry/keybind.nix | 7 +++ 4 files changed, 92 insertions(+), 1 deletion(-) diff --git a/configs/nixos/modules/desktop/session/hyprland/default.nix b/configs/nixos/modules/desktop/session/hyprland/default.nix index b1ca865..2490799 100644 --- a/configs/nixos/modules/desktop/session/hyprland/default.nix +++ b/configs/nixos/modules/desktop/session/hyprland/default.nix @@ -118,6 +118,9 @@ ] ++ lib.optional keybind.repeating { repeating = true; + } + ++ lib.optional keybind.locked { + locked = true; }; }) (lib.attrByPath [ config.networking.hostName ] { } config.registry.keybind); }; diff --git a/configs/nixos/modules/desktop/utilities/audio.nix b/configs/nixos/modules/desktop/utilities/audio.nix index 4bba481..bbbb140 100644 --- a/configs/nixos/modules/desktop/utilities/audio.nix +++ b/configs/nixos/modules/desktop/utilities/audio.nix @@ -1,9 +1,43 @@ -{ config, lib, ... }: +{ + config, + lib, + pkgs, + ... +}: # PipeWire as the desktop audio server. { options.modules.desktop.utilities.audio.enable = lib.mkEnableOption "the PipeWire audio server"; config = lib.mkIf config.modules.desktop.utilities.audio.enable { + registry.keybind.${config.networking.hostName} = { + media-play = { + keys = "XF86AudioPlay"; + locked = true; + action = { + kind = "exec"; + command = "${pkgs.playerctl}/bin/playerctl play-pause"; + }; + }; + + media-next = { + keys = "XF86AudioNext"; + locked = true; + action = { + kind = "exec"; + command = "${pkgs.playerctl}/bin/playerctl next"; + }; + }; + + media-previous = { + keys = "XF86AudioPrev"; + locked = true; + action = { + kind = "exec"; + command = "${pkgs.playerctl}/bin/playerctl previous"; + }; + }; + }; + # Realtime scheduling for the audio threads, so playback survives load. security.rtkit.enable = true; diff --git a/configs/nixos/modules/desktop/utilities/osd.nix b/configs/nixos/modules/desktop/utilities/osd.nix index 8ec715d..3c7511d 100644 --- a/configs/nixos/modules/desktop/utilities/osd.nix +++ b/configs/nixos/modules/desktop/utilities/osd.nix @@ -13,6 +13,53 @@ in lib.mkEnableOption "the SwayOSD volume and brightness popup"; config = lib.mkIf config.modules.desktop.utilities.osd.enable { + 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"; + }; + }; + + brightness-down = { + keys = "XF86MonBrightnessDown"; + repeating = true; + action = { + kind = "exec"; + command = "${pkgs.swayosd}/bin/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 diff --git a/configs/nixos/registry/keybind.nix b/configs/nixos/registry/keybind.nix index fa2e1bc..d8e29ac 100644 --- a/configs/nixos/registry/keybind.nix +++ b/configs/nixos/registry/keybind.nix @@ -53,6 +53,13 @@ example = true; }; + locked = lib.mkOption { + description = "Allows the keybind action while the session is locked."; + type = lib.types.bool; + default = false; + example = true; + }; + action = lib.mkOption { description = "Declares the action this keybind runs."; type = lib.types.submodule { -- 2.47.3