diff --git a/src/preferences/MacroPreferences.swift b/src/preferences/MacroPreferences.swift index d2ff209c..1c5fcf7a 100644 --- a/src/preferences/MacroPreferences.swift +++ b/src/preferences/MacroPreferences.swift @@ -217,14 +217,14 @@ enum TitleTruncationPreference: CaseIterable, MacroPreference { } } -enum ShowAppsOrWindowsPreference: CaseIterable, MacroPreference { - case applications - case windows +enum GroupAppsPreference: CaseIterable, MacroPreference { + case mainWindow + case allWindows var localizedString: LocalizedString { switch self { - case .applications: return NSLocalizedString("Show main window", comment: "") - case .windows: return NSLocalizedString("Show all windows", comment: "") + case .mainWindow: return NSLocalizedString("Show main window", comment: "") + case .allWindows: return NSLocalizedString("Show all windows", comment: "") } } } diff --git a/src/preferences/Preferences.swift b/src/preferences/Preferences.swift index 0df169b6..239bba31 100644 --- a/src/preferences/Preferences.swift +++ b/src/preferences/Preferences.swift @@ -62,7 +62,7 @@ class Preferences { values[indexToName("showWindowlessApps", index)] = ShowHowPreference.showAtTheEnd.indexAsString values[indexToName("windowOrder", index)] = WindowOrderPreference.recentlyFocused.indexAsString values[indexToName("shortcutStyle", index)] = ShortcutStylePreference.focusOnRelease.indexAsString - values[indexToName("showAppsOrWindows", index)] = ShowAppsOrWindowsPreference.windows.indexAsString + values[indexToName("showAppsOrWindows", index)] = GroupAppsPreference.allWindows.indexAsString values[indexToName("showTabsAsWindows", index)] = GroupTabsPreference.singleWindow.indexAsString // Override defaults are the FREE-tier value for Pro-gated prefs (so `snapshotAndDowngrade` // is a no-op for unset overrides), and the global default for non-gated prefs. @@ -150,8 +150,7 @@ class Preferences { static func showFullscreenWindows(_ i: Int) -> ShowHowPreference { CachedUserDefaults.macroPref(indexToName("showFullscreenWindows", i), ShowHowPreference.allCases) } static func showWindowlessApps(_ i: Int) -> ShowHowPreference { CachedUserDefaults.macroPref(indexToName("showWindowlessApps", i), ShowHowPreference.allCases) } static func windowOrder(_ i: Int) -> WindowOrderPreference { CachedUserDefaults.macroPref(indexToName("windowOrder", i), WindowOrderPreference.allCases) } - static var showAppsOrWindows: [ShowAppsOrWindowsPreference] { (0...maxShortcutCount).map { CachedUserDefaults.macroPref(indexToName("showAppsOrWindows", $0), ShowAppsOrWindowsPreference.allCases) } } - static func showAppsOrWindows(_ i: Int) -> ShowAppsOrWindowsPreference { CachedUserDefaults.macroPref(indexToName("showAppsOrWindows", i), ShowAppsOrWindowsPreference.allCases) } + static func groupApps(_ i: Int) -> GroupAppsPreference { CachedUserDefaults.macroPref(indexToName("showAppsOrWindows", i), GroupAppsPreference.allCases) } static func groupTabs(_ i: Int) -> GroupTabsPreference { CachedUserDefaults.macroPref(indexToName("showTabsAsWindows", i), GroupTabsPreference.allCases) } static var shortcutStyle: ShortcutStylePreference { ProGatedPreferences.shortcutStyle.read() } static var menubarIcon: MenubarIconPreference { CachedUserDefaults.macroPref("menubarIcon", MenubarIconPreference.allCases) } @@ -248,8 +247,8 @@ class Preferences { cachedAll = nil } - static func onlyShowApplications(_ index: Int = SwitcherSession.activeShortcutIndex) -> Bool { - return showAppsOrWindows(index) == .applications && effectiveAppearanceStyle(index) != .thumbnails + static func onlyShowMainWindows(_ index: Int = SwitcherSession.activeShortcutIndex) -> Bool { + return groupApps(index) == .mainWindow } // MARK: - Per-shortcut appearance overrides diff --git a/src/preferences/settings-window/tabs/appearance/AppearanceTab.swift b/src/preferences/settings-window/tabs/appearance/AppearanceTab.swift index 267086db..68374f99 100644 --- a/src/preferences/settings-window/tabs/appearance/AppearanceTab.swift +++ b/src/preferences/settings-window/tabs/appearance/AppearanceTab.swift @@ -390,7 +390,6 @@ class AppearanceTab: NSObject { static var animationsButton: NSButton! static var customizeStyleSheet: CustomizeStyleSheet! static var animationsSheet: AnimationsSheet! - static var previewSelectedWindowRowInfo: TableGroupView.RowInfo! // References used by `refreshProLockUi()` to update Pro-lock affordances while Settings stays open. private static weak var styleButtonsStack: NSStackView? @@ -433,7 +432,6 @@ class AppearanceTab: NSObject { animationsButton = nil customizeStyleSheet = nil animationsSheet = nil - previewSelectedWindowRowInfo = nil autoSegmentOverlayRef = nil shortcutStyleSegmentOverlayRef = nil overrideInfoIcons.removeAll() @@ -459,7 +457,6 @@ class AppearanceTab: NSObject { width: SettingsWindow.contentWidth) let styleButtons = LabelAndControl.makeImageRadioButtons("appearanceStyle", AppearanceStylePreference.allCases, extraAction: { _ in toggleCustomizeStyleButton() - updatePreviewSelectedWindowState() ControlsTab.syncOverrideControlsToGlobal() refreshAllOverrideInfoLabels() }, buttonSpacing: 10, proGatedIndices: proGatedAppearanceStyleIndices()) @@ -622,28 +619,8 @@ class AppearanceTab: NSObject { ControlsTab.syncOverrideControlsToGlobal() refreshAllOverrideInfoLabels() }) - previewSelectedWindowRowInfo = table.addRow(leftText: AppearanceTab.labelPreviewSelectedWindow, + _ = table.addRow(leftText: AppearanceTab.labelPreviewSelectedWindow, rightViews: [switchControl, makeOverrideIcon("previewFocusedWindowOverride")]) - updatePreviewSelectedWindowState() - } - - static func updatePreviewSelectedWindowState() { - guard let rowInfo = previewSelectedWindowRowInfo else { return } - let isEnabled = !isPreviewSelectedWindowDisabled() - rowInfo.leftViews?.forEach { view in - if let textField = view as? NSTextField { - textField.textColor = isEnabled ? .textColor : .gray - } - } - rowInfo.rightViews?.forEach { view in - if let switchControl = view as? Switch { - switchControl.isEnabled = isEnabled - } - } - } - - private static func isPreviewSelectedWindowDisabled() -> Bool { - return Preferences.onlyShowApplications() } private static func makeMultipleScreensView() -> NSView { diff --git a/src/preferences/settings-window/tabs/controls/ShortcutEditor.swift b/src/preferences/settings-window/tabs/controls/ShortcutEditor.swift index a21ad2ff..188fa432 100644 --- a/src/preferences/settings-window/tabs/controls/ShortcutEditor.swift +++ b/src/preferences/settings-window/tabs/controls/ShortcutEditor.swift @@ -366,7 +366,7 @@ final class OrderingPane { /// See `FilteringPane.searchableStrings`. static let searchableStrings: [String] = [ labelGroupApps, labelGroupTabs, labelWindowOrder, - ] + ShowAppsOrWindowsPreference.allCases.map { $0.localizedString } + ] + GroupAppsPreference.allCases.map { $0.localizedString } + GroupTabsPreference.allCases.map { $0.localizedString } + WindowOrderPreference.allCases.map { $0.localizedString } @@ -376,7 +376,7 @@ final class OrderingPane { private let windowOrder: ShortcutBoundDropdown init(width: CGFloat) { - showAppsOrWindows = ShortcutBoundDropdown(baseName: "showAppsOrWindows", cases: ShowAppsOrWindowsPreference.allCases) + showAppsOrWindows = ShortcutBoundDropdown(baseName: "showAppsOrWindows", cases: GroupAppsPreference.allCases) showTabsAsWindows = ShortcutBoundDropdown(baseName: "showTabsAsWindows", cases: GroupTabsPreference.allCases) windowOrder = ShortcutBoundDropdown(baseName: "windowOrder", cases: WindowOrderPreference.allCases) diff --git a/src/switcher/main-window/TileView.swift b/src/switcher/main-window/TileView.swift index d4aadef1..72bcd41d 100644 --- a/src/switcher/main-window/TileView.swift +++ b/src/switcher/main-window/TileView.swift @@ -366,7 +366,7 @@ class TileView: FlippedView { private func searchSpanRanges() -> [NSRange] { var spanRanges = [NSRange]() - if Preferences.onlyShowApplications() || Preferences.showTitles == .appName { + if Preferences.showTitles == .appName { for result in window_?.swAppResults ?? [] { spanRanges.append(NSRange(location: result.span.lowerBound, length: result.span.count)) } @@ -570,7 +570,7 @@ class TileView: FlippedView { private func getAppOrAndWindowTitle() -> String { let appName = window_?.application.localizedName let windowTitle = window_?.title - if Preferences.onlyShowApplications() || Preferences.showTitles == .appName { + if Preferences.showTitles == .appName { return appName ?? "" } else if Preferences.showTitles == .appNameAndWindowTitle { if appName == windowTitle { diff --git a/src/switcher/state/Window.swift b/src/switcher/state/Window.swift index e6f4b276..bb3dac58 100644 --- a/src/switcher/state/Window.swift +++ b/src/switcher/state/Window.swift @@ -236,7 +236,7 @@ class Window { App.shared.activate(ignoringOtherApps: true) altTabWindow.makeKeyAndOrderFront(nil) WindowThumbnails.previewSelectedIfNeeded() - } else if isWindowlessApp || cgWindowId == nil || Preferences.onlyShowApplications() { + } else if isWindowlessApp || cgWindowId == nil { if let bundleUrl = application.bundleURL, isWindowlessApp { if (try? NSWorkspace.shared.launchApplication(at: bundleUrl, configuration: [:])) == nil { application.runningApplication.activate(options: .activateAllWindows) diff --git a/src/switcher/state/WindowThumbnails.swift b/src/switcher/state/WindowThumbnails.swift index cf6bfc34..b2c67826 100644 --- a/src/switcher/state/WindowThumbnails.swift +++ b/src/switcher/state/WindowThumbnails.swift @@ -5,7 +5,7 @@ import Cocoa enum WindowThumbnails { static func previewSelectedIfNeeded() { if let session = SwitcherSession.current, ScreenRecordingPermission.status == .granted - && Preferences.effectivePreviewSelectedWindow(session.shortcutIndex) && !Preferences.onlyShowApplications(session.shortcutIndex) + && Preferences.effectivePreviewSelectedWindow(session.shortcutIndex) && TilesPanel.shared.isKeyWindow, let window = Windows.selectedWindow(), let id = window.cgWindowId, @@ -22,7 +22,6 @@ enum WindowThumbnails { static func refreshAsync(_ windows: [Window], _ source: RefreshCausedBy, windowRemoved: Bool = false, prioritizedIds: Set? = nil) { let shortcutIndex = SwitcherSession.activeShortcutIndex guard (!windows.isEmpty || windowRemoved) && ScreenRecordingPermission.status == .granted - && !Preferences.onlyShowApplications(shortcutIndex) && (!Appearance.hideThumbnails || Preferences.effectivePreviewSelectedWindow(shortcutIndex)) && (Preferences.captureWindowsInBackground || SwitcherSession.isActive) else { return } var eligibleWindows = [Window]() diff --git a/src/switcher/state/Windows.swift b/src/switcher/state/Windows.swift index 9d9c8d3e..097622e0 100644 --- a/src/switcher/state/Windows.swift +++ b/src/switcher/state/Windows.swift @@ -95,7 +95,7 @@ class Windows { } static func refreshWhichWindowsToShowTheUser() { - if Preferences.onlyShowApplications() { + if Preferences.onlyShowMainWindows() { // Group windows by application and select the optimal main window let windowsGroupedByApp = Dictionary(grouping: list) { $0.application.pid } windowsGroupedByApp.forEach { (app, windows) in