Skip to content

Commit

Permalink
aerospace: add workspace-to-monitor-force-assignment option and fix o…
Browse files Browse the repository at this point in the history
…n-window-detected type LnL7#1208

trying to fix LnL7#1142

testing requested changes

adding workspace to monitor force assignment

remove formatting

tests pass

proper tests

undo formatting

tests for on-window-detected and workspace-to-monitor-force-assignment

testing submodules

cleanup n if fiz

checking

final

toml null field aerospace callback issue

custom null filter for submodule list

check for no presense of window-regex and if.workspace config check

error
  • Loading branch information
thuvasooriya committed Dec 29, 2024
1 parent 17b97a2 commit a8839a7
Showing 1 changed file with 37 additions and 42 deletions.
79 changes: 37 additions & 42 deletions modules/services/aerospace/default.nix
Original file line number Diff line number Diff line change
Expand Up @@ -3,45 +3,40 @@
lib,
pkgs,
...
}:

let
}: let
cfg = config.services.aerospace;

format = pkgs.formats.toml { };
filterAttrsRecursive =
pred: set:
format = pkgs.formats.toml {};
filterAttrsRecursive = pred: set:
lib.listToAttrs (
lib.concatMap (
name:
let
name: let
v = set.${name};
in
if pred v then
[
if pred v
then [
(lib.nameValuePair name (
if lib.isAttrs v then
filterAttrsRecursive pred v
else if lib.isList v then
(map (i: if lib.isAttrs i then filterAttrsRecursive pred i else i) (lib.filter pred v))
else
v
if lib.isAttrs v
then filterAttrsRecursive pred v
else if lib.isList v
then
(map (i:
if lib.isAttrs i
then filterAttrsRecursive pred i
else i) (lib.filter pred v))
else v
))
]
else
[ ]
else []
) (lib.attrNames set)
);
filterNulls = filterAttrsRecursive (v: v != null);
configFile = format.generate "aerospace.toml" (filterNulls cfg.settings);
in

{
in {
options = {
services.aerospace = with lib.types; {
enable = lib.mkEnableOption "AeroSpace window manager";

package = lib.mkPackageOption pkgs "aerospace" { };
package = lib.mkPackageOption pkgs "aerospace" {};

settings = lib.mkOption {
type = submodule {
Expand All @@ -54,14 +49,14 @@ in
};
after-login-command = lib.mkOption {
type = listOf str;
default = [ ];
default = [];
description = "Do not use AeroSpace to run commands after login. (Managed by launchd instead)";
};
after-startup-command = lib.mkOption {
type = listOf str;
default = [ ];
default = [];
description = "Add commands that run after AeroSpace startup";
example = [ "layout tiles" ];
example = ["layout tiles"];
};
enable-normalization-flatten-containers = lib.mkOption {
type = bool;
Expand Down Expand Up @@ -124,11 +119,11 @@ in
during-aerospace-startup = lib.mkOption {
type = nullOr bool;
default = null;
description = "Whether to match during aerospace startup (optional).";
description = "Whether to match during aerospace startup (optional).";
};
};
};
default = { };
default = {};
description = "Conditions for detecting a window.";
};
check-further-callbacks = lib.mkOption {
Expand All @@ -137,13 +132,13 @@ in
description = "Whether to check further callbacks after this rule (optional).";
};
run = lib.mkOption {
type = oneOf [ str (listOf str) ];
example = [ "move-node-to-workspace m" "resize-node" ];
type = oneOf [str (listOf str)];
example = ["move-node-to-workspace m" "resize-node"];
description = "Commands to execute when the conditions match (required).";
};
};
});
default = [ ];
default = [];
example = [
{
"if" = {
Expand All @@ -154,14 +149,14 @@ in
during-aerospace-startup = false;
};
check-further-callbacks = false;
run = [ "move-node-to-workspace m" "resize-node" ];
run = ["move-node-to-workspace m" "resize-node"];
}
];
description = "Commands to run every time a new window is detected with optional conditions.";
};
workspace-to-monitor-force-assignment = lib.mkOption {
type = attrsOf (oneOf [ int str (listOf str) ]);
default = { };
type = attrsOf (oneOf [int str (listOf str)]);
default = {};
description = ''
Map workspaces to specific monitors.
Left-hand side is the workspace name, and right-hand side is the monitor pattern.
Expand All @@ -172,22 +167,22 @@ in
"3" = "secondary"; # Secondary monitor (non-main).
"4" = "built-in"; # Built-in display.
"5" = "^built-in retina display$"; # Regex for the built-in retina display.
"6" = [ "secondary" "dell" ]; # Match first pattern in the list.
"6" = ["secondary" "dell"]; # Match first pattern in the list.
};
};
on-focus-changed = lib.mkOption {
type = listOf str;
default = [ ];
default = [];
description = "Commands to run every time focused window or workspace changes.";
};
on-focused-monitor-changed = lib.mkOption {
type = listOf str;
default = [ "move-mouse monitor-lazy-center" ];
default = ["move-mouse monitor-lazy-center"];
description = "Commands to run every time focused monitor changes.";
};
exec-on-workspace-change = lib.mkOption {
type = listOf str;
default = [ ];
default = [];
example = [
"/bin/bash"
"-c"
Expand All @@ -205,7 +200,7 @@ in
};
};
};
default = { };
default = {};
example = lib.literalExpression ''
{
gaps = {
Expand Down Expand Up @@ -239,16 +234,16 @@ in
message = "AeroSpace started at login is managed by home-manager and launchd instead of itself via this option.";
}
{
assertion = cfg.settings.after-login-command == [ ];
assertion = cfg.settings.after-login-command == [];
message = "AeroSpace will not run these commands as it does not start itself.";
}
];
environment.systemPackages = [ cfg.package ];
environment.systemPackages = [cfg.package];

launchd.user.agents.aerospace = {
command =
"${cfg.package}/Applications/AeroSpace.app/Contents/MacOS/AeroSpace"
+ (lib.optionalString (cfg.settings != { }) " --config-path ${configFile}");
+ (lib.optionalString (cfg.settings != {}) " --config-path ${configFile}");
serviceConfig = {
KeepAlive = true;
RunAtLoad = true;
Expand Down

0 comments on commit a8839a7

Please sign in to comment.