feat: switcher will show faster (closes #3845)

This commit is contained in:
lwouis committed 2024-12-05 10:45:31 +01:00
1 parent a083b06de0
commit b694c837b4
3 files changed
+4 -13

No files matched your search

+1 -10
View File
@@ -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
@@ -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 {
+2
View File
@@ -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
+1 -3
View File
@@ -310,8 +310,6 @@ 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()
@@ -319,7 +317,7 @@ class App: AppCenterApplication, NSApplicationDelegate {
thumbnailsPanel.show()
Windows.previewFocusedWindowIfNeeded()
guard appIsBeingUsed else { return }
Windows.refreshThumbnailsAsync(screen)
Windows.refreshThumbnailsAsync(screen, 0)
guard appIsBeingUsed else { return }
Applications.refreshBadges()
KeyRepeatTimer.toggleRepeatingKeyNextWindow()