Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: add smart-opposite resize option #742

Closed
wants to merge 6 commits into from
Closed
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
wesbos marked this conversation as resolved.
Show resolved Hide resolved
}
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)))
wesbos marked this conversation as resolved.
Show resolved Hide resolved

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
wesbos marked this conversation as resolved.
Show resolved Hide resolved
}

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
Loading