Skip to content

Commit 893b7a7

Browse files
authored
Merge pull request #740 from slifty/add-horizontal-thirds
Add horizontal thirds
2 parents ef31a6c + 26ff692 commit 893b7a7

9 files changed

+324
-2
lines changed

Rectangle.xcodeproj/project.pbxproj

+20
Original file line numberDiff line numberDiff line change
@@ -97,6 +97,7 @@
9797
98FD7C5F2687BC14009E9DAF /* FirstThreeFourthsCalculation.swift in Sources */ = {isa = PBXBuildFile; fileRef = 98FD7C5E2687BC14009E9DAF /* FirstThreeFourthsCalculation.swift */; };
9898
98FD7C612687BCB6009E9DAF /* LastThreeFourthsCalculation.swift in Sources */ = {isa = PBXBuildFile; fileRef = 98FD7C602687BCB6009E9DAF /* LastThreeFourthsCalculation.swift */; };
9999
CC0B7937429AC28C21ABF5B4 /* Pods_RectangleLauncher.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = F2D8480CC730811C953FC1B6 /* Pods_RectangleLauncher.framework */; };
100+
D0423D8327A8D31D008A4894 /* HorizontalThirdsRepeated.swift in Sources */ = {isa = PBXBuildFile; fileRef = D0423D8227A8D31D008A4894 /* HorizontalThirdsRepeated.swift */; };
100101
D04CE3002781794E00BD47B3 /* TopLeftNinthCalculation.swift in Sources */ = {isa = PBXBuildFile; fileRef = D04CE2FF2781794E00BD47B3 /* TopLeftNinthCalculation.swift */; };
101102
D04CE30227817A6100BD47B3 /* TopCenterNinthCalculation.swift in Sources */ = {isa = PBXBuildFile; fileRef = D04CE30127817A6100BD47B3 /* TopCenterNinthCalculation.swift */; };
102103
D04CE30427817A6F00BD47B3 /* TopRightNinthCalculation.swift in Sources */ = {isa = PBXBuildFile; fileRef = D04CE30327817A6F00BD47B3 /* TopRightNinthCalculation.swift */; };
@@ -107,6 +108,10 @@
107108
D04CE30E27817AB500BD47B3 /* BottomCenterNinthCalculation.swift in Sources */ = {isa = PBXBuildFile; fileRef = D04CE30D27817AB500BD47B3 /* BottomCenterNinthCalculation.swift */; };
108109
D04CE31027817ABE00BD47B3 /* BottomRightNinthCalculation.swift in Sources */ = {isa = PBXBuildFile; fileRef = D04CE30F27817ABE00BD47B3 /* BottomRightNinthCalculation.swift */; };
109110
D04CE31227817C9B00BD47B3 /* NinthsRepeated.swift in Sources */ = {isa = PBXBuildFile; fileRef = D04CE31127817C9B00BD47B3 /* NinthsRepeated.swift */; };
111+
D0CFE33127A8CAED004DA47B /* TopLeftThirdCalculation.swift in Sources */ = {isa = PBXBuildFile; fileRef = D0CFE33027A8CAED004DA47B /* TopLeftThirdCalculation.swift */; };
112+
D0CFE33327A8CCB1004DA47B /* TopRightThirdCalculation.swift in Sources */ = {isa = PBXBuildFile; fileRef = D0CFE33227A8CCB1004DA47B /* TopRightThirdCalculation.swift */; };
113+
D0CFE33527A8CD16004DA47B /* BottomLeftThirdCalculation.swift in Sources */ = {isa = PBXBuildFile; fileRef = D0CFE33427A8CD16004DA47B /* BottomLeftThirdCalculation.swift */; };
114+
D0CFE33727A8CD51004DA47B /* BottomRightThirdCalculation.swift in Sources */ = {isa = PBXBuildFile; fileRef = D0CFE33627A8CD51004DA47B /* BottomRightThirdCalculation.swift */; };
110115
F0A0DFB36FCC3FCE6E184500 /* Pods_Rectangle.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 20A533B9F2D3215AC7B85D1F /* Pods_Rectangle.framework */; };
111116
/* End PBXBuildFile section */
112117

