🎉 Smaller increment

- You can now change brightness and volume in smaller increments just like native holding `alt + shift`
This commit is contained in:
Guillaume Broder 2019-06-05 00:01:23 +02:00
parent 9657e4bd6d
commit bfc91fd5ec
No known key found for this signature in database
GPG key ID: 66FB02D063D9E08F
8 changed files with 38 additions and 30 deletions

View file

@ -1,4 +1,4 @@
github "the0neyouseek/MediaKeyTap" "master" github "the0neyouseek/MediaKeyTap"
github "reitermarkus/DDC.swift" "master" github "reitermarkus/DDC.swift" "master"
github "rnine/AMCoreAudio" github "rnine/AMCoreAudio"
github "shpakovski/MASPreferences" github "shpakovski/MASPreferences"

View file

@ -1,4 +1,4 @@
github "reitermarkus/DDC.swift" "5c03666e17a1a850892c08a5db6f4a208f762f26" github "reitermarkus/DDC.swift" "5c03666e17a1a850892c08a5db6f4a208f762f26"
github "rnine/AMCoreAudio" "3.3" github "rnine/AMCoreAudio" "3.3"
github "shpakovski/MASPreferences" "1.3" github "shpakovski/MASPreferences" "1.3"
github "the0neyouseek/MediaKeyTap" "abfe09f53ccabb1aa14a0f4ab99cfb8812f41919" github "the0neyouseek/MediaKeyTap" "3.1.0"

View file

