Skip to content

Commit

Permalink
Add check for last switch <1s
Browse files Browse the repository at this point in the history
#1089

closes #1099
  • Loading branch information
yspreen authored and nikitabobko committed Feb 16, 2025
1 parent cb60284 commit 7d5aea1
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 4 deletions.
7 changes: 6 additions & 1 deletion Sources/AppBundle/focus.swift
Original file line number Diff line number Diff line change
Expand Up @@ -104,7 +104,12 @@ extension Workspace {
private var _lastKnownFocus: FrozenFocus = _focus

// Used by workspace-back-and-forth
var _prevFocusedWorkspaceName: String? = nil
var _prevFocusedWorkspaceName: String? = nil {
didSet {
prevFocusedWorkspaceDate = .now
}
}
var prevFocusedWorkspaceDate: Date = .distantPast
var prevFocusedWorkspace: Workspace? { _prevFocusedWorkspaceName.map { Workspace.get(byName: $0) } }

// Used by focus-back-and-forth
Expand Down
6 changes: 3 additions & 3 deletions Sources/AppBundle/tree/MacWindow.swift
Original file line number Diff line number Diff line change
Expand Up @@ -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 might want to track the time of the latest workspace switch to make the approximation more accurate
let focus = focus
if let deadWindowWorkspace, deadWindowWorkspace == focus.workspace || deadWindowWorkspace == prevFocusedWorkspace {
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()
Expand Down

0 comments on commit 7d5aea1

Please sign in to comment.