Skip to content

Commit

Permalink
feat: add smart-opposite resize option
Browse files Browse the repository at this point in the history
#741
closes #742
  • Loading branch information
wesbos authored and nikitabobko committed Nov 23, 2024
1 parent 61e427b commit bdf57d3
Show file tree
Hide file tree
Showing 6 changed files with 17 additions and 5 deletions.
6 changes: 6 additions & 0 deletions Sources/AppBundle/command/impl/ResizeCommand.swift
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,12 @@ struct ResizeCommand: Command { // todo cover with tests
node = first
parent = first.parent as! TilingContainer
orientation = parent.orientation
case .smartOpposite:
guard let _orientation = (candidates.first?.parent as? TilingContainer)?.orientation.opposite else { return false }
orientation = _orientation
guard let first = candidates.first(where: { ($0.parent as! TilingContainer).orientation == orientation }) else { return false }
node = first
parent = first.parent as! TilingContainer
}
let diff: CGFloat = switch args.units.val {
case .set(let unit): CGFloat(unit) - node.getWeight(orientation)
Expand Down
6 changes: 5 additions & 1 deletion Sources/AppBundleTests/command/ResizeCommandTest.swift
Original file line number Diff line number Diff line change
Expand Up @@ -10,12 +10,16 @@ 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 smart-opposite 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)))

testParseCommandFail("resize s 10", msg: """
ERROR: Can't parse 's'.
Possible values: (width|height|smart)
Possible values: (width|height|smart|smart-opposite)
""")
testParseCommandFail("resize smart foo", msg: "ERROR: <number> argument must be a number")
}
Expand Down
3 changes: 2 additions & 1 deletion 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 @@ -31,6 +31,7 @@ public struct ResizeCmdArgs: CmdArgs {

public enum Dimension: String, CaseIterable, Equatable {
case width, height, smart
case smartOpposite = "smart-opposite"
}

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
3 changes: 2 additions & 1 deletion docs/aerospace-resize.adoc
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ include::util/man-attributes.adoc[]
== Synopsis
[verse]
// tag::synopsis[]
aerospace resize [-h|--help] [--window-id <window-id>] (smart|width|height) [+|-]<number>
aerospace resize [-h|--help] [--window-id <window-id>] (smart|smart-opposite|width|height) [+|-]<number>

// end::synopsis[]

Expand All @@ -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 bdf57d3

Please sign in to comment.