From c8c825eb8679142f8a81259da3df4c7a1e2d2048 Mon Sep 17 00:00:00 2001 From: fence Date: Mon, 19 Jun 2023 13:18:08 +0200 Subject: [PATCH] Add TwoPaneRight Layout --- Amethyst.xcodeproj/project.pbxproj | 4 + .../contents.xcworkspacedata | 2 +- .../xcshareddata/IDEWorkspaceChecks.plist | 8 ++ .../xcshareddata/swiftpm/Package.resolved | 16 +++ .../xcshareddata/swiftpm/Package.resolved | 24 ++-- Amethyst/Debug/WindowsInfo.swift | 2 + .../Layout/Layouts/TwoPaneRightLayout.swift | 103 ++++++++++++++++++ Amethyst/Managers/LayoutType.swift | 8 ++ Podfile | 2 +- Podfile.lock | 8 +- 10 files changed, 160 insertions(+), 17 deletions(-) create mode 100644 Amethyst.xcodeproj/project.xcworkspace/xcshareddata/IDEWorkspaceChecks.plist create mode 100644 Amethyst.xcodeproj/project.xcworkspace/xcshareddata/swiftpm/Package.resolved create mode 100644 Amethyst/Layout/Layouts/TwoPaneRightLayout.swift diff --git a/Amethyst.xcodeproj/project.pbxproj b/Amethyst.xcodeproj/project.pbxproj index 09edd078..b86d8294 100644 --- a/Amethyst.xcodeproj/project.pbxproj +++ b/Amethyst.xcodeproj/project.pbxproj @@ -111,6 +111,7 @@ AA4AF40D26717DA900D2AE1B /* TwoPaneLayout.swift in Sources */ = {isa = PBXBuildFile; fileRef = AA4AF40C26717DA900D2AE1B /* TwoPaneLayout.swift */; }; AAAC6BAC2677DF7B00BEC1B0 /* TwoPaneLayoutTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = AAAC6BAB2677DF7B00BEC1B0 /* TwoPaneLayoutTests.swift */; }; ED989E6BAE0E8D035277478A /* Pods_Amethyst.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 6611384054CC1D59E32FC049 /* Pods_Amethyst.framework */; }; + F0B42E352A3CA45E00298E30 /* TwoPaneRightLayout.swift in Sources */ = {isa = PBXBuildFile; fileRef = F0B42E342A3CA45E00298E30 /* TwoPaneRightLayout.swift */; }; F46629C4272AD7A30040C275 /* FourColumnLayout.swift in Sources */ = {isa = PBXBuildFile; fileRef = F46629C3272AD7A30040C275 /* FourColumnLayout.swift */; }; /* End PBXBuildFile section */ @@ -255,6 +256,7 @@ A6102745A914DC1AD00462D0 /* Pods-Amethyst.release.xcconfig */ = {isa = PBXFileReference; includeInIndex = 1; lastKnownFileType = text.xcconfig; name = "Pods-Amethyst.release.xcconfig"; path = "Target Support Files/Pods-Amethyst/Pods-Amethyst.release.xcconfig"; sourceTree = ""; }; AA4AF40C26717DA900D2AE1B /* TwoPaneLayout.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = TwoPaneLayout.swift; sourceTree = ""; }; AAAC6BAB2677DF7B00BEC1B0 /* TwoPaneLayoutTests.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = TwoPaneLayoutTests.swift; sourceTree = ""; }; + F0B42E342A3CA45E00298E30 /* TwoPaneRightLayout.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = TwoPaneRightLayout.swift; sourceTree = ""; }; F46629C3272AD7A30040C275 /* FourColumnLayout.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = FourColumnLayout.swift; sourceTree = ""; }; /* End PBXFileReference section */ @@ -358,6 +360,7 @@ 4062AD341C1FA62500DB612B /* WideLayout.swift */, 4062AD3A1C206EA900DB612B /* WidescreenTallLayout.swift */, 4045416E268FFDA000861BE8 /* CustomLayout.swift */, + F0B42E342A3CA45E00298E30 /* TwoPaneRightLayout.swift */, ); path = Layouts; sourceTree = ""; @@ -880,6 +883,7 @@ 40A87FFD2404B1B4005EE9C6 /* DebugInfo.swift in Sources */, 4493EAA22139D9F000AA9623 /* ThreeColumnLayout.swift in Sources */, 40A7AEA7232ECF3000E79964 /* Windows.swift in Sources */, + F0B42E352A3CA45E00298E30 /* TwoPaneRightLayout.swift in Sources */, 404BE9CE1CFBB6E900D6C537 /* BinarySpacePartitioningLayout.swift in Sources */, 4062AD3B1C206EA900DB612B /* WidescreenTallLayout.swift in Sources */, 4058C46F1C4B119500B19D26 /* LayoutNameWindowController.swift in Sources */, diff --git a/Amethyst.xcodeproj/project.xcworkspace/contents.xcworkspacedata b/Amethyst.xcodeproj/project.xcworkspace/contents.xcworkspacedata index ebbb5e47..919434a6 100644 --- a/Amethyst.xcodeproj/project.xcworkspace/contents.xcworkspacedata +++ b/Amethyst.xcodeproj/project.xcworkspace/contents.xcworkspacedata @@ -2,6 +2,6 @@ + location = "self:"> diff --git a/Amethyst.xcodeproj/project.xcworkspace/xcshareddata/IDEWorkspaceChecks.plist b/Amethyst.xcodeproj/project.xcworkspace/xcshareddata/IDEWorkspaceChecks.plist new file mode 100644 index 00000000..18d98100 --- /dev/null +++ b/Amethyst.xcodeproj/project.xcworkspace/xcshareddata/IDEWorkspaceChecks.plist @@ -0,0 +1,8 @@ + + + + + IDEDidComputeMac32BitWarning + + + diff --git a/Amethyst.xcodeproj/project.xcworkspace/xcshareddata/swiftpm/Package.resolved b/Amethyst.xcodeproj/project.xcworkspace/xcshareddata/swiftpm/Package.resolved new file mode 100644 index 00000000..8514912a --- /dev/null +++ b/Amethyst.xcodeproj/project.xcworkspace/xcshareddata/swiftpm/Package.resolved @@ -0,0 +1,16 @@ +{ + "object": { + "pins": [ + { + "package": "swift-argument-parser", + "repositoryURL": "https://github.com/apple/swift-argument-parser.git", + "state": { + "branch": null, + "revision": "fee6933f37fde9a5e12a1e4aeaa93fe60116ff2a", + "version": "1.2.2" + } + } + ] + }, + "version": 1 +} diff --git a/Amethyst.xcworkspace/xcshareddata/swiftpm/Package.resolved b/Amethyst.xcworkspace/xcshareddata/swiftpm/Package.resolved index 0615f405..8514912a 100644 --- a/Amethyst.xcworkspace/xcshareddata/swiftpm/Package.resolved +++ b/Amethyst.xcworkspace/xcshareddata/swiftpm/Package.resolved @@ -1,14 +1,16 @@ { - "pins" : [ - { - "identity" : "swift-argument-parser", - "kind" : "remoteSourceControl", - "location" : "https://github.com/apple/swift-argument-parser.git", - "state" : { - "revision" : "fee6933f37fde9a5e12a1e4aeaa93fe60116ff2a", - "version" : "1.2.2" + "object": { + "pins": [ + { + "package": "swift-argument-parser", + "repositoryURL": "https://github.com/apple/swift-argument-parser.git", + "state": { + "branch": null, + "revision": "fee6933f37fde9a5e12a1e4aeaa93fe60116ff2a", + "version": "1.2.2" + } } - } - ], - "version" : 2 + ] + }, + "version": 1 } diff --git a/Amethyst/Debug/WindowsInfo.swift b/Amethyst/Debug/WindowsInfo.swift index 0de86aab..7d10f953 100644 --- a/Amethyst/Debug/WindowsInfo.swift +++ b/Amethyst/Debug/WindowsInfo.swift @@ -41,11 +41,13 @@ struct Windows: ParsableCommand { for application in applications where includeUnmanaged || application.isManageable == .manageable { let app = SIApplication(runningApplication: application) print("\(app.title() ?? "") (pid \(app.pid()))") + /* for window in app.windows() { let axWindow = AXWindow(element: window)! print(axWindow.debugInfo(redactTitles: redactWindowTitles)) print("") } + */ } } } diff --git a/Amethyst/Layout/Layouts/TwoPaneRightLayout.swift b/Amethyst/Layout/Layouts/TwoPaneRightLayout.swift new file mode 100644 index 00000000..ab299cf7 --- /dev/null +++ b/Amethyst/Layout/Layouts/TwoPaneRightLayout.swift @@ -0,0 +1,103 @@ +// +// TwoPaneRightLayout.swift +// Amethyst +// +// Created by Anja on 16.06.23. +// Copyright © 2023 Ian Ynda-Hummel. All rights reserved. +// + +import Silica + +class TwoPaneRightLayout: Layout, PanedLayout { + override static var layoutName: String { return "Two Pane Right" } + override static var layoutKey: String { return "two-pane-right" } + + enum CodingKeys: String, CodingKey { + case mainPaneCount + case mainPaneRatio + } + + override var layoutDescription: String { return "" } + + private(set) var mainPaneCount: Int = 1 + private(set) var mainPaneRatio: CGFloat = 0.5 + + required init() { + super.init() + } + + required init(from decoder: Decoder) throws { + let values = try decoder.container(keyedBy: CodingKeys.self) + self.mainPaneCount = try values.decode(Int.self, forKey: .mainPaneCount) + self.mainPaneRatio = try values.decode(CGFloat.self, forKey: .mainPaneRatio) + super.init() + } + + override func encode(to encoder: Encoder) throws { + var container = encoder.container(keyedBy: CodingKeys.self) + try container.encode(mainPaneCount, forKey: .mainPaneCount) + try container.encode(mainPaneRatio, forKey: .mainPaneRatio) + } + + func recommendMainPaneRawRatio(rawRatio: CGFloat) { + mainPaneRatio = rawRatio + } + + func increaseMainPaneCount() {} + + func decreaseMainPaneCount() {} + + override func frameAssignments(_ windowSet: WindowSet, on screen: Screen) -> [FrameAssignmentOperation]? { + let windows = windowSet.windows + + guard !windows.isEmpty else { + return [] + } + + let mainPaneCount = min(windows.count, self.mainPaneCount) + let secondaryPaneCount = windows.count > 1 ? 1 : 0 + let hasSecondaryPane = secondaryPaneCount > 0 + + let screenFrame = screen.adjustedFrame() + let isHorizontal = (screenFrame.size.width / screenFrame.size.height) >= 1 + + let mainPaneWindowHeight = screenFrame.size.height * (!isHorizontal && hasSecondaryPane ? mainPaneRatio : 1) + let secondaryPaneWindowHeight = isHorizontal ? mainPaneWindowHeight : screenFrame.size.height - mainPaneWindowHeight + + let mainPaneWindowWidth = screenFrame.size.width * (isHorizontal && hasSecondaryPane ? mainPaneRatio : 1) + let secondaryPaneWindowWidth = !isHorizontal ? mainPaneWindowWidth : screenFrame.size.width - mainPaneWindowWidth + + return windows.reduce([]) { acc, window -> [FrameAssignmentOperation] in + var assignments = acc + var windowFrame = CGRect.zero + let isMain = acc.count < mainPaneCount + var scaleFactor: CGFloat + + if isMain { + scaleFactor = screenFrame.size.width / mainPaneWindowWidth + windowFrame.origin.x = screenFrame.origin.x + (isHorizontal ? mainPaneWindowWidth : 0) + windowFrame.origin.y = screenFrame.origin.y + (isHorizontal ? 0 : mainPaneWindowHeight) + windowFrame.size.width = mainPaneWindowWidth + windowFrame.size.height = mainPaneWindowHeight + } else { + scaleFactor = screenFrame.size.width / secondaryPaneWindowWidth + windowFrame.origin.x = screenFrame.origin.x + windowFrame.origin.y = screenFrame.origin.y + windowFrame.size.width = secondaryPaneWindowWidth + windowFrame.size.height = secondaryPaneWindowHeight + } + + let resizeRules = ResizeRules(isMain: isMain, unconstrainedDimension: .horizontal, scaleFactor: scaleFactor) + let frameAssignment = FrameAssignment( + frame: windowFrame, + window: window, + screenFrame: screenFrame, + resizeRules: resizeRules + ) + + assignments.append(FrameAssignmentOperation(frameAssignment: frameAssignment, windowSet: windowSet)) + + return assignments + } + } +} diff --git a/Amethyst/Managers/LayoutType.swift b/Amethyst/Managers/LayoutType.swift index a143a7c0..e531a889 100644 --- a/Amethyst/Managers/LayoutType.swift +++ b/Amethyst/Managers/LayoutType.swift @@ -46,6 +46,7 @@ enum LayoutType { case tallRight case wide case twoPane + case twoPaneRight case threeColumnLeft case threeColumnMiddle case threeColumnRight @@ -67,6 +68,7 @@ enum LayoutType { .tallRight, .wide, .twoPane, + .twoPaneRight, .threeColumnLeft, .threeColumnMiddle, .threeColumnRight, @@ -92,6 +94,8 @@ enum LayoutType { return "wide" case .twoPane: return "two-pane" + case .twoPaneRight: + return "two-pane-right" case .threeColumnLeft: return "3column-left" case .threeColumnMiddle: @@ -131,6 +135,8 @@ enum LayoutType { return WideLayout.self case .twoPane: return TwoPaneLayout.self + case .twoPaneRight: + return TwoPaneRightLayout.self case .threeColumnLeft: return ThreeColumnLeftLayout.self case .threeColumnMiddle: @@ -170,6 +176,8 @@ enum LayoutType { return .wide case "two-pane": return .twoPane + case "two-pane-right": + return .twoPaneRight case "3column-left": return .threeColumnLeft case "middle-wide": diff --git a/Podfile b/Podfile index e0d762ff..a9191562 100644 --- a/Podfile +++ b/Podfile @@ -11,7 +11,7 @@ target 'Amethyst' do pod 'RxSwiftExt' pod 'Silica', git: 'https://github.com/ianyh/Silica', submodules: true pod 'Sparkle' - pod 'SwiftLint' + pod 'SwiftLint', '~> 0.52' pod 'SwiftyBeaver' pod 'SwiftyJSON' pod 'Yams' diff --git a/Podfile.lock b/Podfile.lock index c085485e..f332afb7 100644 --- a/Podfile.lock +++ b/Podfile.lock @@ -20,7 +20,7 @@ PODS: - RxSwiftExt/Core - Silica (0.3.7) - Sparkle (2.4.0) - - SwiftLint (0.51.0) + - SwiftLint (0.52.2) - SwiftyBeaver (1.9.5) - SwiftyJSON (5.0.1) - Yams (5.0.5) @@ -36,7 +36,7 @@ DEPENDENCIES: - RxSwiftExt - Silica (from `https://github.com/ianyh/Silica`) - Sparkle - - SwiftLint + - SwiftLint (~> 0.52) - SwiftyBeaver - SwiftyJSON - Yams @@ -81,11 +81,11 @@ SPEC CHECKSUMS: RxSwiftExt: d61c4b9b06e0a448041b1c659e0f1b5c5a035afc Silica: e70998fbfa22068602e8ebde94808603dc34ed0d Sparkle: 529aaf23a0dbc6b3e9e2e364c2bd996def4c91f0 - SwiftLint: 1b7561918a19e23bfed960e40759086e70f4dba5 + SwiftLint: 1ac76dac888ca05cb0cf24d0c85887ec1209961d SwiftyBeaver: 84069991dd5dca07d7069100985badaca7f0ce82 SwiftyJSON: 2f33a42c6fbc52764d96f13368585094bfd8aa5e Yams: 271b5757cee031e087ae6322128895c04826c4f3 -PODFILE CHECKSUM: 7f3c6d976af94958786a21fa983f23ac6d6a2228 +PODFILE CHECKSUM: c84debcf612b996261f0dfdd8e7a76a07451f3ab COCOAPODS: 1.12.0