Skip to content

Commit 5c82b99

Browse files
authored
Some minor fixes and improvements (MonitorControl#786)
1 parent 2e05ce1 commit 5c82b99

17 files changed

Lines changed: 264 additions & 252 deletions

.swift-version

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
5.0
1+
5.5

MonitorControl.xcodeproj/project.pbxproj

Lines changed: 45 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,13 @@
4141
AA99521926FE49A300612E07 /* MenuHandler.swift in Sources */ = {isa = PBXBuildFile; fileRef = AA99521826FE49A300612E07 /* MenuHandler.swift */; };
4242
AA9AE86F26B5BF3D00B6CA65 /* OSD.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = AA9AE86E26B5BF3D00B6CA65 /* OSD.framework */; };
4343
AA9AE87126B5BFB700B6CA65 /* CoreDisplay.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = AA9AE87026B5BFB700B6CA65 /* CoreDisplay.framework */; };
44+
AAB2F638273ED099004AB5A4 /* .swiftlint.yml in Resources */ = {isa = PBXBuildFile; fileRef = AAB2F637273ED099004AB5A4 /* .swiftlint.yml */; };
45+
AAB2F63C273ED0AD004AB5A4 /* .swift-version in Resources */ = {isa = PBXBuildFile; fileRef = AAB2F639273ED0AD004AB5A4 /* .swift-version */; };
46+
AAB2F63D273ED0AD004AB5A4 /* .gitignore in Resources */ = {isa = PBXBuildFile; fileRef = AAB2F63A273ED0AD004AB5A4 /* .gitignore */; };
47+
AAB2F63E273ED0AD004AB5A4 /* .swiftformat in Resources */ = {isa = PBXBuildFile; fileRef = AAB2F63B273ED0AD004AB5A4 /* .swiftformat */; };
48+
AAB2F640273ED0B8004AB5A4 /* .bartycrouch.toml in Resources */ = {isa = PBXBuildFile; fileRef = AAB2F63F273ED0B8004AB5A4 /* .bartycrouch.toml */; };
49+
AAB2F642273ED0C7004AB5A4 /* .github in Resources */ = {isa = PBXBuildFile; fileRef = AAB2F641273ED0C7004AB5A4 /* .github */; };
50+
AAB2F644273ED0E9004AB5A4 /* License.txt in Resources */ = {isa = PBXBuildFile; fileRef = AAB2F643273ED0E9004AB5A4 /* License.txt */; };
4451
AACE5E2327050C63006C2A48 /* NSNotification+Extension.swift in Sources */ = {isa = PBXBuildFile; fileRef = AACE5E2227050C63006C2A48 /* NSNotification+Extension.swift */; };
4552
AADB625A26BC196900DFFAA5 /* DisplayServices.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = AADB625926BC196900DFFAA5 /* DisplayServices.framework */; };
4653
F01B0699228221B7008E64DB /* Localizable.strings in Resources */ = {isa = PBXBuildFile; fileRef = F01B0680228221B6008E64DB /* Localizable.strings */; };
@@ -128,6 +135,13 @@
128135
AA9CB6402704C1A40086DC0E /* zh-Hans */ = {isa = PBXFileReference; lastKnownFileType = text.plist.strings; name = "zh-Hans"; path = "zh-Hans.lproj/Localizable.strings"; sourceTree = "<group>"; };
129136
AA9CB6412704C1B80086DC0E /* zh-Hant-TW */ = {isa = PBXFileReference; lastKnownFileType = text.plist.strings; name = "zh-Hant-TW"; path = "zh-Hant-TW.lproj/Main.strings"; sourceTree = "<group>"; };
130137
AA9CB6422704C1B80086DC0E /* zh-Hant-TW */ = {isa = PBXFileReference; lastKnownFileType = text.plist.strings; name = "zh-Hant-TW"; path = "zh-Hant-TW.lproj/Localizable.strings"; sourceTree = "<group>"; };
138+
AAB2F637273ED099004AB5A4 /* .swiftlint.yml */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text.yaml; path = .swiftlint.yml; sourceTree = "<group>"; };
139+
AAB2F639273ED0AD004AB5A4 /* .swift-version */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text; path = ".swift-version"; sourceTree = "<group>"; };
140+
AAB2F63A273ED0AD004AB5A4 /* .gitignore */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text; path = .gitignore; sourceTree = "<group>"; };
141+
AAB2F63B273ED0AD004AB5A4 /* .swiftformat */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text; path = .swiftformat; sourceTree = "<group>"; };
142+
AAB2F63F273ED0B8004AB5A4 /* .bartycrouch.toml */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text; path = .bartycrouch.toml; sourceTree = "<group>"; };
143+
AAB2F641273ED0C7004AB5A4 /* .github */ = {isa = PBXFileReference; lastKnownFileType = folder; path = .github; sourceTree = "<group>"; };
144+
AAB2F643273ED0E9004AB5A4 /* License.txt */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text; path = License.txt; sourceTree = "<group>"; };
131145
AACE5E2227050C63006C2A48 /* NSNotification+Extension.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = "NSNotification+Extension.swift"; sourceTree = "<group>"; };
132146
AADB625926BC196900DFFAA5 /* DisplayServices.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = DisplayServices.framework; path = ../../../../../System/Library/PrivateFrameworks/DisplayServices.framework; sourceTree = "<group>"; };
133147
F01B0682228221B6008E64DB /* en */ = {isa = PBXFileReference; lastKnownFileType = text.plist.strings; name = en; path = en.lproj/Localizable.strings; sourceTree = "<group>"; };
@@ -193,7 +207,7 @@
193207
56754EA21D9A4016007BCDC5 = {
194208
isa = PBXGroup;
195209
children = (
196-
AA3B4A2726AE103C00B74CD2 /* README.md */,
210+
AAB2F646273ED127004AB5A4 /* Misc */,
197211
28D1DDD1227FB759004CB494 /* Frameworks */,
198212
56754EAD1D9A4016007BCDC5 /* MonitorControl */,
199213
F06792E8200A73460066C438 /* MonitorControlHelper */,
@@ -248,6 +262,21 @@
248262
path = Enums;
249263
sourceTree = "<group>";
250264
};
265+
AAB2F646273ED127004AB5A4 /* Misc */ = {
266+
isa = PBXGroup;
267+
children = (
268+
AAB2F641273ED0C7004AB5A4 /* .github */,
269+
AAB2F63A273ED0AD004AB5A4 /* .gitignore */,
270+
AAB2F637273ED099004AB5A4 /* .swiftlint.yml */,
271+
AAB2F639273ED0AD004AB5A4 /* .swift-version */,
272+
AAB2F63B273ED0AD004AB5A4 /* .swiftformat */,
273+
AAB2F63F273ED0B8004AB5A4 /* .bartycrouch.toml */,
274+
AAB2F643273ED0E9004AB5A4 /* License.txt */,
275+
AA3B4A2726AE103C00B74CD2 /* README.md */,
276+
);
277+
name = Misc;
278+
sourceTree = "<group>";
279+
};
251280
F01B067F228221B6008E64DB /* Support */ = {
252281
isa = PBXGroup;
253282
children = (
@@ -412,12 +441,19 @@
412441
isa = PBXResourcesBuildPhase;
413442
buildActionMask = 2147483647;
414443
files = (
444+
AAB2F642273ED0C7004AB5A4 /* .github in Resources */,
445+
AAB2F63E273ED0AD004AB5A4 /* .swiftformat in Resources */,
415446
56754EB11D9A4016007BCDC5 /* Assets.xcassets in Resources */,
416447
6CDA0FCF26485A8300F52125 /* Main.storyboard in Resources */,
448+
AAB2F640273ED0B8004AB5A4 /* .bartycrouch.toml in Resources */,
417449
8C1741852707B91100E88D53 /* InternetAccessPolicy.plist in Resources */,
450+
AAB2F638273ED099004AB5A4 /* .swiftlint.yml in Resources */,
451+
AAB2F63C273ED0AD004AB5A4 /* .swift-version in Resources */,
418452
AA3B4A2826AE103C00B74CD2 /* README.md in Resources */,
419453
F01B0699228221B7008E64DB /* Localizable.strings in Resources */,
454+
AAB2F63D273ED0AD004AB5A4 /* .gitignore in Resources */,
420455
8C1741882707B91F00E88D53 /* InternetAccessPolicy.strings in Resources */,
456+
AAB2F644273ED0E9004AB5A4 /* License.txt in Resources */,
421457
);
422458
runOnlyForDeploymentPostprocessing = 0;
423459
};
@@ -759,13 +795,13 @@
759795
"@executable_path/../Frameworks",
760796
);
761797
MACOSX_DEPLOYMENT_TARGET = 10.14;
762-
MARKETING_VERSION = 4.0.1;
798+
MARKETING_VERSION = 4.0.2;
763799
PRODUCT_BUNDLE_IDENTIFIER = me.guillaumeb.MonitorControl;
764800
PRODUCT_NAME = "$(TARGET_NAME)";
765801
PROVISIONING_PROFILE_SPECIFIER = "";
766802
SWIFT_OBJC_BRIDGING_HEADER = "MonitorControl/Support/Bridging-Header.h";
767803
SWIFT_OPTIMIZATION_LEVEL = "-Onone";
768-
SWIFT_VERSION = 5.0;
804+
SWIFT_VERSION = 5.5;
769805
SYSTEM_FRAMEWORK_SEARCH_PATHS = (
770806
"$(inherited)",
771807
"$(SYSTEM_LIBRARY_DIR)/PrivateFrameworks",
@@ -794,13 +830,13 @@
794830
"@executable_path/../Frameworks",
795831
);
796832
MACOSX_DEPLOYMENT_TARGET = 10.14;
797-
MARKETING_VERSION = 4.0.1;
833+
MARKETING_VERSION = 4.0.2;
798834
PRODUCT_BUNDLE_IDENTIFIER = me.guillaumeb.MonitorControl;
799835
PRODUCT_NAME = "$(TARGET_NAME)";
800836
PROVISIONING_PROFILE_SPECIFIER = "";
801837
SWIFT_OBJC_BRIDGING_HEADER = "MonitorControl/Support/Bridging-Header.h";
802838
SWIFT_OPTIMIZATION_LEVEL = "-O";
803-
SWIFT_VERSION = 5.0;
839+
SWIFT_VERSION = 5.5;
804840
SYSTEM_FRAMEWORK_SEARCH_PATHS = (
805841
"$(inherited)",
806842
"$(SYSTEM_LIBRARY_DIR)/PrivateFrameworks",
@@ -829,11 +865,11 @@
829865
"@executable_path/../Frameworks",
830866
);
831867
MACOSX_DEPLOYMENT_TARGET = 10.14;
832-
MARKETING_VERSION = 4.0.1;
868+
MARKETING_VERSION = 4.0.2;
833869
PRODUCT_BUNDLE_IDENTIFIER = me.guillaumeb.MonitorControlHelper;
834870
PRODUCT_NAME = "$(TARGET_NAME)";
835871
SKIP_INSTALL = YES;
836-
SWIFT_VERSION = 5.0;
872+
SWIFT_VERSION = 5.5;
837873
};
838874
name = Debug;
839875
};
@@ -858,11 +894,11 @@
858894
"@executable_path/../Frameworks",
859895
);
860896
MACOSX_DEPLOYMENT_TARGET = 10.14;
861-
MARKETING_VERSION = 4.0.1;
897+
MARKETING_VERSION = 4.0.2;
862898
PRODUCT_BUNDLE_IDENTIFIER = me.guillaumeb.MonitorControlHelper;
863899
PRODUCT_NAME = "$(TARGET_NAME)";
864900
SKIP_INSTALL = YES;
865-
SWIFT_VERSION = 5.0;
901+
SWIFT_VERSION = 5.5;
866902
};
867903
name = Release;
868904
};

