From 59f18583d1c3cf31a068d4f8e46c6965c9c574d9 Mon Sep 17 00:00:00 2001 From: Sascha Vincent Kurowski Date: Fri, 24 Oct 2014 21:52:41 +0200 Subject: [PATCH] Switch monochrome systray icon color depending on systray brightness. https://github.com/owncloud/mirall/issues/2215 As of version 10.10 Yosemite, Mac OS X offers the user the option to use a dark version of the dock and menu bar. The systray icon was black even on the dark menu bar, thus rendering it nearly impossible to spot. --- src/libsync/theme.cpp | 7 ++----- src/libsync/utility.cpp | 5 +++++ src/libsync/utility.h | 14 +++++++++++++- src/libsync/utility_mac.cpp | 15 +++++++++++++++ src/libsync/utility_unix.cpp | 5 +++++ src/libsync/utility_win.cpp | 5 +++++ 6 files changed, 45 insertions(+), 6 deletions(-) diff --git a/src/libsync/theme.cpp b/src/libsync/theme.cpp index df31decfd1..f3c6f389be 100644 --- a/src/libsync/theme.cpp +++ b/src/libsync/theme.cpp @@ -15,6 +15,7 @@ #include "theme.h" #include "version.h" #include "config.h" +#include "utility.h" #include #ifndef TOKEN_AUTH_ONLY @@ -184,11 +185,7 @@ QString Theme::systrayIconFlavor(bool mono) const { QString flavor; if (mono) { -#ifdef Q_OS_MAC - flavor = QLatin1String("black"); -#else - flavor = QLatin1String("white"); -#endif + flavor = Utility::hasDarkSystray() ? QLatin1String("white") : QLatin1String("black"); } else { flavor = QLatin1String("colored"); } diff --git a/src/libsync/utility.cpp b/src/libsync/utility.cpp index c1ee81b630..1de401b25b 100644 --- a/src/libsync/utility.cpp +++ b/src/libsync/utility.cpp @@ -335,6 +335,11 @@ QString Utility::timeToDescriptiveString(QList > &timeMap return retStr; } +bool Utility::hasDarkSystray() +{ + return hasDarkSystray_private(); +} + bool Utility::isWindows() { diff --git a/src/libsync/utility.h b/src/libsync/utility.h index 8787422aa8..527a64665f 100644 --- a/src/libsync/utility.h +++ b/src/libsync/utility.h @@ -71,7 +71,19 @@ namespace Utility */ OWNCLOUDSYNC_EXPORT QString timeToDescriptiveString(QList > &timeMapping, quint64 msecs, quint8 precision, QString separator, bool specific); OWNCLOUDSYNC_EXPORT QString timeToDescriptiveString(quint64 msecs, quint8 precision, QString separator, bool specific); - + + /** + * @brief hasDarkSystray - determines whether the systray is dark or light. + * + * Use this to check if the OS has a dark or a light systray. + * + * The value might change during the execution of the program + * (e.g. on OS X 10.10). + * + * @return bool which is true for systems with dark systray. + */ + OWNCLOUDSYNC_EXPORT bool hasDarkSystray(); + // convinience OS detection methods OWNCLOUDSYNC_EXPORT bool isWindows(); OWNCLOUDSYNC_EXPORT bool isMac(); diff --git a/src/libsync/utility_mac.cpp b/src/libsync/utility_mac.cpp index a71bbd79ac..d8f87eaf82 100644 --- a/src/libsync/utility_mac.cpp +++ b/src/libsync/utility_mac.cpp @@ -108,3 +108,18 @@ void setLaunchOnStartup_private(const QString &appName, const QString& guiName, CFRelease(urlRef); } +static bool hasDarkSystray_private() +{ + bool returnValue = false; + CFStringRef interfaceStyleKey = CFSTR("AppleInterfaceStyle"); + CFStringRef interfaceStyle = NULL; + CFStringRef darkInterfaceStyle = CFSTR("Dark"); + interfaceStyle = (CFStringRef)CFPreferencesCopyAppValue(interfaceStyleKey, + kCFPreferencesCurrentApplication); + if (interfaceStyle != NULL) { + returnValue = (kCFCompareEqualTo == CFStringCompare(interfaceStyle, darkInterfaceStyle, 0)); + CFRelease(interfaceStyle); + } + return returnValue; +} + diff --git a/src/libsync/utility_unix.cpp b/src/libsync/utility_unix.cpp index a73e003385..3c108f28eb 100644 --- a/src/libsync/utility_unix.cpp +++ b/src/libsync/utility_unix.cpp @@ -86,3 +86,8 @@ void setLaunchOnStartup_private(const QString &appName, const QString& guiName, } } } + +static inline bool hasDarkSystray_private() +{ + return true; +} diff --git a/src/libsync/utility_win.cpp b/src/libsync/utility_win.cpp index 90aac54d71..f4509674c2 100644 --- a/src/libsync/utility_win.cpp +++ b/src/libsync/utility_win.cpp @@ -47,3 +47,8 @@ void setLaunchOnStartup_private(const QString &appName, const QString& guiName, settings.remove(appName); } } + +static inline bool hasDarkSystray_private() +{ + return true; +}