Skip to content

Commit

Permalink
Use Qt 6.5 styleHint colorScheme to detect dark theme
Browse files Browse the repository at this point in the history
- keep linux compatibility

WE2-826

Signed-off-by: Raul Metsma <[email protected]>
  • Loading branch information
metsma committed Feb 26, 2024
1 parent 3f09869 commit a8edd3f
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 16 deletions.
16 changes: 7 additions & 9 deletions src/controller/application.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@
#include <QPalette>
#include <QProcess>
#include <QSettings>
#include <QStyleHints>
#include <QTranslator>

inline CommandWithArguments::second_type parseArgumentJson(const QString& argumentStr)
Expand Down Expand Up @@ -74,19 +75,17 @@ Application::Application(int& argc, char** argv, const QString& name) :
#endif
}

#ifndef Q_OS_MAC
bool Application::isDarkTheme()
{
#ifdef Q_OS_WIN
QSettings settings(
"HKEY_CURRENT_USER\\Software\\Microsoft\\Windows\\CurrentVersion\\Themes\\Personalize",
QSettings::NativeFormat);
return settings.value("AppsUseLightTheme", 1).toInt() == 0;
#if QT_VERSION >= QT_VERSION_CHECK(6, 5, 0)
return styleHints()->colorScheme() == Qt::ColorScheme::Dark;
#else
// There is currently no straightforward way to detect dark mode in Linux, but this works for supported OS-s.
// There is currently no straightforward way to detect dark mode in Linux, but this works for
// supported OS-s.
static const bool isDarkTheme = [] {
QProcess p;
p.start(QStringLiteral("gsettings"), {"get", "org.gnome.desktop.interface", "color-scheme"});
p.start(QStringLiteral("gsettings"),
{"get", "org.gnome.desktop.interface", "color-scheme"});
if (p.waitForFinished()) {
return p.readAllStandardOutput().contains("dark");
}
Expand All @@ -97,7 +96,6 @@ bool Application::isDarkTheme()
return isDarkTheme;
#endif
}
#endif

void Application::loadTranslations(const QString& lang)
{
Expand Down
7 changes: 0 additions & 7 deletions src/controller/application.mm
Original file line number Diff line number Diff line change
Expand Up @@ -27,13 +27,6 @@
#import <AppKit/AppKit.h>
#import <Cocoa/Cocoa.h>

bool Application::isDarkTheme()
{
auto appearance = [NSApp.effectiveAppearance bestMatchFromAppearancesWithNames:
@[ NSAppearanceNameAqua, NSAppearanceNameDarkAqua ]];
return [appearance isEqualToString:NSAppearanceNameDarkAqua];
}

void Application::showAbout()
{
NSLog(@"web-eid-app: starting app");
Expand Down

0 comments on commit a8edd3f

Please sign in to comment.