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.
This commit is contained in:
JoniVR 2020-02-01 14:34:40 +01:00
parent 9f0bcae004
commit bfeb5fc5f5
3 changed files with 20 additions and 22 deletions

View file

@ -231,12 +231,11 @@ extension AppDelegate: MediaKeyTapDelegate {
// Introduce a small delay to handle the media key being held down // Introduce a small delay to handle the media key being held down
let delay = isRepeat ? 0.05 : 0 let delay = isRepeat ? 0.05 : 0
self.keyRepeatTimers[mediaKey] = Timer.scheduledTimer(withTimeInterval: delay, repeats: false, block: { _ in
for display in allDisplays where display.isEnabled { for display in allDisplays where display.isEnabled {
switch mediaKey { switch mediaKey {
case .brightnessUp, .brightnessDown: case .brightnessUp, .brightnessDown:
self.keyRepeatTimers[mediaKey] = Timer.scheduledTimer(withTimeInterval: delay, repeats: false, block: { _ in
display.stepBrightness(isUp: mediaKey == .brightnessUp, isSmallIncrement: isSmallIncrement) display.stepBrightness(isUp: mediaKey == .brightnessUp, isSmallIncrement: isSmallIncrement)
})
case .mute: case .mute:
// The mute key should not respond to press + hold // The mute key should not respond to press + hold
if !isRepeat { if !isRepeat {
@ -248,14 +247,13 @@ extension AppDelegate: MediaKeyTapDelegate {
case .volumeUp, .volumeDown: case .volumeUp, .volumeDown:
// volume only matters for external displays // volume only matters for external displays
if let display = display as? ExternalDisplay { if let display = display as? ExternalDisplay {
self.keyRepeatTimers[mediaKey] = Timer.scheduledTimer(withTimeInterval: delay, repeats: false, block: { _ in
display.stepVolume(isUp: mediaKey == .volumeUp, isSmallIncrement: isSmallIncrement) display.stepVolume(isUp: mediaKey == .volumeUp, isSmallIncrement: isSmallIncrement)
})
} }
default: default:
return return
} }
} }
})
} }
// MARK: - Prefs notification // MARK: - Prefs notification

View file

@ -19,7 +19,7 @@
<key>CFBundleShortVersionString</key> <key>CFBundleShortVersionString</key>
<string>$(MARKETING_VERSION)</string> <string>$(MARKETING_VERSION)</string>
<key>CFBundleVersion</key> <key>CFBundleVersion</key>
<string>636</string> <string>637</string>
<key>LSApplicationCategoryType</key> <key>LSApplicationCategoryType</key>
<string>public.app-category.utilities</string> <string>public.app-category.utilities</string>
<key>LSMinimumSystemVersion</key> <key>LSMinimumSystemVersion</key>

View file

@ -19,7 +19,7 @@
<key>CFBundleShortVersionString</key> <key>CFBundleShortVersionString</key>
<string>$(MARKETING_VERSION)</string> <string>$(MARKETING_VERSION)</string>
<key>CFBundleVersion</key> <key>CFBundleVersion</key>
<string>636</string> <string>637</string>
<key>LSApplicationCategoryType</key> <key>LSApplicationCategoryType</key>
<string>public.app-category.utilities</string> <string>public.app-category.utilities</string>
<key>LSBackgroundOnly</key> <key>LSBackgroundOnly</key>