[plasma/union] src/platform/plasma: platform: Read the default style for the Plasma platform from KConfig

Arjen Hiemstra <[email protected]> Wed, 5 Aug 2026 11:20:05 +0000 (UTC)
Newsgroups gmane.comp.kde.cvs
Message-ID <[email protected]>
Git commit 183a736d76c37a2fdabf6351bcc35876df6c2134 by Arjen Hiemstra.
Committed on 05/08/2026 at 11:15.
Pushed by ahiemstra into branch 'master'.

platform: Read the default style for the Plasma platform from KConfig

This allows changing the style to be used by the platform dynamically.

M  +8    -1    src/platform/plasma/CMakeLists.txt
M  +38   -10   src/platform/plasma/PlasmaPlatformPlugin.cpp
M  +1    -0    src/platform/plasma/PlasmaPlatformPlugin.h
A  +18   -0    src/platform/plasma/unionsettings.kcfg

https://invent.kde.org/plasma/union/-/commit/183a736d76c37a2fdabf6351bcc35876df6c2134

diff --git a/src/platform/plasma/CMakeLists.txt b/src/platform/plasma/CMakeLists.txt
index a2d4d09d..b97bab19 100644
--- a/src/platform/plasma/CMakeLists.txt
+++ b/src/platform/plasma/CMakeLists.txt
@@ -7,7 +7,14 @@ target_sources(union-platform-plasma PRIVATE
     PlasmaPlatformPlugin.h
 )
 
-target_link_libraries(union-platform-plasma PRIVATE Union KF6::CoreAddons KF6::ConfigCore KF6::IconThemes Qt6::DBus)
+kconfig_target_kcfg_file(union-platform-plasma
+    FILE unionsettings.kcfg
+    CLASS_NAME UnionSettings
+    GENERATE_MOC
+    SINGLETON
+)
+
+target_link_libraries(union-platform-plasma PRIVATE Union KF6::CoreAddons KF6::ConfigGui KF6::IconThemes Qt6::DBus)
 
 set_target_properties(union-platform-plasma PROPERTIES
     LIBRARY_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}/bin/union
diff --git a/src/platform/plasma/PlasmaPlatformPlugin.cpp b/src/platform/plasma/PlasmaPlatformPlugin.cpp
index ed364430..b0e474fc 100644
--- a/src/platform/plasma/PlasmaPlatformPlugin.cpp
+++ b/src/platform/plasma/PlasmaPlatformPlugin.cpp
@@ -13,11 +13,14 @@
 #include <KIconColors>
 #include <KRuntimePlatform>
 
+#include "unionsettings.h"
+
 using namespace Qt::StringLiterals;
 
 PlasmaPlatformPlugin::PlasmaPlatformPlugin(QObject *parent)
     : Union::PlatformPlugin(parent)
     , m_kdeGlobalsWatcher(KConfigWatcher::create(KSharedConfig::openConfig()))
+    , m_unionSettingsWatcher(KConfigWatcher::create(UnionSettings::self()->sharedConfig()))
 {
     KConfigGroup generalCfg = KConfigGroup(KSharedConfig::openConfig(), u"KDE"_s);
     m_smoothScroll = generalCfg.readEntry(u"SmoothScroll"_s, true);
@@ -34,28 +37,53 @@ PlasmaPlatformPlugin::PlasmaPlatformPlugin(QObject *parent)
             }
         }
     });
+
+    connect(m_unionSettingsWatcher.get(), &KConfigWatcher::configChanged, this, [this](const KConfigGroup &group, const QByteArrayList &names) {
+        if (group.name() != u"General") {
+            return;
+        }
+
+        if (!names.contains("style")) {
+            return;
+        }
+
+        UnionSettings::self()->read();
+
+        sendDefaultStyleChangedEvent();
+    });
+
+    // Listen to smooth scroll changed events
+    QDBusConnection::sessionBus().connect(QString(),
+                                          QStringLiteral("/SmoothScroll"),
+                                          QStringLiteral("org.kde.SmoothScroll"),
+                                          QStringLiteral("notifyChange"),
+                                          this,
+                                          SLOT(setSmoothScroll(bool)));
 }
 
 QString PlasmaPlatformPlugin::defaultStyleName()
 {
+    auto styleName = UnionSettings::self()->style();
+
     // These values should really be queries by the CSS using media queries,
     // however those are currently unimplemented in cxx-rust-cssparser and will
     // take some time to implement. So until that time, we switch the default
     // style based on these values.
-    if (KRuntimePlatform::runtimePlatform().contains(u"phone"_s)) {
-        return u"breeze-mobile"_s;
-    }
+    if (styleName == u"breeze") {
+        if (KRuntimePlatform::runtimePlatform().contains(u"phone"_s)) {
+            return u"breeze-mobile"_s;
+        }
 
-    if (qEnvironmentVariableIsSet("QT_QUICK_CONTROLS_MOBILE")) {
-        return u"breeze-mobile"_s;
-    }
+        if (qEnvironmentVariableIsSet("QT_QUICK_CONTROLS_MOBILE")) {
+            return u"breeze-mobile"_s;
+        }
 
-    if (qGuiApp->layoutDirection() == Qt::LayoutDirection::RightToLeft) {
-        return u"breeze-rtl"_s;
+        if (qGuiApp->layoutDirection() == Qt::LayoutDirection::RightToLeft) {
+            return u"breeze-rtl"_s;
+        }
     }
 
-    // TODO: Read from config
-    return u"breeze"_s;
+    return styleName;
 }
 
 QIcon PlasmaPlatformPlugin::platformIcon(const QString &name, const QColor &color)
diff --git a/src/platform/plasma/PlasmaPlatformPlugin.h b/src/platform/plasma/PlasmaPlatformPlugin.h
index 817e5c9e..86ebee8b 100644
--- a/src/platform/plasma/PlasmaPlatformPlugin.h
+++ b/src/platform/plasma/PlasmaPlatformPlugin.h
@@ -30,4 +30,5 @@ private:
     bool m_smoothScroll = true;
     qreal m_animationSpeedMultiplier = 1.0;
     KConfigWatcher::Ptr m_kdeGlobalsWatcher;
+    KConfigWatcher::Ptr m_unionSettingsWatcher;
 };
diff --git a/src/platform/plasma/unionsettings.kcfg b/src/platform/plasma/unionsettings.kcfg
new file mode 100644
index 00000000..93b43513
--- /dev/null
+++ b/src/platform/plasma/unionsettings.kcfg
@@ -0,0 +1,18 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!--
+SPDX-License-Identifier: BSD-2-Clause
+SPDX-FileCopyrightText: 2026 Arjen Hiemstra <[email protected]>
+-->
+<kcfg xmlns="http://www.kde.org/standards/kcfg/1.0"
+      xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
+      xsi:schemaLocation="http://www.kde.org/standards/kcfg/1.0
+      http://www.kde.org/standards/kcfg/1.0/kcfg.xsd" >
+    <kcfgfile name="unionrc" />
+    <group name="General">
+        <entry name="style" type="String">
+            <default>breeze</default>
+        </entry>
+        <entry name="variants" type="StringList" />
+    </group>
+</kcfg>
+