From 0c4df95ef0b4fd9ffd8e70089fba3aefc8eea5bb Mon Sep 17 00:00:00 2001 From: Alex Perathoner Date: Mon, 19 Dec 2022 00:09:14 +0100 Subject: [PATCH 1/5] re add keyboard hud --- SlimHUD.xcodeproj/project.pbxproj | 16 ---------------- SlimHUD/AppDelegate.swift | 22 +++++++++++++++++++--- SlimHUD/Support/AppleScript.swift | 10 +++++++--- 3 files changed, 26 insertions(+), 22 deletions(-) diff --git a/SlimHUD.xcodeproj/project.pbxproj b/SlimHUD.xcodeproj/project.pbxproj index a41ca44b..19db8569 100644 --- a/SlimHUD.xcodeproj/project.pbxproj +++ b/SlimHUD.xcodeproj/project.pbxproj @@ -33,8 +33,6 @@ FAD58AAB24570B9F00E6E0D9 /* Settings.storyboard in Resources */ = {isa = PBXBuildFile; fileRef = FAD58AAA24570B9F00E6E0D9 /* Settings.storyboard */; }; FAD58AAD2457139100E6E0D9 /* SettingsWindowController.swift in Sources */ = {isa = PBXBuildFile; fileRef = FAD58AAC2457139100E6E0D9 /* SettingsWindowController.swift */; }; FAF5F6532406D1480011B766 /* Hud.swift in Sources */ = {isa = PBXBuildFile; fileRef = FAF5F6522406D1480011B766 /* Hud.swift */; }; - FAF5F6552408445F0011B766 /* dbrightness in Resources */ = {isa = PBXBuildFile; fileRef = FAF5F6542408445F0011B766 /* dbrightness */; }; - FAF5F658240875800011B766 /* LICENSE in Resources */ = {isa = PBXBuildFile; fileRef = FAF5F6572408757F0011B766 /* LICENSE */; }; /* End PBXBuildFile section */ /* Begin PBXFileReference section */ @@ -69,8 +67,6 @@ FAD58AAA24570B9F00E6E0D9 /* Settings.storyboard */ = {isa = PBXFileReference; lastKnownFileType = file.storyboard; path = Settings.storyboard; sourceTree = ""; }; FAD58AAC2457139100E6E0D9 /* SettingsWindowController.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = SettingsWindowController.swift; sourceTree = ""; }; FAF5F6522406D1480011B766 /* Hud.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = Hud.swift; sourceTree = ""; }; - FAF5F6542408445F0011B766 /* dbrightness */ = {isa = PBXFileReference; lastKnownFileType = "compiled.mach-o.executable"; path = dbrightness; sourceTree = ""; }; - FAF5F6572408757F0011B766 /* LICENSE */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text; path = LICENSE; sourceTree = ""; }; /* End PBXFileReference section */ /* Begin PBXFrameworksBuildPhase section */ @@ -138,7 +134,6 @@ FABE1FD923FEF17B009AD01F /* AppleScript.swift */, FA55B98B2423FE180071E6D9 /* Extensions.swift */, FA5C77E8240B0753004E0937 /* Kauntey Suryawanshi */, - FAF5F656240875670011B766 /* Nick Sweeting */, ); path = Support; sourceTree = ""; @@ -211,15 +206,6 @@ name = Frameworks; sourceTree = ""; }; - FAF5F656240875670011B766 /* Nick Sweeting */ = { - isa = PBXGroup; - children = ( - FAF5F6572408757F0011B766 /* LICENSE */, - FAF5F6542408445F0011B766 /* dbrightness */, - ); - path = "Nick Sweeting"; - sourceTree = ""; - }; /* End PBXGroup section */ /* Begin PBXNativeTarget section */ @@ -280,11 +266,9 @@ isa = PBXResourcesBuildPhase; buildActionMask = 2147483647; files = ( - FAF5F6552408445F0011B766 /* dbrightness in Resources */, FA131C2F24683CBD005908FF /* MainMenu.storyboard in Resources */, FAAFCD872458768E009E5E2E /* About.storyboard in Resources */, FAD58AAB24570B9F00E6E0D9 /* Settings.storyboard in Resources */, - FAF5F658240875800011B766 /* LICENSE in Resources */, FA623A612468591400A6ABCB /* BarView.xib in Resources */, FA69AC8B23F9E2E700AA73FD /* Assets.xcassets in Resources */, ); diff --git a/SlimHUD/AppDelegate.swift b/SlimHUD/AppDelegate.swift index 9aca5cca..23f4c76e 100644 --- a/SlimHUD/AppDelegate.swift +++ b/SlimHUD/AppDelegate.swift @@ -55,6 +55,7 @@ class AppDelegate: NSWindowController, NSApplicationDelegate, SettingsWindowCont oldVolume = getOutputVolume() + oldBacklightRaw = getKeyboardBrightnessProportioned(raw: getRawKeyboardBrightness()) oldBrightness = getDisplayBrightness() @@ -343,13 +344,13 @@ class AppDelegate: NSWindowController, NSApplicationDelegate, SettingsWindowCont @objc func showVolumeHUD() { if(!enabledBars[0]) {return} - let disabled = isMuted() - setColor(for: volumeView.bar!, disabled) + let muted = isMuted() + setColor(for: volumeView.bar!, muted) if(!settingsController!.shouldContinuouslyCheck) { volumeView.bar!.progress = CGFloat(getOutputVolume()) } - if(disabled) { + if(muted) { volumeView.image!.image = NSImage(named: "noVolume") } else { volumeView.image!.image = NSImage(named: "volume") @@ -404,6 +405,9 @@ class AppDelegate: NSWindowController, NSApplicationDelegate, SettingsWindowCont oldFullScreen = newFullScreen } + if(enabledBars[2]) { + checkBacklightChanges() + } if(enabledBars[1]) { checkBrightnessChanges() } @@ -438,6 +442,18 @@ class AppDelegate: NSWindowController, NSApplicationDelegate, SettingsWindowCont } brightnessView.bar?.progress = CGFloat(newBrightness) } + + var oldBacklightRaw: Float = 0.5 + func checkBacklightChanges() { + let newBacklightRaw = getRawKeyboardBrightness() + if(!isAlmost(n1: oldBacklightRaw, n2: newBacklightRaw)) { + NotificationCenter.default.post(name: ObserverApplication.keyboardIlluminationChanged, object: self) + oldBacklightRaw = newBacklightRaw + } + let newBacklightProportioned = getKeyboardBrightnessProportioned(raw: newBacklightRaw) + keyboardView.bar?.progress = CGFloat(newBacklightProportioned) + } + // MARK: - diff --git a/SlimHUD/Support/AppleScript.swift b/SlimHUD/Support/AppleScript.swift index c63e0c24..3b698dc5 100644 --- a/SlimHUD/Support/AppleScript.swift +++ b/SlimHUD/Support/AppleScript.swift @@ -42,7 +42,12 @@ func getDisplayBrightness() -> Float { return brightness } -func getKeyboardBrightness() -> Float { +func getKeyboardBrightnessProportioned(raw: Float) -> Float { + if(raw <= 0.07) { return 0 } + return (log10(raw+0.03)+1) +} + +func getRawKeyboardBrightness() -> Float { let service = IOServiceGetMatchingService(kIOMasterPortDefault, IOServiceMatching("AppleHIDKeyboardEventDriverV2")) defer { IOObjectRelease(service) @@ -52,6 +57,5 @@ func getKeyboardBrightness() -> Float { let result = ser as! Float return result / 342 //max value is 342, proportioning to % } - //couldn't get keyboard backlight - return 0.5 + return 0 // todo: should throw exception, maybe show "disabled" icon? } From 38297570deebb02e578ec61d5f6a07582b383eb6 Mon Sep 17 00:00:00 2001 From: Alex Perathoner Date: Mon, 19 Dec 2022 00:09:21 +0100 Subject: [PATCH 2/5] remove dbrightness --- SlimHUD/Support/Nick Sweeting/LICENSE | 21 --------------------- SlimHUD/Support/Nick Sweeting/dbrightness | Bin 9056 -> 0 bytes 2 files changed, 21 deletions(-) delete mode 100644 SlimHUD/Support/Nick Sweeting/LICENSE delete mode 100755 SlimHUD/Support/Nick Sweeting/dbrightness diff --git a/SlimHUD/Support/Nick Sweeting/LICENSE b/SlimHUD/Support/Nick Sweeting/LICENSE deleted file mode 100644 index 5712b5d8..00000000 --- a/SlimHUD/Support/Nick Sweeting/LICENSE +++ /dev/null @@ -1,21 +0,0 @@ -MIT License - -Copyright (c) 2017 Nick Sweeting - -Permission is hereby granted, free of charge, to any person obtaining a copy -of this software and associated documentation files (the "Software"), to deal -in the Software without restriction, including without limitation the rights -to use, copy, modify, merge, publish, distribute, sublicense, and/or sell -copies of the Software, and to permit persons to whom the Software is -furnished to do so, subject to the following conditions: - -The above copyright notice and this permission notice shall be included in all -copies or substantial portions of the Software. - -THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR -IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, -FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE -AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER -LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, -OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE -SOFTWARE. diff --git a/SlimHUD/Support/Nick Sweeting/dbrightness b/SlimHUD/Support/Nick Sweeting/dbrightness deleted file mode 100755 index d9e553716cb2ef51f51563225d1cb0e9023f227e..0000000000000000000000000000000000000000 GIT binary patch literal 0 HcmV?d00001 literal 9056 zcmeHNU1%It6u#Rw8f$e^T1&O9uGL8VA=?%!d8zI;nPfs+vu&ETwCK(3X0|)HnO$cl zHhBmJV;`0n2?$c84}DazP{Ai3w4z|a2Y(&}!3Te;OfbSiONk|P{mz{`+1bf9eH3I4 z+fI6l_Td=Z-$^NB|Y)tKNshp#3qqDZ=aO z!wF0UA?LO;mbI6g!hDJyU&6pJ z-$#;jyVq<)-)G{p&GSQMJYxmo1)#AvouZvaN>9IkkAa}UZ@?tOl8p8x`b8^aJMlZPi|hnrtx&DdDQI8R1Y_?5RH28V z=~`|@Iq@iCxYbwz1dGu3qGV8lLNQ7u=!alG*&UdVqplE&#{|j-l;oIgC5uKjIWkck z0VdgoLi_miw^KteJoo&?_kMr+^L;~?&BxIu_%^J^9e$Q!N}dl z5wwaw0&9>wfkM|kgE*zQeo|tJ+eji0L>`Dd5P2Z-!2jI?Lu%y@b$TIjE#B604o@`d zY)cx?H)=(3uf;biSKSsgR+Q^Alh@traK`Q%>g=Jb6=iW|a#5Wba^1hsSW%WRU%9GI zf0cOY%RHnr{>Yocbv{3M=fOmrOGNHo6!WSxlU4V;;PnGyAnPnySIByYtk1}T!R9|9>tV7!ghfqLuV*de zbipxo+h*-~w9tavsS6U+^n6P1xz9pVp?6dgvgt8@17@~~+0MTcL>`Dd5P2Z-K;(hQ1Ca+J4@4e_JP>&x@<8N)$OHee z2R80(JHG!gvRf%irio-Y&my0T{T&23I`&bxcNDF>~Y&Y(ygcNaC=KBDJ!OE+^m zn@Y_wX0<(#;@y2chFvad6a51+Qcz?rg;B=Z0ggU-eO5} zG8(1O9P9uiI)Wnxn~m7DDaG}1LoCw;yNv9%lc%{UAluGqCLv#99RDX+$43j8r02#Q z9l3gqj(g~|?#P|&uYY(sY&UB?Hj0z5Q}p3wEvs%r_1$(<7j^&)XJ{$vipMD9L7mA!!%XMENXydOkcMEkW2IA8xJq1 zkiQS%pF;T85GEr3e;9r)o4)N(o|kfkkko2p63BS3^f_U}FC>dx`*MVlXIeuS;KeLSc93s-A-HUIzs From 10babf7b7a3af7b3b2c919f1379cac9265c9c851 Mon Sep 17 00:00:00 2001 From: Alex Perathoner Date: Mon, 19 Dec 2022 00:09:26 +0100 Subject: [PATCH 3/5] update release notes --- Release_Notes.md | 2 ++ 1 file changed, 2 insertions(+) create mode 100644 Release_Notes.md diff --git a/Release_Notes.md b/Release_Notes.md new file mode 100644 index 00000000..914bb169 --- /dev/null +++ b/Release_Notes.md @@ -0,0 +1,2 @@ +# 1.3.8 +* Fix bug: keyboard backlight hud working again \ No newline at end of file From ce93d32bc8a02c2f5936d0fadb8d0ddf57267542 Mon Sep 17 00:00:00 2001 From: Alex Perathoner Date: Mon, 19 Dec 2022 00:12:33 +0100 Subject: [PATCH 4/5] use constant --- SlimHUD/Support/AppleScript.swift | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/SlimHUD/Support/AppleScript.swift b/SlimHUD/Support/AppleScript.swift index 3b698dc5..cc0b0ba2 100644 --- a/SlimHUD/Support/AppleScript.swift +++ b/SlimHUD/Support/AppleScript.swift @@ -47,6 +47,8 @@ func getKeyboardBrightnessProportioned(raw: Float) -> Float { return (log10(raw+0.03)+1) } +let MAX_KEYBOARD_BRIGHTNESS: Float = 342; + func getRawKeyboardBrightness() -> Float { let service = IOServiceGetMatchingService(kIOMasterPortDefault, IOServiceMatching("AppleHIDKeyboardEventDriverV2")) defer { @@ -55,7 +57,7 @@ func getRawKeyboardBrightness() -> Float { if let ser: CFTypeRef = IORegistryEntryCreateCFProperty(service, "KeyboardBacklightBrightness" as CFString, kCFAllocatorDefault, 0)?.takeUnretainedValue() { let result = ser as! Float - return result / 342 //max value is 342, proportioning to % + return result / MAX_KEYBOARD_BRIGHTNESS //max value is 342, proportioning to % } return 0 // todo: should throw exception, maybe show "disabled" icon? } From 5c4841482d34b35aaba9a52e2f7f61892f7bf8ce Mon Sep 17 00:00:00 2001 From: Alex Perathoner Date: Tue, 20 Dec 2022 17:18:27 +0100 Subject: [PATCH 5/5] fix style --- SlimHUD/Services/KeyboardManager.swift | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/SlimHUD/Services/KeyboardManager.swift b/SlimHUD/Services/KeyboardManager.swift index adff1bf4..7a591d36 100644 --- a/SlimHUD/Services/KeyboardManager.swift +++ b/SlimHUD/Services/KeyboardManager.swift @@ -11,12 +11,13 @@ import Foundation class KeyboardManager { private init() {} + // Raw value of sensor is non linear, correcting it static func getKeyboardBrightnessProportioned(raw: Float) -> Float { if raw <= 0.07 { return 0 } return (log10(raw+0.03)+1) } - private static let MAX_KEYBOARD_BRIGHTNESS: Float = 342 + private static let MaxKeyboardBrightness: Float = 342 static func getRawKeyboardBrightness() -> Float { let service = IOServiceGetMatchingService(kIOMasterPortDefault, IOServiceMatching("AppleHIDKeyboardEventDriverV2")) @@ -26,7 +27,7 @@ class KeyboardManager { if let ser: CFTypeRef = IORegistryEntryCreateCFProperty(service, "KeyboardBacklightBrightness" as CFString, kCFAllocatorDefault, 0)?.takeUnretainedValue() { let result = ser as! Float - return result / KeyboardManager.MAX_KEYBOARD_BRIGHTNESS // max value is 342, proportioning to % + return result / KeyboardManager.MaxKeyboardBrightness } return 0 // todo: should throw exception, maybe show "disabled" icon? }