MonitorControl/Extensions/CGDirectDisplayID+Extension.swift

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,14 +4,14 @@ import Cocoa
44

55
public extension CGDirectDisplayID {
66
var vendorNumber: UInt32? {
7-
return CGDisplayVendorNumber(self)
7+
CGDisplayVendorNumber(self)
88
}
99

1010
var modelNumber: UInt32? {
11-
return CGDisplayModelNumber(self)
11+
CGDisplayModelNumber(self)
1212
}
1313

1414
var serialNumber: UInt32? {
15-
return CGDisplaySerialNumber(self)
15+
CGDisplaySerialNumber(self)
1616
}
1717
}

MonitorControl/Extensions/NSScreen+Extension.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ import Cocoa
44

55
public extension NSScreen {
66
var displayID: CGDirectDisplayID {
7-
return (self.deviceDescription[NSDeviceDescriptionKey("NSScreenNumber")] as? CGDirectDisplayID)!
7+
(self.deviceDescription[NSDeviceDescriptionKey("NSScreenNumber")] as? CGDirectDisplayID)!
88
}
99

1010
var vendorNumber: UInt32? {

MonitorControl/Info.plist

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@
1919
<key>CFBundleShortVersionString</key>
2020
<string>$(MARKETING_VERSION)</string>
2121
<key>CFBundleVersion</key>
22-
<string>6941</string>
22+
<string>6956</string>
2323
<key>LSApplicationCategoryType</key>
2424
<string>public.app-category.utilities</string>
2525
<key>LSMinimumSystemVersion</key>

MonitorControl/Model/Display.swift

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ class Display: Equatable {
1616
let swBrightnessSemaphore = DispatchSemaphore(value: 1)
1717

1818
static func == (lhs: Display, rhs: Display) -> Bool {
19-
return lhs.identifier == rhs.identifier
19+
lhs.identifier == rhs.identifier
2020
}
2121

2222
var sliderHandler: [Command: SliderHandler] = [:]
@@ -31,7 +31,7 @@ class Display: Equatable {
3131
var defaultGammaTablePeak: Float = 1
3232

3333
func prefExists(key: PrefKey? = nil, for command: Command? = nil) -> Bool {
34-
return prefs.object(forKey: self.getKey(key: key, for: command)) != nil
34+
prefs.object(forKey: self.getKey(key: key, for: command)) != nil
3535
}
3636

3737
func removePref(key: PrefKey, for command: Command? = nil) {
@@ -43,23 +43,23 @@ class Display: Equatable {
4343
}
4444

4545
func readPrefAsFloat(key: PrefKey? = nil, for command: Command? = nil) -> Float {
46-
return prefs.float(forKey: self.getKey(key: key, for: command))
46+
prefs.float(forKey: self.getKey(key: key, for: command))
4747
}
4848

4949
func readPrefAsInt(key: PrefKey? = nil, for command: Command? = nil) -> Int {
50-
return prefs.integer(forKey: self.getKey(key: key, for: command))
50+
prefs.integer(forKey: self.getKey(key: key, for: command))
5151
}
5252

5353
func readPrefAsBool(key: PrefKey? = nil, for command: Command? = nil) -> Bool {
54-
return prefs.bool(forKey: self.getKey(key: key, for: command))
54+
prefs.bool(forKey: self.getKey(key: key, for: command))
5555
}
5656

5757
func readPrefAsString(key: PrefKey? = nil, for command: Command? = nil) -> String {
58-
return prefs.string(forKey: self.getKey(key: key, for: command)) ?? ""
58+
prefs.string(forKey: self.getKey(key: key, for: command)) ?? ""
5959
}
6060

6161
private func getKey(key: PrefKey? = nil, for command: Command? = nil) -> String {
62-
return (key ?? PrefKey.value).rawValue + (command != nil ? String((command ?? Command.none).rawValue) : "") + self.prefsId
62+
(key ?? PrefKey.value).rawValue + (command != nil ? String((command ?? Command.none).rawValue) : "") + self.prefsId
6363
}
6464

6565
internal init(_ identifier: CGDirectDisplayID, name: String, vendorNumber: UInt32?, modelNumber: UInt32?, isVirtual: Bool = false, isDummy: Bool = false) {
@@ -321,7 +321,7 @@ class Display: Equatable {
321321
}
322322

323323
func resetSwBrightness() -> Bool {
324-
return self.setSwBrightness(1)
324+
self.setSwBrightness(1)
325325
}
326326

327327
func isSwBrightnessNotDefault() -> Bool {
@@ -335,7 +335,7 @@ class Display: Equatable {
335335
}
336336

337337
func refreshBrightness() -> Float {
338-
return 0
338+
0
339339
}
340340

341341
func isBuiltIn() -> Bool {

MonitorControl/Model/OtherDisplay.swift

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -72,7 +72,7 @@ class OtherDisplay: Display {
7272
}
7373

7474
func getDDCValueFromPrefs(_ command: Command) -> UInt16 {
75-
return self.convValueToDDC(for: command, from: (!prefs.bool(forKey: PrefKey.disableCombinedBrightness.rawValue) && command == .brightness) ? max(0, self.readPrefAsFloat(for: command) - self.combinedBrightnessSwitchingValue()) * (1 / (1 - self.combinedBrightnessSwitchingValue())) : self.readPrefAsFloat(for: command))
75+
self.convValueToDDC(for: command, from: (!prefs.bool(forKey: PrefKey.disableCombinedBrightness.rawValue) && command == .brightness) ? max(0, self.readPrefAsFloat(for: command) - self.combinedBrightnessSwitchingValue()) * (1 / (1 - self.combinedBrightnessSwitchingValue())) : self.readPrefAsFloat(for: command))
7676
}
7777

7878
func restoreDDCSettingsToDisplay(command: Command) {
@@ -162,7 +162,7 @@ class OtherDisplay: Display {
162162
}
163163

164164
func setupSliderCurrentValue(command: Command) -> Float {
165-
return (command == .audioSpeakerVolume && self.readPrefAsBool(key: .enableMuteUnmute) && self.readPrefAsInt(for: .audioMuteScreenBlank) == 1) ? 0 : self.readPrefAsFloat(for: command)
165+
(command == .audioSpeakerVolume && self.readPrefAsBool(key: .enableMuteUnmute) && self.readPrefAsInt(for: .audioMuteScreenBlank) == 1) ? 0 : self.readPrefAsFloat(for: command)
166166
}
167167

168168
func stepVolume(isUp: Bool, isSmallIncrement: Bool) {
@@ -255,7 +255,7 @@ class OtherDisplay: Display {
255255
}
256256

257257
func isSwOnly() -> Bool {
258-
return (!self.arm64ddc && self.ddc == nil) || self.isVirtual || self.isDummy
258+
(!self.arm64ddc && self.ddc == nil) || self.isVirtual || self.isDummy
259259
}
260260

261261
func isSw() -> Bool {
@@ -362,7 +362,7 @@ class OtherDisplay: Display {
362362
}
363363

364364
override func getBrightness() -> Float {
365-
return self.prefExists(for: .brightness) ? self.readPrefAsFloat(for: .brightness) : 1
365+
self.prefExists(for: .brightness) ? self.readPrefAsFloat(for: .brightness) : 1
366366
}
367367

368368
func getRemapControlCodes(command: Command) -> [UInt8] {
@@ -510,6 +510,6 @@ class OtherDisplay: Display {
510510
}
511511

512512
func combinedBrightnessSwitchingValue() -> Float {
513-
return Float(self.readPrefAsInt(key: .combinedBrightnessSwitchingPoint) + 8) / 16
513+
Float(self.readPrefAsInt(key: .combinedBrightnessSwitchingPoint) + 8) / 16
514514
}
515515
}

MonitorControl/Support/AppDelegate.swift

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -117,12 +117,13 @@ class AppDelegate: NSObject, NSApplicationDelegate {
117117
DisplayManager.shared.resetSwBrightnessForAllDisplays(noPrefSave: true)
118118
CGDisplayRestoreColorSyncSettings()
119119
self.reconfigureID += 1
120+
self.updateMediaKeyTap()
120121
os_log("Bumping reconfigureID to %{public}@", type: .info, String(self.reconfigureID))
121122
_ = DisplayManager.shared.destroyAllShades()
122123
if self.sleepID == 0 {
123124
let dispatchedReconfigureID = self.reconfigureID
124125
os_log("Display to be reconfigured with reconfigureID %{public}@", type: .info, String(dispatchedReconfigureID))
125-
DispatchQueue.main.asyncAfter(deadline: .now() + 2.0) {
126+
DispatchQueue.main.asyncAfter(deadline: .now() + 1.0) {
126127
self.configure(dispatchedReconfigureID: dispatchedReconfigureID)
127128
}
128129
}
@@ -159,7 +160,7 @@ class AppDelegate: NSObject, NSApplicationDelegate {
159160

160161
func checkPermissions() {
161162
let permissionsRequired: Bool = [KeyboardVolume.media.rawValue, KeyboardVolume.both.rawValue].contains(prefs.integer(forKey: PrefKey.keyboardVolume.rawValue)) || [KeyboardBrightness.media.rawValue, KeyboardBrightness.both.rawValue].contains(prefs.integer(forKey: PrefKey.keyboardBrightness.rawValue))
162-
if !MediaKeyTapManager.readPrivileges(prompt: false) && permissionsRequired {
163+
if !MediaKeyTapManager.readPrivileges(prompt: false), permissionsRequired {
163164
MediaKeyTapManager.acquirePrivileges()
164165
}
165166
}
@@ -177,13 +178,14 @@ class AppDelegate: NSObject, NSApplicationDelegate {
177178
@objc private func sleepNotification() {
178179
self.sleepID += 1
179180
os_log("Sleeping with sleep %{public}@", type: .info, String(self.sleepID))
181+
self.updateMediaKeyTap()
180182
}
181183

182184
@objc private func wakeNotification() {
183185
if self.sleepID != 0 {
184186
os_log("Waking up from sleep %{public}@", type: .info, String(self.sleepID))
185187
let dispatchedSleepID = self.sleepID
186-
DispatchQueue.main.asyncAfter(deadline: .now() + 6.0) { // Some displays take time to recover...
188+
DispatchQueue.main.asyncAfter(deadline: .now() + 3.0) { // Some displays take time to recover...
187189
self.soberNow(dispatchedSleepID: dispatchedSleepID)
188190
}
189191
}
@@ -203,6 +205,7 @@ class AppDelegate: NSObject, NSApplicationDelegate {
203205
self.job(start: true)
204206
}
205207
self.startupActionWriteRepeatAfterSober()
208+
self.updateMediaKeyTap()
206209
}
207210
}
208211

MonitorControl/Support/DisplayManager.swift

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -235,27 +235,27 @@ class DisplayManager {
235235
}
236236

237237
func getOtherDisplays() -> [OtherDisplay] {
238-
return self.displays.compactMap { $0 as? OtherDisplay }
238+
self.displays.compactMap { $0 as? OtherDisplay }
239239
}
240240

241241
func getAllDisplays() -> [Display] {
242-
return self.displays
242+
self.displays
243243
}
244244

245245
func getDdcCapableDisplays() -> [OtherDisplay] {
246-
return self.displays.compactMap { display -> OtherDisplay? in
246+
self.displays.compactMap { display -> OtherDisplay? in
247247
if let otherDisplay = display as? OtherDisplay, !otherDisplay.isSw() {
248248
return otherDisplay
249249
} else { return nil }
250250
}
251251
}
252252

253253
func getAppleDisplays() -> [AppleDisplay] {
254-
return self.displays.compactMap { $0 as? AppleDisplay }
254+
self.displays.compactMap { $0 as? AppleDisplay }
255255
}
256256

257257
func getBuiltInDisplay() -> Display? {
258-
return self.displays.first { CGDisplayIsBuiltin($0.identifier) != 0 }
258+
self.displays.first { CGDisplayIsBuiltin($0.identifier) != 0 }
259259
}
260260

261261
func getCurrentDisplay(byFocus: Bool = false) -> Display? {
@@ -481,7 +481,7 @@ class DisplayManager {
481481
}
482482

483483
static func getByDisplayID(displayID: CGDirectDisplayID) -> NSScreen? {
484-
return NSScreen.screens.first { $0.displayID == displayID }
484+
NSScreen.screens.first { $0.displayID == displayID }
485485
}
486486

487487
static func getDisplayRawNameByID(displayID: CGDirectDisplayID) -> String {

MonitorControl/Support/MediaKeyTapManager.swift

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -164,11 +164,15 @@ class MediaKeyTapManager: MediaKeyTapDelegate {
164164
keys.append(contentsOf: [.mute, .volumeUp, .volumeDown])
165165
}
166166
// Remove brightness keys if no external displays are connected, but only if brightness fine control is not active
167-
var isInternalDisplayOnly = true
167+
var disengageBrightness = true
168168
for display in DisplayManager.shared.getAllDisplays() where !display.isBuiltIn() {
169-
isInternalDisplayOnly = false
169+
disengageBrightness = false
170170
}
171-
if isInternalDisplayOnly, !prefs.bool(forKey: PrefKey.useFineScaleBrightness.rawValue) {
171+
// Disengage brightness keys on sleep so MacBook native screen can be controlled meanwhile
172+
if app.sleepID != 0 || app.reconfigureID != 0 {
173+
disengageBrightness = true
174+
}
175+
if disengageBrightness, !prefs.bool(forKey: PrefKey.useFineScaleBrightness.rawValue) {
172176
let keysToDelete: [MediaKey] = [.brightnessUp, .brightnessDown]
173177
keys.removeAll { keysToDelete.contains($0) }
174178
}

0 commit comments

Comments
 (0)