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

Add TwoPaneRight Layout #1515

Open
wants to merge 1 commit into
base: development
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
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
4 changes: 4 additions & 0 deletions Amethyst.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -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 */

Expand Down Expand Up @@ -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 = "<group>"; };
AA4AF40C26717DA900D2AE1B /* TwoPaneLayout.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = TwoPaneLayout.swift; sourceTree = "<group>"; };
AAAC6BAB2677DF7B00BEC1B0 /* TwoPaneLayoutTests.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = TwoPaneLayoutTests.swift; sourceTree = "<group>"; };
F0B42E342A3CA45E00298E30 /* TwoPaneRightLayout.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = TwoPaneRightLayout.swift; sourceTree = "<group>"; };
F46629C3272AD7A30040C275 /* FourColumnLayout.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = FourColumnLayout.swift; sourceTree = "<group>"; };
/* End PBXFileReference section */

Expand Down Expand Up @@ -358,6 +360,7 @@
4062AD341C1FA62500DB612B /* WideLayout.swift */,
4062AD3A1C206EA900DB612B /* WidescreenTallLayout.swift */,
4045416E268FFDA000861BE8 /* CustomLayout.swift */,
F0B42E342A3CA45E00298E30 /* TwoPaneRightLayout.swift */,
);
path = Layouts;
sourceTree = "<group>";
Expand Down Expand Up @@ -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 */,
Expand Down

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<dict>
<key>IDEDidComputeMac32BitWarning</key>
<true/>
</dict>
</plist>
Original file line number Diff line number Diff line change
@@ -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
}
24 changes: 13 additions & 11 deletions Amethyst.xcworkspace/xcshareddata/swiftpm/Package.resolved
Original file line number Diff line number Diff line change
@@ -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
}
2 changes: 2 additions & 0 deletions Amethyst/Debug/WindowsInfo.swift
Original file line number Diff line number Diff line change
Expand Up @@ -41,11 +41,13 @@ struct Windows: ParsableCommand {
for application in applications where includeUnmanaged || application.isManageable == .manageable {
let app = SIApplication(runningApplication: application)
print("\(app.title() ?? "<no title>") (pid \(app.pid()))")
/*
for window in app.windows() {
let axWindow = AXWindow(element: window)!
print(axWindow.debugInfo(redactTitles: redactWindowTitles))
print("")
}
*/
}
}
}
103 changes: 103 additions & 0 deletions Amethyst/Layout/Layouts/TwoPaneRightLayout.swift
Original file line number Diff line number Diff line change
@@ -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<Window: WindowType>: Layout<Window>, 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<Window>, on screen: Screen) -> [FrameAssignmentOperation<Window>]? {
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<Window>] 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<Window>(
frame: windowFrame,
window: window,
screenFrame: screenFrame,
resizeRules: resizeRules
)

assignments.append(FrameAssignmentOperation(frameAssignment: frameAssignment, windowSet: windowSet))

return assignments
}
}
}
8 changes: 8 additions & 0 deletions Amethyst/Managers/LayoutType.swift
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,7 @@ enum LayoutType<Window: WindowType> {
case tallRight
case wide
case twoPane
case twoPaneRight
case threeColumnLeft
case threeColumnMiddle
case threeColumnRight
Expand All @@ -67,6 +68,7 @@ enum LayoutType<Window: WindowType> {
.tallRight,
.wide,
.twoPane,
.twoPaneRight,
.threeColumnLeft,
.threeColumnMiddle,
.threeColumnRight,
Expand All @@ -92,6 +94,8 @@ enum LayoutType<Window: WindowType> {
return "wide"
case .twoPane:
return "two-pane"
case .twoPaneRight:
return "two-pane-right"
case .threeColumnLeft:
return "3column-left"
case .threeColumnMiddle:
Expand Down Expand Up @@ -131,6 +135,8 @@ enum LayoutType<Window: WindowType> {
return WideLayout<Window>.self
case .twoPane:
return TwoPaneLayout<Window>.self
case .twoPaneRight:
return TwoPaneRightLayout<Window>.self
case .threeColumnLeft:
return ThreeColumnLeftLayout<Window>.self
case .threeColumnMiddle:
Expand Down Expand Up @@ -170,6 +176,8 @@ enum LayoutType<Window: WindowType> {
return .wide
case "two-pane":
return .twoPane
case "two-pane-right":
return .twoPaneRight
case "3column-left":
return .threeColumnLeft
case "middle-wide":
Expand Down
2 changes: 1 addition & 1 deletion Podfile
Original file line number Diff line number Diff line change
Expand Up @@ -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'
Expand Down
8 changes: 4 additions & 4 deletions Podfile.lock
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand All @@ -36,7 +36,7 @@ DEPENDENCIES:
- RxSwiftExt
- Silica (from `https://github.com/ianyh/Silica`)
- Sparkle
- SwiftLint
- SwiftLint (~> 0.52)
- SwiftyBeaver
- SwiftyJSON
- Yams
Expand Down Expand Up @@ -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