@@ -272,6 +277,7 @@
272277
98FE8976246E79C400871535 /* zh-Hant-HK */ = {isa = PBXFileReference; lastKnownFileType = text.plist.strings; name = "zh-Hant-HK"; path = "zh-Hant-HK.lproj/Main.strings"; sourceTree = "<group>"; };
273278
98FE8977246E79C400871535 /* zh-Hant-HK */ = {isa = PBXFileReference; lastKnownFileType = text.plist.strings; name = "zh-Hant-HK"; path = "zh-Hant-HK.lproj/Main.strings"; sourceTree = "<group>"; };
274279
BFFF93EBEA6E2FF7245A7CF5 /* Pods-Rectangle.release.xcconfig */ = {isa = PBXFileReference; includeInIndex = 1; lastKnownFileType = text.xcconfig; name = "Pods-Rectangle.release.xcconfig"; path = "Target Support Files/Pods-Rectangle/Pods-Rectangle.release.xcconfig"; sourceTree = "<group>"; };
280+
D0423D8227A8D31D008A4894 /* HorizontalThirdsRepeated.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = HorizontalThirdsRepeated.swift; sourceTree = "<group>"; };
275281
D04CE2FF2781794E00BD47B3 /* TopLeftNinthCalculation.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = TopLeftNinthCalculation.swift; sourceTree = "<group>"; };
276282
D04CE30127817A6100BD47B3 /* TopCenterNinthCalculation.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = TopCenterNinthCalculation.swift; sourceTree = "<group>"; };
277283
D04CE30327817A6F00BD47B3 /* TopRightNinthCalculation.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = TopRightNinthCalculation.swift; sourceTree = "<group>"; };
@@ -282,6 +288,10 @@
282288
D04CE30D27817AB500BD47B3 /* BottomCenterNinthCalculation.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = BottomCenterNinthCalculation.swift; sourceTree = "<group>"; };
283289
D04CE30F27817ABE00BD47B3 /* BottomRightNinthCalculation.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = BottomRightNinthCalculation.swift; sourceTree = "<group>"; };
284290
D04CE31127817C9B00BD47B3 /* NinthsRepeated.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = NinthsRepeated.swift; sourceTree = "<group>"; };
291+
D0CFE33027A8CAED004DA47B /* TopLeftThirdCalculation.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = TopLeftThirdCalculation.swift; sourceTree = "<group>"; };
292+
D0CFE33227A8CCB1004DA47B /* TopRightThirdCalculation.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = TopRightThirdCalculation.swift; sourceTree = "<group>"; };
293+
D0CFE33427A8CD16004DA47B /* BottomLeftThirdCalculation.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = BottomLeftThirdCalculation.swift; sourceTree = "<group>"; };
294+
D0CFE33627A8CD51004DA47B /* BottomRightThirdCalculation.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = BottomRightThirdCalculation.swift; sourceTree = "<group>"; };
285295
DE4AE568B8BDB98BF602D588 /* Pods-RectangleMAS.release.xcconfig */ = {isa = PBXFileReference; includeInIndex = 1; lastKnownFileType = text.xcconfig; name = "Pods-RectangleMAS.release.xcconfig"; path = "Target Support Files/Pods-RectangleMAS/Pods-RectangleMAS.release.xcconfig"; sourceTree = "<group>"; };
286296
E2625F45B180F733E8508494 /* Pods-RectangleMAS.debug.xcconfig */ = {isa = PBXFileReference; includeInIndex = 1; lastKnownFileType = text.xcconfig; name = "Pods-RectangleMAS.debug.xcconfig"; path = "Target Support Files/Pods-RectangleMAS/Pods-RectangleMAS.debug.xcconfig"; sourceTree = "<group>"; };
287297
F2D8480CC730811C953FC1B6 /* Pods_RectangleLauncher.framework */ = {isa = PBXFileReference; explicitFileType = wrapper.framework; includeInIndex = 0; path = Pods_RectangleLauncher.framework; sourceTree = BUILT_PRODUCTS_DIR; };
@@ -419,6 +429,11 @@
419429
D04CE30B27817AA900BD47B3 /* BottomLeftNinthCalculation.swift */,
420430
D04CE30D27817AB500BD47B3 /* BottomCenterNinthCalculation.swift */,
421431
D04CE30F27817ABE00BD47B3 /* BottomRightNinthCalculation.swift */,
432+
D0CFE33027A8CAED004DA47B /* TopLeftThirdCalculation.swift */,
433+
D0CFE33227A8CCB1004DA47B /* TopRightThirdCalculation.swift */,
434+
D0CFE33427A8CD16004DA47B /* BottomLeftThirdCalculation.swift */,
435+
D0CFE33627A8CD51004DA47B /* BottomRightThirdCalculation.swift */,
436+
D0423D8227A8D31D008A4894 /* HorizontalThirdsRepeated.swift */,
422437
);
423438
path = WindowCalculation;
424439
sourceTree = "<group>";
@@ -847,12 +862,14 @@
847862
98A009BB2512539900CFBF0C /* BottomLeftSixthCalculation.swift in Sources */,
848863
9821402322B3886100ABFB3F /* CenterCalculation.swift in Sources */,
849864
98A009AB2512491300CFBF0C /* CenterHalfCalculation.swift in Sources */,
865+
D0CFE33327A8CCB1004DA47B /* TopRightThirdCalculation.swift in Sources */,
850866
9821403522B38A2B00ABFB3F /* UpperRightCalculation.swift in Sources */,
851867
9824702F22AFA2E50037B409 /* AccessibilityAuthorization.swift in Sources */,
852868
988D066322EB4CA5004EABD7 /* FirstTwoThirdsCalculation.swift in Sources */,
853869
D04CE30A27817A9F00BD47B3 /* MiddleRightNinthCalculation.swift in Sources */,
854870
98BEFA482620DEDD00D9D54F /* NSImageExtension.swift in Sources */,
855871
98FA9497235A2D7600F95C4F /* RepeatedExecutionsCalculation.swift in Sources */,
872+
D0CFE33727A8CD51004DA47B /* BottomRightThirdCalculation.swift in Sources */,
856873
9824705122B28D7A0037B409 /* LeftRightHalfCalculation.swift in Sources */,
857874
9824703D22B13C7E0037B409 /* AccessibilityElement.swift in Sources */,
858875
98D1441324560B1E0090C603 /* AlertUtil.swift in Sources */,
@@ -865,6 +882,8 @@
865882
98A009AF2512517900CFBF0C /* SecondFourthCalculation.swift in Sources */,
866883
D04CE30C27817AA900BD47B3 /* BottomLeftNinthCalculation.swift in Sources */,
867884
9821406022B3EFB200ABFB3F /* Defaults.swift in Sources */,
885+
D0CFE33527A8CD16004DA47B /* BottomLeftThirdCalculation.swift in Sources */,
886+
D0CFE33127A8CAED004DA47B /* TopLeftThirdCalculation.swift in Sources */,
868887
98192DDA270F606C00015E66 /* Debounce.swift in Sources */,
869888
D04CE3002781794E00BD47B3 /* TopLeftNinthCalculation.swift in Sources */,
870889
9821403122B38A0500ABFB3F /* TopHalfCalculation.swift in Sources */,
@@ -895,6 +914,7 @@
895914
98C275672322E2DA009B9292 /* WindowHistory.swift in Sources */,
896915
9821403722B3D16700ABFB3F /* MaximizeHeightCalculation.swift in Sources */,
897916
9824704122B186D00037B409 /* WindowManager.swift in Sources */,
917+
D0423D8327A8D31D008A4894 /* HorizontalThirdsRepeated.swift in Sources */,
898918
98C97FFD25893B040061F01F /* Config.swift in Sources */,
899919
989DA30E243FC0DF008C7AA4 /* WelcomeViewController.swift in Sources */,
900920
98C27561231FFA5F009B9292 /* SnappingManager.swift in Sources */,

