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

Improve macOS and Windows platform integration #5851

Merged
merged 2 commits into from
Jan 7, 2021
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
Prev Previous commit
Add dynamic theme switching on Windows 10
  • Loading branch information
phoerious committed Jan 7, 2021
commit 134926698e45fe3daf553028b53ece532daffc42
2 changes: 1 addition & 1 deletion src/gui/ApplicationSettingsWidget.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -251,7 +251,7 @@ void ApplicationSettingsWidget::loadSettings()
}

m_generalUi->trayIconAppearance->clear();
#ifdef Q_OS_MACOS
#if defined(Q_OS_MACOS) || defined(Q_OS_WIN)
m_generalUi->trayIconAppearance->addItem(tr("Monochrome"), "monochrome");
#else
m_generalUi->trayIconAppearance->addItem(tr("Monochrome (light)"), "monochrome-light");
Expand Down
2 changes: 1 addition & 1 deletion src/gui/Icons.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,7 @@ QIcon Icons::trayIcon(QString style)
}

QIcon i;
#ifdef Q_OS_MACOS
#if defined(Q_OS_MACOS) || defined(Q_OS_WIN)
if (osUtils->isStatusBarDark()) {
i = icon(QString("keepassxc-monochrome-light%1").arg(style), false);
} else {
Expand Down
21 changes: 13 additions & 8 deletions src/gui/osutils/winutils/WinUtils.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,8 @@ WinUtils* WinUtils::instance()
{
if (!m_instance) {
m_instance = new WinUtils(qApp);
m_instance->m_darkAppThemeActive = m_instance->isDarkMode();
m_instance->m_darkSystemThemeActive = m_instance->isStatusBarDark();

#ifdef QT_DEBUG
// Attach console to enable debug output
Expand Down Expand Up @@ -63,15 +65,17 @@ bool WinUtils::nativeEventFilter(const QByteArray& eventType, void* message, lon

auto* msg = static_cast<MSG*>(message);
switch (msg->message) {
/* TODO: indicate dark mode support for black title bar
case WM_CREATE:
case WM_INITDIALOG: {
if (msg->hwnd && winUtils()->isDarkMode()) {
case WM_SETTINGCHANGE:
if (m_darkAppThemeActive != isDarkMode()) {
m_darkAppThemeActive = !m_darkAppThemeActive;
emit interfaceThemeChanged();
}

if (m_darkSystemThemeActive != isStatusBarDark()) {
m_darkSystemThemeActive = !m_darkSystemThemeActive;
emit statusbarThemeChanged();
}
break;
}
*/
case WM_HOTKEY:
triggerGlobalShortcut(msg->wParam);
break;
Expand All @@ -89,8 +93,9 @@ bool WinUtils::isDarkMode() const

bool WinUtils::isStatusBarDark() const
{
// TODO: implement
return isDarkMode();
QSettings settings(R"(HKEY_CURRENT_USER\Software\Microsoft\Windows\CurrentVersion\Themes\Personalize)",
QSettings::NativeFormat);
return settings.value("SystemUsesLightTheme", 0).toInt() == 0;
}

bool WinUtils::isLaunchAtStartupEnabled() const
Expand Down
3 changes: 3 additions & 0 deletions src/gui/osutils/winutils/WinUtils.h
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,9 @@ class WinUtils : public OSUtilsBase, QAbstractNativeEventFilter
int m_nextShortcutId = 1;
QHash<QString, QSharedPointer<globalShortcut>> m_globalShortcuts;

bool m_darkAppThemeActive;
bool m_darkSystemThemeActive;

Q_DISABLE_COPY(WinUtils)
};

Expand Down