Skip to content

Commit

Permalink
feat: switcher will show faster (closes #3845)
Browse files Browse the repository at this point in the history
  • Loading branch information
lwouis committed Dec 5, 2024
1 parent a083b06 commit b694c83
Show file tree
Hide file tree
Showing 3 changed files with 4 additions and 13 deletions.
11 changes: 1 addition & 10 deletions src/logic/Windows.swift
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,6 @@ class Windows {
static var list = [Window]()
static var focusedWindowIndex = Int(0)
static var hoveredWindowIndex: Int?
// the first few thumbnails are the most commonly looked at; we pay special attention to them
static let criticalFirstThumbnails = 3
static var lastWindowActivityType = WindowActivityType.none

/// reordered list based on preferences, keeping the original index
Expand Down Expand Up @@ -265,14 +263,7 @@ class Windows {
Windows.list = sortedTuples.map { $0.1 }
}

static func refreshFirstFewThumbnailsSync() {
if Appearance.hideThumbnails { return }
list.filter { $0.shouldShowTheUser }
.prefix(criticalFirstThumbnails)
.forEachAsync { window in window.refreshThumbnail() }
}

static func refreshThumbnailsAsync(_ screen: NSScreen, _ currentIndex: Int = criticalFirstThumbnails) {
static func refreshThumbnailsAsync(_ screen: NSScreen, _ currentIndex: Int) {
DispatchQueue.main.async {
if !App.app.appIsBeingUsed || Appearance.hideThumbnails { return }
BackgroundWork.mainQueueConcurrentWorkQueue.async {
Expand Down
2 changes: 2 additions & 0 deletions src/logic/events/KeyboardEvents.swift
Original file line number Diff line number Diff line change
Expand Up @@ -121,6 +121,8 @@ class KeyboardEvents {

fileprivate let cgEventFlagsChangedHandler: CGEventTapCallBack = {_, type, cgEvent, _ in
if type == .flagsChanged {
// TODO: it would be great to shortcut matching and trigger on the background thread
// it would enable us to set App.app.isBeingUsed here, and could stop tasks on main when they check the flag
DispatchQueue.main.async {
let modifiers = NSEvent.ModifierFlags(rawValue: UInt(cgEvent.flags.rawValue))
// TODO: ideally, we want to absorb all modifier keys except holdShortcut
Expand Down
4 changes: 1 addition & 3 deletions src/ui/App.swift
Original file line number Diff line number Diff line change
Expand Up @@ -310,16 +310,14 @@ class App: AppCenterApplication, NSApplicationDelegate {
guard appIsBeingUsed else { return }
Appearance.update()
guard appIsBeingUsed else { return }
Windows.refreshFirstFewThumbnailsSync()
guard appIsBeingUsed else { return }
thumbnailsPanel.makeKeyAndOrderFront(nil) // workaround: without this, switching between 2 screens make thumbnailPanel invisible
guard appIsBeingUsed else { return }
refreshOpenUi()
guard appIsBeingUsed else { return }
thumbnailsPanel.show()
Windows.previewFocusedWindowIfNeeded()
guard appIsBeingUsed else { return }
Windows.refreshThumbnailsAsync(screen)
Windows.refreshThumbnailsAsync(screen, 0)
guard appIsBeingUsed else { return }
Applications.refreshBadges()
KeyRepeatTimer.toggleRepeatingKeyNextWindow()
Expand Down

0 comments on commit b694c83

Please sign in to comment.