From d5ee654b29412ffbd64fb5a5041409d4de5fba38 Mon Sep 17 00:00:00 2001 From: Strategic Conquest Date: Tue, 9 Jul 2024 22:05:44 -0700 Subject: [PATCH] Inform the user when macOS 15 tiling is enabled --- Rectangle.xcodeproj/project.pbxproj | 8 ++++ Rectangle/AppDelegate.swift | 35 +++++++++++++++++ Rectangle/Defaults.swift | 1 + Rectangle/Utilities/MacTilingDefaults.swift | 42 +++++++++++++++++++++ Rectangle/Utilities/StringExtension.swift | 16 ++++++++ Rectangle/mul.lproj/Main.xcstrings | 21 +++++++++++ 6 files changed, 123 insertions(+) create mode 100644 Rectangle/Utilities/MacTilingDefaults.swift create mode 100644 Rectangle/Utilities/StringExtension.swift diff --git a/Rectangle.xcodeproj/project.pbxproj b/Rectangle.xcodeproj/project.pbxproj index f121d4c2..5ae29fc5 100644 --- a/Rectangle.xcodeproj/project.pbxproj +++ b/Rectangle.xcodeproj/project.pbxproj @@ -20,6 +20,8 @@ 6490B3A127BF98C70056C220 /* BottomRightEighthCalculation.swift in Sources */ = {isa = PBXBuildFile; fileRef = 6490B3A027BF98C70056C220 /* BottomRightEighthCalculation.swift */; }; 729E0A982AFF76B1006E2F48 /* CenterProminentlyCalculation.swift in Sources */ = {isa = PBXBuildFile; fileRef = 729E0A972AFF76B1006E2F48 /* CenterProminentlyCalculation.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 */; }; 9818E00D28B59205004AA524 /* CompoundSnapArea.swift in Sources */ = {isa = PBXBuildFile; fileRef = 9818E00C28B59205004AA524 /* CompoundSnapArea.swift */; }; 9818E01028B59396004AA524 /* HalvesCompoundCalculation.swift in Sources */ = {isa = PBXBuildFile; fileRef = 9818E00F28B59396004AA524 /* HalvesCompoundCalculation.swift */; }; 9818E01228B59B64004AA524 /* ThirdsCompoundCalculation.swift in Sources */ = {isa = PBXBuildFile; fileRef = 9818E01128B59B64004AA524 /* ThirdsCompoundCalculation.swift */; }; @@ -185,6 +187,8 @@ 6490B3A027BF98C70056C220 /* BottomRightEighthCalculation.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = BottomRightEighthCalculation.swift; sourceTree = ""; }; 729E0A972AFF76B1006E2F48 /* CenterProminentlyCalculation.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = CenterProminentlyCalculation.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 = ""; }; 9808018523D05C0B0077774A /* RectangleRelease.entitlements */ = {isa = PBXFileReference; lastKnownFileType = text.plist.entitlements; path = RectangleRelease.entitlements; sourceTree = ""; }; 9808018623D05C1F0077774A /* RectangleLauncherRelease.entitlements */ = {isa = PBXFileReference; lastKnownFileType = text.plist.entitlements; path = RectangleLauncherRelease.entitlements; sourceTree = ""; }; 9818E00C28B59205004AA524 /* CompoundSnapArea.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = CompoundSnapArea.swift; sourceTree = ""; }; @@ -498,6 +502,8 @@ 98BEFA472620DEDC00D9D54F /* NSImageExtension.swift */, 98192DD9270F606C00015E66 /* Debounce.swift */, AA0ACC2E2864A86D0025E376 /* StageUtil.swift */, + 94E9B08D2C3B8D97004C7F41 /* MacTilingDefaults.swift */, + 94E9B08F2C3E4578004C7F41 /* StringExtension.swift */, AAADE1AE28CBAB0000036331 /* WindowUtil.swift */, AA4DA2FA28FDC94A00355CEB /* DispatchTimeExtension.swift */, AA536C2629005DD000579AC6 /* TimeoutCache.swift */, @@ -840,6 +846,7 @@ 98A009AB2512491300CFBF0C /* CenterHalfCalculation.swift in Sources */, 9818E01828B63C48004AA524 /* FourthsCompoundCalculation.swift in Sources */, D0CFE33327A8CCB1004DA47B /* TopRightThirdCalculation.swift in Sources */, + 94E9B08E2C3B8D97004C7F41 /* MacTilingDefaults.swift in Sources */, 9821403522B38A2B00ABFB3F /* UpperRightCalculation.swift in Sources */, 984EDB0F29A42ED200D119D2 /* LaunchOnLogin.swift in Sources */, 9824702F22AFA2E50037B409 /* AccessibilityAuthorization.swift in Sources */, @@ -883,6 +890,7 @@ 9824703B22B139780037B409 /* CUtil.swift in Sources */, 988D067D22EB4E17004EABD7 /* AlmostMaximizeCalculation.swift in Sources */, 98C1008C2305F1FA006E5344 /* SubsequentExecutionMode.swift in Sources */, + 94E9B0902C3E4578004C7F41 /* StringExtension.swift in Sources */, 6490B3A127BF98C70056C220 /* BottomRightEighthCalculation.swift in Sources */, 985B9BF922BB6F5100A2E8F0 /* MessageView.swift in Sources */, 988D066722EB4CC0004EABD7 /* LastTwoThirdsCalculation.swift in Sources */, diff --git a/Rectangle/AppDelegate.swift b/Rectangle/AppDelegate.swift index 4f54fcb3..97adc78b 100644 --- a/Rectangle/AppDelegate.swift +++ b/Rectangle/AppDelegate.swift @@ -120,6 +120,7 @@ class AppDelegate: NSObject, NSApplicationDelegate { self.titleBarManager = TitleBarManager() self.initializeTodo() checkForProblematicApps() + checkForBuiltInTiling() } func checkForConflictingApps() { @@ -191,6 +192,40 @@ class AppDelegate: NSObject, NSApplicationDelegate { } } + func checkForBuiltInTiling() { + guard #available(macOS 15, *), !Defaults.internalTilingNotified.enabled + else { + return + } + + Defaults.internalTilingNotified.enabled = true + if MacTilingDefaults.tilingByEdgeDrag.enabled || MacTilingDefaults.tilingOptionAccelerator.enabled { + let result = AlertUtil.threeButtonAlert( + question: "Conflict with macOS tiling".localized, + text: "Drag to screen edge tiling is enabled in both Rectangle and macOS.".localized, + buttonOneText: "Disable in macOS".localized, + buttonTwoText: "Disable in Rectangle".localized, + buttonThreeText: "Dismiss".localized) + switch result { + case .alertFirstButtonReturn: + MacTilingDefaults.tilingByEdgeDrag.disable() + MacTilingDefaults.tilingOptionAccelerator.disable() + + let result = AlertUtil.twoButtonAlert( + question: "Tiling in macOS has been disabled".localized, + text: "To re-enable it, go to System Settings → Desktop & Dock → Windows".localized, + cancelText: "Open System Settings".localized) + if result == .alertSecondButtonReturn { + MacTilingDefaults.openSystemSettings() + } + case .alertSecondButtonReturn: + Defaults.windowSnapping.enabled = false + default: + break + } + } + } + private func showWelcomeWindow() { let welcomeWindowController = NSStoryboard(name: "Main", bundle: nil) .instantiateController(withIdentifier: "WelcomeWindowController") as? NSWindowController diff --git a/Rectangle/Defaults.swift b/Rectangle/Defaults.swift index 1b22f4ce..b1628a1e 100644 --- a/Rectangle/Defaults.swift +++ b/Rectangle/Defaults.swift @@ -87,6 +87,7 @@ class Defaults { static let ignoreDragSnapToo = OptionalBoolDefault(key: "ignoreDragSnapToo") static let systemWideMouseDown = OptionalBoolDefault(key: "systemWideMouseDown") static let systemWideMouseDownApps = JSONDefault>(key:"systemWideMouseDownApps", defaultValue: Set(["org.languagetool.desktop", "com.microsoft.teams2"])) + static let internalTilingNotified = BoolDefault(key: "internalTilingNotified") static var array: [Default] = [ launchOnLogin, diff --git a/Rectangle/Utilities/MacTilingDefaults.swift b/Rectangle/Utilities/MacTilingDefaults.swift new file mode 100644 index 00000000..4e9d3c82 --- /dev/null +++ b/Rectangle/Utilities/MacTilingDefaults.swift @@ -0,0 +1,42 @@ +// +// MacTilingDefaults.swift +// Rectangle +// +// Copyright © 2024 Ryan Hanson. All rights reserved. +// + +import Foundation + +/// Read / disable the user defaults values for the macOS built-in window tiling, added in macOS 15 Sequoia. +/// These are toggled in the Desktop & Dock System Settings Pane: +enum MacTilingDefaults: String { + case tilingByEdgeDrag = "EnableTilingByEdgeDrag" + case tilingOptionAccelerator = "EnableTilingOptionAccelerator" + case tiledWindowMargins = "EnableTiledWindowMargins" + + var enabled: Bool { + guard #available(macOS 15, *), let defaults = UserDefaults(suiteName: "com.apple.WindowManager") + else { + return false + } + + if defaults.object(forKey: self.rawValue) == nil { // These are enabled by default + return true + } + return defaults.bool(forKey: self.rawValue) + } + + func disable() { + guard let defaults = UserDefaults(suiteName: "com.apple.WindowManager") + else { + return + } + + defaults.set(false, forKey: self.rawValue) + defaults.synchronize() + } + + static func openSystemSettings() { + NSWorkspace.shared.open(URL(string:"x-apple.systempreferences:com.apple.preference.Desktop-Settings.extension")!) + } +} diff --git a/Rectangle/Utilities/StringExtension.swift b/Rectangle/Utilities/StringExtension.swift new file mode 100644 index 00000000..a9500430 --- /dev/null +++ b/Rectangle/Utilities/StringExtension.swift @@ -0,0 +1,16 @@ +// +// StringExtension.swift +// Rectangle +// +// Copyright © 2024 Ryan Hanson. All rights reserved. +// + +import Foundation + +extension String { + + var localized: String { + NSLocalizedString(self, tableName: "Main", comment: "") + } + +} diff --git a/Rectangle/mul.lproj/Main.xcstrings b/Rectangle/mul.lproj/Main.xcstrings index 870b0a38..5d47e8d6 100644 --- a/Rectangle/mul.lproj/Main.xcstrings +++ b/Rectangle/mul.lproj/Main.xcstrings @@ -11643,6 +11643,9 @@ } } }, + "Conflict with macOS tiling" : { + "extractionState" : "manual" + }, "Conflict with system setting" : { "localizations" : { "ar" : { @@ -13741,6 +13744,15 @@ } } }, + "Disable in macOS" : { + "extractionState" : "manual" + }, + "Disable in Rectangle" : { + "extractionState" : "manual" + }, + "Dismiss" : { + "extractionState" : "manual" + }, "Display" : { "localizations" : { "ar" : { @@ -14093,6 +14105,9 @@ } } }, + "Drag to screen edge tiling is enabled in both Rectangle and macOS." : { + "extractionState" : "manual" + }, "dRJ-4n-Yzg.title" : { "comment" : "Class = \"NSMenuItem\"; title = \"Undo\"; ObjectID = \"dRJ-4n-Yzg\";", "extractionState" : "extracted_with_value", @@ -39755,6 +39770,9 @@ } } }, + "Tiling in macOS has been disabled" : { + "extractionState" : "manual" + }, "tlD-Oa-oAM.title" : { "comment" : "Class = \"NSMenu\"; title = \"Kern\"; ObjectID = \"tlD-Oa-oAM\";", "extractionState" : "manual", @@ -40065,6 +40083,9 @@ } } }, + "To re-enable it, go to System Settings → Desktop & Dock → Windows" : { + "extractionState" : "manual" + }, "Top sixths from corners; maximize" : { "localizations" : { "ar" : {