refactor(hyprland): simplify keybind registry schema

This commit is contained in:
2026-10-10 14:19:34 -04:00
parent 5fdec143ae
commit 2f9955dfb8

View File

@@ -1,54 +1,4 @@
{ lib, ... }:
let
actionType = lib.types.addCheck (lib.types.attrsOf lib.types.anything) isAction;
isAction =
action:
builtins.hasAttr "type" action
&& builtins.hasAttr action.type actionFields
&& (
let
fields = builtins.getAttr action.type actionFields;
allowedFields = [ "type" ] ++ fields;
in
lib.all (field: builtins.hasAttr field action) fields
&& lib.all (field: lib.elem field allowedFields) (builtins.attrNames action)
&& lib.all (field: actionFieldChecks.${field} action.${field}) fields
);
actionFields = {
exec = [ "command" ];
focus = [ "direction" ];
"move-window" = [ "direction" ];
"resize-window" = [
"x"
"y"
];
"toggle-floating" = [ ];
fullscreen = [ ];
layout = [ "message" ];
"close-window" = [ ];
"kill-window" = [ ];
"focus-workspace" = [ "workspace" ];
"move-to-workspace" = [ "workspace" ];
};
actionFieldChecks = {
command = builtins.isString;
direction =
direction:
lib.elem direction [
"left"
"down"
"up"
"right"
];
x = builtins.isInt;
y = builtins.isInt;
workspace = builtins.isInt;
message = builtins.isString;
};
in
{
checks = [
{
@@ -69,7 +19,26 @@ in
};
action = lib.mkOption {
type = actionType;
type = lib.types.submodule {
freeformType = lib.types.attrsOf lib.types.anything;
options.type = 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.";
};
};