feat(hyprland): add directional focus binds #150

Merged
alexion merged 1 commits from feat/hyprland-lua-direction-focus into main 2026-10-11 16:02:26 -04:00
2 changed files with 71 additions and 16 deletions

View File

@@ -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 (
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-workspace";
kind = "focus";
inherit workspace;
};
};
}) (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}

View File

@@ -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;