Skip to content

Commit

Permalink
fix: should not alter focus when displayed (closes #16)
Browse files Browse the repository at this point in the history
  • Loading branch information
Louis Pontoise committed Sep 2, 2019
1 parent 0aa330b commit 376a21b
Showing 1 changed file with 8 additions and 9 deletions.
17 changes: 8 additions & 9 deletions alt-tab-macos/ui/Application.swift
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ class Application: NSApplication, NSApplicationDelegate, NSWindowDelegate, NSCol
var item: NSStatusItem?
var backgroundView: NSVisualEffectView?
var collectionView_: NSCollectionView?
var window: NSWindow?
var window: NSPanel?
var selectedOpenWindow: Int = 0
var numberOfColumns: Int = 0
var openWindows: [OpenWindow] = []
Expand Down Expand Up @@ -59,6 +59,9 @@ class Application: NSApplication, NSApplicationDelegate, NSWindowDelegate, NSCol
window!.contentView = backgroundView
listenToGlobalKeyboardEvents(self)
listenToScreenChanges()
Application.shared.activate(ignoringOtherApps: true)
Application.shared.runModal(for: window!)
Application.shared.hide(nil)
}

func listenToScreenChanges() {
Expand Down Expand Up @@ -93,12 +96,12 @@ class Application: NSApplication, NSApplicationDelegate, NSWindowDelegate, NSCol
}

func makeWindow() {
window = NSWindow()
window = NSPanel()
window!.styleMask = [.borderless]
window!.level = .floating
window!.animationBehavior = NSWindow.AnimationBehavior.none
window!.backgroundColor = .clear
window!.hidesOnDeactivate = true
window!.setIsVisible(true)
window!.delegate = self
}

Expand Down Expand Up @@ -186,7 +189,7 @@ class Application: NSApplication, NSApplicationDelegate, NSWindowDelegate, NSCol
self.computeOpenWindows()
self.computeThumbnails()
self.highlightThumbnail(step)
self.showWindow()
Application.shared.unhideWithoutActivation()
}
workItems.append(workItem)
DispatchQueue.main.asyncAfter(deadline: .now() + 0.2, execute: workItem)
Expand All @@ -200,15 +203,11 @@ class Application: NSApplication, NSApplicationDelegate, NSWindowDelegate, NSCol
return openWindows.count > selectedOpenWindow ? openWindows[selectedOpenWindow] : nil
}

func showWindow() {
window!.makeKeyAndOrderFront(nil)
NSRunningApplication.current.activate(options: [.activateIgnoringOtherApps])
}

func focusSelectedWindow(_ window: OpenWindow?) {
workItems.forEach({ $0.cancel() })
workItems.removeAll()
window?.focus()
Application.shared.hide(nil)
appIsBeingUsed = false
isFirstSummon = true
}
Expand Down

0 comments on commit 376a21b

Please sign in to comment.