From e52326b78195b9f94f775e3c748a38da7df3662e Mon Sep 17 00:00:00 2001 From: Louis Pontoise Date: Thu, 17 Oct 2019 02:14:04 +0900 Subject: [PATCH] feat: add window display delay as a preference --- alt-tab-macos/logic/Preferences.swift | 3 +++ alt-tab-macos/resources/preferences.json | 3 ++- alt-tab-macos/ui/Application.swift | 2 +- 3 files changed, 6 insertions(+), 2 deletions(-) diff --git a/alt-tab-macos/logic/Preferences.swift b/alt-tab-macos/logic/Preferences.swift index 77450a276..324e54dc6 100644 --- a/alt-tab-macos/logic/Preferences.swift +++ b/alt-tab-macos/logic/Preferences.swift @@ -17,6 +17,7 @@ struct PreferencesDecodable: Decodable { let metaModifierFlagInt: UInt? let highlightColorString : String? let thumbnailQuality : UInt? + let windowDisplayDelay: Int? } func fileLines(_ url: URL) throws -> Int { @@ -79,6 +80,8 @@ class Preferences: Decodable { static let thumbnailQuality = NSImageInterpolation.init(rawValue: decoded?.thumbnailQuality ?? 3) ?? .high // NSEvent.ModifierFlags (e.g. control=262144, command=1048576, shift=131072, option=524288) static let metaModifierFlag = NSEvent.ModifierFlags(rawValue: decoded?.metaModifierFlagInt ?? 262144) + // delay (in ms) before the window is displayed after the shortcut is pressed + static let windowDisplayDelay = DispatchTimeInterval.milliseconds(decoded?.windowDisplayDelay ?? 200) // color for the currently selected cell static let highlightColor = NSColor.white // derived properties diff --git a/alt-tab-macos/resources/preferences.json b/alt-tab-macos/resources/preferences.json index 1f3b19b5d..2998345ba 100644 --- a/alt-tab-macos/resources/preferences.json +++ b/alt-tab-macos/resources/preferences.json @@ -13,5 +13,6 @@ "metaKey": 59, "metaModifierFlagInt": 262144, "highlightColorString": "white", - "thumbnailQuality": 4 + "thumbnailQuality": 4, + "windowDisplayDelay": 200 } diff --git a/alt-tab-macos/ui/Application.swift b/alt-tab-macos/ui/Application.swift index 4bbf7ae4a..0aecd7b44 100644 --- a/alt-tab-macos/ui/Application.swift +++ b/alt-tab-macos/ui/Application.swift @@ -180,7 +180,7 @@ class Application: NSApplication, NSApplicationDelegate, NSWindowDelegate, NSCol Application.shared.unhideWithoutActivation() } workItems.append(workItem) - DispatchQueue.main.asyncAfter(deadline: .now() + 0.2, execute: workItem) + DispatchQueue.main.asyncAfter(deadline: DispatchTime.now() + Preferences.windowDisplayDelay, execute: workItem) } else { highlightThumbnail(step) }