Skip to content

Commit

Permalink
feat: add smart-opposite resize option
Browse files Browse the repository at this point in the history
  • Loading branch information
wesbos committed Nov 22, 2024
1 parent 00cbb63 commit 13568f6
Show file tree
Hide file tree
Showing 6 changed files with 14 additions and 4 deletions.
5 changes: 5 additions & 0 deletions Sources/AppBundle/command/impl/ResizeCommand.swift
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,11 @@ struct ResizeCommand: Command { // todo cover with tests
node = first
parent = first.parent as! TilingContainer
orientation = parent.orientation
case .smartOpposite:
guard let first = candidates.first else { return false }
node = first
parent = first.parent as! TilingContainer
orientation = parent.orientation == .h ? .v : .h
}
let diff: CGFloat = switch args.units.val {
case .set(let unit): CGFloat(unit) - node.getWeight(orientation)
Expand Down
4 changes: 4 additions & 0 deletions Sources/AppBundleTests/command/ResizeCommandTest.swift
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,10 @@ final class ResizeCommandTest: XCTestCase {
testParseCommandSucc("resize smart -10", ResizeCmdArgs(rawArgs: [], dimension: .smart, units: .subtract(10)))
testParseCommandSucc("resize smart 10", ResizeCmdArgs(rawArgs: [], dimension: .smart, units: .set(10)))

testParseCommandSucc("resize smart-opposite +10", ResizeCmdArgs(rawArgs: [], dimension: .smartOpposite, units: .add(10)))
testParseCommandSucc("resize smart-opposite -10", ResizeCmdArgs(rawArgs: [], dimension: .smartOpposite, units: .subtract(10)))
testParseCommandSucc("resize smartopposite 10", ResizeCmdArgs(rawArgs: [], dimension: .smartOpposite, units: .set(10)))

testParseCommandSucc("resize height 10", ResizeCmdArgs(rawArgs: [], dimension: .height, units: .set(10)))
testParseCommandSucc("resize width 10", ResizeCmdArgs(rawArgs: [], dimension: .width, units: .set(10)))

Expand Down
4 changes: 2 additions & 2 deletions Sources/Common/cmdArgs/impl/ResizeCmdArgs.swift
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ public struct ResizeCmdArgs: CmdArgs {
"--window-id": optionalWindowIdFlag(),
],
arguments: [
newArgParser(\.dimension, parseDimension, mandatoryArgPlaceholder: "(smart|width|height)"),
newArgParser(\.dimension, parseDimension, mandatoryArgPlaceholder: "(smart|smart-opposite|width|height)"),
newArgParser(\.units, parseUnits, mandatoryArgPlaceholder: "[+|-]<number>"),
]
)
Expand All @@ -30,7 +30,7 @@ public struct ResizeCmdArgs: CmdArgs {
}

public enum Dimension: String, CaseIterable, Equatable {
case width, height, smart
case width, height, smart, smartOpposite
}

public enum Units: Equatable {
Expand Down
2 changes: 1 addition & 1 deletion Sources/Common/cmdHelpGenerated.swift
Original file line number Diff line number Diff line change
Expand Up @@ -115,7 +115,7 @@ let reload_config_help_generated = """
USAGE: reload-config [-h|--help] [--no-gui] [--dry-run]
"""
let resize_help_generated = """
USAGE: resize [-h|--help] [--window-id <window-id>] (smart|width|height) [+|-]<number>
USAGE: resize [-h|--help] [--window-id <window-id>] (smart|smart-opposite|width|height) [+|-]<number>
"""
let split_help_generated = """
USAGE: split [-h|--help] [--window-id <window-id>] (horizontal|vertical|opposite)
Expand Down
1 change: 1 addition & 0 deletions docs/aerospace-resize.adoc
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ The dimension to resize is chosen by the first argument
* `height` changes height
* `smart` changes width if the parent has horizontal orientation, and
it changes height if the parent has vertical orientation
* `smart-opposite` does resizes the opposite axis of smart

Second argument controls how much the size is changes

Expand Down
2 changes: 1 addition & 1 deletion grammar/commands-bnf-grammar.txt
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ aerospace -h;

| reload-config [--no-gui | --dry-run]...

| resize [--window-id <window_id>] (smart|width|height) [+|-]<number> [--window-id <window_id>]
| resize [--window-id <window_id>] (smart|smart-opposite|width|height) [+|-]<number> [--window-id <window_id>]

| split [--window-id <window_id>] (horizontal|vertical|opposite) [--window-id <window_id>]

Expand Down

0 comments on commit 13568f6

Please sign in to comment.