Skip to content
This repository has been archived by the owner on Sep 17, 2021. It is now read-only.

Commit

Permalink
Appearance: use smooth transitions
Browse files Browse the repository at this point in the history
  • Loading branch information
billziss-gh committed Oct 1, 2018
1 parent b1d7824 commit 44fdc0f
Show file tree
Hide file tree
Showing 4 changed files with 51 additions and 15 deletions.
10 changes: 6 additions & 4 deletions build/Xcode/EnergyBar.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -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 */; };
Expand Down Expand Up @@ -68,7 +68,7 @@
3C01F8ED2161B93000FFD2C6 /* Base */ = {isa = PBXFileReference; lastKnownFileType = file.xib; name = Base; path = "Base.lproj/BrightnessBar-Mojave.xib"; sourceTree = "<group>"; };
3C01F8EF2161CE7400FFD2C6 /* SkyLight.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = SkyLight.framework; path = ../../../../../../System/Library/PrivateFrameworks/SkyLight.framework; sourceTree = "<group>"; };
3C01F8F12161D07800FFD2C6 /* Appearance.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = Appearance.h; sourceTree = "<group>"; };
3C01F8F22161D07800FFD2C6 /* Appearance.c */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.c; path = Appearance.c; sourceTree = "<group>"; };
3C01F8F22161D07800FFD2C6 /* Appearance.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = Appearance.m; sourceTree = "<group>"; };
3C04600F211D7C66003EB021 /* KeyEvent.c */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.c; path = KeyEvent.c; sourceTree = "<group>"; };
3C046010211D7C66003EB021 /* KeyEvent.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = KeyEvent.h; sourceTree = "<group>"; };
3C080A492139EB0D00EED01D /* FolderController.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = FolderController.h; sourceTree = "<group>"; };
Expand All @@ -88,6 +88,7 @@
3C163BC92118F33C00F015EC /* Base */ = {isa = PBXFileReference; lastKnownFileType = file.xib; name = Base; path = Base.lproj/MainWindow.xib; sourceTree = "<group>"; };
3C1A5676211D6B7D008E1F9F /* AppBarController.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = AppBarController.h; sourceTree = "<group>"; };
3C1A5677211D6B7D008E1F9F /* AppBarController.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = AppBarController.m; sourceTree = "<group>"; };
3C1DF6BA2162D83B006A1EBF /* NSGlobalPreferenceTransition.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = NSGlobalPreferenceTransition.h; sourceTree = "<group>"; };
3C200ECD212DFF390000B04D /* FixedSizeLabel.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = FixedSizeLabel.h; sourceTree = "<group>"; };
3C200ECE212DFF390000B04D /* FixedSizeLabel.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = FixedSizeLabel.m; sourceTree = "<group>"; };
3C3464BD21465319001F45BB /* WeatherWidget.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = WeatherWidget.h; sourceTree = "<group>"; };
Expand Down Expand Up @@ -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 */,
Expand All @@ -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 */,
Expand Down Expand Up @@ -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 */,
Expand Down
4 changes: 2 additions & 2 deletions src/System/Appearance.h
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,8 @@

typedef enum
{
AppearanceAqua = 0,
AppearanceDarkAqua = 1,
AppearanceLight = 0,
AppearanceDark = 1,
} Appearance;

Appearance GetAppearance(void);
Expand Down
29 changes: 20 additions & 9 deletions src/System/Appearance.c → src/System/Appearance.m
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/**
* @file Appearance.c
* @file Appearance.m
*
* @copyright 2018 Bill Zissimopoulos
*/
Expand All @@ -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;
}
}

Expand All @@ -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:^
{
}];
}
23 changes: 23 additions & 0 deletions src/System/NSGlobalPreferenceTransition.h
Original file line number Diff line number Diff line change
@@ -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 <Cocoa/Cocoa.h>

typedef void (^NSGlobalPreferenceTransitionBlock)(void);

@interface NSGlobalPreferenceTransition : NSObject
+ (id)transition;
- (void)waitForTransitionWithCompletionHandler:(NSGlobalPreferenceTransitionBlock)arg1;
- (void)postChangeNotification:(unsigned long long)arg1
completionHandler:(NSGlobalPreferenceTransitionBlock)arg2;
@end

0 comments on commit 44fdc0f

Please sign in to comment.