From 7dc2baf74d67761ecee579af26a1b80ba7daa92c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Martin=20Gr=C3=A4=C3=9Flin?= Date: Thu, 8 Jan 2015 17:03:25 +0100 Subject: [PATCH] Update cursor theme when it changes at runtime Connecting to the DBus signal emitted on KGlobalAccels by the cursor kcm and forcing a reload of all cursors. For runtime config change we need to take the config value and need to ignore the now outdated environment variables. REVIEW: 121928 BUG: 325763 FIXED-IN: 5.2.0 --- cursor.cpp | 30 ++++++++++++++++++++++++------ cursor.h | 2 ++ 2 files changed, 26 insertions(+), 6 deletions(-) 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;