nikitabobko / AeroSpace

AeroSpace is an i3-like tiling window manager for macOS
https://nikitabobko.github.io/AeroSpace/guide
MIT License
6.22k stars 101 forks source link

implement balance-sizes command #290

Closed karadnik-flutterint closed 3 months ago

karadnik-flutterint commented 3 months ago

command sets the same size for all windows that share common parent

karadnik-flutterint commented 3 months ago

@nikitabobko, all comments should be addressed now.

this is how docs look like

Screenshot 2024-06-20 at 17 11 38
nikitabobko commented 3 months ago

Thanks!

Merged with the following patch:

diff --git a/Sources/AppBundle/command/BalanceSizesCommand.swift b/Sources/AppBundle/command/BalanceSizesCommand.swift
index d1d7c369..9456cdc2 100644
--- a/Sources/AppBundle/command/BalanceSizesCommand.swift
+++ b/Sources/AppBundle/command/BalanceSizesCommand.swift
@@ -3,7 +3,7 @@ import Common
 import Foundation

 struct BalanceSizesCommand: Command {
-    let args = BalanceSizesCmdArgs(rawArgs: [])
+    let args: BalanceSizesCmdArgs

     func _run(_ state: CommandMutableState, stdin: String) -> Bool {
         check(Thread.current.isMainThread)
@@ -12,9 +12,10 @@ struct BalanceSizesCommand: Command {
     }

     func balance(_ parent: TilingContainer) {
-        parent.children.forEach { child in
-            if parent.layout == .tiles {
-                child.setWeight(parent.orientation, 1)
+        for child in parent.children {
+            switch parent.layout {
+                case .tiles: child.setWeight(parent.orientation, 1)
+                case .accordion: break // Do nothing
             }
             if let child = child as? TilingContainer {
                 balance(child)
diff --git a/Sources/AppBundle/command/other/parseCommand.swift b/Sources/AppBundle/command/other/parseCommand.swift
index d58a88f9..41bdf8eb 100644
--- a/Sources/AppBundle/command/other/parseCommand.swift
+++ b/Sources/AppBundle/command/other/parseCommand.swift
@@ -20,7 +20,7 @@ extension CmdArgs {
         let command: any Command
         switch Self.info.kind {
             case .balanceSizes:
-                command = BalanceSizesCommand()
+                command = BalanceSizesCommand(args: self as! BalanceSizesCmdArgs)
             case .close:
                 command = CloseCommand(args: self as! CloseCmdArgs)
             case .closeAllWindowsButCurrent:
diff --git a/Sources/Cli/subcommandDescriptionsGenerated.swift b/Sources/Cli/subcommandDescriptionsGenerated.swift
index 335eb414..df36c278 100644
--- a/Sources/Cli/subcommandDescriptionsGenerated.swift
+++ b/Sources/Cli/subcommandDescriptionsGenerated.swift
@@ -1,5 +1,6 @@
 // FILE IS GENERATED BY generate.sh
 let subcommandDescriptions = [
+    ["  balance-sizes", "Balance sizes of all windows in the current workspace"],
     ["  close-all-windows-but-current", "On the focused workspace, close all windows but current"],
     ["  close", "Close the focused window"],
     ["  config", "Query AeroSpace config options"],
diff --git a/docs/aerospace-balance-sizes.adoc b/docs/aerospace-balance-sizes.adoc
index 3f49ee3b..41dbd4f8 100644
--- a/docs/aerospace-balance-sizes.adoc
+++ b/docs/aerospace-balance-sizes.adoc
@@ -2,24 +2,23 @@
 include::util/man-attributes.adoc[]
 :manname: aerospace-balance-sizes
 // tag::purpose[]
-:manpurpose: Balance the sizes of all opened windows in current workspace
+:manpurpose: Balance sizes of all windows in the current workspace
 // end::purpose[]

 == Synopsis
 // tag::synopsis[]
-aerospace balance-sizes [-h|--help] 
+aerospace balance-sizes [-h|--help]
 // end::synopsis[]

 == Description
-Balance the sizes of all opened windows in current workspace

 // tag::body[]
 {manpurpose}

+// end::body[]
+
 include::util/conditional-options-header.adoc[]

 -h, --help:: Print help

-// end::body[]
-
 include::util/man-footer.adoc[]