From c078a63ccdd99c62157fdcb46640697daeda9127 Mon Sep 17 00:00:00 2001 From: Nikita Bobko Date: Sun, 8 Sep 2024 21:47:33 +0200 Subject: [PATCH] Add windowId and workspace properties to all CmdArgs https://github.com/nikitabobko/AeroSpace/issues/186 --- .../Common/cmdArgs/BalanceSizesCmdArgs.swift | 2 + .../CloseAllWindowsButCurrentCmdArgs.swift | 2 + Sources/Common/cmdArgs/CloseCmdArgs.swift | 2 + Sources/Common/cmdArgs/EnableCmdArgs.swift | 7 ++-- .../Common/cmdArgs/ExecAndForgetCmdArgs.swift | 7 +++- .../cmdArgs/FlattenWorkspaceTreeCmdArgs.swift | 3 ++ .../cmdArgs/FocusBackAndForthCmdArgs.swift | 3 ++ Sources/Common/cmdArgs/FocusCmdArgs.swift | 8 ++-- .../Common/cmdArgs/FocusMonitorCmdArgs.swift | 2 + .../Common/cmdArgs/FullscreenCmdArgs.swift | 2 + Sources/Common/cmdArgs/JoinWithCmdArgs.swift | 8 ++-- Sources/Common/cmdArgs/LayoutCmdArgs.swift | 8 ++-- .../cmdArgs/ListExecEnvVarsCmdArgs.swift | 3 ++ .../cmdArgs/MacosNativeFullscreen.swift | 6 ++- .../Common/cmdArgs/MacosNativeMinimize.swift | 3 ++ Sources/Common/cmdArgs/ModeCmdArgs.swift | 3 ++ Sources/Common/cmdArgs/MoveCmdArgs.swift | 8 ++-- Sources/Common/cmdArgs/MoveMouseCmdArgs.swift | 2 + .../cmdArgs/MoveNodeToMonitorCmdArgs.swift | 2 + .../cmdArgs/MoveNodeToWorkspaceCmdArgs.swift | 17 +++++---- .../cmdArgs/MoveWorkspaceToMonitor.swift | 2 + .../Common/cmdArgs/ReloadConfigCmdArgs.swift | 3 +- Sources/Common/cmdArgs/ResizeCmdArgs.swift | 7 ++-- .../ServerVersionInternalCommandCmdArgs.swift | 3 ++ Sources/Common/cmdArgs/SplitCmdArgs.swift | 8 ++-- .../cmdArgs/TriggerBindingCmdArgs.swift | 2 + .../WorkspaceBackAndForthCmdArgs.swift | 3 ++ Sources/Common/cmdArgs/WorkspaceCmdArgs.swift | 37 ++++++++----------- .../cmdArgs/other/parseCmdArgsUtils.swift | 4 ++ .../Common/cmdArgs/query/ConfigCmdArgs.swift | 2 + .../cmdArgs/query/DebugWindowsCmdArgs.swift | 3 ++ .../cmdArgs/query/ListAppsCmdArgs.swift | 2 + .../cmdArgs/query/ListMonitorsCmdArgs.swift | 7 ++-- .../cmdArgs/query/ListWindowsCmdArgs.swift | 4 +- .../cmdArgs/query/ListWorkspacesCmdArgs.swift | 2 + 35 files changed, 127 insertions(+), 60 deletions(-) diff --git a/Sources/Common/cmdArgs/BalanceSizesCmdArgs.swift b/Sources/Common/cmdArgs/BalanceSizesCmdArgs.swift index 444bc539..0068b254 100644 --- a/Sources/Common/cmdArgs/BalanceSizesCmdArgs.swift +++ b/Sources/Common/cmdArgs/BalanceSizesCmdArgs.swift @@ -2,4 +2,6 @@ public struct BalanceSizesCmdArgs: RawCmdArgs, CmdArgs { public let rawArgs: EquatableNoop<[String]> public init(rawArgs: [String]) { self.rawArgs = .init(rawArgs) } public static let parser: CmdParser = noArgsParser(.balanceSizes, allowInConfig: true) + public var windowId: UInt32? + public var workspaceName: String? } diff --git a/Sources/Common/cmdArgs/CloseAllWindowsButCurrentCmdArgs.swift b/Sources/Common/cmdArgs/CloseAllWindowsButCurrentCmdArgs.swift index 55320b25..8ed44fcf 100644 --- a/Sources/Common/cmdArgs/CloseAllWindowsButCurrentCmdArgs.swift +++ b/Sources/Common/cmdArgs/CloseAllWindowsButCurrentCmdArgs.swift @@ -18,6 +18,8 @@ public struct CloseAllWindowsButCurrentCmdArgs: RawCmdArgs, CmdArgs { ) public var closeArgs = CloseCmdArgs(rawArgs: []) + public var windowId: UInt32? + public var workspaceName: String? } public func parseCloseAllWindowsButCurrentCmdArgs(_ args: [String]) -> ParsedCmd { diff --git a/Sources/Common/cmdArgs/CloseCmdArgs.swift b/Sources/Common/cmdArgs/CloseCmdArgs.swift index 32b13914..3958197d 100644 --- a/Sources/Common/cmdArgs/CloseCmdArgs.swift +++ b/Sources/Common/cmdArgs/CloseCmdArgs.swift @@ -18,4 +18,6 @@ public struct CloseCmdArgs: RawCmdArgs, CmdArgs { ) public var quitIfLastWindow: Bool = false + public var windowId: UInt32? + public var workspaceName: String? } diff --git a/Sources/Common/cmdArgs/EnableCmdArgs.swift b/Sources/Common/cmdArgs/EnableCmdArgs.swift index 2ec7debb..f5aee2a8 100644 --- a/Sources/Common/cmdArgs/EnableCmdArgs.swift +++ b/Sources/Common/cmdArgs/EnableCmdArgs.swift @@ -1,4 +1,6 @@ public struct EnableCmdArgs: RawCmdArgs { + public let rawArgs: EquatableNoop<[String]> + fileprivate init(rawArgs: [String]) { self.rawArgs = .init(rawArgs) } public static let parser: CmdParser = cmdParser( kind: .enable, allowInConfig: true, @@ -16,12 +18,11 @@ public struct EnableCmdArgs: RawCmdArgs { ], arguments: [newArgParser(\.targetState, parseState, mandatoryArgPlaceholder: EnableCmdArgs.State.unionLiteral)] ) + public var windowId: UInt32? + public var workspaceName: String? public var targetState: Lateinit = .uninitialized public var failIfNoop: Bool = false - public let rawArgs: EquatableNoop<[String]> - fileprivate init(rawArgs: [String]) { self.rawArgs = .init(rawArgs) } - public init(rawArgs: [String], targetState: State) { self.rawArgs = .init(rawArgs) self.targetState = .initialized(targetState) diff --git a/Sources/Common/cmdArgs/ExecAndForgetCmdArgs.swift b/Sources/Common/cmdArgs/ExecAndForgetCmdArgs.swift index 4f1accc7..ea4f48af 100644 --- a/Sources/Common/cmdArgs/ExecAndForgetCmdArgs.swift +++ b/Sources/Common/cmdArgs/ExecAndForgetCmdArgs.swift @@ -1,13 +1,16 @@ public struct ExecAndForgetCmdArgs: CmdArgs { - public let bashScript: String + public var rawArgs: EquatableNoop<[String]> { .init([bashScript]) } public static let info: CmdStaticInfo = CmdStaticInfo( help: "USAGE: exec-and-forget ", kind: .execAndForget, allowInConfig: true ) - public var rawArgs: EquatableNoop<[String]> { .init([bashScript]) } public init(bashScript: String) { self.bashScript = bashScript } + + public let bashScript: String + public var windowId: UInt32? + public var workspaceName: String? } diff --git a/Sources/Common/cmdArgs/FlattenWorkspaceTreeCmdArgs.swift b/Sources/Common/cmdArgs/FlattenWorkspaceTreeCmdArgs.swift index 5ebc8b36..d4a4f56d 100644 --- a/Sources/Common/cmdArgs/FlattenWorkspaceTreeCmdArgs.swift +++ b/Sources/Common/cmdArgs/FlattenWorkspaceTreeCmdArgs.swift @@ -2,4 +2,7 @@ public struct FlattenWorkspaceTreeCmdArgs: RawCmdArgs, CmdArgs { public let rawArgs: EquatableNoop<[String]> public init(rawArgs: [String]) { self.rawArgs = .init(rawArgs) } public static let parser: CmdParser = noArgsParser(.flattenWorkspaceTree, allowInConfig: true) + + public var windowId: UInt32? + public var workspaceName: String? } diff --git a/Sources/Common/cmdArgs/FocusBackAndForthCmdArgs.swift b/Sources/Common/cmdArgs/FocusBackAndForthCmdArgs.swift index 489a94b8..9a44b4ba 100644 --- a/Sources/Common/cmdArgs/FocusBackAndForthCmdArgs.swift +++ b/Sources/Common/cmdArgs/FocusBackAndForthCmdArgs.swift @@ -2,4 +2,7 @@ public struct FocusBackAndForthCmdArgs: RawCmdArgs, CmdArgs { public let rawArgs: EquatableNoop<[String]> public init(rawArgs: [String]) { self.rawArgs = .init(rawArgs) } public static let parser: CmdParser = noArgsParser(.focusBackAndForth, allowInConfig: true) + + public var windowId: UInt32? + public var workspaceName: String? } diff --git a/Sources/Common/cmdArgs/FocusCmdArgs.swift b/Sources/Common/cmdArgs/FocusCmdArgs.swift index 824deb1b..f4470c99 100644 --- a/Sources/Common/cmdArgs/FocusCmdArgs.swift +++ b/Sources/Common/cmdArgs/FocusCmdArgs.swift @@ -2,6 +2,8 @@ private let boundar = "" private let actio = "" public struct FocusCmdArgs: CmdArgs, RawCmdArgs, Equatable, AeroAny { + public let rawArgs: EquatableNoop<[String]> + fileprivate init(rawArgs: [String]) { self.rawArgs = .init(rawArgs) } public static let parser: CmdParser = cmdParser( kind: .focus, allowInConfig: true, @@ -37,13 +39,11 @@ public struct FocusCmdArgs: CmdArgs, RawCmdArgs, Equatable, AeroAny { public var rawBoundaries: Boundaries? = nil // todo cover boundaries wrapping with tests public var rawBoundariesAction: WhenBoundariesCrossed? = nil - public var windowId: UInt32? = nil public var dfsIndex: UInt32? = nil public var direction: CardinalDirection? = nil public var floatingAsTiling: Bool = true - - public let rawArgs: EquatableNoop<[String]> - fileprivate init(rawArgs: [String]) { self.rawArgs = .init(rawArgs) } + public var windowId: UInt32? + public var workspaceName: String? public init(rawArgs: [String], direction: CardinalDirection) { self.rawArgs = .init(rawArgs) diff --git a/Sources/Common/cmdArgs/FocusMonitorCmdArgs.swift b/Sources/Common/cmdArgs/FocusMonitorCmdArgs.swift index a1512347..029767ba 100644 --- a/Sources/Common/cmdArgs/FocusMonitorCmdArgs.swift +++ b/Sources/Common/cmdArgs/FocusMonitorCmdArgs.swift @@ -29,6 +29,8 @@ public struct FocusMonitorCmdArgs: RawCmdArgs, CmdArgs { public var wrapAround: Bool = false public var target: Lateinit = .uninitialized + public var windowId: UInt32? + public var workspaceName: String? } public func parseFocusMonitorCmdArgs(_ args: [String]) -> ParsedCmd { diff --git a/Sources/Common/cmdArgs/FullscreenCmdArgs.swift b/Sources/Common/cmdArgs/FullscreenCmdArgs.swift index 922c56b5..d705b1ad 100644 --- a/Sources/Common/cmdArgs/FullscreenCmdArgs.swift +++ b/Sources/Common/cmdArgs/FullscreenCmdArgs.swift @@ -28,6 +28,8 @@ public struct FullscreenCmdArgs: CmdArgs, RawCmdArgs { public var toggle: ToggleEnum = .toggle public var noOuterGaps: Bool = false public var failIfNoop: Bool = false + public var windowId: UInt32? + public var workspaceName: String? } public func parseFullscreenCmdArgs(_ args: [String]) -> ParsedCmd { diff --git a/Sources/Common/cmdArgs/JoinWithCmdArgs.swift b/Sources/Common/cmdArgs/JoinWithCmdArgs.swift index 96499d05..ffd9a1c8 100644 --- a/Sources/Common/cmdArgs/JoinWithCmdArgs.swift +++ b/Sources/Common/cmdArgs/JoinWithCmdArgs.swift @@ -1,4 +1,6 @@ public struct JoinWithCmdArgs: CmdArgs, RawCmdArgs { + public let rawArgs: EquatableNoop<[String]> + init(rawArgs: [String]) { self.rawArgs = .init(rawArgs) } public static let parser: CmdParser = cmdParser( kind: .joinWith, allowInConfig: true, @@ -11,10 +13,10 @@ public struct JoinWithCmdArgs: CmdArgs, RawCmdArgs { options: [:], arguments: [newArgParser(\.direction, parseCardinalDirectionArg, mandatoryArgPlaceholder: CardinalDirection.unionLiteral)] ) - public var direction: Lateinit = .uninitialized - public let rawArgs: EquatableNoop<[String]> - init(rawArgs: [String]) { self.rawArgs = .init(rawArgs) } + public var direction: Lateinit = .uninitialized + public var windowId: UInt32? + public var workspaceName: String? public init(rawArgs: [String], direction: CardinalDirection) { self.rawArgs = .init(rawArgs) diff --git a/Sources/Common/cmdArgs/LayoutCmdArgs.swift b/Sources/Common/cmdArgs/LayoutCmdArgs.swift index 4c68b75e..bf0d4a98 100644 --- a/Sources/Common/cmdArgs/LayoutCmdArgs.swift +++ b/Sources/Common/cmdArgs/LayoutCmdArgs.swift @@ -1,4 +1,6 @@ public struct LayoutCmdArgs: CmdArgs, RawCmdArgs, Equatable { + public let rawArgs: EquatableNoop<[String]> + fileprivate init(rawArgs: [String]) { self.rawArgs = .init(rawArgs) } public static let parser: CmdParser = cmdParser( kind: .layout, allowInConfig: true, @@ -11,10 +13,10 @@ public struct LayoutCmdArgs: CmdArgs, RawCmdArgs, Equatable { options: [:], arguments: [newArgParser(\.toggleBetween, parseToggleBetween, mandatoryArgPlaceholder: LayoutDescription.unionLiteral)] ) - public var toggleBetween: Lateinit<[LayoutDescription]> = .uninitialized - public let rawArgs: EquatableNoop<[String]> - fileprivate init(rawArgs: [String]) { self.rawArgs = .init(rawArgs) } + public var toggleBetween: Lateinit<[LayoutDescription]> = .uninitialized + public var windowId: UInt32? + public var workspaceName: String? public init(rawArgs: [String], toggleBetween: [LayoutDescription]) { self.rawArgs = .init(rawArgs) diff --git a/Sources/Common/cmdArgs/ListExecEnvVarsCmdArgs.swift b/Sources/Common/cmdArgs/ListExecEnvVarsCmdArgs.swift index 4d75b019..779c2707 100644 --- a/Sources/Common/cmdArgs/ListExecEnvVarsCmdArgs.swift +++ b/Sources/Common/cmdArgs/ListExecEnvVarsCmdArgs.swift @@ -2,4 +2,7 @@ public struct ListExecEnvVarsCmdArgs: RawCmdArgs, CmdArgs { public let rawArgs: EquatableNoop<[String]> public init(rawArgs: [String]) { self.rawArgs = .init(rawArgs) } public static let parser: CmdParser = noArgsParser(.listExecEnvVars, allowInConfig: true) + + public var windowId: UInt32? + public var workspaceName: String? } diff --git a/Sources/Common/cmdArgs/MacosNativeFullscreen.swift b/Sources/Common/cmdArgs/MacosNativeFullscreen.swift index 18101972..37c42242 100644 --- a/Sources/Common/cmdArgs/MacosNativeFullscreen.swift +++ b/Sources/Common/cmdArgs/MacosNativeFullscreen.swift @@ -1,7 +1,5 @@ public struct MacosNativeFullscreenCmdArgs: CmdArgs, RawCmdArgs { public let rawArgs: EquatableNoop<[String]> - public var failIfNoop: Bool = false - public init(rawArgs: [String]) { self.rawArgs = .init(rawArgs) } public static let parser: CmdParser = cmdParser( kind: .macosNativeFullscreen, @@ -24,7 +22,11 @@ public struct MacosNativeFullscreenCmdArgs: CmdArgs, RawCmdArgs { ], arguments: [ArgParser(\.toggle, parseToggleEnum)] ) + public var toggle: ToggleEnum = .toggle + public var failIfNoop: Bool = false + public var windowId: UInt32? + public var workspaceName: String? } public func parseMacosNativeFullscreenCmdArgs(_ args: [String]) -> ParsedCmd { diff --git a/Sources/Common/cmdArgs/MacosNativeMinimize.swift b/Sources/Common/cmdArgs/MacosNativeMinimize.swift index 3285e239..e77351f0 100644 --- a/Sources/Common/cmdArgs/MacosNativeMinimize.swift +++ b/Sources/Common/cmdArgs/MacosNativeMinimize.swift @@ -2,4 +2,7 @@ public struct MacosNativeMinimizeCmdArgs: RawCmdArgs, CmdArgs { public let rawArgs: EquatableNoop<[String]> public init(rawArgs: [String]) { self.rawArgs = .init(rawArgs) } public static let parser: CmdParser = noArgsParser(.macosNativeMinimize, allowInConfig: true) + + public var windowId: UInt32? + public var workspaceName: String? } diff --git a/Sources/Common/cmdArgs/ModeCmdArgs.swift b/Sources/Common/cmdArgs/ModeCmdArgs.swift index bd502a49..852002ac 100644 --- a/Sources/Common/cmdArgs/ModeCmdArgs.swift +++ b/Sources/Common/cmdArgs/ModeCmdArgs.swift @@ -16,7 +16,10 @@ public struct ModeCmdArgs: RawCmdArgs { options: [:], arguments: [newArgParser(\.targetMode, parseTargetMode, mandatoryArgPlaceholder: "")] ) + public var targetMode: Lateinit = .uninitialized + public var windowId: UInt32? + public var workspaceName: String? } private func parseTargetMode(arg: String, nextArgs: inout [String]) -> Parsed { diff --git a/Sources/Common/cmdArgs/MoveCmdArgs.swift b/Sources/Common/cmdArgs/MoveCmdArgs.swift index b9949447..63030b65 100644 --- a/Sources/Common/cmdArgs/MoveCmdArgs.swift +++ b/Sources/Common/cmdArgs/MoveCmdArgs.swift @@ -1,4 +1,6 @@ public struct MoveCmdArgs: CmdArgs, RawCmdArgs { + public let rawArgs: EquatableNoop<[String]> + fileprivate init(rawArgs: [String]) { self.rawArgs = .init(rawArgs) } public static let parser: CmdParser = cmdParser( kind: .move, allowInConfig: true, @@ -11,10 +13,10 @@ public struct MoveCmdArgs: CmdArgs, RawCmdArgs { options: [:], arguments: [newArgParser(\.direction, parseCardinalDirectionArg, mandatoryArgPlaceholder: CardinalDirection.unionLiteral)] ) - public var direction: Lateinit = .uninitialized - public let rawArgs: EquatableNoop<[String]> - fileprivate init(rawArgs: [String]) { self.rawArgs = .init(rawArgs) } + public var direction: Lateinit = .uninitialized + public var windowId: UInt32? + public var workspaceName: String? public init(rawArgs: [String], _ direction: CardinalDirection) { self.rawArgs = .init(rawArgs) diff --git a/Sources/Common/cmdArgs/MoveMouseCmdArgs.swift b/Sources/Common/cmdArgs/MoveMouseCmdArgs.swift index 83cee663..3e53061f 100644 --- a/Sources/Common/cmdArgs/MoveMouseCmdArgs.swift +++ b/Sources/Common/cmdArgs/MoveMouseCmdArgs.swift @@ -22,6 +22,8 @@ public struct MoveMouseCmdArgs: CmdArgs, RawCmdArgs { public var failIfNoop: Bool = false public var mouseTarget: Lateinit = .uninitialized + public var windowId: UInt32? + public var workspaceName: String? } func parseMouseTarget(arg: String, nextArgs: inout [String]) -> Parsed { diff --git a/Sources/Common/cmdArgs/MoveNodeToMonitorCmdArgs.swift b/Sources/Common/cmdArgs/MoveNodeToMonitorCmdArgs.swift index fead1b69..8d1f4333 100644 --- a/Sources/Common/cmdArgs/MoveNodeToMonitorCmdArgs.swift +++ b/Sources/Common/cmdArgs/MoveNodeToMonitorCmdArgs.swift @@ -29,6 +29,8 @@ public struct MoveNodeToMonitorCmdArgs: RawCmdArgs, CmdArgs, Equatable { public var wrapAround: Bool = false public var target: Lateinit = .uninitialized + public var windowId: UInt32? + public var workspaceName: String? } public func parseMoveNodeToMonitorCmdArgs(_ args: [String]) -> ParsedCmd { diff --git a/Sources/Common/cmdArgs/MoveNodeToWorkspaceCmdArgs.swift b/Sources/Common/cmdArgs/MoveNodeToWorkspaceCmdArgs.swift index 2436bc37..48b46400 100644 --- a/Sources/Common/cmdArgs/MoveNodeToWorkspaceCmdArgs.swift +++ b/Sources/Common/cmdArgs/MoveNodeToWorkspaceCmdArgs.swift @@ -1,14 +1,6 @@ public struct MoveNodeToWorkspaceCmdArgs: CmdArgs, RawCmdArgs { public let rawArgs: EquatableNoop<[String]> public var target: Lateinit = .uninitialized - - public var _wrapAround: Bool? - public var failIfNoop: Bool = false - - public init(rawArgs: [String]) { - self.rawArgs = .init(rawArgs) - } - public static let parser: CmdParser = cmdParser( kind: .moveNodeToWorkspace, allowInConfig: true, @@ -31,6 +23,15 @@ public struct MoveNodeToWorkspaceCmdArgs: CmdArgs, RawCmdArgs { ], arguments: [newArgParser(\.target, parseWorkspaceTarget, mandatoryArgPlaceholder: workspaceTargetPlaceholder)] ) + + public var _wrapAround: Bool? + public var failIfNoop: Bool = false + public var windowId: UInt32? + public var workspaceName: String? + + public init(rawArgs: [String]) { + self.rawArgs = .init(rawArgs) + } } public extension MoveNodeToWorkspaceCmdArgs { diff --git a/Sources/Common/cmdArgs/MoveWorkspaceToMonitor.swift b/Sources/Common/cmdArgs/MoveWorkspaceToMonitor.swift index 1183629c..cc657c7d 100644 --- a/Sources/Common/cmdArgs/MoveWorkspaceToMonitor.swift +++ b/Sources/Common/cmdArgs/MoveWorkspaceToMonitor.swift @@ -17,6 +17,8 @@ public struct MoveWorkspaceToMonitorCmdArgs: RawCmdArgs { arguments: [newArgParser(\.target, parseMonitorTarget, mandatoryArgPlaceholder: "(next|prev)")] ) + public var windowId: UInt32? + public var workspaceName: String? public var wrapAround: Bool = false public var target: Lateinit = .uninitialized public enum MonitorTarget: String, CaseIterable { diff --git a/Sources/Common/cmdArgs/ReloadConfigCmdArgs.swift b/Sources/Common/cmdArgs/ReloadConfigCmdArgs.swift index 25fa8d7b..d31a6870 100644 --- a/Sources/Common/cmdArgs/ReloadConfigCmdArgs.swift +++ b/Sources/Common/cmdArgs/ReloadConfigCmdArgs.swift @@ -1,7 +1,6 @@ public struct ReloadConfigCmdArgs: RawCmdArgs, CmdArgs { public let rawArgs: EquatableNoop<[String]> public init(rawArgs: [String]) { self.rawArgs = .init(rawArgs) } - public static let parser: CmdParser = cmdParser( kind: .reloadConfig, allowInConfig: true, @@ -22,4 +21,6 @@ public struct ReloadConfigCmdArgs: RawCmdArgs, CmdArgs { public var noGui: Bool = false public var dryRun: Bool = false + public var windowId: UInt32? + public var workspaceName: String? } diff --git a/Sources/Common/cmdArgs/ResizeCmdArgs.swift b/Sources/Common/cmdArgs/ResizeCmdArgs.swift index 960a9824..82be2b8c 100644 --- a/Sources/Common/cmdArgs/ResizeCmdArgs.swift +++ b/Sources/Common/cmdArgs/ResizeCmdArgs.swift @@ -1,4 +1,6 @@ public struct ResizeCmdArgs: RawCmdArgs, Equatable { + public let rawArgs: EquatableNoop<[String]> + fileprivate init(rawArgs: [String]) { self.rawArgs = .init(rawArgs) } public static let parser: CmdParser = cmdParser( kind: .resize, allowInConfig: true, @@ -21,8 +23,9 @@ public struct ResizeCmdArgs: RawCmdArgs, Equatable { public var dimension: Lateinit = .uninitialized public var units: Lateinit = .uninitialized + public var windowId: UInt32? + public var workspaceName: String? - public let rawArgs: EquatableNoop<[String]> public init( rawArgs: [String], dimension: Dimension, @@ -33,8 +36,6 @@ public struct ResizeCmdArgs: RawCmdArgs, Equatable { self.units = .initialized(units) } - fileprivate init(rawArgs: [String]) { self.rawArgs = .init(rawArgs) } - public enum Dimension: String, CaseIterable, Equatable { case width, height, smart } diff --git a/Sources/Common/cmdArgs/ServerVersionInternalCommandCmdArgs.swift b/Sources/Common/cmdArgs/ServerVersionInternalCommandCmdArgs.swift index 5865304a..085d71de 100644 --- a/Sources/Common/cmdArgs/ServerVersionInternalCommandCmdArgs.swift +++ b/Sources/Common/cmdArgs/ServerVersionInternalCommandCmdArgs.swift @@ -2,4 +2,7 @@ public struct ServerVersionInternalCommandCmdArgs: RawCmdArgs, CmdArgs { public let rawArgs: EquatableNoop<[String]> public init(rawArgs: [String]) { self.rawArgs = .init(rawArgs) } public static let parser: CmdParser = noArgsParser(.serverVersionInternalCommand, allowInConfig: false) + + public var windowId: UInt32? + public var workspaceName: String? } diff --git a/Sources/Common/cmdArgs/SplitCmdArgs.swift b/Sources/Common/cmdArgs/SplitCmdArgs.swift index 89e912ab..95262bfe 100644 --- a/Sources/Common/cmdArgs/SplitCmdArgs.swift +++ b/Sources/Common/cmdArgs/SplitCmdArgs.swift @@ -1,4 +1,6 @@ public struct SplitCmdArgs: RawCmdArgs { + public let rawArgs: EquatableNoop<[String]> + fileprivate init(rawArgs: [String]) { self.rawArgs = .init(rawArgs) } public static let parser: CmdParser = cmdParser( kind: .split, allowInConfig: true, @@ -11,10 +13,10 @@ public struct SplitCmdArgs: RawCmdArgs { options: [:], arguments: [newArgParser(\.arg, parseSplitArg, mandatoryArgPlaceholder: SplitArg.unionLiteral)] ) - public var arg: Lateinit = .uninitialized - public let rawArgs: EquatableNoop<[String]> - fileprivate init(rawArgs: [String]) { self.rawArgs = .init(rawArgs) } + public var arg: Lateinit = .uninitialized + public var windowId: UInt32? + public var workspaceName: String? public init(rawArgs: [String], _ arg: SplitArg) { self.rawArgs = .init(rawArgs) diff --git a/Sources/Common/cmdArgs/TriggerBindingCmdArgs.swift b/Sources/Common/cmdArgs/TriggerBindingCmdArgs.swift index b3f1db97..33e542f8 100644 --- a/Sources/Common/cmdArgs/TriggerBindingCmdArgs.swift +++ b/Sources/Common/cmdArgs/TriggerBindingCmdArgs.swift @@ -21,6 +21,8 @@ public struct TriggerBindingCmdArgs: RawCmdArgs, CmdArgs { public var _mode: String? = nil public var binding: Lateinit = .uninitialized + public var windowId: UInt32? + public var workspaceName: String? } public extension TriggerBindingCmdArgs { diff --git a/Sources/Common/cmdArgs/WorkspaceBackAndForthCmdArgs.swift b/Sources/Common/cmdArgs/WorkspaceBackAndForthCmdArgs.swift index da3ef940..14b29030 100644 --- a/Sources/Common/cmdArgs/WorkspaceBackAndForthCmdArgs.swift +++ b/Sources/Common/cmdArgs/WorkspaceBackAndForthCmdArgs.swift @@ -2,4 +2,7 @@ public struct WorkspaceBackAndForthCmdArgs: RawCmdArgs, CmdArgs { public let rawArgs: EquatableNoop<[String]> public init(rawArgs: [String]) { self.rawArgs = .init(rawArgs) } public static let parser: CmdParser = noArgsParser(.workspaceBackAndForth, allowInConfig: true) + + public var windowId: UInt32? + public var workspaceName: String? } diff --git a/Sources/Common/cmdArgs/WorkspaceCmdArgs.swift b/Sources/Common/cmdArgs/WorkspaceCmdArgs.swift index 444379e2..c3277d18 100644 --- a/Sources/Common/cmdArgs/WorkspaceCmdArgs.swift +++ b/Sources/Common/cmdArgs/WorkspaceCmdArgs.swift @@ -1,18 +1,6 @@ public struct WorkspaceCmdArgs: RawCmdArgs { public let rawArgs: EquatableNoop<[String]> - public var target: Lateinit = .uninitialized - - // direct workspace target OPTIONS - public var _autoBackAndForth: Bool? - public var failIfNoop: Bool = false - - // next|prev OPTIONS - public var _wrapAround: Bool? - - public init(rawArgs: [String]) { - self.rawArgs = .init(rawArgs) - } - + public init(rawArgs: [String]) { self.rawArgs = .init(rawArgs) } public static let parser: CmdParser = cmdParser( kind: .workspace, allowInConfig: true, @@ -38,6 +26,21 @@ public struct WorkspaceCmdArgs: RawCmdArgs { ], arguments: [newArgParser(\.target, parseWorkspaceTarget, mandatoryArgPlaceholder: workspaceTargetPlaceholder)] ) + + public var windowId: UInt32? + public var workspaceName: String? + public var target: Lateinit = .uninitialized + public var _autoBackAndForth: Bool? + public var failIfNoop: Bool = false + public var _wrapAround: Bool? +} + +public func parseWorkspaceCmdArgs(_ args: [String]) -> ParsedCmd { + parseRawCmdArgs(WorkspaceCmdArgs(rawArgs: args), args) + .filter("--wrapAround requires using (prev|next) argument") { ($0._wrapAround != nil).implies($0.target.val.isRelatve) } + .filterNot("--auto-back-and-forth is incompatible with (next|prev)") { $0._autoBackAndForth != nil && $0.target.val.isRelatve } + .filterNot("--fail-if-noop is incompatible with (next|prev)") { $0.failIfNoop && $0.target.val.isRelatve } + .filterNot("--fail-if-noop is incompatible with --auto-back-and-forth") { $0.autoBackAndForth && $0.failIfNoop } } public extension WorkspaceCmdArgs { @@ -60,14 +63,6 @@ public enum WorkspaceTarget: Equatable { } } -public func parseWorkspaceCmdArgs(_ args: [String]) -> ParsedCmd { - parseRawCmdArgs(WorkspaceCmdArgs(rawArgs: args), args) - .filter("--wrapAround requires using (prev|next) argument") { ($0._wrapAround != nil).implies($0.target.val.isRelatve) } - .filterNot("--auto-back-and-forth is incompatible with (next|prev)") { $0._autoBackAndForth != nil && $0.target.val.isRelatve } - .filterNot("--fail-if-noop is incompatible with (next|prev)") { $0.failIfNoop && $0.target.val.isRelatve } - .filterNot("--fail-if-noop is incompatible with --auto-back-and-forth") { $0.autoBackAndForth && $0.failIfNoop } -} - let workspaceTargetPlaceholder = "(|next|prev)" func parseWorkspaceTarget(arg: String, nextArgs: inout [String]) -> Parsed { diff --git a/Sources/Common/cmdArgs/other/parseCmdArgsUtils.swift b/Sources/Common/cmdArgs/other/parseCmdArgsUtils.swift index d4a3d98c..647d744c 100644 --- a/Sources/Common/cmdArgs/other/parseCmdArgsUtils.swift +++ b/Sources/Common/cmdArgs/other/parseCmdArgsUtils.swift @@ -9,6 +9,10 @@ public extension RawCmdArgs { public protocol CmdArgs: Equatable, CustomStringConvertible { static var info: CmdStaticInfo { get } var rawArgs: EquatableNoop<[String]> { get } // Non Equatable because test comparion + + // Two very common flags among commands + var windowId: UInt32? { get set } + var workspaceName: String? { get set } } public extension CmdArgs { diff --git a/Sources/Common/cmdArgs/query/ConfigCmdArgs.swift b/Sources/Common/cmdArgs/query/ConfigCmdArgs.swift index 5d2612a1..ab3dc777 100644 --- a/Sources/Common/cmdArgs/query/ConfigCmdArgs.swift +++ b/Sources/Common/cmdArgs/query/ConfigCmdArgs.swift @@ -36,6 +36,8 @@ public struct ConfigCmdArgs: CmdArgs, RawCmdArgs, Equatable { public var allKeys: Bool = false public var configPath: Bool = false public var keyNameToGet: String? = nil + public var windowId: UInt32? + public var workspaceName: String? } public extension ConfigCmdArgs { diff --git a/Sources/Common/cmdArgs/query/DebugWindowsCmdArgs.swift b/Sources/Common/cmdArgs/query/DebugWindowsCmdArgs.swift index 3f877ac8..4a2b193f 100644 --- a/Sources/Common/cmdArgs/query/DebugWindowsCmdArgs.swift +++ b/Sources/Common/cmdArgs/query/DebugWindowsCmdArgs.swift @@ -2,4 +2,7 @@ public struct DebugWindowsCmdArgs: RawCmdArgs, CmdArgs { public let rawArgs: EquatableNoop<[String]> public init(rawArgs: EquatableNoop<[String]>) { self.rawArgs = rawArgs } public static let parser: CmdParser = noArgsParser(.debugWindows, allowInConfig: false) + + public var windowId: UInt32? + public var workspaceName: String? } diff --git a/Sources/Common/cmdArgs/query/ListAppsCmdArgs.swift b/Sources/Common/cmdArgs/query/ListAppsCmdArgs.swift index 8463345a..618e89bf 100644 --- a/Sources/Common/cmdArgs/query/ListAppsCmdArgs.swift +++ b/Sources/Common/cmdArgs/query/ListAppsCmdArgs.swift @@ -20,6 +20,8 @@ public struct ListAppsCmdArgs: RawCmdArgs, CmdArgs { arguments: [] ) + public var windowId: UInt32? + public var workspaceName: String? public var macosHidden: Bool? public var format: [StringInterToken] = [ .value("app-pid"), .value("right-padding"), .literal(" | "), diff --git a/Sources/Common/cmdArgs/query/ListMonitorsCmdArgs.swift b/Sources/Common/cmdArgs/query/ListMonitorsCmdArgs.swift index 4bb6cde8..d263de73 100644 --- a/Sources/Common/cmdArgs/query/ListMonitorsCmdArgs.swift +++ b/Sources/Common/cmdArgs/query/ListMonitorsCmdArgs.swift @@ -1,4 +1,6 @@ public struct ListMonitorsCmdArgs: RawCmdArgs, CmdArgs, Equatable { + public let rawArgs: EquatableNoop<[String]> + public init(rawArgs: [String]) { self.rawArgs = .init(rawArgs) } public static let parser: CmdParser = cmdParser( kind: .listMonitors, allowInConfig: false, @@ -19,13 +21,12 @@ public struct ListMonitorsCmdArgs: RawCmdArgs, CmdArgs, Equatable { arguments: [] ) + public var windowId: UInt32? + public var workspaceName: String? public var focused: Bool? public var mouse: Bool? public var format: [StringInterToken] = [ .value("monitor-id"), .value("right-padding"), .literal(" | "), .value("monitor-name"), ] - - public let rawArgs: EquatableNoop<[String]> - public init(rawArgs: [String]) { self.rawArgs = .init(rawArgs) } } diff --git a/Sources/Common/cmdArgs/query/ListWindowsCmdArgs.swift b/Sources/Common/cmdArgs/query/ListWindowsCmdArgs.swift index 26edbab6..3862139c 100644 --- a/Sources/Common/cmdArgs/query/ListWindowsCmdArgs.swift +++ b/Sources/Common/cmdArgs/query/ListWindowsCmdArgs.swift @@ -39,8 +39,10 @@ public struct ListWindowsCmdArgs: RawCmdArgs, CmdArgs, Equatable { ) fileprivate var all: Bool = false // ALIAS - public var focused: Bool = false + public var windowId: UInt32? + public var workspaceName: String? + public var focused: Bool = false public var monitors: [MonitorId] = [] public var workspaces: [WorkspaceFilter] = [] public var pidFilter: Int32? diff --git a/Sources/Common/cmdArgs/query/ListWorkspacesCmdArgs.swift b/Sources/Common/cmdArgs/query/ListWorkspacesCmdArgs.swift index d4b28b32..669ff5bf 100644 --- a/Sources/Common/cmdArgs/query/ListWorkspacesCmdArgs.swift +++ b/Sources/Common/cmdArgs/query/ListWorkspacesCmdArgs.swift @@ -37,6 +37,8 @@ public struct ListWorkspacesCmdArgs: RawCmdArgs, CmdArgs { fileprivate var all: Bool = false // Alias fileprivate var focused: Bool = false // Alias + public var windowId: UInt32? + public var workspaceName: String? public var onMonitors: [MonitorId] = [] public var visible: Bool? public var empty: Bool?