Skip to content

Commit

Permalink
fix: reduced blinking while activating workspace
Browse files Browse the repository at this point in the history
Resolves #69
  • Loading branch information
wojciech-kulik committed Feb 3, 2025
1 parent a7e429d commit 62a402a
Show file tree
Hide file tree
Showing 3 changed files with 31 additions and 8 deletions.
9 changes: 9 additions & 0 deletions FlashSpace/Extensions/NSRunningApplication.swift
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,15 @@ extension NSRunningApplication {
}
}

var isMinimized: Bool {
guard let mainWindow else { return false }

var minimized: CFTypeRef?
AXUIElementCopyAttributeValue(mainWindow, NSAccessibility.Attribute.minimized as CFString, &minimized)

return minimized as? Bool == true
}

func raise() {
guard let mainWindow else {
unhide()
Expand Down
2 changes: 1 addition & 1 deletion FlashSpace/Settings/MenuBarSettingsView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ struct MenuBarSettingsView: View {

var body: some View {
Form {
Section(header: Text("Menu Bar")) {
Section {
Toggle("Show Title", isOn: $settings.showMenuBarTitle)

HStack {
Expand Down
28 changes: 21 additions & 7 deletions FlashSpace/Workspaces/WorkspaceManager.swift
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,6 @@ final class WorkspaceManager: ObservableObject {

NotificationCenter.default
.publisher(for: NSApplication.didChangeScreenParametersNotification)
.print()
.sink { [weak self] _ in
self?.activeWorkspace = [:]
self?.mostRecentWorkspace = [:]
Expand Down Expand Up @@ -91,7 +90,7 @@ final class WorkspaceManager: ObservableObject {
let regularApps = NSWorkspace.shared.runningApplications
.filter { $0.activationPolicy == .regular }
let floatingApps = (settingsRepository.floatingApps ?? [])
let appsToShow = regularApps
var appsToShow = regularApps
.filter {
workspace.apps.contains($0.localizedName ?? "") ||
floatingApps.contains($0.localizedName ?? "") &&
Expand All @@ -101,16 +100,31 @@ final class WorkspaceManager: ObservableObject {
observeFocusCancellable = nil
defer { observeFocus() }

for app in appsToShow {
print("SHOW: \(app.localizedName ?? "")")
app.raise()
}

if setFocus {
let toFocus = findAppToFocus(in: workspace, apps: appsToShow)

// Make sure to raise the app that should be focused
// as the last one
if let toFocus {
appsToShow.removeAll { $0 == toFocus }
appsToShow.append(toFocus)
}

for app in appsToShow {
print("SHOW: \(app.localizedName ?? "")")
if app.isHidden || app.isMinimized {
app.raise()
}
}

print("FOCUS: \(toFocus?.localizedName ?? "")")
toFocus?.activate()
centerCursorIfNeeded(in: toFocus?.frame)
} else {
for app in appsToShow {
print("SHOW: \(app.localizedName ?? "")")
app.raise()
}
}
}

Expand Down

0 comments on commit 62a402a

Please sign in to comment.