diff --git a/cursor.cpp b/cursor.cpp
index cdd6c85de6..1207483313 100644
--- a/cursor.cpp
+++ b/cursor.cpp
@@ -30,6 +30,7 @@ along with this program. If not, see .
#include
#include
// Qt
+#include
#include
// Xlib
#include
@@ -64,9 +65,8 @@ Cursor::Cursor(QObject *parent)
, m_themeSize(24)
{
loadThemeSettings();
- // TODO: we need to connect for cursor theme changes
- // in KDE4 times this was done through KGlobaSettings::cursorChanged
- // which got emitted from the cursors KCM, this needs porting
+ QDBusConnection::sessionBus().connect(QString(), QStringLiteral("/KGlobalSettings"), QStringLiteral("org.kde.KGlobalSettings"),
+ QStringLiteral("notifyChange"), this, SLOT(slotKGlobalSettingsNotifyChange(int,int)));
}
Cursor::~Cursor()
@@ -84,10 +84,15 @@ void Cursor::loadThemeSettings()
return;
}
// didn't get from environment variables, read from config file
+ loadThemeFromKConfig();
+}
+
+void Cursor::loadThemeFromKConfig()
+{
KConfigGroup mousecfg(KSharedConfig::openConfig("kcminputrc", KConfig::NoGlobals), "Mouse");
- themeName = mousecfg.readEntry("cursorTheme", "default");
- ok = false;
- themeSize = mousecfg.readEntry("cursorSize", QString("24")).toUInt(&ok);
+ const QString themeName = mousecfg.readEntry("cursorTheme", "default");
+ bool ok = false;
+ uint themeSize = mousecfg.readEntry("cursorSize", QString("24")).toUInt(&ok);
if (!ok) {
themeSize = 24;
}
@@ -103,6 +108,17 @@ void Cursor::updateTheme(const QString &name, int size)
}
}
+void Cursor::slotKGlobalSettingsNotifyChange(int type, int arg)
+{
+ Q_UNUSED(arg)
+ if (type == 5 /*CursorChanged*/) {
+ loadThemeFromKConfig();
+ // sync to environment
+ qputenv("XCURSOR_THEME", m_themeName.toUtf8());
+ qputenv("XCURSOR_SIZE", QByteArray::number(m_themeSize));
+ }
+}
+
QPoint Cursor::pos()
{
s_self->doGetPos();
@@ -224,6 +240,8 @@ X11Cursor::X11Cursor(QObject *parent)
// TODO: How often do we really need to poll?
m_mousePollingTimer->setInterval(50);
connect(m_mousePollingTimer, SIGNAL(timeout()), SLOT(mousePolled()));
+
+ connect(this, &Cursor::themeChanged, this, [this] { m_cursors.clear(); });
}
X11Cursor::~X11Cursor()
diff --git a/cursor.h b/cursor.h
index 3df0f21d21..4bb3a3c1dd 100644
--- a/cursor.h
+++ b/cursor.h
@@ -190,9 +190,11 @@ protected:
private Q_SLOTS:
void loadThemeSettings();
+ void slotKGlobalSettingsNotifyChange(int type, int arg);
private:
void updateTheme(const QString &name, int size);
+ void loadThemeFromKConfig();
QPoint m_pos;
int m_mousePollingCounter;
int m_cursorTrackingCounter;