fix: focus issues with show-main-window setting (closes #5684)

This commit is contained in:
lwouis committed 2026-05-28 13:56:51 +02:00
1 parent 3059dc2356
commit 0899f61654
8 files changed
+17 -42

No files matched your search

+5 -5
View File
@@ -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: "")
}
}
}
+4 -5
View File
@@ -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
@@ -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 {
@@ -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)
+2 -2
View File
@@ -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 {
+1 -1
View File
@@ -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)
+1 -2
View File
@@ -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<CGWindowID>? = 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]()
+1 -1
View File
@@ -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