From 4a3bbceb82b23d61a967cad63649b812ac3771d0 Mon Sep 17 00:00:00 2001 From: Eskil Gjerde Sviggum Date: Fri, 2 Aug 2024 14:40:26 +0200 Subject: [PATCH 01/17] Add model CycleBetweenDivision --- Rectangle/CycleBetweenDivisions.swift | 127 ++++++++++++++++++++++++++ 1 file changed, 127 insertions(+) create mode 100644 Rectangle/CycleBetweenDivisions.swift diff --git a/Rectangle/CycleBetweenDivisions.swift b/Rectangle/CycleBetweenDivisions.swift new file mode 100644 index 00000000..95084210 --- /dev/null +++ b/Rectangle/CycleBetweenDivisions.swift @@ -0,0 +1,127 @@ +// +// CycleBetweenDivisions.swift +// Rectangle +// +// Created by Eskil Gjerde Sviggum on 01/08/2024. +// Copyright © 2024 Ryan Hanson. All rights reserved. +// + +import Foundation + +enum CycleBetweenDivision: Int, CaseIterable { + case twoThirds = 0 + case oneHalf = 1 + case oneThird = 2 + case oneQuarter = 3 + + static func fromBits(bits: Int) -> Set { + Set( + Self.allCases.filter { + (bits >> $0.rawValue) & 1 == 1 + } + ) + } + + static var firstDivision = CycleBetweenDivision.oneHalf + static var defaultCycleSizes: Set = [.oneHalf, .oneThird, .twoThirds] + + // The expected order of the cycle sizes is to start with the + // first division, then go gradually downwards in size and wrap + // around to the larger sizes. + // + // For example if all cycles are used, the order should be: + // 1/2, 1/3, 1/4, 2/3, + static var sortedCycleDivisions: [CycleBetweenDivision] = { + let sortedDivisions = Self.allCases.sorted(by: { $0.fraction < $1.fraction }) + + guard let firstDivisionIndex = sortedDivisions.firstIndex(of: firstDivision) else { + return sortedDivisions + } + + let lessThanFistDivision = sortedDivisions[0.. Int { + var bits = 0 + self.forEach { + bits |= 1 << $0.rawValue + } + return bits + } +} + +class CycleBetweenDivisionsDefault: Default { + public private(set) var key: String = "cycleBetweenDivisions" + private var initialized = false + + var value: Set { + didSet { + if initialized { + UserDefaults.standard.set(value.toBits(), forKey: key) + } + } + } + + init() { + let bits = UserDefaults.standard.integer(forKey: key) + value = CycleBetweenDivision.fromBits(bits: bits) + initialized = true + } + + func load(from codable: CodableDefault) { + if let bits = codable.int { + let divisions = CycleBetweenDivision.fromBits(bits: bits) + value = divisions + } + } + + func toCodable() -> CodableDefault { + return CodableDefault(int: value.toBits()) + } + +} From 8ec589b4f4b0b2f4912a54a07c33a22b557a0438 Mon Sep 17 00:00:00 2001 From: Eskil Gjerde Sviggum Date: Fri, 2 Aug 2024 14:41:33 +0200 Subject: [PATCH 02/17] Add `cycleBetweenDivisions` and `cycleBetweenDivisionsIsChanged` to Defaults --- Rectangle/Defaults.swift | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/Rectangle/Defaults.swift b/Rectangle/Defaults.swift index b1628a1e..7228569d 100644 --- a/Rectangle/Defaults.swift +++ b/Rectangle/Defaults.swift @@ -14,6 +14,8 @@ class Defaults { static let hideMenuBarIcon = BoolDefault(key: "hideMenubarIcon") static let alternateDefaultShortcuts = BoolDefault(key: "alternateDefaultShortcuts") // switch to magnet defaults static let subsequentExecutionMode = SubsequentExecutionDefault() + static let cycleBetweenDivisions = CycleBetweenDivisionsDefault() + static let cycleBetweenDivisionsIsChanged = BoolDefault(key: "cycleBetweenDivisionsIsChanged") static let allowAnyShortcut = BoolDefault(key: "allowAnyShortcut") static let windowSnapping = OptionalBoolDefault(key: "windowSnapping") static let almostMaximizeHeight = FloatDefault(key: "almostMaximizeHeight") @@ -95,6 +97,8 @@ class Defaults { hideMenuBarIcon, alternateDefaultShortcuts, subsequentExecutionMode, + cycleBetweenDivisions, + cycleBetweenDivisionsIsChanged, allowAnyShortcut, windowSnapping, almostMaximizeHeight, From 4dd13ba644668c2ed1208137731dc348ff87df92 Mon Sep 17 00:00:00 2001 From: Eskil Gjerde Sviggum Date: Fri, 2 Aug 2024 14:48:34 +0200 Subject: [PATCH 03/17] Add Cycle Between sizes stackview to SettingsViewController --- Rectangle/Base.lproj/Main.storyboard | 186 ++++++++++-------- .../PrefsWindow/SettingsViewController.swift | 4 + Rectangle/mul.lproj/Main.xcstrings | 14 +- 3 files changed, 123 insertions(+), 81 deletions(-) diff --git a/Rectangle/Base.lproj/Main.storyboard b/Rectangle/Base.lproj/Main.storyboard index 026f8243..369c3593 100644 --- a/Rectangle/Base.lproj/Main.storyboard +++ b/Rectangle/Base.lproj/Main.storyboard @@ -1,8 +1,8 @@ - + - + @@ -337,7 +337,7 @@ - + @@ -386,7 +386,7 @@ - + @@ -435,7 +435,7 @@ - + @@ -484,7 +484,7 @@ - + @@ -536,7 +536,7 @@ - + @@ -595,7 +595,7 @@ - + @@ -647,7 +647,7 @@ - + @@ -699,7 +699,7 @@ - + @@ -751,7 +751,7 @@ - + @@ -832,7 +832,7 @@ - + @@ -881,7 +881,7 @@ - + @@ -930,7 +930,7 @@ - + @@ -979,7 +979,7 @@ - + @@ -1028,7 +1028,7 @@ - + @@ -1077,7 +1077,7 @@ - + @@ -1126,7 +1126,7 @@ - + @@ -1182,7 +1182,7 @@ - + @@ -1231,7 +1231,7 @@ - + @@ -1351,7 +1351,7 @@ - + @@ -1400,7 +1400,7 @@ - + @@ -1449,7 +1449,7 @@ - + @@ -1498,7 +1498,7 @@ - + @@ -1547,7 +1547,7 @@ - + @@ -1603,7 +1603,7 @@ - + @@ -1652,7 +1652,7 @@ - + @@ -1701,7 +1701,7 @@ - + @@ -1750,7 +1750,7 @@ - + @@ -1799,7 +1799,7 @@ - + @@ -1848,7 +1848,7 @@ - + @@ -1930,7 +1930,7 @@ - + @@ -1979,7 +1979,7 @@ - + @@ -2028,7 +2028,7 @@ - + @@ -2077,7 +2077,7 @@ - + @@ -2133,7 +2133,7 @@ - + @@ -2182,7 +2182,7 @@ - + @@ -2231,7 +2231,7 @@ - + @@ -2280,7 +2280,7 @@ - + @@ -2329,7 +2329,7 @@ - + @@ -2378,7 +2378,7 @@ - + @@ -2569,14 +2569,14 @@ - + - - + + - + - + @@ -2613,7 +2613,7 @@ - - + + @@ -2631,7 +2631,7 @@ - + - + @@ -3305,7 +3331,7 @@ DQ - + @@ -3366,7 +3392,7 @@ DQ - + @@ -3382,7 +3408,7 @@ DQ - + @@ -3393,7 +3419,7 @@ DQ - + @@ -3401,7 +3427,7 @@ DQ - + @@ -3411,7 +3437,7 @@ DQ - + @@ -3431,7 +3457,7 @@ DQ - + @@ -3528,7 +3554,7 @@ DQ - + @@ -3536,7 +3562,7 @@ DQ - + @@ -3584,7 +3610,7 @@ DQ - + @@ -3592,7 +3618,7 @@ DQ - + diff --git a/Rectangle/PrefsWindow/SettingsViewController.swift b/Rectangle/PrefsWindow/SettingsViewController.swift index 376bd804..5f9a2357 100644 --- a/Rectangle/PrefsWindow/SettingsViewController.swift +++ b/Rectangle/PrefsWindow/SettingsViewController.swift @@ -34,6 +34,10 @@ class SettingsViewController: NSViewController { @IBOutlet weak var stageSlider: NSSlider! @IBOutlet weak var stageLabel: NSTextField! + @IBOutlet weak var cycleBetweenOptionsView: NSStackView! + + @IBOutlet var cycleBetweenOptionsViewHeightConstraint: NSLayoutConstraint! + private var aboutTodoWindowController: NSWindowController? @IBAction func toggleLaunchOnLogin(_ sender: NSButton) { diff --git a/Rectangle/mul.lproj/Main.xcstrings b/Rectangle/mul.lproj/Main.xcstrings index 162a10ac..abeff08f 100644 --- a/Rectangle/mul.lproj/Main.xcstrings +++ b/Rectangle/mul.lproj/Main.xcstrings @@ -38754,6 +38754,18 @@ } } }, + "Sz9-vr-PgO.title" : { + "comment" : "Class = \"NSTextFieldCell\"; title = \"Cycle between sizes\"; ObjectID = \"Sz9-vr-PgO\";", + "extractionState" : "extracted_with_value", + "localizations" : { + "en" : { + "stringUnit" : { + "state" : "new", + "value" : "Cycle between sizes" + } + } + } + }, "t7n-mU-75I.title" : { "comment" : "Class = \"NSTextFieldCell\"; title = \"Enable Rectangle.app\"; ObjectID = \"t7n-mU-75I\";", "extractionState" : "extracted_with_value", @@ -43131,7 +43143,7 @@ "en-GB" : { "stringUnit" : { "state" : "translated", - "value": "Centre" + "value" : "Centre" } }, "es" : { From 53cf249e63fb3d417c290c34f72fdf6d8371a08e Mon Sep 17 00:00:00 2001 From: Eskil Gjerde Sviggum Date: Fri, 2 Aug 2024 14:52:16 +0200 Subject: [PATCH 04/17] Add checkbox for each cycle size to stack view in settings Toggle cycle sizes stack view based on which repeated action is selected --- .../PrefsWindow/SettingsViewController.swift | 99 +++++++++++++++++++ 1 file changed, 99 insertions(+) diff --git a/Rectangle/PrefsWindow/SettingsViewController.swift b/Rectangle/PrefsWindow/SettingsViewController.swift index 5f9a2357..08842a49 100644 --- a/Rectangle/PrefsWindow/SettingsViewController.swift +++ b/Rectangle/PrefsWindow/SettingsViewController.swift @@ -40,6 +40,8 @@ class SettingsViewController: NSViewController { private var aboutTodoWindowController: NSWindowController? + private var cycleBetweenSizeCheckboxes = [NSButton]() + @IBAction func toggleLaunchOnLogin(_ sender: NSButton) { let newSetting: Bool = sender.state == .on if #available(macOS 13, *) { @@ -68,6 +70,7 @@ class SettingsViewController: NSViewController { } Defaults.subsequentExecutionMode.value = mode + initializeCycleBetweenOptionsView(animated: true) } @IBAction func gapSliderChanged(_ sender: NSSlider) { @@ -230,9 +233,20 @@ class SettingsViewController: NSViewController { initializeTodoModeSettings() + self.cycleBetweenSizeCheckboxes.forEach { + $0.removeFromSuperview() + } + + let cycleBetweenSizesCheckboxes = makeCycleBetweenSizesCheckboxes() + cycleBetweenSizesCheckboxes.forEach { checkbox in + cycleBetweenOptionsView.addArrangedSubview(checkbox) + } + self.cycleBetweenSizeCheckboxes = cycleBetweenSizesCheckboxes + Notification.Name.configImported.onPost(using: {_ in self.initializeTodoModeSettings() self.initializeToggles() + self.initializeCycleBetweenOptionsView(animated: false) }) Notification.Name.menuBarIconHidden.onPost(using: {_ in @@ -286,6 +300,91 @@ class SettingsViewController: NSViewController { } else { stageView.isHidden = true } + + + setToggleStatesForCycleSizeCheckboxes() + } + + private func initializeCycleBetweenOptionsView(animated: Bool = false) { + let showOptionsView = Defaults.subsequentExecutionMode.value == .resize + + if showOptionsView { + setToggleStatesForCycleSizeCheckboxes() + } + + animateChanges(animated: animated) { + cycleBetweenOptionsView.isHidden = !showOptionsView + cycleBetweenOptionsViewHeightConstraint.isActive = !showOptionsView + } + } + + private func animateChanges(animated: Bool, block: () -> Void) { + if animated { + NSAnimationContext.runAnimationGroup({context in + context.duration = 0.3 + context.allowsImplicitAnimation = true + + block() + view.layoutSubtreeIfNeeded() + }, completionHandler: nil) + } else { + block() + } + } + + private func makeCycleBetweenSizesCheckboxes() -> [NSButton] { + CycleBetweenDivision.sortedCycleDivisions.map { division in + let button = NSButton(checkboxWithTitle: division.title, target: self, action: #selector(didCheckCycleBetweenCheckbox(sender:))) + button.tag = division.rawValue + return button + } + } + + @objc private func didCheckCycleBetweenCheckbox(sender: Any?) { + guard let checkbox = sender as? NSButton else { + Logger.log("Expected action to be sent from NSButton. Instead, sender is: \(String(describing: sender))") + return + } + + let rawValue = checkbox.tag + + guard let cycleDivision = CycleBetweenDivision(rawValue: rawValue) else { + Logger.log("Expected tag of cycle between checkbox to match a value of CycleBetweenDivision. Got: \(String(describing: rawValue))") + return + } + + // If cycle between divisions has not been changed, write the defaults. + if !Defaults.cycleBetweenDivisionsIsChanged.enabled { + Defaults.cycleBetweenDivisions.value = CycleBetweenDivision.defaultCycleSizes + } + + Defaults.cycleBetweenDivisionsIsChanged.enabled = true + + if checkbox.state == .on { + Defaults.cycleBetweenDivisions.value.insert(cycleDivision) + } else { + Defaults.cycleBetweenDivisions.value.remove(cycleDivision) + } + } + + private func setToggleStatesForCycleSizeCheckboxes() { + let useDefaultCycleSizes = !Defaults.cycleBetweenDivisionsIsChanged.enabled + let cycleBetweenSizes = useDefaultCycleSizes ? CycleBetweenDivision.defaultCycleSizes : Defaults.cycleBetweenDivisions.value + + cycleBetweenSizeCheckboxes.forEach { checkbox in + guard let cycleBetweenSizeForCheckbox = CycleBetweenDivision(rawValue: checkbox.tag) else { + return + } + + let isAlwaysEnabled = cycleBetweenSizeForCheckbox.isAlwaysEnabled + let isChecked = isAlwaysEnabled || cycleBetweenSizes.contains(cycleBetweenSizeForCheckbox) + checkbox.state = isChecked ? .on : .off + + // Show that the box cannot be unchecked. + if isAlwaysEnabled { + checkbox.isEnabled = false + } + } } } From ba142399473a79eec8437f543fb9bef948de1e8a Mon Sep 17 00:00:00 2001 From: Eskil Gjerde Sviggum Date: Fri, 2 Aug 2024 14:54:09 +0200 Subject: [PATCH 05/17] Make repeated executions calculation take selected cycle sizes into account --- Rectangle.xcodeproj/project.pbxproj | 4 ++++ .../RepeatedExecutionsCalculation.swift | 22 ++++++++----------- ...epeatedExecutionsInThirdsCalculation.swift | 10 +++------ 3 files changed, 16 insertions(+), 20 deletions(-) diff --git a/Rectangle.xcodeproj/project.pbxproj b/Rectangle.xcodeproj/project.pbxproj index a8ec95c2..e72e6212 100644 --- a/Rectangle.xcodeproj/project.pbxproj +++ b/Rectangle.xcodeproj/project.pbxproj @@ -19,6 +19,7 @@ 6490B39F27BF98840056C220 /* BottomCenterRightEighthCalculation.swift in Sources */ = {isa = PBXBuildFile; fileRef = 6490B39E27BF98840056C220 /* BottomCenterRightEighthCalculation.swift */; }; 6490B3A127BF98C70056C220 /* BottomRightEighthCalculation.swift in Sources */ = {isa = PBXBuildFile; fileRef = 6490B3A027BF98C70056C220 /* BottomRightEighthCalculation.swift */; }; 729E0A982AFF76B1006E2F48 /* CenterProminentlyCalculation.swift in Sources */ = {isa = PBXBuildFile; fileRef = 729E0A972AFF76B1006E2F48 /* CenterProminentlyCalculation.swift */; }; + 7BE578EF2C5BF4EE0083DAE3 /* CycleBetweenDivisions.swift in Sources */ = {isa = PBXBuildFile; fileRef = 7BE578EE2C5BF4ED0083DAE3 /* CycleBetweenDivisions.swift */; }; 866661F2257D248A00A9CD2D /* RepeatedExecutionsInThirdsCalculation.swift in Sources */ = {isa = PBXBuildFile; fileRef = 866661F1257D248A00A9CD2D /* RepeatedExecutionsInThirdsCalculation.swift */; }; 94E9B08E2C3B8D97004C7F41 /* MacTilingDefaults.swift in Sources */ = {isa = PBXBuildFile; fileRef = 94E9B08D2C3B8D97004C7F41 /* MacTilingDefaults.swift */; }; 94E9B0902C3E4578004C7F41 /* StringExtension.swift in Sources */ = {isa = PBXBuildFile; fileRef = 94E9B08F2C3E4578004C7F41 /* StringExtension.swift */; }; @@ -186,6 +187,7 @@ 6490B39E27BF98840056C220 /* BottomCenterRightEighthCalculation.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = BottomCenterRightEighthCalculation.swift; sourceTree = ""; }; 6490B3A027BF98C70056C220 /* BottomRightEighthCalculation.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = BottomRightEighthCalculation.swift; sourceTree = ""; }; 729E0A972AFF76B1006E2F48 /* CenterProminentlyCalculation.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = CenterProminentlyCalculation.swift; sourceTree = ""; }; + 7BE578EE2C5BF4ED0083DAE3 /* CycleBetweenDivisions.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = CycleBetweenDivisions.swift; sourceTree = ""; }; 866661F1257D248A00A9CD2D /* RepeatedExecutionsInThirdsCalculation.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = RepeatedExecutionsInThirdsCalculation.swift; sourceTree = ""; }; 94E9B08D2C3B8D97004C7F41 /* MacTilingDefaults.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = MacTilingDefaults.swift; sourceTree = ""; }; 94E9B08F2C3E4578004C7F41 /* StringExtension.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = StringExtension.swift; sourceTree = ""; }; @@ -552,6 +554,7 @@ 9821405F22B3EFB200ABFB3F /* Defaults.swift */, 984EDB0E29A42ED200D119D2 /* LaunchOnLogin.swift */, 98C1008B2305F1FA006E5344 /* SubsequentExecutionMode.swift */, + 7BE578EE2C5BF4ED0083DAE3 /* CycleBetweenDivisions.swift */, 985B9BF422B93EEC00A2E8F0 /* ApplicationToggle.swift */, 9824703022AFA8470037B409 /* RectangleStatusItem.swift */, 9824703622B0F3200037B409 /* WindowAction.swift */, @@ -922,6 +925,7 @@ 9824703722B0F3200037B409 /* WindowAction.swift in Sources */, B4521F932BD7CEFB00FD43CC /* ChangeWindowDimensionCalculation.swift in Sources */, 9821402922B3889100ABFB3F /* LowerLeftCalculation.swift in Sources */, + 7BE578EF2C5BF4EE0083DAE3 /* CycleBetweenDivisions.swift in Sources */, 9821402122B3884600ABFB3F /* BottomHalfCalculation.swift in Sources */, 98910B42231476B30066EC23 /* PrefsViewController.swift in Sources */, 9851A5C3251BEBA300ECF78C /* OrientationAware.swift in Sources */, diff --git a/Rectangle/WindowCalculation/RepeatedExecutionsCalculation.swift b/Rectangle/WindowCalculation/RepeatedExecutionsCalculation.swift index b12c78ad..bf32fe18 100644 --- a/Rectangle/WindowCalculation/RepeatedExecutionsCalculation.swift +++ b/Rectangle/WindowCalculation/RepeatedExecutionsCalculation.swift @@ -12,9 +12,7 @@ protocol RepeatedExecutionsCalculation { func calculateFirstRect(_ params: RectCalculationParameters) -> RectResult - func calculateSecondRect(_ params: RectCalculationParameters) -> RectResult - - func calculateThirdRect(_ params: RectCalculationParameters) -> RectResult + func calculateRect(for cycleDivision: CycleBetweenDivision, params: RectCalculationParameters) -> RectResult } @@ -27,18 +25,16 @@ extension RepeatedExecutionsCalculation { else { return calculateFirstRect(params) } - - let position = count % 3 - switch (position) { - case 1: - return calculateSecondRect(params) - case 2: - return calculateThirdRect(params) - default: - return calculateFirstRect(params) - } + let useDefaultPositions = !Defaults.cycleBetweenDivisionsIsChanged.enabled + let positions = useDefaultPositions ? CycleBetweenDivision.defaultCycleSizes : Defaults.cycleBetweenDivisions.value + + let sortedPositions = CycleBetweenDivision.sortedCycleDivisions + .filter { positions.contains($0) } + + let position = count % sortedPositions.count + return calculateRect(for: sortedPositions[position], params: params) } } diff --git a/Rectangle/WindowCalculation/RepeatedExecutionsInThirdsCalculation.swift b/Rectangle/WindowCalculation/RepeatedExecutionsInThirdsCalculation.swift index 9ef75d18..19a3d8c3 100644 --- a/Rectangle/WindowCalculation/RepeatedExecutionsInThirdsCalculation.swift +++ b/Rectangle/WindowCalculation/RepeatedExecutionsInThirdsCalculation.swift @@ -20,13 +20,9 @@ extension RepeatedExecutionsInThirdsCalculation { return calculateFractionalRect(params, fraction: 1 / 2.0) } - func calculateSecondRect(_ params: RectCalculationParameters) -> RectResult { - let fraction: Float = Defaults.altThirdCycle.userEnabled ? (1 / 3.0) : (2 / 3.0) - return calculateFractionalRect(params, fraction: fraction) - } - - func calculateThirdRect(_ params: RectCalculationParameters) -> RectResult { - let fraction: Float = Defaults.altThirdCycle.userEnabled ? (2 / 3.0) : (1 / 3.0) + // FIXME: Check how Defaults.altThirdCycle is used, potentially remove. + func calculateRect(for cycleDivision: CycleBetweenDivision, params: RectCalculationParameters) -> RectResult { + let fraction = cycleDivision.fraction return calculateFractionalRect(params, fraction: fraction) } From ebb0126cd701de9c29ccbc566bb25013c8eb635c Mon Sep 17 00:00:00 2001 From: Eskil Gjerde Sviggum Date: Fri, 2 Aug 2024 15:10:09 +0200 Subject: [PATCH 06/17] Animate toggling todo mode in Settings view --- Rectangle/Base.lproj/Main.storyboard | 54 ++++++++++--------- .../PrefsWindow/SettingsViewController.swift | 15 ++++-- 2 files changed, 39 insertions(+), 30 deletions(-) diff --git a/Rectangle/Base.lproj/Main.storyboard b/Rectangle/Base.lproj/Main.storyboard index 369c3593..0fc97ae2 100644 --- a/Rectangle/Base.lproj/Main.storyboard +++ b/Rectangle/Base.lproj/Main.storyboard @@ -2569,14 +2569,14 @@ - + - + - + - + @@ -2631,7 +2631,7 @@ - + - + - + - + @@ -2631,7 +2631,7 @@ - + - + @@ -2622,7 +2622,7 @@ - + @@ -2672,7 +2672,7 @@ - + @@ -2712,7 +2712,7 @@ - + @@ -3304,7 +3304,7 @@ - + @@ -3325,7 +3325,7 @@ DQ - + @@ -3333,7 +3333,7 @@ DQ - + @@ -3394,7 +3394,7 @@ DQ - + @@ -3410,7 +3410,7 @@ DQ - + @@ -3421,7 +3421,7 @@ DQ - + @@ -3429,7 +3429,7 @@ DQ - + @@ -3439,7 +3439,7 @@ DQ - + @@ -3459,7 +3459,7 @@ DQ - + @@ -3556,7 +3556,7 @@ DQ - + @@ -3564,7 +3564,7 @@ DQ - + @@ -3612,7 +3612,7 @@ DQ - + @@ -3620,7 +3620,7 @@ DQ - + From 0e7af4a695a122507869f8e79dc2c8f202c6ae5b Mon Sep 17 00:00:00 2001 From: Eskil Gjerde Sviggum Date: Fri, 2 Aug 2024 22:42:10 +0200 Subject: [PATCH 12/17] Remove FIXME --- .../RepeatedExecutionsInThirdsCalculation.swift | 1 - 1 file changed, 1 deletion(-) diff --git a/Rectangle/WindowCalculation/RepeatedExecutionsInThirdsCalculation.swift b/Rectangle/WindowCalculation/RepeatedExecutionsInThirdsCalculation.swift index 19a3d8c3..c36b52f6 100644 --- a/Rectangle/WindowCalculation/RepeatedExecutionsInThirdsCalculation.swift +++ b/Rectangle/WindowCalculation/RepeatedExecutionsInThirdsCalculation.swift @@ -20,7 +20,6 @@ extension RepeatedExecutionsInThirdsCalculation { return calculateFractionalRect(params, fraction: 1 / 2.0) } - // FIXME: Check how Defaults.altThirdCycle is used, potentially remove. func calculateRect(for cycleDivision: CycleBetweenDivision, params: RectCalculationParameters) -> RectResult { let fraction = cycleDivision.fraction return calculateFractionalRect(params, fraction: fraction) From fd1e05d02c7d5fa4550c7701127ea750a0ebf17e Mon Sep 17 00:00:00 2001 From: Eskil Gjerde Sviggum Date: Fri, 2 Aug 2024 22:55:23 +0200 Subject: [PATCH 13/17] Fix showing cycle sizes view accross app launches --- Rectangle/PrefsWindow/SettingsViewController.swift | 2 ++ 1 file changed, 2 insertions(+) diff --git a/Rectangle/PrefsWindow/SettingsViewController.swift b/Rectangle/PrefsWindow/SettingsViewController.swift index de16f37d..029a2029 100644 --- a/Rectangle/PrefsWindow/SettingsViewController.swift +++ b/Rectangle/PrefsWindow/SettingsViewController.swift @@ -246,6 +246,8 @@ class SettingsViewController: NSViewController { } self.cycleBetweenSizeCheckboxes = cycleBetweenSizesCheckboxes + initializeCycleBetweenOptionsView(animated: false) + Notification.Name.configImported.onPost(using: {_ in self.initializeTodoModeSettings() self.initializeToggles() From e429224c04847a7ad6abc90b3d0f954d0200cabe Mon Sep 17 00:00:00 2001 From: Eskil Gjerde Sviggum Date: Thu, 8 Aug 2024 18:12:19 +0200 Subject: [PATCH 14/17] Change text of menu item Remove cycle sizes options text field --- Rectangle/Base.lproj/Main.storyboard | 153 +++++++++++++-------------- Rectangle/mul.lproj/Main.xcstrings | 40 +------ 2 files changed, 79 insertions(+), 114 deletions(-) diff --git a/Rectangle/Base.lproj/Main.storyboard b/Rectangle/Base.lproj/Main.storyboard index 6628796d..b9d37271 100644 --- a/Rectangle/Base.lproj/Main.storyboard +++ b/Rectangle/Base.lproj/Main.storyboard @@ -337,7 +337,7 @@ - + @@ -386,7 +386,7 @@ - + @@ -435,7 +435,7 @@ - + @@ -484,7 +484,7 @@ - + @@ -536,7 +536,7 @@ - + @@ -595,7 +595,7 @@ - + @@ -647,7 +647,7 @@ - + @@ -699,7 +699,7 @@ - + @@ -751,7 +751,7 @@ - + @@ -832,7 +832,7 @@ - + @@ -881,7 +881,7 @@ - + @@ -930,7 +930,7 @@ - + @@ -979,7 +979,7 @@ - + @@ -1028,7 +1028,7 @@ - + @@ -1077,7 +1077,7 @@ - + @@ -1126,7 +1126,7 @@ - + @@ -1182,7 +1182,7 @@ - + @@ -1231,7 +1231,7 @@ - + @@ -1351,7 +1351,7 @@ - + @@ -1400,7 +1400,7 @@ - + @@ -1449,7 +1449,7 @@ - + @@ -1498,7 +1498,7 @@ - + @@ -1547,7 +1547,7 @@ - + @@ -1603,7 +1603,7 @@ - + @@ -1652,7 +1652,7 @@ - + @@ -1701,7 +1701,7 @@ - + @@ -1750,7 +1750,7 @@ - + @@ -1799,7 +1799,7 @@ - + @@ -1848,7 +1848,7 @@ - + @@ -1930,7 +1930,7 @@ - + @@ -1979,7 +1979,7 @@ - + @@ -2028,7 +2028,7 @@ - + @@ -2077,7 +2077,7 @@ - + @@ -2133,7 +2133,7 @@ - + @@ -2182,7 +2182,7 @@ - + @@ -2231,7 +2231,7 @@ - + @@ -2280,7 +2280,7 @@ - + @@ -2329,7 +2329,7 @@ - + @@ -2378,7 +2378,7 @@ - + @@ -2588,7 +2588,7 @@ - + @@ -2622,7 +2622,7 @@ - + @@ -2672,7 +2672,7 @@ - + @@ -2689,7 +2689,7 @@ - + @@ -2710,16 +2710,11 @@ - + @@ -3421,7 +3416,7 @@ DQ - + @@ -3429,7 +3424,7 @@ DQ - + @@ -3439,7 +3434,7 @@ DQ - + @@ -3459,7 +3454,7 @@ DQ - + @@ -3556,7 +3551,7 @@ DQ - + @@ -3564,7 +3559,7 @@ DQ - + @@ -3612,7 +3607,7 @@ DQ - + @@ -3620,7 +3615,7 @@ DQ - + diff --git a/Rectangle/mul.lproj/Main.xcstrings b/Rectangle/mul.lproj/Main.xcstrings index c6a859f5..ae6e761c 100644 --- a/Rectangle/mul.lproj/Main.xcstrings +++ b/Rectangle/mul.lproj/Main.xcstrings @@ -19003,7 +19003,7 @@ } }, "gHH-BV-5kP.title" : { - "comment" : "Class = \"NSMenuItem\"; title = \"cycle between sizes on half actions\"; ObjectID = \"gHH-BV-5kP\";", + "comment" : "Class = \"NSMenuItem\"; title = \"cycle sizes on half actions\"; ObjectID = \"gHH-BV-5kP\";", "extractionState" : "extracted_with_value", "localizations" : { "ar" : { @@ -19039,7 +19039,7 @@ "en" : { "stringUnit" : { "state" : "new", - "value" : "cycle between sizes on half actions" + "value" : "cycle sizes on half actions" } }, "es" : { @@ -38724,36 +38724,6 @@ } } }, - "Sz9-vr-PgO.title" : { - "comment" : "Class = \"NSTextFieldCell\"; title = \"Cycle between sizes\"; ObjectID = \"Sz9-vr-PgO\";", - "extractionState" : "extracted_with_value", - "localizations" : { - "en" : { - "stringUnit" : { - "state" : "new", - "value" : "Cycle between sizes" - } - }, - "nb" : { - "stringUnit" : { - "state" : "translated", - "value" : "Bytt mellom størrelser" - } - }, - "nn" : { - "stringUnit" : { - "state" : "translated", - "value" : "Bytt mellom storleikar" - } - }, - "sv-SE" : { - "stringUnit" : { - "state" : "translated", - "value" : "Växla mellan storlekar" - } - } - } - }, "t7n-mU-75I.title" : { "comment" : "Class = \"NSTextFieldCell\"; title = \"Enable Rectangle.app\"; ObjectID = \"t7n-mU-75I\";", "extractionState" : "extracted_with_value", @@ -47510,7 +47480,7 @@ }, "nb" : { "stringUnit" : { - "state" : "needs_review", + "state" : "translated", "value" : "Innstillinger…" } }, @@ -47522,7 +47492,7 @@ }, "nn" : { "stringUnit" : { - "state" : "needs_review", + "state" : "translated", "value" : "Innstillingar…" } }, @@ -47564,7 +47534,7 @@ }, "sv-SE" : { "stringUnit" : { - "state" : "needs_review", + "state" : "translated", "value" : "Inställningar…" } }, From 82133c5fa8d5364df2c1bce55bbc55baaebc39c7 Mon Sep 17 00:00:00 2001 From: Eskil Gjerde Sviggum Date: Thu, 8 Aug 2024 18:13:08 +0200 Subject: [PATCH 15/17] Change cycle divisions to go gradually *upwards* in size --- Rectangle/CycleBetweenDivisions.swift | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/Rectangle/CycleBetweenDivisions.swift b/Rectangle/CycleBetweenDivisions.swift index b761305e..51be292b 100644 --- a/Rectangle/CycleBetweenDivisions.swift +++ b/Rectangle/CycleBetweenDivisions.swift @@ -27,11 +27,11 @@ enum CycleBetweenDivision: Int, CaseIterable { static var defaultCycleSizes: Set = [.oneHalf, .oneThird, .twoThirds] // The expected order of the cycle sizes is to start with the - // first division, then go gradually downwards in size and wrap - // around to the larger sizes. + // first division, then go gradually upwards in size and wrap + // around to the smaller sizes. // // For example if all cycles are used, the order should be: - // 1/2, 1/3, 1/4, 3/4, 2/3 + // 1/2, 2/3, 3/4, 1/4, 1/3 static var sortedCycleDivisions: [CycleBetweenDivision] = { let sortedDivisions = Self.allCases.sorted(by: { $0.fraction < $1.fraction }) @@ -42,7 +42,7 @@ enum CycleBetweenDivision: Int, CaseIterable { let lessThanFistDivision = sortedDivisions[0.. Date: Thu, 8 Aug 2024 18:31:15 +0200 Subject: [PATCH 16/17] Rename enum `CycleBetweenDivision` to CycleSize Refactor Change CycleSizeDefault key to `selectedCycleSizes` Change cycleSizesIsChanges key to `cycleSizesIsChanged` --- Rectangle.xcodeproj/project.pbxproj | 8 +-- Rectangle/Base.lproj/Main.storyboard | 4 +- ...BetweenDivisions.swift => CycleSize.swift} | 32 +++++------ Rectangle/Defaults.swift | 8 +-- .../PrefsWindow/SettingsViewController.swift | 54 +++++++++---------- .../RepeatedExecutionsCalculation.swift | 8 +-- ...epeatedExecutionsInThirdsCalculation.swift | 2 +- 7 files changed, 58 insertions(+), 58 deletions(-) rename Rectangle/{CycleBetweenDivisions.swift => CycleSize.swift} (73%) diff --git a/Rectangle.xcodeproj/project.pbxproj b/Rectangle.xcodeproj/project.pbxproj index e72e6212..ad05e4bf 100644 --- a/Rectangle.xcodeproj/project.pbxproj +++ b/Rectangle.xcodeproj/project.pbxproj @@ -19,7 +19,7 @@ 6490B39F27BF98840056C220 /* BottomCenterRightEighthCalculation.swift in Sources */ = {isa = PBXBuildFile; fileRef = 6490B39E27BF98840056C220 /* BottomCenterRightEighthCalculation.swift */; }; 6490B3A127BF98C70056C220 /* BottomRightEighthCalculation.swift in Sources */ = {isa = PBXBuildFile; fileRef = 6490B3A027BF98C70056C220 /* BottomRightEighthCalculation.swift */; }; 729E0A982AFF76B1006E2F48 /* CenterProminentlyCalculation.swift in Sources */ = {isa = PBXBuildFile; fileRef = 729E0A972AFF76B1006E2F48 /* CenterProminentlyCalculation.swift */; }; - 7BE578EF2C5BF4EE0083DAE3 /* CycleBetweenDivisions.swift in Sources */ = {isa = PBXBuildFile; fileRef = 7BE578EE2C5BF4ED0083DAE3 /* CycleBetweenDivisions.swift */; }; + 7BE578EF2C5BF4EE0083DAE3 /* CycleSize.swift in Sources */ = {isa = PBXBuildFile; fileRef = 7BE578EE2C5BF4ED0083DAE3 /* CycleSize.swift */; }; 866661F2257D248A00A9CD2D /* RepeatedExecutionsInThirdsCalculation.swift in Sources */ = {isa = PBXBuildFile; fileRef = 866661F1257D248A00A9CD2D /* RepeatedExecutionsInThirdsCalculation.swift */; }; 94E9B08E2C3B8D97004C7F41 /* MacTilingDefaults.swift in Sources */ = {isa = PBXBuildFile; fileRef = 94E9B08D2C3B8D97004C7F41 /* MacTilingDefaults.swift */; }; 94E9B0902C3E4578004C7F41 /* StringExtension.swift in Sources */ = {isa = PBXBuildFile; fileRef = 94E9B08F2C3E4578004C7F41 /* StringExtension.swift */; }; @@ -187,7 +187,7 @@ 6490B39E27BF98840056C220 /* BottomCenterRightEighthCalculation.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = BottomCenterRightEighthCalculation.swift; sourceTree = ""; }; 6490B3A027BF98C70056C220 /* BottomRightEighthCalculation.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = BottomRightEighthCalculation.swift; sourceTree = ""; }; 729E0A972AFF76B1006E2F48 /* CenterProminentlyCalculation.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = CenterProminentlyCalculation.swift; sourceTree = ""; }; - 7BE578EE2C5BF4ED0083DAE3 /* CycleBetweenDivisions.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = CycleBetweenDivisions.swift; sourceTree = ""; }; + 7BE578EE2C5BF4ED0083DAE3 /* CycleSize.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = CycleSize.swift; sourceTree = ""; }; 866661F1257D248A00A9CD2D /* RepeatedExecutionsInThirdsCalculation.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = RepeatedExecutionsInThirdsCalculation.swift; sourceTree = ""; }; 94E9B08D2C3B8D97004C7F41 /* MacTilingDefaults.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = MacTilingDefaults.swift; sourceTree = ""; }; 94E9B08F2C3E4578004C7F41 /* StringExtension.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = StringExtension.swift; sourceTree = ""; }; @@ -554,7 +554,7 @@ 9821405F22B3EFB200ABFB3F /* Defaults.swift */, 984EDB0E29A42ED200D119D2 /* LaunchOnLogin.swift */, 98C1008B2305F1FA006E5344 /* SubsequentExecutionMode.swift */, - 7BE578EE2C5BF4ED0083DAE3 /* CycleBetweenDivisions.swift */, + 7BE578EE2C5BF4ED0083DAE3 /* CycleSize.swift */, 985B9BF422B93EEC00A2E8F0 /* ApplicationToggle.swift */, 9824703022AFA8470037B409 /* RectangleStatusItem.swift */, 9824703622B0F3200037B409 /* WindowAction.swift */, @@ -925,7 +925,7 @@ 9824703722B0F3200037B409 /* WindowAction.swift in Sources */, B4521F932BD7CEFB00FD43CC /* ChangeWindowDimensionCalculation.swift in Sources */, 9821402922B3889100ABFB3F /* LowerLeftCalculation.swift in Sources */, - 7BE578EF2C5BF4EE0083DAE3 /* CycleBetweenDivisions.swift in Sources */, + 7BE578EF2C5BF4EE0083DAE3 /* CycleSize.swift in Sources */, 9821402122B3884600ABFB3F /* BottomHalfCalculation.swift in Sources */, 98910B42231476B30066EC23 /* PrefsViewController.swift in Sources */, 9851A5C3251BEBA300ECF78C /* OrientationAware.swift in Sources */, diff --git a/Rectangle/Base.lproj/Main.storyboard b/Rectangle/Base.lproj/Main.storyboard index b9d37271..4ae20109 100644 --- a/Rectangle/Base.lproj/Main.storyboard +++ b/Rectangle/Base.lproj/Main.storyboard @@ -3216,8 +3216,8 @@ - - + + diff --git a/Rectangle/CycleBetweenDivisions.swift b/Rectangle/CycleSize.swift similarity index 73% rename from Rectangle/CycleBetweenDivisions.swift rename to Rectangle/CycleSize.swift index 51be292b..ee4e065c 100644 --- a/Rectangle/CycleBetweenDivisions.swift +++ b/Rectangle/CycleSize.swift @@ -1,5 +1,5 @@ // -// CycleBetweenDivisions.swift +// CycleSize.swift // Rectangle // // Created by Eskil Gjerde Sviggum on 01/08/2024. @@ -8,14 +8,14 @@ import Foundation -enum CycleBetweenDivision: Int, CaseIterable { +enum CycleSize: Int, CaseIterable { case twoThirds = 0 case oneHalf = 1 case oneThird = 2 case oneQuarter = 3 case threeQuarters = 4 - static func fromBits(bits: Int) -> Set { + static func fromBits(bits: Int) -> Set { Set( Self.allCases.filter { (bits >> $0.rawValue) & 1 == 1 @@ -23,8 +23,8 @@ enum CycleBetweenDivision: Int, CaseIterable { ) } - static var firstDivision = CycleBetweenDivision.oneHalf - static var defaultCycleSizes: Set = [.oneHalf, .oneThird, .twoThirds] + static var firstSize = CycleSize.oneHalf + static var defaultSizes: Set = [.oneHalf, .twoThirds, .oneThird] // The expected order of the cycle sizes is to start with the // first division, then go gradually upwards in size and wrap @@ -32,21 +32,21 @@ enum CycleBetweenDivision: Int, CaseIterable { // // For example if all cycles are used, the order should be: // 1/2, 2/3, 3/4, 1/4, 1/3 - static var sortedCycleDivisions: [CycleBetweenDivision] = { + static var sortedSizes: [CycleSize] = { let sortedDivisions = Self.allCases.sorted(by: { $0.fraction < $1.fraction }) - guard let firstDivisionIndex = sortedDivisions.firstIndex(of: firstDivision) else { + guard let firstDivisionIndex = sortedDivisions.firstIndex(of: firstSize) else { return sortedDivisions } let lessThanFistDivision = sortedDivisions[0.. Int { var bits = 0 self.forEach { @@ -98,11 +98,11 @@ extension Set where Element == CycleBetweenDivision { } } -class CycleBetweenDivisionsDefault: Default { - public private(set) var key: String = "cycleBetweenDivisions" +class CycleSizesDefault: Default { + public private(set) var key: String = "selectedCycleSizes" private var initialized = false - var value: Set { + var value: Set { didSet { if initialized { UserDefaults.standard.set(value.toBits(), forKey: key) @@ -112,13 +112,13 @@ class CycleBetweenDivisionsDefault: Default { init() { let bits = UserDefaults.standard.integer(forKey: key) - value = CycleBetweenDivision.fromBits(bits: bits) + value = CycleSize.fromBits(bits: bits) initialized = true } func load(from codable: CodableDefault) { if let bits = codable.int { - let divisions = CycleBetweenDivision.fromBits(bits: bits) + let divisions = CycleSize.fromBits(bits: bits) value = divisions } } diff --git a/Rectangle/Defaults.swift b/Rectangle/Defaults.swift index 7228569d..13bd2954 100644 --- a/Rectangle/Defaults.swift +++ b/Rectangle/Defaults.swift @@ -14,8 +14,8 @@ class Defaults { static let hideMenuBarIcon = BoolDefault(key: "hideMenubarIcon") static let alternateDefaultShortcuts = BoolDefault(key: "alternateDefaultShortcuts") // switch to magnet defaults static let subsequentExecutionMode = SubsequentExecutionDefault() - static let cycleBetweenDivisions = CycleBetweenDivisionsDefault() - static let cycleBetweenDivisionsIsChanged = BoolDefault(key: "cycleBetweenDivisionsIsChanged") + static let selectedCycleSizes = CycleSizesDefault() + static let cycleSizesIsChanged = BoolDefault(key: "cycleSizesIsChanged") static let allowAnyShortcut = BoolDefault(key: "allowAnyShortcut") static let windowSnapping = OptionalBoolDefault(key: "windowSnapping") static let almostMaximizeHeight = FloatDefault(key: "almostMaximizeHeight") @@ -97,8 +97,8 @@ class Defaults { hideMenuBarIcon, alternateDefaultShortcuts, subsequentExecutionMode, - cycleBetweenDivisions, - cycleBetweenDivisionsIsChanged, + selectedCycleSizes, + cycleSizesIsChanged, allowAnyShortcut, windowSnapping, almostMaximizeHeight, diff --git a/Rectangle/PrefsWindow/SettingsViewController.swift b/Rectangle/PrefsWindow/SettingsViewController.swift index 029a2029..d0d8f943 100644 --- a/Rectangle/PrefsWindow/SettingsViewController.swift +++ b/Rectangle/PrefsWindow/SettingsViewController.swift @@ -34,16 +34,16 @@ class SettingsViewController: NSViewController { @IBOutlet weak var stageSlider: NSSlider! @IBOutlet weak var stageLabel: NSTextField! - @IBOutlet weak var cycleBetweenOptionsView: NSStackView! + @IBOutlet weak var cycleSizesView: NSStackView! - @IBOutlet var cycleBetweenOptionsViewHeightConstraint: NSLayoutConstraint! + @IBOutlet var cycleSizesViewHeightConstraint: NSLayoutConstraint! @IBOutlet var todoViewHeightConstraint: NSLayoutConstraint! private var aboutTodoWindowController: NSWindowController? - private var cycleBetweenSizeCheckboxes = [NSButton]() + private var cycleSizeCheckboxes = [NSButton]() @IBAction func toggleLaunchOnLogin(_ sender: NSButton) { let newSetting: Bool = sender.state == .on @@ -236,15 +236,15 @@ class SettingsViewController: NSViewController { initializeTodoModeSettings() - self.cycleBetweenSizeCheckboxes.forEach { + self.cycleSizeCheckboxes.forEach { $0.removeFromSuperview() } - let cycleBetweenSizesCheckboxes = makeCycleBetweenSizesCheckboxes() - cycleBetweenSizesCheckboxes.forEach { checkbox in - cycleBetweenOptionsView.addArrangedSubview(checkbox) + let cycleSizeCheckboxes = makeCycleSizeCheckboxes() + cycleSizeCheckboxes.forEach { checkbox in + cycleSizesView.addArrangedSubview(checkbox) } - self.cycleBetweenSizeCheckboxes = cycleBetweenSizesCheckboxes + self.cycleSizeCheckboxes = cycleSizeCheckboxes initializeCycleBetweenOptionsView(animated: false) @@ -322,8 +322,8 @@ class SettingsViewController: NSViewController { } animateChanges(animated: animated) { - cycleBetweenOptionsView.isHidden = !showOptionsView - cycleBetweenOptionsViewHeightConstraint.isActive = !showOptionsView + cycleSizesView.isHidden = !showOptionsView + cycleSizesViewHeightConstraint.isActive = !showOptionsView } } @@ -341,16 +341,16 @@ class SettingsViewController: NSViewController { } } - private func makeCycleBetweenSizesCheckboxes() -> [NSButton] { - CycleBetweenDivision.sortedCycleDivisions.map { division in - let button = NSButton(checkboxWithTitle: division.title, target: self, action: #selector(didCheckCycleBetweenCheckbox(sender:))) + private func makeCycleSizeCheckboxes() -> [NSButton] { + CycleSize.sortedSizes.map { division in + let button = NSButton(checkboxWithTitle: division.title, target: self, action: #selector(didCheckCycleSizeCheckbox(sender:))) button.tag = division.rawValue button.setContentCompressionResistancePriority(.required, for: .vertical) return button } } - @objc private func didCheckCycleBetweenCheckbox(sender: Any?) { + @objc private func didCheckCycleSizeCheckbox(sender: Any?) { guard let checkbox = sender as? NSButton else { Logger.log("Expected action to be sent from NSButton. Instead, sender is: \(String(describing: sender))") return @@ -358,36 +358,36 @@ class SettingsViewController: NSViewController { let rawValue = checkbox.tag - guard let cycleDivision = CycleBetweenDivision(rawValue: rawValue) else { + guard let cycleSize = CycleSize(rawValue: rawValue) else { Logger.log("Expected tag of cycle between checkbox to match a value of CycleBetweenDivision. Got: \(String(describing: rawValue))") return } - // If cycle between divisions has not been changed, write the defaults. - if !Defaults.cycleBetweenDivisionsIsChanged.enabled { - Defaults.cycleBetweenDivisions.value = CycleBetweenDivision.defaultCycleSizes + // If selected cycle sizes has not been changed, write the defaults. + if !Defaults.cycleSizesIsChanged.enabled { + Defaults.selectedCycleSizes.value = CycleSize.defaultSizes } - Defaults.cycleBetweenDivisionsIsChanged.enabled = true + Defaults.cycleSizesIsChanged.enabled = true if checkbox.state == .on { - Defaults.cycleBetweenDivisions.value.insert(cycleDivision) + Defaults.selectedCycleSizes.value.insert(cycleSize) } else { - Defaults.cycleBetweenDivisions.value.remove(cycleDivision) + Defaults.selectedCycleSizes.value.remove(cycleSize) } } private func setToggleStatesForCycleSizeCheckboxes() { - let useDefaultCycleSizes = !Defaults.cycleBetweenDivisionsIsChanged.enabled - let cycleBetweenSizes = useDefaultCycleSizes ? CycleBetweenDivision.defaultCycleSizes : Defaults.cycleBetweenDivisions.value + let useDefaultCycleSizes = !Defaults.cycleSizesIsChanged.enabled + let cycleSizes = useDefaultCycleSizes ? CycleSize.defaultSizes : Defaults.selectedCycleSizes.value - cycleBetweenSizeCheckboxes.forEach { checkbox in - guard let cycleBetweenSizeForCheckbox = CycleBetweenDivision(rawValue: checkbox.tag) else { + cycleSizeCheckboxes.forEach { checkbox in + guard let cycleSizeForCheckbox = CycleSize(rawValue: checkbox.tag) else { return } - let isAlwaysEnabled = cycleBetweenSizeForCheckbox.isAlwaysEnabled - let isChecked = isAlwaysEnabled || cycleBetweenSizes.contains(cycleBetweenSizeForCheckbox) + let isAlwaysEnabled = cycleSizeForCheckbox.isAlwaysEnabled + let isChecked = isAlwaysEnabled || cycleSizes.contains(cycleSizeForCheckbox) checkbox.state = isChecked ? .on : .off // Show that the box cannot be unchecked. diff --git a/Rectangle/WindowCalculation/RepeatedExecutionsCalculation.swift b/Rectangle/WindowCalculation/RepeatedExecutionsCalculation.swift index bf32fe18..160f5b52 100644 --- a/Rectangle/WindowCalculation/RepeatedExecutionsCalculation.swift +++ b/Rectangle/WindowCalculation/RepeatedExecutionsCalculation.swift @@ -12,7 +12,7 @@ protocol RepeatedExecutionsCalculation { func calculateFirstRect(_ params: RectCalculationParameters) -> RectResult - func calculateRect(for cycleDivision: CycleBetweenDivision, params: RectCalculationParameters) -> RectResult + func calculateRect(for cycleDivision: CycleSize, params: RectCalculationParameters) -> RectResult } @@ -26,10 +26,10 @@ extension RepeatedExecutionsCalculation { return calculateFirstRect(params) } - let useDefaultPositions = !Defaults.cycleBetweenDivisionsIsChanged.enabled - let positions = useDefaultPositions ? CycleBetweenDivision.defaultCycleSizes : Defaults.cycleBetweenDivisions.value + let useDefaultPositions = !Defaults.cycleSizesIsChanged.enabled + let positions = useDefaultPositions ? CycleSize.defaultSizes : Defaults.selectedCycleSizes.value - let sortedPositions = CycleBetweenDivision.sortedCycleDivisions + let sortedPositions = CycleSize.sortedSizes .filter { positions.contains($0) } let position = count % sortedPositions.count diff --git a/Rectangle/WindowCalculation/RepeatedExecutionsInThirdsCalculation.swift b/Rectangle/WindowCalculation/RepeatedExecutionsInThirdsCalculation.swift index c36b52f6..5e6590db 100644 --- a/Rectangle/WindowCalculation/RepeatedExecutionsInThirdsCalculation.swift +++ b/Rectangle/WindowCalculation/RepeatedExecutionsInThirdsCalculation.swift @@ -20,7 +20,7 @@ extension RepeatedExecutionsInThirdsCalculation { return calculateFractionalRect(params, fraction: 1 / 2.0) } - func calculateRect(for cycleDivision: CycleBetweenDivision, params: RectCalculationParameters) -> RectResult { + func calculateRect(for cycleDivision: CycleSize, params: RectCalculationParameters) -> RectResult { let fraction = cycleDivision.fraction return calculateFractionalRect(params, fraction: fraction) } From 49415a3d5cd5f38c052d5b270488f9558f6241d0 Mon Sep 17 00:00:00 2001 From: Eskil Gjerde Sviggum Date: Thu, 8 Aug 2024 18:59:39 +0200 Subject: [PATCH 17/17] =?UTF-8?q?More=20renaming=20=E2=80=9Ccycle=20betwee?= =?UTF-8?q?n=20divisions=E2=80=9D=20to=20=E2=80=9Ccycle=20sizes=E2=80=9D?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- Rectangle/CycleSize.swift | 12 ++++++------ Rectangle/PrefsWindow/SettingsViewController.swift | 10 +++++----- 2 files changed, 11 insertions(+), 11 deletions(-) diff --git a/Rectangle/CycleSize.swift b/Rectangle/CycleSize.swift index ee4e065c..9a912e81 100644 --- a/Rectangle/CycleSize.swift +++ b/Rectangle/CycleSize.swift @@ -33,16 +33,16 @@ enum CycleSize: Int, CaseIterable { // For example if all cycles are used, the order should be: // 1/2, 2/3, 3/4, 1/4, 1/3 static var sortedSizes: [CycleSize] = { - let sortedDivisions = Self.allCases.sorted(by: { $0.fraction < $1.fraction }) + let sortedSizes = Self.allCases.sorted(by: { $0.fraction < $1.fraction }) - guard let firstDivisionIndex = sortedDivisions.firstIndex(of: firstSize) else { - return sortedDivisions + guard let firstSizeIndex = sortedSizes.firstIndex(of: firstSize) else { + return sortedSizes } - let lessThanFistDivision = sortedDivisions[0..