Fix referenced entry color on macOS dark mode (#2984)

Introduce macUtils()->isDarkMode() function to detect Mojave dark
mode and correct reference entry text color. Fixes #860.
This commit is contained in:
Jonathan White 2019-04-12 13:57:49 -04:00 committed by Janek Bevendorff
parent cc27a367d6
commit e7815787c7
6 changed files with 24 additions and 0 deletions

View File

@ -30,6 +30,9 @@
#include "core/Global.h"
#include "core/Group.h"
#include "core/Metadata.h"
#ifdef Q_OS_MACOS
#include "gui/macutils/MacUtils.h"
#endif
EntryModel::EntryModel(QObject* parent)
: QAbstractTableModel(parent)
@ -270,6 +273,11 @@ QVariant EntryModel::data(const QModelIndex& index, int role) const
} else if (role == Qt::ForegroundRole) {
if (entry->hasReferences()) {
QPalette p;
#ifdef Q_OS_MACOS
if (macUtils()->isDarkMode()) {
return QVariant(p.color(QPalette::Inactive, QPalette::Dark));
}
#endif
return QVariant(p.color(QPalette::Active, QPalette::Mid));
} else if (entry->foregroundColor().isValid()) {
return QVariant(entry->foregroundColor());

View File

@ -35,6 +35,7 @@ public:
bool activateProcess(pid_t pid);
bool hideProcess(pid_t pid);
bool isHidden(pid_t pid);
bool isDarkMode();
private:
void *self;

View File

@ -30,5 +30,6 @@
- (bool) activateProcess:(pid_t) pid;
- (bool) hideProcess:(pid_t) pid;
- (bool) isHidden:(pid_t) pid;
- (bool) isDarkMode;
@end

View File

@ -127,4 +127,12 @@ bool AppKit::isHidden(pid_t pid)
return [static_cast<id>(self) isHidden:pid];
}
bool AppKit::isDarkMode()
{
NSDictionary *dict = [[NSUserDefaults standardUserDefaults] persistentDomainForName:NSGlobalDomain];
id style = [dict objectForKey:@"AppleInterfaceStyle"];
return ( style && [style isKindOfClass:[NSString class]]
&& NSOrderedSame == [style caseInsensitiveCompare:@"dark"] );
}
@end

View File

@ -70,3 +70,8 @@ bool MacUtils::isHidden()
{
return m_appkit->isHidden(m_appkit->ownProcessId());
}
bool MacUtils::isDarkMode()
{
return m_appkit->isDarkMode();
}

View File

@ -37,6 +37,7 @@ public:
bool raiseOwnWindow();
bool hideOwnWindow();
bool isHidden();
bool isDarkMode();
private:
explicit MacUtils(QObject* parent = nullptr);