From 44fdc0f55fd483a72a60ce038a1d0ba5d47e1875 Mon Sep 17 00:00:00 2001 From: Bill Zissimopoulos Date: Mon, 1 Oct 2018 15:55:44 -0700 Subject: [PATCH] Appearance: use smooth transitions --- .../Xcode/EnergyBar.xcodeproj/project.pbxproj | 10 ++++--- src/System/Appearance.h | 4 +-- src/System/{Appearance.c => Appearance.m} | 29 +++++++++++++------ src/System/NSGlobalPreferenceTransition.h | 23 +++++++++++++++ 4 files changed, 51 insertions(+), 15 deletions(-) rename src/System/{Appearance.c => Appearance.m} (55%) create mode 100644 src/System/NSGlobalPreferenceTransition.h diff --git a/build/Xcode/EnergyBar.xcodeproj/project.pbxproj b/build/Xcode/EnergyBar.xcodeproj/project.pbxproj index 6ab2a44..7643078 100644 --- a/build/Xcode/EnergyBar.xcodeproj/project.pbxproj +++ b/build/Xcode/EnergyBar.xcodeproj/project.pbxproj @@ -9,7 +9,7 @@ /* Begin PBXBuildFile section */ 3C01F8EC2161B93000FFD2C6 /* BrightnessBar-Mojave.xib in Resources */ = {isa = PBXBuildFile; fileRef = 3C01F8EE2161B93000FFD2C6 /* BrightnessBar-Mojave.xib */; }; 3C01F8F02161CE7400FFD2C6 /* SkyLight.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 3C01F8EF2161CE7400FFD2C6 /* SkyLight.framework */; settings = {ATTRIBUTES = (Weak, ); }; }; - 3C01F8F32161D07800FFD2C6 /* Appearance.c in Sources */ = {isa = PBXBuildFile; fileRef = 3C01F8F22161D07800FFD2C6 /* Appearance.c */; }; + 3C01F8F32161D07800FFD2C6 /* Appearance.m in Sources */ = {isa = PBXBuildFile; fileRef = 3C01F8F22161D07800FFD2C6 /* Appearance.m */; }; 3C046013211D7C66003EB021 /* KeyEvent.c in Sources */ = {isa = PBXBuildFile; fileRef = 3C04600F211D7C66003EB021 /* KeyEvent.c */; }; 3C080A4B2139EB0E00EED01D /* FolderController.m in Sources */ = {isa = PBXBuildFile; fileRef = 3C080A4A2139EB0D00EED01D /* FolderController.m */; }; 3C102D482119641500FFB2CF /* CustomWidget.m in Sources */ = {isa = PBXBuildFile; fileRef = 3C102D462119641500FFB2CF /* CustomWidget.m */; }; @@ -68,7 +68,7 @@ 3C01F8ED2161B93000FFD2C6 /* Base */ = {isa = PBXFileReference; lastKnownFileType = file.xib; name = Base; path = "Base.lproj/BrightnessBar-Mojave.xib"; sourceTree = ""; }; 3C01F8EF2161CE7400FFD2C6 /* SkyLight.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = SkyLight.framework; path = ../../../../../../System/Library/PrivateFrameworks/SkyLight.framework; sourceTree = ""; }; 3C01F8F12161D07800FFD2C6 /* Appearance.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = Appearance.h; sourceTree = ""; }; - 3C01F8F22161D07800FFD2C6 /* Appearance.c */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.c; path = Appearance.c; sourceTree = ""; }; + 3C01F8F22161D07800FFD2C6 /* Appearance.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = Appearance.m; sourceTree = ""; }; 3C04600F211D7C66003EB021 /* KeyEvent.c */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.c; path = KeyEvent.c; sourceTree = ""; }; 3C046010211D7C66003EB021 /* KeyEvent.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = KeyEvent.h; sourceTree = ""; }; 3C080A492139EB0D00EED01D /* FolderController.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = FolderController.h; sourceTree = ""; }; @@ -88,6 +88,7 @@ 3C163BC92118F33C00F015EC /* Base */ = {isa = PBXFileReference; lastKnownFileType = file.xib; name = Base; path = Base.lproj/MainWindow.xib; sourceTree = ""; }; 3C1A5676211D6B7D008E1F9F /* AppBarController.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = AppBarController.h; sourceTree = ""; }; 3C1A5677211D6B7D008E1F9F /* AppBarController.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = AppBarController.m; sourceTree = ""; }; + 3C1DF6BA2162D83B006A1EBF /* NSGlobalPreferenceTransition.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = NSGlobalPreferenceTransition.h; sourceTree = ""; }; 3C200ECD212DFF390000B04D /* FixedSizeLabel.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = FixedSizeLabel.h; sourceTree = ""; }; 3C200ECE212DFF390000B04D /* FixedSizeLabel.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = FixedSizeLabel.m; sourceTree = ""; }; 3C3464BD21465319001F45BB /* WeatherWidget.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = WeatherWidget.h; sourceTree = ""; }; @@ -159,7 +160,7 @@ isa = PBXGroup; children = ( 3C01F8F12161D07800FFD2C6 /* Appearance.h */, - 3C01F8F22161D07800FFD2C6 /* Appearance.c */, + 3C01F8F22161D07800FFD2C6 /* Appearance.m */, 3C8E4131212F81A60010C2B3 /* AudioControl.h */, 3C8E4132212F81A60010C2B3 /* AudioControl.m */, 3C9E2648211E2A9F0042C2E8 /* Brightness.h */, @@ -172,6 +173,7 @@ 3C6944CE212E922F0082E3BF /* Log.h */, 3CFECA112122611F00BB58E9 /* LoginItem.h */, 3CFECA102122611F00BB58E9 /* LoginItem.c */, + 3C1DF6BA2162D83B006A1EBF /* NSGlobalPreferenceTransition.h */, 3CA8519F212B84B000585D29 /* NSTouchBar+SystemModal.h */, 3CA8519E212B84B000585D29 /* NSTouchBar+SystemModal.m */, 3CA8519B212B832100585D29 /* NSWorkspace+Finder.h */, @@ -397,7 +399,7 @@ 3CAA9C6D2127B3E100D5B467 /* StringToUrlTransformer.m in Sources */, 3C1A5678211D6B7D008E1F9F /* AppBarController.m in Sources */, 3CA8519D212B832100585D29 /* NSWorkspace+Finder.m in Sources */, - 3C01F8F32161D07800FFD2C6 /* Appearance.c in Sources */, + 3C01F8F32161D07800FFD2C6 /* Appearance.m in Sources */, 3CA1DD8B212D3FC000D95DE1 /* NowPlaying.m in Sources */, 3C102D4E2119872800FFB2CF /* EscKeyWidget.m in Sources */, 3C8E4133212F81A60010C2B3 /* AudioControl.m in Sources */, diff --git a/src/System/Appearance.h b/src/System/Appearance.h index 99dffac..5834fdf 100644 --- a/src/System/Appearance.h +++ b/src/System/Appearance.h @@ -16,8 +16,8 @@ typedef enum { - AppearanceAqua = 0, - AppearanceDarkAqua = 1, + AppearanceLight = 0, + AppearanceDark = 1, } Appearance; Appearance GetAppearance(void); diff --git a/src/System/Appearance.c b/src/System/Appearance.m similarity index 55% rename from src/System/Appearance.c rename to src/System/Appearance.m index df3871c..759fc58 100644 --- a/src/System/Appearance.c +++ b/src/System/Appearance.m @@ -1,5 +1,5 @@ /** - * @file Appearance.c + * @file Appearance.m * * @copyright 2018 Bill Zissimopoulos */ @@ -11,23 +11,25 @@ * Foundation. */ -#include "Appearance.h" +#import "Appearance.h" +#import "NSGlobalPreferenceTransition.h" extern int SLSGetAppearanceThemeLegacy(void) __attribute__((weak_import)); extern void SLSSetAppearanceThemeLegacy(int) __attribute__((weak_import)); +extern void SLSSetAppearanceThemeNotifying(int, int) __attribute__((weak_import)); Appearance GetAppearance(void) { if (0 == SLSGetAppearanceThemeLegacy) - return AppearanceAqua; + return AppearanceLight; switch (SLSGetAppearanceThemeLegacy()) { default: case 0: - return AppearanceAqua; + return AppearanceLight; case 1: - return AppearanceDarkAqua; + return AppearanceDark; } } @@ -36,14 +38,23 @@ void SetAppearance(Appearance appearance) if (0 == SLSSetAppearanceThemeLegacy) return; + int theme = 0; switch (appearance) { default: - case AppearanceAqua: - SLSSetAppearanceThemeLegacy(0); + case AppearanceLight: + theme = 0; break; - case AppearanceDarkAqua: - SLSSetAppearanceThemeLegacy(1); + case AppearanceDark: + theme = 1; break; } + + Class cls = NSClassFromString(@"NSGlobalPreferenceTransition"); + id transition = [cls transition]; + SLSSetAppearanceThemeNotifying(theme, nil == transition); + + [transition postChangeNotification:0 completionHandler:^ + { + }]; } diff --git a/src/System/NSGlobalPreferenceTransition.h b/src/System/NSGlobalPreferenceTransition.h new file mode 100644 index 0000000..ed4d103 --- /dev/null +++ b/src/System/NSGlobalPreferenceTransition.h @@ -0,0 +1,23 @@ +/** + * @file NSGlobalPreferenceTransition.h + * + * @copyright 2018 Bill Zissimopoulos + */ +/* + * This file is part of EnergyBar. + * + * You can redistribute it and/or modify it under the terms of the GNU + * General Public License version 3 as published by the Free Software + * Foundation. + */ + +#import + +typedef void (^NSGlobalPreferenceTransitionBlock)(void); + +@interface NSGlobalPreferenceTransition : NSObject ++ (id)transition; +- (void)waitForTransitionWithCompletionHandler:(NSGlobalPreferenceTransitionBlock)arg1; +- (void)postChangeNotification:(unsigned long long)arg1 + completionHandler:(NSGlobalPreferenceTransitionBlock)arg2; +@end