mirror of
https://github.com/MonitorControl/MonitorControl.git
synced 2026-05-16 14:15:55 -06:00
Add open sound/brightness preferences from media keys (#168)
This commit is contained in:
parent
afa31400d8
commit
31c313d17b
6 changed files with 32 additions and 6 deletions
|
|
@ -1,5 +1,5 @@
|
|||
--indent 2
|
||||
--ranges no-space
|
||||
--nospaceoperators
|
||||
--self insert
|
||||
--exponentcase lowercase
|
||||
--exclude Carthage
|
||||
|
|
|
|||
|
|
@ -192,12 +192,35 @@ class AppDelegate: NSObject, NSApplicationDelegate {
|
|||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
func handleOpenPrefPane(mediaKey: MediaKey, event: KeyEvent?, modifiers: NSEvent.ModifierFlags?) -> 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 }
|
||||
|
||||
|
|
|
|||
|
|
@ -19,7 +19,7 @@
|
|||
<key>CFBundleShortVersionString</key>
|
||||
<string>$(MARKETING_VERSION)</string>
|
||||
<key>CFBundleVersion</key>
|
||||
<string>640</string>
|
||||
<string>642</string>
|
||||
<key>LSApplicationCategoryType</key>
|
||||
<string>public.app-category.utilities</string>
|
||||
<key>LSMinimumSystemVersion</key>
|
||||
|
|
|
|||
|
|
@ -19,7 +19,7 @@
|
|||
<key>CFBundleShortVersionString</key>
|
||||
<string>$(MARKETING_VERSION)</string>
|
||||
<key>CFBundleVersion</key>
|
||||
<string>640</string>
|
||||
<string>642</string>
|
||||
<key>LSApplicationCategoryType</key>
|
||||
<string>public.app-category.utilities</string>
|
||||
<key>LSBackgroundOnly</key>
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue