diff --git a/configs/nixos/modules/desktop/session/hyprland/default.nix b/configs/nixos/modules/desktop/session/hyprland/default.nix index d723a32..e919e97 100644 --- a/configs/nixos/modules/desktop/session/hyprland/default.nix +++ b/configs/nixos/modules/desktop/session/hyprland/default.nix @@ -14,7 +14,7 @@ value = { keys = "SUPER + ${toString workspace}"; action = { - kind = "focus-workspace"; + kind = "focus"; inherit workspace; }; }; @@ -28,7 +28,7 @@ value = { keys = "SUPER + ${key}"; action = { - kind = "focus-direction"; + kind = "focus"; inherit direction; }; }; @@ -80,23 +80,26 @@ settings = { config.general.layout = "dwindle"; - bind = lib.mapAttrsToList (_name: keybind: { - _args = [ - keybind.keys - (lib.generators.mkLuaInline ( - { - exec = "hl.dsp.exec_cmd(${lib.generators.toLua { } keybind.action.command})"; - "focus-direction" = "hl.dsp.focus(${ - lib.generators.toLua { } { inherit (keybind.action) direction; } - })"; - "focus-workspace" = "hl.dsp.focus(${ - lib.generators.toLua { } { inherit (keybind.action) workspace; } - })"; - } - .${keybind.action.kind} - )) - ]; - }) (lib.attrByPath [ config.networking.hostName ] { } config.registry.keybind); + bind = lib.mapAttrsToList ( + _name: keybind: + let + focusOptions = lib.filterAttrs (_name: value: value != null) { + inherit (keybind.action) direction workspace; + }; + in + { + _args = [ + keybind.keys + (lib.generators.mkLuaInline ( + { + exec = "hl.dsp.exec_cmd(${lib.generators.toLua { } keybind.action.command})"; + focus = "hl.dsp.focus(${lib.generators.toLua { } focusOptions})"; + } + .${keybind.action.kind} + )) + ]; + } + ) (lib.attrByPath [ config.networking.hostName ] { } config.registry.keybind); }; }; }; diff --git a/configs/nixos/registry/keybind.nix b/configs/nixos/registry/keybind.nix index 4bc3f8c..3db17b2 100644 --- a/configs/nixos/registry/keybind.nix +++ b/configs/nixos/registry/keybind.nix @@ -10,9 +10,15 @@ entries: lib.all ( entry: - (entry.value.action.kind == "exec" && entry.value.action.command != null) - || (entry.value.action.kind == "focus-direction" && entry.value.action.direction != null) - || (entry.value.action.kind == "focus-workspace" && entry.value.action.workspace != null) + let + action = entry.value.action; + 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; message = "Desktop keybind actions must set the fields their kind requires."; } @@ -34,8 +40,7 @@ description = "Selects the keybind action kind."; type = lib.types.enum [ "exec" - "focus-direction" - "focus-workspace" + "focus" ]; }; @@ -47,7 +52,7 @@ }; direction = lib.mkOption { - description = "Direction focused by a focus-direction keybind."; + description = "Direction focused by a focus keybind."; type = lib.types.nullOr ( lib.types.enum [ "down" @@ -61,7 +66,7 @@ }; 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;