From a2fc568704faf7ba110c417e7a986a3883b44ab5 Mon Sep 17 00:00:00 2001 From: alexion Date: Sun, 11 Oct 2026 12:58:56 -0400 Subject: [PATCH] feat(hyprland): add directional focus binds --- .../desktop/session/hyprland/default.nix | 64 +++++++++++++++---- configs/nixos/registry/keybind.nix | 23 ++++++- 2 files changed, 71 insertions(+), 16 deletions(-) diff --git a/configs/nixos/modules/desktop/session/hyprland/default.nix b/configs/nixos/modules/desktop/session/hyprland/default.nix index 733810a..5bcd5fb 100644 --- a/configs/nixos/modules/desktop/session/hyprland/default.nix +++ b/configs/nixos/modules/desktop/session/hyprland/default.nix @@ -8,18 +8,56 @@ options.modules.desktop.session.hyprland.enable = lib.mkEnableOption "the Hyprland compositor"; config = lib.mkIf config.modules.desktop.session.hyprland.enable { - registry.keybind.${config.networking.hostName} = lib.listToAttrs ( - map (workspace: { - name = "hyprland-workspace-${toString workspace}"; - value = { - keys = "SUPER + ${toString workspace}"; - action = { - kind = "focus-workspace"; - inherit workspace; + registry.keybind.${config.networking.hostName} = lib.mkMerge [ + # Generate numeric workspace keybinds. + (lib.listToAttrs ( + map (workspace: { + name = "hyprland-workspace-${toString workspace}"; + value = { + keys = "SUPER + ${toString workspace}"; + action = { + kind = "focus"; + inherit workspace; + }; }; - }; - }) (lib.range 1 9) - ); + }) (lib.range 1 9) + )) + # Generate directional keybinds. + (lib.listToAttrs ( + map + ( + { direction, key }: + { + name = "hyprland-focus-${direction}"; + value = { + keys = "SUPER + ${key}"; + action = { + kind = "focus"; + inherit direction; + }; + }; + } + ) + [ + { + key = "H"; + direction = "left"; + } + { + key = "J"; + direction = "down"; + } + { + key = "K"; + direction = "up"; + } + { + key = "L"; + direction = "right"; + } + ] + )) + ]; # This program integration owns the session, portals, and polkit, launched # through the universal Wayland session manager. @@ -53,8 +91,8 @@ (lib.generators.mkLuaInline ( { exec = "hl.dsp.exec_cmd(${lib.generators.toLua { } keybind.action.command})"; - "focus-workspace" = "hl.dsp.focus(${ - lib.generators.toLua { } { inherit (keybind.action) workspace; } + focus = "hl.dsp.focus(${ + lib.generators.toLua { } { inherit (keybind.action) direction workspace; } })"; } .${keybind.action.kind} diff --git a/configs/nixos/registry/keybind.nix b/configs/nixos/registry/keybind.nix index 8bc80fa..05530b7 100644 --- a/configs/nixos/registry/keybind.nix +++ b/configs/nixos/registry/keybind.nix @@ -11,7 +11,10 @@ lib.all ( entry: (entry.value.action.kind == "exec" && entry.value.action.command != null) - || (entry.value.action.kind == "focus-workspace" && entry.value.action.workspace != null) + || ( + entry.value.action.kind == "focus" + && lib.xor (entry.value.action.direction != null) (entry.value.action.workspace != null) + ) ) entries; message = "Desktop keybind actions must set the fields their kind requires."; } @@ -33,7 +36,7 @@ description = "Selects the keybind action kind."; type = lib.types.enum [ "exec" - "focus-workspace" + "focus" ]; }; @@ -44,8 +47,22 @@ example = "ghostty"; }; + direction = lib.mkOption { + description = "Direction focused by a focus keybind."; + type = lib.types.nullOr ( + lib.types.enum [ + "down" + "left" + "right" + "up" + ] + ); + default = null; + example = "left"; + }; + workspace = lib.mkOption { - description = "Workspace focused by a focus-workspace keybind."; + description = "Workspace focused by a focus keybind."; type = lib.types.nullOr lib.types.int; default = null; example = 1;