From 7abbd5450f9c6b4519325fd5a91a2450bd507cc0 Mon Sep 17 00:00:00 2001 From: alexion Date: Sat, 10 Oct 2026 14:36:00 -0400 Subject: [PATCH] refactor(hyprland): limit keybind registry slice --- .../desktop/session/hyprland/default.nix | 200 +----------------- configs/nixos/registry/desktop-keybind.nix | 26 +-- 2 files changed, 7 insertions(+), 219 deletions(-) diff --git a/configs/nixos/modules/desktop/session/hyprland/default.nix b/configs/nixos/modules/desktop/session/hyprland/default.nix index af15bcf..30aced2 100644 --- a/configs/nixos/modules/desktop/session/hyprland/default.nix +++ b/configs/nixos/modules/desktop/session/hyprland/default.nix @@ -5,156 +5,13 @@ }: # The Hyprland compositor. let - directionalKeybinds = lib.listToAttrs ( - lib.concatLists ( - lib.mapAttrsToList - (key: direction: [ - { - name = "hyprland-focus-${direction}"; - value = { - keys = [ - "SUPER" - key - ]; - action = { - kind = "focus"; - inherit direction; - }; - }; - } - { - name = "hyprland-move-window-${direction}"; - value = { - keys = [ - "SUPER" - "SHIFT" - key - ]; - action = { - kind = "move-window"; - inherit direction; - }; - }; - } - ]) - { - H = "left"; - J = "down"; - K = "up"; - L = "right"; - } - ) - ); - - resizeKeybinds = lib.listToAttrs ( - lib.mapAttrsToList - (key: delta: { - name = "hyprland-resize-${delta.name}"; - value = { - keys = [ - "SUPER" - "ALT" - key - ]; - action = { - kind = "resize-window"; - inherit (delta) x y; - }; - }; - }) - { - H = { - name = "left"; - x = -40; - y = 0; - }; - J = { - name = "down"; - x = 0; - y = 40; - }; - K = { - name = "up"; - x = 0; - y = -40; - }; - L = { - name = "right"; - x = 40; - y = 0; - }; - } - ); - - workspaceKeybinds = lib.listToAttrs ( - lib.concatMap ( - workspace: - let - workspaceName = toString workspace; - in - [ - { - name = "hyprland-focus-workspace-${workspaceName}"; - value = { - keys = [ - "SUPER" - workspaceName - ]; - action = { - kind = "focus-workspace"; - inherit workspace; - }; - }; - } - { - name = "hyprland-move-to-workspace-${workspaceName}"; - value = { - keys = [ - "SUPER" - "SHIFT" - workspaceName - ]; - action = { - kind = "move-to-workspace"; - inherit workspace; - }; - }; - } - ] - ) (lib.range 1 9) - ); mkBind = keybind: { _args = [ (lib.concatStringsSep " + " keybind.keys) - (mkDispatcher keybind.action) + (lib.generators.mkLuaInline "hl.dsp.exec_cmd(${toLua keybind.command})") ]; }; - - mkDispatcher = - action: - lib.generators.mkLuaInline ( - { - exec = "hl.dsp.exec_cmd(${toLua action.command})"; - focus = "hl.dsp.focus(${toLua { inherit (action) direction; }})"; - "move-window" = "hl.dsp.window.move(${toLua { inherit (action) direction; }})"; - "resize-window" = "hl.dsp.window.resize(${ - toLua ({ - inherit (action) x y; - relative = true; - }) - })"; - "toggle-floating" = "hl.dsp.window.float(${toLua { action = "toggle"; }})"; - fullscreen = "hl.dsp.window.fullscreen()"; - layout = "hl.dsp.layout(${toLua action.message})"; - "close-window" = "hl.dsp.window.close()"; - "kill-window" = "hl.dsp.window.kill()"; - "focus-workspace" = "hl.dsp.focus(${toLua { inherit (action) workspace; }})"; - "move-to-workspace" = "hl.dsp.window.move(${toLua { inherit (action) workspace; }})"; - } - .${action.kind} - ); - keybinds = lib.attrValues ( lib.attrByPath [ config.networking.hostName ] { } config.registry.desktop-keybind ); @@ -171,60 +28,9 @@ in "SUPER" "Return" ]; - action = { - kind = "exec"; - command = "ghostty"; - }; + command = "ghostty"; }; - - hyprland-toggle-floating = { - keys = [ - "SUPER" - "Space" - ]; - action.kind = "toggle-floating"; - }; - - hyprland-fullscreen = { - keys = [ - "SUPER" - "F" - ]; - action.kind = "fullscreen"; - }; - - hyprland-toggle-split = { - keys = [ - "SUPER" - "T" - ]; - action = { - kind = "layout"; - message = "togglesplit"; - }; - }; - - hyprland-close-window = { - keys = [ - "SUPER" - "SHIFT" - "Q" - ]; - action.kind = "close-window"; - }; - - hyprland-kill-window = { - keys = [ - "SUPER" - "CTRL" - "Q" - ]; - action.kind = "kill-window"; - }; - } - // directionalKeybinds - // resizeKeybinds - // workspaceKeybinds; + }; # This program integration owns the session, portals, and polkit, launched # through the universal Wayland session manager. diff --git a/configs/nixos/registry/desktop-keybind.nix b/configs/nixos/registry/desktop-keybind.nix index c5d5cdc..ab0578e 100644 --- a/configs/nixos/registry/desktop-keybind.nix +++ b/configs/nixos/registry/desktop-keybind.nix @@ -18,28 +18,10 @@ description = "Sets the ordered key parts for this desktop keybind."; }; - action = lib.mkOption { - type = lib.types.submodule { - freeformType = lib.types.attrsOf lib.types.anything; - - options.kind = lib.mkOption { - type = lib.types.enum [ - "exec" - "focus" - "move-window" - "resize-window" - "toggle-floating" - "fullscreen" - "layout" - "close-window" - "kill-window" - "focus-workspace" - "move-to-workspace" - ]; - description = "Selects the desktop action this keybind triggers."; - }; - }; - description = "Declares the desktop action for this keybind."; + command = lib.mkOption { + type = lib.types.str; + example = "ghostty"; + description = "Command executed by this keybind."; }; }; };