diff --git a/src/logic/Preferences.swift b/src/logic/Preferences.swift index 0dc711c2..b995d303 100644 --- a/src/logic/Preferences.swift +++ b/src/logic/Preferences.swift @@ -7,9 +7,6 @@ class Preferences { // default values static var defaultValues: [String: String] = [ "maxScreenUsage": "80", - "minCellsPerRow": "5", - "maxCellsPerRow": "10", - "rowsCount": "3", "iconSize": "32", "fontHeight": "15", "holdShortcut": "⌥", @@ -41,7 +38,7 @@ class Preferences { "dontShowBlacklist": "", "disableShortcutsBlacklist": ["com.realvnc.vncviewer", "com.microsoft.rdc.macos", "com.teamviewer.TeamViewer", "org.virtualbox.app.VirtualBoxVM", "com.parallels.vm", "com.citrix.XenAppViewer"].joined(separator: "\n"), "disableShortcutsBlacklistOnlyFullscreen": "true", - ] + ].merging(defaultsDependingOnScreenRatio()) { (_, new) in new } // constant values // not exposed as preferences now but may be in the future, probably through macro preferences @@ -147,6 +144,21 @@ class Preferences { static func blacklistStringToArray(_ blacklist: String) -> [String] { return blacklist.components(separatedBy: "\n").map { $0.trimmingCharacters(in: .whitespaces) } } + + static func defaultsDependingOnScreenRatio() -> [String: String] { + let ratio = Screen.mainScreenRatio() + // landscape + if ratio > 1 { + // 15/10 and wider; tested with 16/10 and 16/9 + if ratio > (15 / 10) { + return ["rowsCount": "4", "minCellsPerRow": "4", "maxCellsPerRow": "7"] + } + // narrower than 15/10; tested with 4/3 + return ["rowsCount": "3", "minCellsPerRow": "4", "maxCellsPerRow": "7"] + } + // vertical; tested with 10/16 + return ["rowsCount": "6", "minCellsPerRow": "3", "maxCellsPerRow": "4"] + } } // MacroPreference are collection of values derived from a single key diff --git a/src/logic/Screen.swift b/src/logic/Screen.swift index 47c5645b..2d33301a 100644 --- a/src/logic/Screen.swift +++ b/src/logic/Screen.swift @@ -1,6 +1,11 @@ import Cocoa class Screen { + static func mainScreenRatio() -> CGFloat { + let mainScreen = NSScreen.main!.frame + return mainScreen.width / mainScreen.height + } + static func preferred() -> NSScreen { switch Preferences.showOnScreen { case .includingMouse: return withMouse() ?? NSScreen.main! // .main as fall-back diff --git a/src/ui/preferences-window/tabs/AppearanceTab.swift b/src/ui/preferences-window/tabs/AppearanceTab.swift index 0dba9b10..dae6feb5 100644 --- a/src/ui/preferences-window/tabs/AppearanceTab.swift +++ b/src/ui/preferences-window/tabs/AppearanceTab.swift @@ -11,9 +11,9 @@ class AppearanceTab: NSViewController, PreferencePane { LabelAndControl.makeLabelWithDropdown(NSLocalizedString("Theme:", comment: ""), "theme", ThemePreference.allCases), LabelAndControl.makeLabelWithDropdown(NSLocalizedString("Align windows:", comment: ""), "alignThumbnails", AlignThumbnailsPreference.allCases), LabelAndControl.makeLabelWithSlider(NSLocalizedString("Max size on screen:", comment: ""), "maxScreenUsage", 10, 100, 10, true, "%"), + LabelAndControl.makeLabelWithSlider(NSLocalizedString("Rows of windows:", comment: ""), "rowsCount", 1, 20, 20, true), LabelAndControl.makeLabelWithSlider(NSLocalizedString("Min windows per row:", comment: ""), "minCellsPerRow", 1, 20, 20, true), LabelAndControl.makeLabelWithSlider(NSLocalizedString("Max windows per row:", comment: ""), "maxCellsPerRow", 1, 40, 20, true), - LabelAndControl.makeLabelWithSlider(NSLocalizedString("Rows of windows:", comment: ""), "rowsCount", 1, 20, 20, true), LabelAndControl.makeLabelWithSlider(NSLocalizedString("Window app icon size:", comment: ""), "iconSize", 0, 64, 11, false, "px"), LabelAndControl.makeLabelWithSlider(NSLocalizedString("Window title font size:", comment: ""), "fontHeight", 0, 64, 11, false, "px"), LabelAndControl.makeLabelWithDropdown(NSLocalizedString("Window title truncation:", comment: ""), "titleTruncation", TitleTruncationPreference.allCases),