From a8839a720fb1ba520b4b612e0aed2ba255826b6f Mon Sep 17 00:00:00 2001 From: thuvasooriya Date: Mon, 2 Dec 2024 07:06:09 +0530 Subject: [PATCH] aerospace: add workspace-to-monitor-force-assignment option and fix on-window-detected type #1208 trying to fix #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 --- modules/services/aerospace/default.nix | 79 ++++++++++++-------------- 1 file changed, 37 insertions(+), 42 deletions(-) diff --git a/modules/services/aerospace/default.nix b/modules/services/aerospace/default.nix index e4732899a..47d8b952c 100644 --- a/modules/services/aerospace/default.nix +++ b/modules/services/aerospace/default.nix @@ -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 { @@ -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; @@ -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 { @@ -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" = { @@ -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. @@ -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" @@ -205,7 +200,7 @@ in }; }; }; - default = { }; + default = {}; example = lib.literalExpression '' { gaps = { @@ -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;