Skip to content

Commit

Permalink
feat: default layout based on screen aspect ratio (closes #436)
Browse files Browse the repository at this point in the history
  • Loading branch information
lwouis committed Jul 20, 2020
1 parent dc0371a commit 11fb95d
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 5 deletions.
20 changes: 16 additions & 4 deletions src/logic/Preferences.swift
Original file line number Diff line number Diff line change
Expand Up @@ -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": "",
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down
5 changes: 5 additions & 0 deletions src/logic/Screen.swift
Original file line number Diff line number Diff line change
@@ -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
Expand Down
2 changes: 1 addition & 1 deletion src/ui/preferences-window/tabs/AppearanceTab.swift
Original file line number Diff line number Diff line change
Expand Up @@ -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),
Expand Down

0 comments on commit 11fb95d

Please sign in to comment.