From 3d2edf180719e4915a8a58dc0109a5dd8eb284ea Mon Sep 17 00:00:00 2001 From: Levi Neely Date: Thu, 1 Oct 2026 09:15:31 +0200 Subject: [PATCH] Fix system theme consistency MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - In system mode, read palette from QGuiApplication::palette() rather than parsing kdeglobals (platform plugin already handles this) - Don't call setPalette() in system mode — let Qt handle it - Add isOverriding property for QML to check mode - Use Fusion style by default for consistent palette respect - Improved fallback logic in systemSchemePath() for dark/light detection - Added /etc/xdg/kdeglobals as fallback for system-wide defaults --- ui/qml/Main.qml | 3 ++- ui/src/main.cpp | 6 +++++ ui/src/thememanager.cpp | 57 +++++++++++++++++++++++++++++++++++------ ui/src/thememanager.h | 2 ++ 4 files changed, 59 insertions(+), 9 deletions(-) diff --git a/ui/qml/Main.qml b/ui/qml/Main.qml index 013170a..0c37888 100644 --- a/ui/qml/Main.qml +++ b/ui/qml/Main.qml @@ -13,7 +13,8 @@ ApplicationWindow { font.family: theme.fontFamily || Qt.application.font.family font.pointSize: theme.fontSize > 0 ? theme.fontSize : Qt.application.font.pointSize - // Apply theme palette to Qt Quick Controls + // Apply theme palette to Qt Quick Controls. + // theme.* colors return system palette when mode="system", override colors otherwise. palette.active.window: theme.windowColor palette.active.windowText: theme.windowTextColor palette.active.base: theme.baseColor diff --git a/ui/src/main.cpp b/ui/src/main.cpp index 5e1cde0..1fd303b 100644 --- a/ui/src/main.cpp +++ b/ui/src/main.cpp @@ -55,6 +55,12 @@ static void dumpModel(const DocumentModel &m, const QModelIndex &parent, int dep } int main(int argc, char *argv[]) { + // Use Fusion style for consistent cross-platform look that respects palette + // This can be overridden with QT_QUICK_CONTROLS_STYLE env var + if (qEnvironmentVariableIsEmpty("QT_QUICK_CONTROLS_STYLE")) { + qputenv("QT_QUICK_CONTROLS_STYLE", "Fusion"); + } + QGuiApplication app(argc, argv); app.setApplicationName("orkmode"); app.setOrganizationName("orkmode"); diff --git a/ui/src/thememanager.cpp b/ui/src/thememanager.cpp index 11c2153..e97734d 100644 --- a/ui/src/thememanager.cpp +++ b/ui/src/thememanager.cpp @@ -54,22 +54,34 @@ QStringList ThemeManager::availableSchemes() const bool ThemeManager::isDark() const { - QColor bg = m_palette.color(QPalette::Window); + // Use the stored palette (which reflects system or override) + QColor bg = m_palette.color(QPalette::Active, QPalette::Window); + // If palette not yet loaded, fall back to app palette + if (!bg.isValid()) + bg = QGuiApplication::palette().color(QPalette::Window); qreal luminance = 0.2126 * bg.redF() + 0.7152 * bg.greenF() + 0.0722 * bg.blueF(); return luminance < 0.5; } +bool ThemeManager::isOverriding() const +{ + return m_mode != "system"; +} + void ThemeManager::applyPalette() { - QString path; if (m_mode == "system") { - path = systemSchemePath(); - } else { - path = schemePath(m_mode); + // Don't override — let the platform theme (KDE, GNOME, etc.) handle it + // Just read the current system palette + m_palette = QGuiApplication::palette(); + return; } + + // Mode is a specific scheme name + QString path = schemePath(m_mode); if (path.isEmpty() || !QFile::exists(path)) { - // Fallback to application default palette + // Fallback: don't override m_palette = QGuiApplication::palette(); return; } @@ -297,10 +309,12 @@ QColor ThemeManager::parseColor(const QVariant &value) const QString ThemeManager::systemSchemePath() const { - // Try to read from kdeglobals + // Try to read from kdeglobals - KDE's config format QString kdeglobals = QDir::homePath() + "/.config/kdeglobals"; if (QFile::exists(kdeglobals)) { QSettings settings(kdeglobals, QSettings::IniFormat); + + // KDE stores ColorScheme in [General] section settings.beginGroup("General"); QString schemeName = settings.value("ColorScheme").toString(); settings.endGroup(); @@ -312,7 +326,34 @@ QString ThemeManager::systemSchemePath() const } } - // Fallback to BreezeLight + // Also check kdedefaults for system-wide default + QString kdedefaults = "/etc/xdg/kdeglobals"; + if (QFile::exists(kdedefaults)) { + QSettings settings(kdedefaults, QSettings::IniFormat); + settings.beginGroup("General"); + QString schemeName = settings.value("ColorScheme").toString(); + settings.endGroup(); + + if (!schemeName.isEmpty()) { + QString path = schemePath(schemeName); + if (QFile::exists(path)) + return path; + } + } + + // Last resort: check what Qt's platform plugin thinks + // by examining the application palette's window color + QPalette sysPal = QGuiApplication::palette(); + QColor windowBg = sysPal.color(QPalette::Window); + qreal luminance = 0.2126 * windowBg.redF() + 0.7152 * windowBg.greenF() + 0.0722 * windowBg.blueF(); + + // If system palette is dark, try BreezeDark, else BreezeLight + if (luminance < 0.5) { + QString darkPath = schemePath("BreezeDark"); + if (QFile::exists(darkPath)) + return darkPath; + } + return schemePath("BreezeLight"); } diff --git a/ui/src/thememanager.h b/ui/src/thememanager.h index b56f13f..d8cccf6 100644 --- a/ui/src/thememanager.h +++ b/ui/src/thememanager.h @@ -22,6 +22,7 @@ class ThemeManager : public QObject Q_PROPERTY(QString mode READ mode WRITE setMode NOTIFY modeChanged) Q_PROPERTY(QStringList availableSchemes READ availableSchemes CONSTANT) Q_PROPERTY(bool isDark READ isDark NOTIFY paletteChanged) + Q_PROPERTY(bool isOverriding READ isOverriding NOTIFY paletteChanged) // Palette colors for QML Q_PROPERTY(QColor windowColor READ windowColor NOTIFY paletteChanged) @@ -71,6 +72,7 @@ public: void setMode(const QString &mode); QStringList availableSchemes() const; bool isDark() const; + bool isOverriding() const; // Palette colors QColor windowColor() const;