From 64e0bbc21389acbf5f1fcccda7ede6f44d0b77b7 Mon Sep 17 00:00:00 2001 From: Nikita Bobko Date: Sun, 17 Sep 2023 21:49:14 +0200 Subject: [PATCH] CardinalDirection --- AeroSpace.xcodeproj/project.pbxproj | 8 ++++---- src/command/FocusCommand.swift | 10 +++++----- src/command/parseCommand.swift | 2 +- src/tree/TreeNodeEx.swift | 2 +- src/util/{Direction.swift => CardinalDirection.swift} | 6 +++--- 5 files changed, 14 insertions(+), 14 deletions(-) rename src/util/{Direction.swift => CardinalDirection.swift} (79%) diff --git a/AeroSpace.xcodeproj/project.pbxproj b/AeroSpace.xcodeproj/project.pbxproj index 182f121f..6c2efaab 100644 --- a/AeroSpace.xcodeproj/project.pbxproj +++ b/AeroSpace.xcodeproj/project.pbxproj @@ -38,11 +38,11 @@ A5BFF75CF8021A585BC1F9D5 /* parseCommand.swift in Sources */ = {isa = PBXBuildFile; fileRef = CB03A4736BC3F6D19E4E69F3 /* parseCommand.swift */; }; AE76A183D0454E4C8ADCE380 /* SequenceEx.swift in Sources */ = {isa = PBXBuildFile; fileRef = AAE5DCAEC5EE619CE33859E7 /* SequenceEx.swift */; }; B0D0C37BAE7E7F0D0FF1E9FC /* GlobalObserver.swift in Sources */ = {isa = PBXBuildFile; fileRef = 3C2E5977331398421A4FC168 /* GlobalObserver.swift */; }; + B22C56FDE08827A03A92669B /* CardinalDirection.swift in Sources */ = {isa = PBXBuildFile; fileRef = 91E1664607E2B1A6030978BB /* CardinalDirection.swift */; }; B3702BB393A9B03CCAE4C60E /* refresh.swift in Sources */ = {isa = PBXBuildFile; fileRef = 526B113159987FA43EA41120 /* refresh.swift */; }; BC6511DA2ABE84164D90C181 /* ExecAndForgetCommand.swift in Sources */ = {isa = PBXBuildFile; fileRef = 569422C0C4C23EF3E024C8E6 /* ExecAndForgetCommand.swift */; }; BD6301B2CFC16FDE4223ACB8 /* MacApp.swift in Sources */ = {isa = PBXBuildFile; fileRef = B7DB782C527ABE0CF31740EB /* MacApp.swift */; }; BF16873111EEDE60A8AACD6B /* Workspace.swift in Sources */ = {isa = PBXBuildFile; fileRef = C3F068BCC50ED846DCBFDE57 /* Workspace.swift */; }; - C6C7B2520B940E3D028B334A /* Direction.swift in Sources */ = {isa = PBXBuildFile; fileRef = 6094492F5D46B22BAFA3741F /* Direction.swift */; }; D941E6DBC319F08676B40E5B /* TrayModel.swift in Sources */ = {isa = PBXBuildFile; fileRef = 4A8D2390FEF4421BBCA411C6 /* TrayModel.swift */; }; E5682579AEC6B84CF6FCE90D /* TilingContainer.swift in Sources */ = {isa = PBXBuildFile; fileRef = C848D6E57FDF22AAF0FB45E6 /* TilingContainer.swift */; }; EDFDE707B4DC5E500B1709B1 /* MoveThroughCommand.swift in Sources */ = {isa = PBXBuildFile; fileRef = 67B9FFF81EB0327ABD51A7FE /* MoveThroughCommand.swift */; }; @@ -82,7 +82,6 @@ 526B113159987FA43EA41120 /* refresh.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = refresh.swift; sourceTree = ""; }; 5274C575044C2A7123C57584 /* AeroSpace-Tests.xctest */ = {isa = PBXFileReference; explicitFileType = wrapper.cfbundle; includeInIndex = 0; path = "AeroSpace-Tests.xctest"; sourceTree = BUILT_PRODUCTS_DIR; }; 569422C0C4C23EF3E024C8E6 /* ExecAndForgetCommand.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ExecAndForgetCommand.swift; sourceTree = ""; }; - 6094492F5D46B22BAFA3741F /* Direction.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = Direction.swift; sourceTree = ""; }; 67B9FFF81EB0327ABD51A7FE /* MoveThroughCommand.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = MoveThroughCommand.swift; sourceTree = ""; }; 67DBAF4ECF8A0B931FC34EAD /* parseConfig.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = parseConfig.swift; sourceTree = ""; }; 6935AF0A2DB3D186D1C6218F /* NSWorkspaceEx.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = NSWorkspaceEx.swift; sourceTree = ""; }; @@ -90,6 +89,7 @@ 883D7F7F87FBE7D0BDE4E87F /* ArrayEx.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ArrayEx.swift; sourceTree = ""; }; 8B7A2DF0D1F72B80B1F04240 /* BundleEx.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = BundleEx.swift; sourceTree = ""; }; 8FE45A887100EB70912B07F0 /* default-config.toml */ = {isa = PBXFileReference; path = "default-config.toml"; sourceTree = ""; }; + 91E1664607E2B1A6030978BB /* CardinalDirection.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = CardinalDirection.swift; sourceTree = ""; }; 9245C6FACF389672EA71173B /* MacWindow.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = MacWindow.swift; sourceTree = ""; }; 954A434EE57D76F5A9D4140D /* MruStack.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = MruStack.swift; sourceTree = ""; }; 9752080BBA547C2A0EF076F0 /* Config.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = Config.swift; sourceTree = ""; }; @@ -230,8 +230,8 @@ 9D31BF26EAFA96F675D2C14B /* accessibility.swift */, 883D7F7F87FBE7D0BDE4E87F /* ArrayEx.swift */, 8B7A2DF0D1F72B80B1F04240 /* BundleEx.swift */, + 91E1664607E2B1A6030978BB /* CardinalDirection.swift */, 51CE37C1B8D858C81A396F40 /* CollectionEx.swift */, - 6094492F5D46B22BAFA3741F /* Direction.swift */, 345148B22F8A8F85109229AE /* Maybe.swift */, F6507EBAA795220FD0C05384 /* Monitor.swift */, 954A434EE57D76F5A9D4140D /* MruStack.swift */, @@ -349,12 +349,12 @@ 66E6CDA75DDD5E4B9647EDE2 /* AeroSpaceApp.swift in Sources */, A2CBF9674964F9083BB198D2 /* ArrayEx.swift in Sources */, 45AA5FD4A023AF751922BC22 /* BundleEx.swift in Sources */, + B22C56FDE08827A03A92669B /* CardinalDirection.swift in Sources */, 77FA83225024151CD556E1ED /* CloseAllWindowsButCurrentCommand.swift in Sources */, 1C46EBB55D401C0D1AFD50F0 /* CollectionEx.swift in Sources */, F982DB924450BBBB4FDF4C2C /* Command.swift in Sources */, 1D408CDF1A489E527327EB15 /* CompositeCommand.swift in Sources */, FD4386BC632BAA6A4105FFD8 /* Config.swift in Sources */, - C6C7B2520B940E3D028B334A /* Direction.swift in Sources */, BC6511DA2ABE84164D90C181 /* ExecAndForgetCommand.swift in Sources */, 2E06134604F2510189F1FA85 /* ExecAndWaitCommand.swift in Sources */, 0A90EEEAC020DD3A56736014 /* FocusCommand.swift in Sources */, diff --git a/src/command/FocusCommand.swift b/src/command/FocusCommand.swift index 82a50cf7..f84a6e82 100644 --- a/src/command/FocusCommand.swift +++ b/src/command/FocusCommand.swift @@ -1,7 +1,7 @@ struct FocusCommand: Command { - let direction: FDirection + let direction: Direction - enum FDirection: String { + enum Direction: String { case up, down, left, right case parent, child //, floating, tiling, toggle_tiling_floating // not needed @@ -13,7 +13,7 @@ struct FocusCommand: Command { func run() async { precondition(Thread.current.isMainThread) guard let window = NSWorkspace.focusedApp?.macApp?.focusedWindow ?? Workspace.focused.mruWindows.mostRecent else { return } - if let direction = direction.direction { + if let direction = direction.cardinal { let orientation = direction.orientation guard let topMostChild = window.parentsWithSelf.lazy.first(where: { $0.parent is Workspace || ($0.parent as? TilingContainer)?.orientation == orientation @@ -31,8 +31,8 @@ struct FocusCommand: Command { } } -extension FocusCommand.FDirection { - var direction: Direction? { +extension FocusCommand.Direction { + var cardinal: CardinalDirection? { switch self { case .up: return .up diff --git a/src/command/parseCommand.swift b/src/command/parseCommand.swift index 13859bdf..89f2d796 100644 --- a/src/command/parseCommand.swift +++ b/src/command/parseCommand.swift @@ -30,7 +30,7 @@ private func parseSingleCommand(_ raw: String, _ backtrace: TomlBacktrace) -> Co } else if firstWord == "exec_and_forget" { return ExecAndForgetCommand(bashCommand: raw.removePrefix(firstWord)) } else if firstWord == "focus" { - let direction = FocusCommand.FDirection(rawValue: parseSingleArg(args, firstWord, backtrace)) + let direction = FocusCommand.Direction(rawValue: parseSingleArg(args, firstWord, backtrace)) ?? errorT("\(backtrace): Can't parse '\(firstWord)' direction") return FocusCommand(direction: direction) } else if firstWord == "move_through" { diff --git a/src/tree/TreeNodeEx.swift b/src/tree/TreeNodeEx.swift index f83e26c7..c33a61dd 100644 --- a/src/tree/TreeNodeEx.swift +++ b/src/tree/TreeNodeEx.swift @@ -22,7 +22,7 @@ extension TreeNode { self as? Workspace ?? parent.workspace } - func allLeafWindowsRecursive(snappedTo: Direction) -> [MacWindow] { + func allLeafWindowsRecursive(snappedTo: CardinalDirection) -> [MacWindow] { if let workspace = self as? Workspace { return workspace.rootTilingContainer.allLeafWindowsRecursive(snappedTo: snappedTo) } else if let window = self as? MacWindow { diff --git a/src/util/Direction.swift b/src/util/CardinalDirection.swift similarity index 79% rename from src/util/Direction.swift rename to src/util/CardinalDirection.swift index f8cd49e1..8ac4e56c 100644 --- a/src/util/Direction.swift +++ b/src/util/CardinalDirection.swift @@ -1,11 +1,11 @@ -enum Direction: String { +enum CardinalDirection: String { case left, down, up, right } -extension Direction { +extension CardinalDirection { var orientation: Orientation { self == .up || self == .down ? .V : .H } var isPositive: Bool { self == .down || self == .right } - var opposite: Direction { + var opposite: CardinalDirection { switch self { case .left: return .right