[plasma/plasma-workspace] shell: Use KConfigWatcher instead of KDirWatch for config changes

Nicolas Fella <[email protected]>
Newsgroups gmane.comp.kde.cvs
Message-ID <[email protected]>
Git commit 414faa83a989811ef9efd304e8927364fcce8a5a by Nicolas Fella.
Committed on 23/07/2026 at 08:05.
Pushed by nicolasfella into branch 'master'.

Use KConfigWatcher instead of KDirWatch for config changes

M  +1    -0    shell/osd.cpp
M  +2    -0    shell/osd.h
M  +0    -14   shell/shellcorona.cpp
M  +0    -2    shell/shellcorona.h

https://invent.kde.org/plasma/plasma-workspace/-/commit/414faa83a989811ef9efd304e8927364fcce8a5a

diff --git a/shell/osd.cpp b/shell/osd.cpp
index d496e6f12b..a066296787 100644
--- a/shell/osd.cpp
+++ b/shell/osd.cpp
@@ -32,6 +32,7 @@ Osd::Osd(const KSharedConfig::Ptr &config, ShellCorona *corona)
     , m_corona(corona)
     , m_engine(PlasmaQuick::globalEngine())
     , m_osdConfigGroup(config, u"OSD"_s)
+    , m_configWatcher(KConfigWatcher::create(config)) // will automatically refresh m_osdConfigGroup
 {
     QDBusConnection::sessionBus().registerObject(u"/org/kde/osdService"_s, this, QDBusConnection::ExportAllSlots | QDBusConnection::ExportAllSignals);
 }
diff --git a/shell/osd.h b/shell/osd.h
index 143c3b6035..bc1071db58 100644
--- a/shell/osd.h
+++ b/shell/osd.h
@@ -12,6 +12,7 @@
 #include <QUrl>
 
 #include <KConfigGroup>
+#include <KConfigWatcher>
 #include <KSharedConfig>
 
 class QTimer;
@@ -62,6 +63,7 @@ private:
     int m_timeout = 0;
 
     KConfigGroup m_osdConfigGroup;
+    KConfigWatcher::Ptr m_configWatcher;
 
     struct ScreenBrightnessInfo {
         QString id;
diff --git a/shell/shellcorona.cpp b/shell/shellcorona.cpp
index 82a550a58b..7738db545b 100644
--- a/shell/shellcorona.cpp
+++ b/shell/shellcorona.cpp
@@ -28,7 +28,6 @@
 
 #include <KActionCollection>
 #include <KAuthorized>
-#include <KDirWatch>
 #include <KGlobalAccel>
 #include <KLocalizedString>
 #include <KMessageBox>
@@ -225,12 +224,6 @@ void ShellCorona::init()
 
     new Osd(m_config, this);
 
-    // catch when plasmarc changes, so we e.g. enable/disable the OSd
-    m_configPath = QStandardPaths::writableLocation(QStandardPaths::GenericConfigLocation) + QLatin1Char('/') + m_config->name();
-    KDirWatch::self()->addFile(m_configPath);
-    connect(KDirWatch::self(), &KDirWatch::dirty, this, &ShellCorona::configurationChanged);
-    connect(KDirWatch::self(), &KDirWatch::created, this, &ShellCorona::configurationChanged);
-
     connect(qApp, &QGuiApplication::focusWindowChanged, this, [this](QWindow *focusWindow) {
         if (!focusWindow) {
             setEditMode(false);
@@ -2924,13 +2917,6 @@ void ShellCorona::updateStruts()
     }
 }
 
-void ShellCorona::configurationChanged(const QString &path)
-{
-    if (path == m_configPath) {
-        m_config->reparseConfiguration();
-    }
-}
-
 void ShellCorona::activateLauncherMenu()
 {
     auto message = QDBusMessage::createMethodCall(u"org.kde.KWin"_s, u"/KWin"_s, u"org.kde.KWin"_s, u"activeOutputName"_s);
diff --git a/shell/shellcorona.h b/shell/shellcorona.h
index 115ad041b8..9dbfb8c3a6 100644
--- a/shell/shellcorona.h
+++ b/shell/shellcorona.h
@@ -285,7 +285,6 @@ private:
     void sanitizeScreenLayout(const QString &configFileName);
     void destroyDesktopsAndPanels();
     void updateStruts();
-    void configurationChanged(const QString &path);
     DesktopView *desktopForScreen(QScreen *screen) const;
     void setupWaylandIntegration();
     void executeSetupPlasmoidScript(Plasma::Containment *containment, Plasma::Applet *applet);
@@ -300,7 +299,6 @@ private:
 #endif
 
     KSharedConfig::Ptr m_config;
-    QString m_configPath;
 
     // Accent color setting
     KConfigWatcher::Ptr m_kdeGlobalsConfigWatcher;
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.