Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix referenced entry color on macOS dark mode #2984

Merged
merged 1 commit into from
Apr 12, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 8 additions & 0 deletions src/gui/entry/EntryModel.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -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());
Expand Down
1 change: 1 addition & 0 deletions src/gui/macutils/AppKit.h
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ class AppKit
bool activateProcess(pid_t pid);
bool hideProcess(pid_t pid);
bool isHidden(pid_t pid);
bool isDarkMode();

private:
void *self;
Expand Down
1 change: 1 addition & 0 deletions src/gui/macutils/AppKitImpl.h
Original file line number Diff line number Diff line change
Expand Up @@ -30,5 +30,6 @@
- (bool) activateProcess:(pid_t) pid;
- (bool) hideProcess:(pid_t) pid;
- (bool) isHidden:(pid_t) pid;
- (bool) isDarkMode;

@end
8 changes: 8 additions & 0 deletions src/gui/macutils/AppKitImpl.mm
Original file line number Diff line number Diff line change
Expand Up @@ -127,4 +127,12 @@ - (bool) 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
5 changes: 5 additions & 0 deletions src/gui/macutils/MacUtils.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -70,3 +70,8 @@ bool MacUtils::isHidden()
{
return m_appkit->isHidden(m_appkit->ownProcessId());
}

bool MacUtils::isDarkMode()
{
return m_appkit->isDarkMode();
}
1 change: 1 addition & 0 deletions src/gui/macutils/MacUtils.h
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@ class MacUtils : public QObject
bool raiseOwnWindow();
bool hideOwnWindow();
bool isHidden();
bool isDarkMode();

private:
explicit MacUtils(QObject* parent = nullptr);
Expand Down