Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add check for last switch <1s #1099

Closed
wants to merge 1 commit into from
Closed

Conversation

yspreen
Copy link
Contributor

@yspreen yspreen commented Feb 16, 2025

fixes #1089

@nikitabobko
Copy link
Owner

Merged with the following stylistic patch:

diff --git a/Sources/AppBundle/focus.swift b/Sources/AppBundle/focus.swift
index 8d87e259..a5216a06 100644
--- a/Sources/AppBundle/focus.swift
+++ b/Sources/AppBundle/focus.swift
@@ -106,7 +106,7 @@ private var _lastKnownFocus: FrozenFocus = _focus
 // Used by workspace-back-and-forth
 var _prevFocusedWorkspaceName: String? = nil {
     didSet {
-        prevFocusedWorkspaceDate = Date()
+        prevFocusedWorkspaceDate = .now
     }
 }
 var prevFocusedWorkspaceDate: Date = .distantPast
diff --git a/Sources/AppBundle/tree/MacWindow.swift b/Sources/AppBundle/tree/MacWindow.swift
index fcf10cbc..c3e626cf 100644
--- a/Sources/AppBundle/tree/MacWindow.swift
+++ b/Sources/AppBundle/tree/MacWindow.swift
@@ -73,10 +73,10 @@ final class MacWindow: Window, CustomStringConvertible {
             AXObserverRemoveNotification(obs.obs, obs.ax, obs.notif)
         }
         axObservers = []
-        // todo the if is an approximation to filter out cases when window just closed itself (or was killed remotely)
-        // we check if the workspace switch was <1s ago
         let focus = focus
-        if let deadWindowWorkspace, deadWindowWorkspace == focus.workspace || (deadWindowWorkspace == prevFocusedWorkspace && -prevFocusedWorkspaceDate.timeIntervalSinceNow < 1) {
+        if let deadWindowWorkspace, deadWindowWorkspace == focus.workspace ||
+            deadWindowWorkspace == prevFocusedWorkspace && prevFocusedWorkspaceDate.distance(to: .now) < 1
+        {
             switch parent.cases {
                 case .tilingContainer, .workspace, .macosHiddenAppsWindowsContainer, .macosFullscreenWindowsContainer:
                     let deadWindowFocus = deadWindowWorkspace.toLiveFocus()

@nikitabobko nikitabobko added the pr-accepted Pull Request is accepted label Feb 16, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
pr-accepted Pull Request is accepted
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Closing an app from the background (e.g. Raycast auto close) messes with window order
2 participants