Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
macOS: add support for Mojave Dark Mode
This commit adds to our UI the support for macOS 10.14+ Dark Mode. Qt already adapts a large fraction of the color scheme, but some label colors had to be adjusted and were put in separate STYLE_DARK constants. To determine if the OS is set in Dark or Light Mode, we use a new dependency, included in the vendor folder: Darkdetect - license: BSD-3-Clause To allow the app bundle to use the Dark Mode APIs, a constant is added in the info.plist ('NSRequiresAquaSystemAppearance': False)
- Loading branch information
1 parent
12fc043
commit bc242c2
Showing
7 changed files
with
175 additions
and
17 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Original file line | Diff line number | Diff line change |
---|---|---|---|
@@ -0,0 +1,18 @@ | |||
#----------------------------------------------------------------------------- | |||
# Copyright (C) 2019 Alberto Sottile | |||
# | |||
# Distributed under the terms of the 3-clause BSD License. | |||
#----------------------------------------------------------------------------- | |||
|
|||
__version__ = '0.1.0' | |||
|
|||
import sys | |||
import platform | |||
from distutils.version import LooseVersion as V | |||
|
|||
if sys.platform != "darwin" or V(platform.mac_ver()[0]) < V("10.14"): | |||
from ._dummy import * | |||
else: | |||
from ._detect import * | |||
|
|||
del sys, platform, V |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Original file line | Diff line number | Diff line change |
---|---|---|---|
@@ -0,0 +1,64 @@ | |||
#----------------------------------------------------------------------------- | |||
# Copyright (C) 2019 Alberto Sottile | |||
# | |||
# Distributed under the terms of the 3-clause BSD License. | |||
#----------------------------------------------------------------------------- | |||
|
|||
import ctypes | |||
import ctypes.util | |||
|
|||
appkit = ctypes.cdll.LoadLibrary(ctypes.util.find_library('AppKit')) | |||
objc = ctypes.cdll.LoadLibrary(ctypes.util.find_library('objc')) | |||
|
|||
void_p = ctypes.c_void_p | |||
ull = ctypes.c_uint64 | |||
|
|||
objc.objc_getClass.restype = void_p | |||
objc.sel_registerName.restype = void_p | |||
objc.objc_msgSend.restype = void_p | |||
objc.objc_msgSend.argtypes = [void_p, void_p] | |||
|
|||
msg = objc.objc_msgSend | |||
|
|||
def _utf8(s): | |||
if not isinstance(s, bytes): | |||
s = s.encode('utf8') | |||
return s | |||
|
|||
def n(name): | |||
return objc.sel_registerName(_utf8(name)) | |||
|
|||
def C(classname): | |||
return objc.objc_getClass(_utf8(classname)) | |||
|
|||
def theme(): | |||
NSAutoreleasePool = objc.objc_getClass('NSAutoreleasePool') | |||
pool = msg(NSAutoreleasePool, n('alloc')) | |||
pool = msg(pool, n('init')) | |||
|
|||
NSUserDefaults = C('NSUserDefaults') | |||
stdUserDef = msg(NSUserDefaults, n('standardUserDefaults')) | |||
|
|||
NSString = C('NSString') | |||
|
|||
key = msg(NSString, n("stringWithUTF8String:"), _utf8('AppleInterfaceStyle')) | |||
appearanceNS = msg(stdUserDef, n('stringForKey:'), void_p(key)) | |||
appearanceC = msg(appearanceNS, n('UTF8String')) | |||
|
|||
if appearanceC is not None: | |||
out = ctypes.string_at(appearanceC) | |||
else: | |||
out = None | |||
|
|||
msg(pool, n('release')) | |||
|
|||
if out is not None: | |||
return out.decode('utf-8') | |||
else: | |||
return 'Light' | |||
|
|||
def isDark(): | |||
return theme() == 'Dark' | |||
|
|||
def isLight(): | |||
return theme() == 'Light' |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Original file line | Diff line number | Diff line change |
---|---|---|---|
@@ -0,0 +1,14 @@ | |||
#----------------------------------------------------------------------------- | |||
# Copyright (C) 2019 Alberto Sottile | |||
# | |||
# Distributed under the terms of the 3-clause BSD License. | |||
#----------------------------------------------------------------------------- | |||
|
|||
def theme(): | |||
return None | |||
|
|||
def isDark(): | |||
return None | |||
|
|||
def isLight(): | |||
return None |