Files
dev/configs/nixos/registry/desktop-keybind.nix

134 lines
3.6 KiB
Nix

{ lib, ... }:
let
actionMatchesType =
action:
let
required = actionFields.${action.type};
in
lib.all (field: action.${field} != null) required
&& lib.all (field: lib.elem field required || action.${field} == null) actionOptions;
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" ];
};
actionOptions = [
"command"
"direction"
"x"
"y"
"workspace"
"message"
];
in
{
checks = [
{
assertion = entries: lib.all (entry: entry.value.keys != [ ]) entries;
message = "Desktop keybinds must set at least one key.";
}
{
assertion = entries: lib.all (entry: actionMatchesType entry.value.action) entries;
message = "Desktop keybind action fields must match their type.";
}
];
type = lib.types.submodule {
options = {
keys = lib.mkOption {
type = lib.types.listOf lib.types.str;
example = [
"SUPER"
"Return"
];
description = "Sets the ordered key parts for this desktop keybind.";
};
action = lib.mkOption {
type = lib.types.submodule {
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.";
};
command = lib.mkOption {
type = lib.types.nullOr lib.types.str;
default = null;
example = "ghostty";
description = "Command executed by an exec action.";
};
direction = lib.mkOption {
type = lib.types.nullOr (
lib.types.enum [
"left"
"down"
"up"
"right"
]
);
default = null;
description = "Direction used by focus and move-window actions.";
};
x = lib.mkOption {
type = lib.types.nullOr lib.types.int;
default = null;
example = 40;
description = "Horizontal delta used by resize-window actions.";
};
y = lib.mkOption {
type = lib.types.nullOr lib.types.int;
default = null;
example = 40;
description = "Vertical delta used by resize-window actions.";
};
workspace = lib.mkOption {
type = lib.types.nullOr lib.types.int;
default = null;
example = 1;
description = "Workspace number used by workspace actions.";
};
message = lib.mkOption {
type = lib.types.nullOr lib.types.str;
default = null;
example = "togglesplit";
description = "Layout message sent by layout actions.";
};
};
};
description = "Declares the desktop action for this keybind.";
};
};
};
}