From 13568f63dc7dd2a7c280fc737b5623ed625931e4 Mon Sep 17 00:00:00 2001 From: Wes Bos Date: Fri, 22 Nov 2024 10:28:47 -0500 Subject: [PATCH] feat: add smart-opposite resize option --- Sources/AppBundle/command/impl/ResizeCommand.swift | 5 +++++ Sources/AppBundleTests/command/ResizeCommandTest.swift | 4 ++++ Sources/Common/cmdArgs/impl/ResizeCmdArgs.swift | 4 ++-- Sources/Common/cmdHelpGenerated.swift | 2 +- docs/aerospace-resize.adoc | 1 + grammar/commands-bnf-grammar.txt | 2 +- 6 files changed, 14 insertions(+), 4 deletions(-) diff --git a/Sources/AppBundle/command/impl/ResizeCommand.swift b/Sources/AppBundle/command/impl/ResizeCommand.swift index c24ce6aa..1d1f337c 100644 --- a/Sources/AppBundle/command/impl/ResizeCommand.swift +++ b/Sources/AppBundle/command/impl/ResizeCommand.swift @@ -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) diff --git a/Sources/AppBundleTests/command/ResizeCommandTest.swift b/Sources/AppBundleTests/command/ResizeCommandTest.swift index 3489a67e..1ab6422d 100644 --- a/Sources/AppBundleTests/command/ResizeCommandTest.swift +++ b/Sources/AppBundleTests/command/ResizeCommandTest.swift @@ -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))) diff --git a/Sources/Common/cmdArgs/impl/ResizeCmdArgs.swift b/Sources/Common/cmdArgs/impl/ResizeCmdArgs.swift index d4147a1e..c8c05c18 100644 --- a/Sources/Common/cmdArgs/impl/ResizeCmdArgs.swift +++ b/Sources/Common/cmdArgs/impl/ResizeCmdArgs.swift @@ -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: "[+|-]"), ] ) @@ -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 { diff --git a/Sources/Common/cmdHelpGenerated.swift b/Sources/Common/cmdHelpGenerated.swift index e27a6b68..295327b2 100644 --- a/Sources/Common/cmdHelpGenerated.swift +++ b/Sources/Common/cmdHelpGenerated.swift @@ -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 ] (smart|width|height) [+|-] + USAGE: resize [-h|--help] [--window-id ] (smart|smart-opposite|width|height) [+|-] """ let split_help_generated = """ USAGE: split [-h|--help] [--window-id ] (horizontal|vertical|opposite) diff --git a/docs/aerospace-resize.adoc b/docs/aerospace-resize.adoc index 4de1a3d4..7b950baa 100644 --- a/docs/aerospace-resize.adoc +++ b/docs/aerospace-resize.adoc @@ -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 diff --git a/grammar/commands-bnf-grammar.txt b/grammar/commands-bnf-grammar.txt index d1b57bad..4114b4c2 100644 --- a/grammar/commands-bnf-grammar.txt +++ b/grammar/commands-bnf-grammar.txt @@ -55,7 +55,7 @@ aerospace -h; | reload-config [--no-gui | --dry-run]... - | resize [--window-id ] (smart|width|height) [+|-] [--window-id ] + | resize [--window-id ] (smart|smart-opposite|width|height) [+|-] [--window-id ] | split [--window-id ] (horizontal|vertical|opposite) [--window-id ]