From 9f0bcae004fee5d802f56fd1ce90f0c23cfde5cb Mon Sep 17 00:00:00 2001 From: JoniVR Date: Sat, 1 Feb 2020 14:08:09 +0100 Subject: [PATCH] Update MediaKeyTap dependency, Implement ctrl modifier for internal display --- Cartfile | 2 +- Cartfile.resolved | 4 ++-- MonitorControl/AppDelegate.swift | 25 +++++++++++++------------ MonitorControl/Info.plist | 2 +- MonitorControlHelper/Info.plist | 2 +- 5 files changed, 18 insertions(+), 17 deletions(-) diff --git a/Cartfile b/Cartfile index b19a532..6d10a3f 100644 --- a/Cartfile +++ b/Cartfile @@ -1,4 +1,4 @@ -github "the0neyouseek/MediaKeyTap" +github "the0neyouseek/MediaKeyTap" "master" github "reitermarkus/DDC.swift" "master" github "rnine/AMCoreAudio" github "shpakovski/MASPreferences" diff --git a/Cartfile.resolved b/Cartfile.resolved index 464c2c5..5887f69 100644 --- a/Cartfile.resolved +++ b/Cartfile.resolved @@ -1,4 +1,4 @@ -github "reitermarkus/DDC.swift" "41e7c49b0450033c5349ca1cf5234a26ebc011b8" +github "reitermarkus/DDC.swift" "1763870c94c555ff93878caaec8235fd3a9a429d" github "rnine/AMCoreAudio" "3.3.1" github "shpakovski/MASPreferences" "1.3" -github "the0neyouseek/MediaKeyTap" "3.1.0" +github "the0neyouseek/MediaKeyTap" "4314a361486c2907956756748939c61f460241bd" diff --git a/MonitorControl/AppDelegate.swift b/MonitorControl/AppDelegate.swift index 4e1f108..06aac1f 100644 --- a/MonitorControl/AppDelegate.swift +++ b/MonitorControl/AppDelegate.swift @@ -198,6 +198,17 @@ class AppDelegate: NSObject, NSApplicationDelegate { extension AppDelegate: MediaKeyTapDelegate { func handle(mediaKey: MediaKey, event: KeyEvent?, modifiers: NSEvent.ModifierFlags?) { + let isSmallIncrement = modifiers?.isSuperset(of: NSEvent.ModifierFlags([.shift, .option])) ?? false + + // control internal display when holding ctrl modifier + let isControlModifier = modifiers?.isSuperset(of: NSEvent.ModifierFlags([.control])) ?? false + if isControlModifier, mediaKey == .brightnessUp || mediaKey == .brightnessDown { + if let internalDisplay = DisplayManager.shared.getBuiltInDisplay() as? InternalDisplay { + internalDisplay.stepBrightness(isUp: mediaKey == .brightnessUp, isSmallIncrement: isSmallIncrement) + return + } + } + let oppositeKey: MediaKey? = self.oppositeMediaKey(mediaKey: mediaKey) let isRepeat = event?.keyRepeat ?? false @@ -216,20 +227,10 @@ extension AppDelegate: MediaKeyTapDelegate { guard let currentDisplay = DisplayManager.shared.getCurrentDisplay() else { return } let allDisplays = prefs.bool(forKey: Utils.PrefKeys.allScreens.rawValue) ? displays : [currentDisplay] - let isSmallIncrement = modifiers?.isSuperset(of: NSEvent.ModifierFlags([.shift, .option])) ?? false // Introduce a small delay to handle the media key being held down let delay = isRepeat ? 0.05 : 0 - // PR open! https://github.com/the0neyouseek/MediaKeyTap/pull/5 -// if (modifiers?.isSuperset(of: NSEvent.ModifierFlags([.control]))) ?? false && -// if mediaKey == .brightnessUp || mediaKey == .brightnessDown { -// if let internalDisplay = DisplayManager.shared.getBuiltInDisplay() as? InternalDisplay { -// internalDisplay.stepBrightness(isUp: mediaKey == .brightnessUp, isSmallIncrement: isSmallIncrement) -// return -// } -// } - for display in allDisplays where display.isEnabled { switch mediaKey { case .brightnessUp, .brightnessDown: @@ -239,13 +240,13 @@ extension AppDelegate: MediaKeyTapDelegate { case .mute: // The mute key should not respond to press + hold if !isRepeat { - // volume/mute only matters for external displays + // mute only matters for external displays if let display = display as? ExternalDisplay { display.toggleMute() } } case .volumeUp, .volumeDown: - // volume/mute only matters for external displays + // volume only matters for external displays if let display = display as? ExternalDisplay { self.keyRepeatTimers[mediaKey] = Timer.scheduledTimer(withTimeInterval: delay, repeats: false, block: { _ in display.stepVolume(isUp: mediaKey == .volumeUp, isSmallIncrement: isSmallIncrement) diff --git a/MonitorControl/Info.plist b/MonitorControl/Info.plist index 5a6d624..6389d0e 100644 --- a/MonitorControl/Info.plist +++ b/MonitorControl/Info.plist @@ -19,7 +19,7 @@ CFBundleShortVersionString $(MARKETING_VERSION) CFBundleVersion - 632 + 636 LSApplicationCategoryType public.app-category.utilities LSMinimumSystemVersion diff --git a/MonitorControlHelper/Info.plist b/MonitorControlHelper/Info.plist index c45f069..b620712 100644 --- a/MonitorControlHelper/Info.plist +++ b/MonitorControlHelper/Info.plist @@ -19,7 +19,7 @@ CFBundleShortVersionString $(MARKETING_VERSION) CFBundleVersion - 632 + 636 LSApplicationCategoryType public.app-category.utilities LSBackgroundOnly