diff --git a/.swiftformat b/.swiftformat index e9c0c81..4afae51 100644 --- a/.swiftformat +++ b/.swiftformat @@ -1,5 +1,5 @@ --indent 2 ---ranges no-space +--nospaceoperators --self insert --exponentcase lowercase --exclude Carthage diff --git a/MonitorControl/AppDelegate.swift b/MonitorControl/AppDelegate.swift index 427c8de..2fd6afb 100644 --- a/MonitorControl/AppDelegate.swift +++ b/MonitorControl/AppDelegate.swift @@ -67,7 +67,7 @@ class AppDelegate: NSObject, NSApplicationDelegate { func clearDisplays() { if self.statusMenu.items.count > 2 { var items: [NSMenuItem] = [] - for i in 0.. Bool { + guard let modifiers = modifiers else { return false } + if !(modifiers.contains(.option) && !modifiers.contains(.shift)) { + return false + } + if event?.keyRepeat == true { + return false + } + switch mediaKey { + case .brightnessUp, .brightnessDown: + NSWorkspace.shared.open(URL(fileURLWithPath: "/System/Library/PreferencePanes/Displays.prefPane")) + case .mute, .volumeUp, .volumeDown: + NSWorkspace.shared.open(URL(fileURLWithPath: "/System/Library/PreferencePanes/Sound.prefPane")) + default: + return false + } + return true + } } // MARK: - Media Key Tap delegate extension AppDelegate: MediaKeyTapDelegate { func handle(mediaKey: MediaKey, event: KeyEvent?, modifiers: NSEvent.ModifierFlags?) { + if self.handleOpenPrefPane(mediaKey: mediaKey, event: event, modifiers: modifiers) { + return + } + let isSmallIncrement = modifiers?.isSuperset(of: NSEvent.ModifierFlags([.shift, .option])) ?? false // control internal display when holding ctrl modifier @@ -222,7 +245,10 @@ extension AppDelegate: MediaKeyTapDelegate { } mediaKeyTimer.invalidate() } + self.sendDisplayCommand(mediaKey: mediaKey, isRepeat: isRepeat, isSmallIncrement: isSmallIncrement) + } + private func sendDisplayCommand(mediaKey: MediaKey, isRepeat: Bool, isSmallIncrement: Bool) { let displays = DisplayManager.shared.getAllDisplays() guard let currentDisplay = DisplayManager.shared.getCurrentDisplay() else { return } diff --git a/MonitorControl/Info.plist b/MonitorControl/Info.plist index f672b6f..76e69a2 100644 --- a/MonitorControl/Info.plist +++ b/MonitorControl/Info.plist @@ -19,7 +19,7 @@ CFBundleShortVersionString $(MARKETING_VERSION) CFBundleVersion - 640 + 642 LSApplicationCategoryType public.app-category.utilities LSMinimumSystemVersion diff --git a/MonitorControl/Model/ExternalDisplay.swift b/MonitorControl/Model/ExternalDisplay.swift index 468540c..279b906 100644 --- a/MonitorControl/Model/ExternalDisplay.swift +++ b/MonitorControl/Model/ExternalDisplay.swift @@ -46,7 +46,7 @@ class ExternalDisplay: Display { return } - for _ in 0..<20 { + for _ in 0 ..< 20 { _ = self.ddc?.write(command: .osd, value: UInt16(1), errorRecoveryWaitTime: 2000) } } diff --git a/MonitorControlHelper/Info.plist b/MonitorControlHelper/Info.plist index 5c8fdb0..3cf059d 100644 --- a/MonitorControlHelper/Info.plist +++ b/MonitorControlHelper/Info.plist @@ -19,7 +19,7 @@ CFBundleShortVersionString $(MARKETING_VERSION) CFBundleVersion - 640 + 642 LSApplicationCategoryType public.app-category.utilities LSBackgroundOnly diff --git a/MonitorControlHelper/main.swift b/MonitorControlHelper/main.swift index 29613c4..9251541 100644 --- a/MonitorControlHelper/main.swift +++ b/MonitorControlHelper/main.swift @@ -11,7 +11,7 @@ class AppDelegate: NSObject, NSApplicationDelegate { } let pathComponents = bundlePath.pathComponents - let path = NSString.path(withComponents: Array(pathComponents[0..<(pathComponents.count - 4)])) + let path = NSString.path(withComponents: Array(pathComponents[0 ..< (pathComponents.count - 4)])) NSWorkspace.shared.launchApplication(path) NSApp.terminate(nil)