Rectangle/WindowAction.swift

+27-2
Original file line numberDiff line numberDiff line change
@@ -66,7 +66,11 @@ enum WindowAction: Int {
6666
middleRightNinth = 50,
6767
bottomLeftNinth = 51,
6868
bottomCenterNinth = 52,
69-
bottomRightNinth = 53
69+
bottomRightNinth = 53,
70+
topLeftThird = 54,
71+
topRightThird = 55,
72+
bottomLeftThird = 56,
73+
bottomRightThird = 57
7074

7175
// Order matters here - it's used in the menu
7276
static let active = [leftHalf, rightHalf, centerHalf, topHalf, bottomHalf,
@@ -81,6 +85,7 @@ enum WindowAction: Int {
8185
topLeftNinth, topCenterNinth, topRightNinth,
8286
middleLeftNinth, middleCenterNinth, middleRightNinth,
8387
bottomLeftNinth, bottomCenterNinth, bottomRightNinth,
88+
topLeftThird, topRightThird, bottomLeftThird, bottomRightThird,
8489
]
8590

8691
func post() {
@@ -157,6 +162,10 @@ enum WindowAction: Int {
157162
case .bottomLeftNinth: return "bottomLeftNinth"
158163
case .bottomCenterNinth: return "bottomCenterNinth"
159164
case .bottomRightNinth: return "bottomRightNinth"
165+
case .topLeftThird: return "topLeftThird"
166+
case .topRightThird: return "topRightThird"
167+
case .bottomLeftThird: return "bottomLeftThird"
168+
case .bottomRightThird: return "bottomRightThird"
160169
}
161170
}
162171

@@ -284,6 +293,8 @@ enum WindowAction: Int {
284293
value = "Bottom Right Sixth"
285294
case .topLeftNinth, .topCenterNinth, .topRightNinth, .middleLeftNinth, .middleCenterNinth, .middleRightNinth, .bottomLeftNinth, .bottomCenterNinth, .bottomRightNinth:
286295
return nil
296+
case .topLeftThird, .topRightThird, .bottomLeftThird, .bottomRightThird:
297+
return nil
287298
case .specified, .reverseAll:
288299
return nil
289300
}
@@ -409,6 +420,10 @@ enum WindowAction: Int {
409420
case .bottomLeftNinth: return NSImage()
410421
case .bottomCenterNinth: return NSImage()
411422
case .bottomRightNinth: return NSImage()
423+
case .topLeftThird: return NSImage()
424+
case .topRightThird: return NSImage()
425+
case .bottomLeftThird: return NSImage()
426+
case .bottomRightThird: return NSImage()
412427
case .specified, .reverseAll: return NSImage()
413428
}
414429
}
@@ -436,7 +451,8 @@ enum WindowAction: Int {
436451
switch self {
437452
case .leftHalf, .rightHalf, .bottomHalf, .topHalf, .centerHalf, .bottomLeft, .bottomRight, .topLeft, .topRight, .firstThird, .firstTwoThirds, .centerThird, .lastTwoThirds, .lastThird,
438453
.firstFourth, .secondFourth, .thirdFourth, .lastFourth, .firstThreeFourths, .lastThreeFourths, .topLeftSixth, .topCenterSixth, .topRightSixth, .bottomLeftSixth, .bottomCenterSixth, .bottomRightSixth,
439-
.topLeftNinth, .topCenterNinth, .topRightNinth, .middleLeftNinth, .middleCenterNinth, .middleRightNinth, .bottomLeftNinth, .bottomCenterNinth, .bottomRightNinth:
454+
.topLeftNinth, .topCenterNinth, .topRightNinth, .middleLeftNinth, .middleCenterNinth, .middleRightNinth, .bottomLeftNinth, .bottomCenterNinth, .bottomRightNinth,
455+
.topLeftThird, .topRightThird, .bottomLeftThird, .bottomRightThird:
440456
return .both
441457
case .moveUp, .moveDown:
442458
return Defaults.resizeOnDirectionalMove.enabled ? .vertical : .none;
@@ -532,6 +548,11 @@ enum SubWindowAction {
532548
bottomLeftNinth,
533549
bottomCenterNinth,
534550
bottomRightNinth,
551+
552+
topLeftThird,
553+
topRightThird,
554+
bottomLeftThird,
555+
bottomRightThird,
535556

536557
maximize
537558

@@ -590,6 +611,10 @@ enum SubWindowAction {
590611
case .bottomLeftNinth: return [.top, .right]
591612
case .bottomCenterNinth: return [.left, .top, .right]
592613
case .bottomRightNinth: return [.left, .top]
614+
case .topLeftThird: return [.right, .bottom]
615+
case .topRightThird: return [.left, .bottom]
616+
case .bottomLeftThird: return [.right, .top]
617+
case .bottomRightThird: return [.left, .top]
593618
case .maximize: return .none
594619
}
595620
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,51 @@
1+
//
2+
// BottomLeftThirdCalculation.swift
3+
// Rectangle
4+
//
5+
// Created by Daniel Schultz on 1/2/22.
6+
// Copyright © 2022 Ryan Hanson. All rights reserved.
7+
//
8+
9+
import Foundation
10+
11+
class BottomLeftThirdCalculation: WindowCalculation, OrientationAware, HorizontalThirdsRepeated {
12+
13+
override func calculateRect(_ params: RectCalculationParameters) -> RectResult {
14+
let visibleFrameOfScreen = params.visibleFrameOfScreen
15+
16+
guard Defaults.subsequentExecutionMode.value != .none,
17+
let last = params.lastAction,
18+
let lastSubAction = last.subAction
19+
else {
20+
return orientationBasedRect(visibleFrameOfScreen)
21+
}
22+
23+
if last.action != .bottomLeftThird {
24+
return orientationBasedRect(visibleFrameOfScreen)
25+
}
26+
27+
if let calculation = self.nextCalculation(subAction: lastSubAction, direction: .right) {
28+
return calculation(visibleFrameOfScreen)
29+
}
30+
31+
return orientationBasedRect(visibleFrameOfScreen)
32+
}
33+
34+
func landscapeRect(_ visibleFrameOfScreen: CGRect) -> RectResult {
35+
var rect = visibleFrameOfScreen
36+
rect.size.width = floor(2.0 * visibleFrameOfScreen.width / 3.0)
37+
rect.size.height = floor(visibleFrameOfScreen.height / 2.0)
38+
rect.origin.y = visibleFrameOfScreen.minY
39+
rect.origin.x = visibleFrameOfScreen.minX
40+
return RectResult(rect, subAction: .bottomLeftThird)
41+
}
42+
43+
func portraitRect(_ visibleFrameOfScreen: CGRect) -> RectResult {
44+
var rect = visibleFrameOfScreen
45+
rect.size.width = floor(visibleFrameOfScreen.width / 2.0)
46+
rect.size.height = floor(2.0 * visibleFrameOfScreen.height / 3.0)
47+
rect.origin.y = visibleFrameOfScreen.minY
48+
rect.origin.x = visibleFrameOfScreen.minX
49+
return RectResult(rect, subAction: .bottomLeftThird)
50+
}
51+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,51 @@
1+
//
2+
// BottomRightThirdCalculation.swift
3+
// Rectangle
4+
//
5+
// Created by Daniel Schultz on 1/2/22.
6+
// Copyright © 2022 Ryan Hanson. All rights reserved.
7+
//
8+
9+
import Foundation
10+
11+
class BottomRightThirdCalculation: WindowCalculation, OrientationAware, HorizontalThirdsRepeated {
12+
13+
override func calculateRect(_ params: RectCalculationParameters) -> RectResult {
14+
let visibleFrameOfScreen = params.visibleFrameOfScreen
15+
16+
guard Defaults.subsequentExecutionMode.value != .none,
17+
let last = params.lastAction,
18+
let lastSubAction = last.subAction
19+
else {
20+
return orientationBasedRect(visibleFrameOfScreen)
21+
}
22+
23+
if last.action != .bottomRightThird {
24+
return orientationBasedRect(visibleFrameOfScreen)
25+
}
26+
27+
if let calculation = self.nextCalculation(subAction: lastSubAction, direction: .right) {
28+
return calculation(visibleFrameOfScreen)
29+
}
30+
31+
return orientationBasedRect(visibleFrameOfScreen)
32+
}
33+
34+
func landscapeRect(_ visibleFrameOfScreen: CGRect) -> RectResult {
35+
var rect = visibleFrameOfScreen
36+
rect.size.width = floor(2.0 * visibleFrameOfScreen.width / 3.0)
37+
rect.size.height = floor(visibleFrameOfScreen.height / 2.0)
38+
rect.origin.y = visibleFrameOfScreen.minY
39+
rect.origin.x = visibleFrameOfScreen.minX + visibleFrameOfScreen.width / 3.0
40+
return RectResult(rect, subAction: .bottomRightThird)
41+
}
42+
43+
func portraitRect(_ visibleFrameOfScreen: CGRect) -> RectResult {
44+
var rect = visibleFrameOfScreen
45+
rect.size.width = floor(visibleFrameOfScreen.width / 2.0)
46+
rect.size.height = floor(2.0 * visibleFrameOfScreen.height / 3.0)
47+
rect.origin.y = visibleFrameOfScreen.minY
48+
rect.origin.x = visibleFrameOfScreen.minX + visibleFrameOfScreen.width / 2.0
49+
return RectResult(rect, subAction: .bottomRightThird)
50+
}
51+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
1+
//
2+
// HorizontalThirdsRepeated.swift
3+
// Rectangle
4+
//
5+
// Created by Daniel Schultz on 1/2/22.
6+
// Copyright © 2022 Ryan Hanson. All rights reserved.
7+
//
8+
9+
import Foundation
10+
11+
protocol HorizontalThirdsRepeated {
12+
func nextCalculation(subAction: SubWindowAction, direction: Direction) -> SimpleCalc?
13+
}
14+
15+
extension HorizontalThirdsRepeated {
16+
func nextCalculation(subAction: SubWindowAction, direction: Direction) -> SimpleCalc? {
17+
18+
if direction == .left {
19+
switch subAction {
20+
case .topLeftThird:
21+
return WindowCalculationFactory.bottomRightThirdCalculation.orientationBasedRect
22+
case .topRightThird:
23+
return WindowCalculationFactory.topLeftThirdCalculation.orientationBasedRect
24+
case .bottomLeftThird:
25+
return WindowCalculationFactory.topRightThirdCalculation.orientationBasedRect
26+
case .bottomRightThird:
27+
return WindowCalculationFactory.bottomLeftThirdCalculation.orientationBasedRect
28+
default: break
29+
}
30+
}
31+
32+
else if direction == .right {
33+
switch subAction {
34+
case .topLeftThird:
35+
return WindowCalculationFactory.topRightThirdCalculation.orientationBasedRect
36+
case .topRightThird:
37+
return WindowCalculationFactory.bottomLeftThirdCalculation.orientationBasedRect
38+
case .bottomLeftThird:
39+
return WindowCalculationFactory.bottomRightThirdCalculation.orientationBasedRect
40+
case .bottomRightThird:
41+
return WindowCalculationFactory.topLeftThirdCalculation.orientationBasedRect
42+
default: break
43+
}
44+
}
45+
46+
return nil
47+
}
48+
}

0 commit comments

Comments
 (0)