From bfeb5fc5f5b633e67b84c7836bb02a78ea6ee83e Mon Sep 17 00:00:00 2001 From: JoniVR Date: Sat, 1 Feb 2020 14:34:40 +0100 Subject: [PATCH] Fix `keyRepeatTimer` issue with multiple displays while holding down a MediaKey When holding down a mediakey, we'd get stuck inside the specific keyRepeatTimer block in the display loop. This caused only one display (the first one in the array) to be controlled while holding down a mediakey. --- MonitorControl/AppDelegate.swift | 38 +++++++++++++++----------------- MonitorControl/Info.plist | 2 +- MonitorControlHelper/Info.plist | 2 +- 3 files changed, 20 insertions(+), 22 deletions(-) diff --git a/MonitorControl/AppDelegate.swift b/MonitorControl/AppDelegate.swift index 06aac1f..a981e3c 100644 --- a/MonitorControl/AppDelegate.swift +++ b/MonitorControl/AppDelegate.swift @@ -231,31 +231,29 @@ extension AppDelegate: MediaKeyTapDelegate { // Introduce a small delay to handle the media key being held down let delay = isRepeat ? 0.05 : 0 - for display in allDisplays where display.isEnabled { - switch mediaKey { - case .brightnessUp, .brightnessDown: - self.keyRepeatTimers[mediaKey] = Timer.scheduledTimer(withTimeInterval: delay, repeats: false, block: { _ in + self.keyRepeatTimers[mediaKey] = Timer.scheduledTimer(withTimeInterval: delay, repeats: false, block: { _ in + for display in allDisplays where display.isEnabled { + switch mediaKey { + case .brightnessUp, .brightnessDown: display.stepBrightness(isUp: mediaKey == .brightnessUp, isSmallIncrement: isSmallIncrement) - }) - case .mute: - // The mute key should not respond to press + hold - if !isRepeat { - // mute only matters for external displays - if let display = display as? ExternalDisplay { - display.toggleMute() + case .mute: + // The mute key should not respond to press + hold + if !isRepeat { + // mute only matters for external displays + if let display = display as? ExternalDisplay { + display.toggleMute() + } } - } - case .volumeUp, .volumeDown: - // volume only matters for external displays - if let display = display as? ExternalDisplay { - self.keyRepeatTimers[mediaKey] = Timer.scheduledTimer(withTimeInterval: delay, repeats: false, block: { _ in + case .volumeUp, .volumeDown: + // volume only matters for external displays + if let display = display as? ExternalDisplay { display.stepVolume(isUp: mediaKey == .volumeUp, isSmallIncrement: isSmallIncrement) - }) + } + default: + return } - default: - return } - } + }) } // MARK: - Prefs notification diff --git a/MonitorControl/Info.plist b/MonitorControl/Info.plist index 6389d0e..7051d63 100644 --- a/MonitorControl/Info.plist +++ b/MonitorControl/Info.plist @@ -19,7 +19,7 @@ CFBundleShortVersionString $(MARKETING_VERSION) CFBundleVersion - 636 + 637 LSApplicationCategoryType public.app-category.utilities LSMinimumSystemVersion diff --git a/MonitorControlHelper/Info.plist b/MonitorControlHelper/Info.plist index b620712..bbf725a 100644 --- a/MonitorControlHelper/Info.plist +++ b/MonitorControlHelper/Info.plist @@ -19,7 +19,7 @@ CFBundleShortVersionString $(MARKETING_VERSION) CFBundleVersion - 636 + 637 LSApplicationCategoryType public.app-category.utilities LSBackgroundOnly