From 4f94d09258b6207f41ce2d520236d02f90cc6329 Mon Sep 17 00:00:00 2001 From: Juraj Oravec Date: Tue, 17 Dec 2024 23:41:09 +0100 Subject: [PATCH] Add "Preffer color scheme" option BUG: 439891 CCBUG: 497331 Signed-off-by: Juraj Oravec --- src/lib/app/mainapplication.cpp | 38 +++++++++++++++++++++++------ src/lib/app/mainapplication.h | 2 ++ src/lib/app/qzcommon.h | 6 +++++ src/lib/preferences/preferences.cpp | 15 ++++++++++++ src/lib/preferences/preferences.ui | 29 +++++++++++++++++++++- 5 files changed, 81 insertions(+), 9 deletions(-) diff --git a/src/lib/app/mainapplication.cpp b/src/lib/app/mainapplication.cpp index 3bac9e3d9..8e260e2c9 100644 --- a/src/lib/app/mainapplication.cpp +++ b/src/lib/app/mainapplication.cpp @@ -67,6 +67,8 @@ #include #include #include +#include +#include #include #include @@ -149,10 +151,6 @@ MainApplication::MainApplication(int &argc, char** argv) } #endif - QByteArray chromium_flags = qgetenv("QTWEBENGINE_CHROMIUM_FLAGS"); - chromium_flags.append(" --enable-features=WebRTCPipeWireCapturer"); - qputenv("QTWEBENGINE_CHROMIUM_FLAGS", chromium_flags); - QUrl startUrl; QString startProfile; QStringList messages; @@ -287,11 +285,8 @@ MainApplication::MainApplication(int &argc, char** argv) profileManager.initCurrentProfile(startProfile); Settings::createSettings(DataPaths::currentProfilePath() + QLatin1String("/settings.ini")); - if (Settings::globalSettings()->value("Web-Browser-Settings/hardwareAccel", false).toBool()) { - chromium_flags.append(" --enable-oop-rasterization --enable-gpu-rasterization --enable-native-gpu-memory-buffers --use-gl=desktop"); - qputenv("QTWEBENGINE_CHROMIUM_FLAGS", chromium_flags); - } + setChromiumFlags(); NetworkManager::registerSchemes(); registerAllowedSchemes(); @@ -412,6 +407,33 @@ MainApplication::~MainApplication() Settings::syncSettings(); } +void MainApplication::setChromiumFlags() +{ + QByteArray chromium_flags = qgetenv("QTWEBENGINE_CHROMIUM_FLAGS"); + chromium_flags.append(" --enable-features=WebRTCPipeWireCapturer"); + + if (Settings::globalSettings()->value("Web-Browser-Settings/hardwareAccel", false).toBool()) { + chromium_flags.append(" --enable-oop-rasterization --enable-gpu-rasterization --enable-native-gpu-memory-buffers --use-gl=desktop"); + } + + int prefferColorScheme = Settings::globalSettings()->value("Web-Browser-Settings/prefferColorScheme", Qz::ColorScheme_Auto).toInt(); + if ( (prefferColorScheme == Qz::ColorScheme_Dark) +#if QTGUI_VERSION >= QT_VERSION_CHECK(6, 5, 0) + || ((prefferColorScheme == Qz::ColorScheme_Auto) && (styleHints()->colorScheme() == Qt::ColorScheme::Dark)) +#endif + ) { + chromium_flags.append(" --blink-settings=preferredColorScheme=0"); + } + else if ((prefferColorScheme == Qz::ColorScheme_Light) +#if QTGUI_VERSION >= QT_VERSION_CHECK(6, 5, 0) + || ((prefferColorScheme == Qz::ColorScheme_Auto) && (styleHints()->colorScheme() == Qt::ColorScheme::Light)) +#endif + ) { + chromium_flags.append(" --blink-settings=preferredColorScheme=1"); + } + qputenv("QTWEBENGINE_CHROMIUM_FLAGS", chromium_flags); +} + bool MainApplication::isClosing() const { return m_isClosing; diff --git a/src/lib/app/mainapplication.h b/src/lib/app/mainapplication.h index 87e2d6415..f55201c8c 100644 --- a/src/lib/app/mainapplication.h +++ b/src/lib/app/mainapplication.h @@ -71,6 +71,8 @@ public: explicit MainApplication(int &argc, char** argv); ~MainApplication(); + void setChromiumFlags(); + bool isClosing() const; bool isPrivate() const; bool isPortable() const; diff --git a/src/lib/app/qzcommon.h b/src/lib/app/qzcommon.h index 3d43426ca..b2a8e192c 100644 --- a/src/lib/app/qzcommon.h +++ b/src/lib/app/qzcommon.h @@ -111,6 +111,12 @@ enum NewTabPositionFlag { Q_DECLARE_FLAGS(NewTabPositionFlags, NewTabPositionFlag) Q_DECLARE_OPERATORS_FOR_FLAGS(Qz::NewTabPositionFlags) +enum ColorScheme { + ColorScheme_Auto = 0, + ColorScheme_Light, + ColorScheme_Dark +}; + } #if defined(Q_OS_WIN) || defined(Q_OS_OS2) diff --git a/src/lib/preferences/preferences.cpp b/src/lib/preferences/preferences.cpp index d8d58c329..df59d5fa5 100644 --- a/src/lib/preferences/preferences.cpp +++ b/src/lib/preferences/preferences.cpp @@ -63,6 +63,7 @@ #include #include #include +#include static QString createLanguageItem(const QString &lang) { @@ -308,6 +309,19 @@ Preferences::Preferences(BrowserWindow* window) ui->forceDarkMode->hide(); #endif + int prefferColorSchemeSetting = settings.value(QSL("prefferColorScheme"), Qz::ColorScheme_Auto).toInt(); +#if QTGUI_VERSION >= QT_VERSION_CHECK(6, 5, 0) + ui->prefferColorScheme->addItem(tr("Auto"), Qz::ColorScheme_Auto); +#endif + ui->prefferColorScheme->addItem(tr("Light"), Qz::ColorScheme_Light); + ui->prefferColorScheme->addItem(tr("Dark"), Qz::ColorScheme_Dark); +#if QTGUI_VERSION < QT_VERSION_CHECK(6, 5, 0) + if (prefferColorSchemeSetting > 0) { + prefferColorSchemeSetting--; + } +#endif + ui->prefferColorScheme->setCurrentIndex(prefferColorSchemeSetting); + const auto levels = WebView::zoomLevels(); for (int level : levels) { ui->defaultZoomLevel->addItem(tr("%1%").arg(QString::number(level))); @@ -1016,6 +1030,7 @@ void Preferences::saveSettings() #if QTWEBENGINECORE_VERSION >= QT_VERSION_CHECK(6, 7, 0) settings.setValue(QSL("forceDarkMode"), ui->forceDarkMode->isChecked()); #endif + settings.setValue(QSL("prefferColorScheme"), ui->prefferColorScheme->currentData().toInt()); #ifdef Q_OS_WIN settings.setValue(QSL("CheckDefaultBrowser"), ui->checkDefaultBrowser->isChecked()); #endif diff --git a/src/lib/preferences/preferences.ui b/src/lib/preferences/preferences.ui index 761ae62f2..f208c2644 100644 --- a/src/lib/preferences/preferences.ui +++ b/src/lib/preferences/preferences.ui @@ -160,7 +160,7 @@ 0 0 783 - 651 + 723 @@ -1145,6 +1145,33 @@ + + + + + + Preffer color scheme: + + + + + + + + + + Qt::Horizontal + + + + 40 + 20 + + + + + +