@ -312,7 +312,7 @@
isa = PBXProject; isa = PBXProject;
attributes = { attributes = {
LastSwiftUpdateCheck = 0920; LastSwiftUpdateCheck = 0920;
LastUpgradeCheck = 1020; LastUpgradeCheck = 1100;
ORGANIZATIONNAME = "Guillaume Broder"; ORGANIZATIONNAME = "Guillaume Broder";
TargetAttributes = { TargetAttributes = {
56754EAA1D9A4016007BCDC5 = { 56754EAA1D9A4016007BCDC5 = {
@ -634,7 +634,9 @@
CODE_SIGN_IDENTITY = "Mac Developer"; CODE_SIGN_IDENTITY = "Mac Developer";
CODE_SIGN_STYLE = Automatic; CODE_SIGN_STYLE = Automatic;
COMBINE_HIDPI_IMAGES = YES; COMBINE_HIDPI_IMAGES = YES;
CURRENT_PROJECT_VERSION = 560;
DEVELOPMENT_TEAM = KGY56RWR9A; DEVELOPMENT_TEAM = KGY56RWR9A;
ENABLE_HARDENED_RUNTIME = YES;
FRAMEWORK_SEARCH_PATHS = ( FRAMEWORK_SEARCH_PATHS = (
"$(inherited)", "$(inherited)",
"$(PROJECT_DIR)/Carthage/Build/Mac", "$(PROJECT_DIR)/Carthage/Build/Mac",
@ -643,6 +645,7 @@
); );
INFOPLIST_FILE = MonitorControl/Info.plist; INFOPLIST_FILE = MonitorControl/Info.plist;
LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/../Frameworks"; LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/../Frameworks";
MARKETING_VERSION = 1.6.0;
PRODUCT_BUNDLE_IDENTIFIER = me.guillaumeb.MonitorControl; PRODUCT_BUNDLE_IDENTIFIER = me.guillaumeb.MonitorControl;
PRODUCT_NAME = "$(TARGET_NAME)"; PRODUCT_NAME = "$(TARGET_NAME)";
PROVISIONING_PROFILE_SPECIFIER = ""; PROVISIONING_PROFILE_SPECIFIER = "";
@ -658,7 +661,9 @@
CODE_SIGN_IDENTITY = "Mac Developer"; CODE_SIGN_IDENTITY = "Mac Developer";
CODE_SIGN_STYLE = Automatic; CODE_SIGN_STYLE = Automatic;
COMBINE_HIDPI_IMAGES = YES; COMBINE_HIDPI_IMAGES = YES;
CURRENT_PROJECT_VERSION = 560;
DEVELOPMENT_TEAM = KGY56RWR9A; DEVELOPMENT_TEAM = KGY56RWR9A;
ENABLE_HARDENED_RUNTIME = YES;
FRAMEWORK_SEARCH_PATHS = ( FRAMEWORK_SEARCH_PATHS = (
"$(inherited)", "$(inherited)",
"$(PROJECT_DIR)/Carthage/Build/Mac", "$(PROJECT_DIR)/Carthage/Build/Mac",
@ -667,6 +672,7 @@
); );
INFOPLIST_FILE = MonitorControl/Info.plist; INFOPLIST_FILE = MonitorControl/Info.plist;
LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/../Frameworks"; LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/../Frameworks";
MARKETING_VERSION = 1.6.0;
PRODUCT_BUNDLE_IDENTIFIER = me.guillaumeb.MonitorControl; PRODUCT_BUNDLE_IDENTIFIER = me.guillaumeb.MonitorControl;
PRODUCT_NAME = "$(TARGET_NAME)"; PRODUCT_NAME = "$(TARGET_NAME)";
PROVISIONING_PROFILE_SPECIFIER = ""; PROVISIONING_PROFILE_SPECIFIER = "";
@ -686,10 +692,13 @@
CODE_SIGN_IDENTITY = "Mac Developer"; CODE_SIGN_IDENTITY = "Mac Developer";
CODE_SIGN_STYLE = Automatic; CODE_SIGN_STYLE = Automatic;
COMBINE_HIDPI_IMAGES = YES; COMBINE_HIDPI_IMAGES = YES;
CURRENT_PROJECT_VERSION = 560;
DEVELOPMENT_TEAM = KGY56RWR9A; DEVELOPMENT_TEAM = KGY56RWR9A;
ENABLE_HARDENED_RUNTIME = YES;
GCC_C_LANGUAGE_STANDARD = gnu11; GCC_C_LANGUAGE_STANDARD = gnu11;
INFOPLIST_FILE = MonitorControlHelper/Info.plist; INFOPLIST_FILE = MonitorControlHelper/Info.plist;
LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/../Frameworks"; LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/../Frameworks";
MARKETING_VERSION = 1.6.0;
PRODUCT_BUNDLE_IDENTIFIER = me.guillaumeb.MonitorControlHelper; PRODUCT_BUNDLE_IDENTIFIER = me.guillaumeb.MonitorControlHelper;
PRODUCT_NAME = "$(TARGET_NAME)"; PRODUCT_NAME = "$(TARGET_NAME)";
SKIP_INSTALL = YES; SKIP_INSTALL = YES;
@ -708,10 +717,13 @@
CODE_SIGN_IDENTITY = "Mac Developer"; CODE_SIGN_IDENTITY = "Mac Developer";
CODE_SIGN_STYLE = Automatic; CODE_SIGN_STYLE = Automatic;
COMBINE_HIDPI_IMAGES = YES; COMBINE_HIDPI_IMAGES = YES;
CURRENT_PROJECT_VERSION = 560;
DEVELOPMENT_TEAM = KGY56RWR9A; DEVELOPMENT_TEAM = KGY56RWR9A;
ENABLE_HARDENED_RUNTIME = YES;
GCC_C_LANGUAGE_STANDARD = gnu11; GCC_C_LANGUAGE_STANDARD = gnu11;
INFOPLIST_FILE = MonitorControlHelper/Info.plist; INFOPLIST_FILE = MonitorControlHelper/Info.plist;
LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/../Frameworks"; LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/../Frameworks";
MARKETING_VERSION = 1.6.0;
PRODUCT_BUNDLE_IDENTIFIER = me.guillaumeb.MonitorControlHelper; PRODUCT_BUNDLE_IDENTIFIER = me.guillaumeb.MonitorControlHelper;
PRODUCT_NAME = "$(TARGET_NAME)"; PRODUCT_NAME = "$(TARGET_NAME)";
SKIP_INSTALL = YES; SKIP_INSTALL = YES;

View file

@ -1,6 +1,6 @@
<?xml version="1.0" encoding="UTF-8"?> <?xml version="1.0" encoding="UTF-8"?>
<Scheme <Scheme
LastUpgradeVersion = "1020" LastUpgradeVersion = "1100"
version = "1.3"> version = "1.3">
<BuildAction <BuildAction
parallelizeBuildables = "YES" parallelizeBuildables = "YES"
@ -27,8 +27,6 @@
selectedDebuggerIdentifier = "Xcode.DebuggerFoundation.Debugger.LLDB" selectedDebuggerIdentifier = "Xcode.DebuggerFoundation.Debugger.LLDB"
selectedLauncherIdentifier = "Xcode.DebuggerFoundation.Launcher.LLDB" selectedLauncherIdentifier = "Xcode.DebuggerFoundation.Launcher.LLDB"
shouldUseLaunchSchemeArgsEnv = "YES"> shouldUseLaunchSchemeArgsEnv = "YES">
<Testables>
</Testables>
<MacroExpansion> <MacroExpansion>
<BuildableReference <BuildableReference
BuildableIdentifier = "primary" BuildableIdentifier = "primary"
@ -38,8 +36,8 @@
ReferencedContainer = "container:MonitorControl.xcodeproj"> ReferencedContainer = "container:MonitorControl.xcodeproj">
</BuildableReference> </BuildableReference>
</MacroExpansion> </MacroExpansion>
<AdditionalOptions> <Testables>
</AdditionalOptions> </Testables>
</TestAction> </TestAction>
<LaunchAction <LaunchAction
buildConfiguration = "Debug" buildConfiguration = "Debug"
@ -61,8 +59,6 @@
ReferencedContainer = "container:MonitorControl.xcodeproj"> ReferencedContainer = "container:MonitorControl.xcodeproj">
</BuildableReference> </BuildableReference>
</BuildableProductRunnable> </BuildableProductRunnable>
<AdditionalOptions>
</AdditionalOptions>
</LaunchAction> </LaunchAction>
<ProfileAction <ProfileAction
buildConfiguration = "Release" buildConfiguration = "Release"

View file

@ -197,29 +197,29 @@ class AppDelegate: NSObject, NSApplicationDelegate {
// MARK: - Media Key Tap delegate // MARK: - Media Key Tap delegate
extension AppDelegate: MediaKeyTapDelegate { extension AppDelegate: MediaKeyTapDelegate {
func handle(mediaKey: MediaKey, event _: KeyEvent?) { func handle(mediaKey: MediaKey, event _: KeyEvent?, modifiers: NSEvent.ModifierFlags?) {
guard let currentDisplay = Utils.getCurrentDisplay(from: displays) else { return } guard let currentDisplay = Utils.getCurrentDisplay(from: displays) else { return }
let allDisplays = prefs.bool(forKey: Utils.PrefKeys.allScreens.rawValue) ? self.displays : [currentDisplay] let allDisplays = prefs.bool(forKey: Utils.PrefKeys.allScreens.rawValue) ? self.displays : [currentDisplay]
let isSmallIncrement = modifiers?.isSuperset(of: NSEvent.ModifierFlags([.shift, .option])) ?? false
for display in allDisplays { for display in allDisplays {
if (prefs.object(forKey: "\(display.identifier)-state") as? Bool) ?? true { if (prefs.object(forKey: "\(display.identifier)-state") as? Bool) ?? true {
switch mediaKey { switch mediaKey {
case .brightnessUp: case .brightnessUp:
let value = display.calcNewValue(for: .brightness, withRel: +self.step) let value = display.calcNewValue(for: .brightness, withRel: +(isSmallIncrement ? self.step / 4 : self.step))
display.setBrightness(to: value) display.setBrightness(to: value, isSmallIncrement: isSmallIncrement)
case .brightnessDown: case .brightnessDown:
let value = currentDisplay.calcNewValue(for: .brightness, withRel: -self.step) let value = currentDisplay.calcNewValue(for: .brightness, withRel: -(isSmallIncrement ? self.step / 4 : self.step))
display.setBrightness(to: value) display.setBrightness(to: value, isSmallIncrement: isSmallIncrement)
case .mute: case .mute:
display.mute() display.mute()
case .volumeUp: case .volumeUp:
let value = display.calcNewValue(for: .audioSpeakerVolume, withRel: +self.step) let value = display.calcNewValue(for: .audioSpeakerVolume, withRel: +(isSmallIncrement ? self.step / 4 : self.step))
display.setVolume(to: value) display.setVolume(to: value, isSmallIncrement: isSmallIncrement)
case .volumeDown: case .volumeDown:
let value = display.calcNewValue(for: .audioSpeakerVolume, withRel: -self.step) let value = display.calcNewValue(for: .audioSpeakerVolume, withRel: -(isSmallIncrement ? self.step / 4 : self.step))
display.setVolume(to: value) display.setVolume(to: value, isSmallIncrement: isSmallIncrement)
default: default:
return return
} }

View file

@ -71,7 +71,7 @@ class Display {
} }
} }
func setVolume(to value: Int) { func setVolume(to value: Int, isSmallIncrement: Bool = false) {
if value > 0, self.isMuted { if value > 0, self.isMuted {
self.mute(forceVolume: value) self.mute(forceVolume: value)
} else if value == 0 { } else if value == 0 {
@ -85,7 +85,7 @@ class Display {
} }
self.hideDisplayOsd() self.hideDisplayOsd()
self.showOsd(command: .audioSpeakerVolume, value: value) self.showOsd(command: .audioSpeakerVolume, value: value, isSmallIncrement: isSmallIncrement)
self.playVolumeChangedSound() self.playVolumeChangedSound()
} }
@ -96,7 +96,7 @@ class Display {
self.saveValue(value, for: .audioSpeakerVolume) self.saveValue(value, for: .audioSpeakerVolume)
} }
func setBrightness(to value: Int) { func setBrightness(to value: Int, isSmallIncrement: Bool = false) {
if self.prefs.bool(forKey: Utils.PrefKeys.lowerContrast.rawValue) { if self.prefs.bool(forKey: Utils.PrefKeys.lowerContrast.rawValue) {
if value == 0 { if value == 0 {
DispatchQueue.global(qos: .userInitiated).async { DispatchQueue.global(qos: .userInitiated).async {
@ -120,7 +120,7 @@ class Display {
return return
} }
self.showOsd(command: .brightness, value: value) self.showOsd(command: .brightness, value: value, isSmallIncrement: isSmallIncrement)
} }
if let slider = brightnessSliderHandler?.slider { if let slider = brightnessSliderHandler?.slider {
@ -161,7 +161,7 @@ class Display {
return self.prefs.string(forKey: "friendlyName-\(self.identifier)") ?? self.name return self.prefs.string(forKey: "friendlyName-\(self.identifier)") ?? self.name
} }
private func showOsd(command: DDC.Command, value: Int) { private func showOsd(command: DDC.Command, value: Int, isSmallIncrement: Bool = false) {
guard let manager = OSDManager.sharedManager() as? OSDManager else { guard let manager = OSDManager.sharedManager() as? OSDManager else {
return return
} }
@ -176,7 +176,7 @@ class Display {
} }
} }
let step = maxValue / 16 let step = isSmallIncrement ? maxValue / maxValue : maxValue / 16
manager.showImage(osdImage, manager.showImage(osdImage,
onDisplayID: self.identifier, onDisplayID: self.identifier,

View file

@ -17,9 +17,9 @@
<key>CFBundlePackageType</key> <key>CFBundlePackageType</key>
<string>APPL</string> <string>APPL</string>
<key>CFBundleShortVersionString</key> <key>CFBundleShortVersionString</key>
<string>1.5.2</string> <string>$(MARKETING_VERSION)</string>
<key>CFBundleVersion</key> <key>CFBundleVersion</key>
<string>560</string> <string>$(CURRENT_PROJECT_VERSION)</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

@ -17,9 +17,9 @@
<key>CFBundlePackageType</key> <key>CFBundlePackageType</key>
<string>APPL</string> <string>APPL</string>
<key>CFBundleShortVersionString</key> <key>CFBundleShortVersionString</key>
<string>1.5.2</string> <string>$(MARKETING_VERSION)</string>
<key>CFBundleVersion</key> <key>CFBundleVersion</key>
<string>533</string> <string>$(CURRENT_PROJECT_VERSION)</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>