refactor(hyprland): limit keybind registry slice

This commit is contained in:
2026-10-10 14:36:00 -04:00
parent a84aa68274
commit 7abbd5450f
2 changed files with 7 additions and 219 deletions

View File

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

View File

@@ -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.";
};
};
};