refactor(hyprland): share focus keybind action

This commit is contained in:
2026-10-11 12:20:48 -04:00
parent e088ee7846
commit 7cd05d219b
2 changed files with 34 additions and 26 deletions

View File

@@ -14,7 +14,7 @@
value = { value = {
keys = "SUPER + ${toString workspace}"; keys = "SUPER + ${toString workspace}";
action = { action = {
kind = "focus-workspace"; kind = "focus";
inherit workspace; inherit workspace;
}; };
}; };
@@ -28,7 +28,7 @@
value = { value = {
keys = "SUPER + ${key}"; keys = "SUPER + ${key}";
action = { action = {
kind = "focus-direction"; kind = "focus";
inherit direction; inherit direction;
}; };
}; };
@@ -80,23 +80,26 @@
settings = { settings = {
config.general.layout = "dwindle"; config.general.layout = "dwindle";
bind = lib.mapAttrsToList (_name: keybind: { bind = lib.mapAttrsToList (
_args = [ _name: keybind:
keybind.keys let
(lib.generators.mkLuaInline ( focusOptions = lib.filterAttrs (_name: value: value != null) {
{ inherit (keybind.action) direction workspace;
exec = "hl.dsp.exec_cmd(${lib.generators.toLua { } keybind.action.command})"; };
"focus-direction" = "hl.dsp.focus(${ in
lib.generators.toLua { } { inherit (keybind.action) direction; } {
})"; _args = [
"focus-workspace" = "hl.dsp.focus(${ keybind.keys
lib.generators.toLua { } { inherit (keybind.action) workspace; } (lib.generators.mkLuaInline (
})"; {
} exec = "hl.dsp.exec_cmd(${lib.generators.toLua { } keybind.action.command})";
.${keybind.action.kind} focus = "hl.dsp.focus(${lib.generators.toLua { } focusOptions})";
)) }
]; .${keybind.action.kind}
}) (lib.attrByPath [ config.networking.hostName ] { } config.registry.keybind); ))
];
}
) (lib.attrByPath [ config.networking.hostName ] { } config.registry.keybind);
}; };
}; };
}; };

View File

@@ -10,9 +10,15 @@
entries: entries:
lib.all ( lib.all (
entry: entry:
(entry.value.action.kind == "exec" && entry.value.action.command != null) let
|| (entry.value.action.kind == "focus-direction" && entry.value.action.direction != null) action = entry.value.action;
|| (entry.value.action.kind == "focus-workspace" && entry.value.action.workspace != null) focusTargets = lib.filter (target: target != null) [
action.direction
action.workspace
];
in
(action.kind == "exec" && action.command != null)
|| (action.kind == "focus" && builtins.length focusTargets == 1)
) entries; ) entries;
message = "Desktop keybind actions must set the fields their kind requires."; message = "Desktop keybind actions must set the fields their kind requires.";
} }
@@ -34,8 +40,7 @@
description = "Selects the keybind action kind."; description = "Selects the keybind action kind.";
type = lib.types.enum [ type = lib.types.enum [
"exec" "exec"
"focus-direction" "focus"
"focus-workspace"
]; ];
}; };
@@ -47,7 +52,7 @@
}; };
direction = lib.mkOption { direction = lib.mkOption {
description = "Direction focused by a focus-direction keybind."; description = "Direction focused by a focus keybind.";
type = lib.types.nullOr ( type = lib.types.nullOr (
lib.types.enum [ lib.types.enum [
"down" "down"
@@ -61,7 +66,7 @@
}; };
workspace = lib.mkOption { 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; type = lib.types.nullOr lib.types.int;
default = null; default = null;
example = 1; example = 1;