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
This commit is contained in:
Martin Gräßlin 2015-01-08 17:03:25 +01:00
parent ab4b1ba25a
commit 7dc2baf74d
2 changed files with 26 additions and 6 deletions

View file

@ -30,6 +30,7 @@ along with this program. If not, see <http://www.gnu.org/licenses/>.
#include <KConfigGroup> #include <KConfigGroup>
#include <KSharedConfig> #include <KSharedConfig>
// Qt // Qt
#include <QDBusConnection>
#include <QTimer> #include <QTimer>
// Xlib // Xlib
#include <X11/Xcursor/Xcursor.h> #include <X11/Xcursor/Xcursor.h>
@ -64,9 +65,8 @@ Cursor::Cursor(QObject *parent)
, m_themeSize(24) , m_themeSize(24)
{ {
loadThemeSettings(); loadThemeSettings();
// TODO: we need to connect for cursor theme changes QDBusConnection::sessionBus().connect(QString(), QStringLiteral("/KGlobalSettings"), QStringLiteral("org.kde.KGlobalSettings"),
// in KDE4 times this was done through KGlobaSettings::cursorChanged QStringLiteral("notifyChange"), this, SLOT(slotKGlobalSettingsNotifyChange(int,int)));
// which got emitted from the cursors KCM, this needs porting
} }
Cursor::~Cursor() Cursor::~Cursor()
@ -84,10 +84,15 @@ void Cursor::loadThemeSettings()
return; return;
} }
// didn't get from environment variables, read from config file // didn't get from environment variables, read from config file
loadThemeFromKConfig();
}
void Cursor::loadThemeFromKConfig()
{
KConfigGroup mousecfg(KSharedConfig::openConfig("kcminputrc", KConfig::NoGlobals), "Mouse"); KConfigGroup mousecfg(KSharedConfig::openConfig("kcminputrc", KConfig::NoGlobals), "Mouse");
themeName = mousecfg.readEntry("cursorTheme", "default"); const QString themeName = mousecfg.readEntry("cursorTheme", "default");
ok = false; bool ok = false;
themeSize = mousecfg.readEntry("cursorSize", QString("24")).toUInt(&ok); uint themeSize = mousecfg.readEntry("cursorSize", QString("24")).toUInt(&ok);
if (!ok) { if (!ok) {
themeSize = 24; 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() QPoint Cursor::pos()
{ {
s_self->doGetPos(); s_self->doGetPos();
@ -224,6 +240,8 @@ X11Cursor::X11Cursor(QObject *parent)
// TODO: How often do we really need to poll? // TODO: How often do we really need to poll?
m_mousePollingTimer->setInterval(50); m_mousePollingTimer->setInterval(50);
connect(m_mousePollingTimer, SIGNAL(timeout()), SLOT(mousePolled())); connect(m_mousePollingTimer, SIGNAL(timeout()), SLOT(mousePolled()));
connect(this, &Cursor::themeChanged, this, [this] { m_cursors.clear(); });
} }
X11Cursor::~X11Cursor() X11Cursor::~X11Cursor()

View file

@ -190,9 +190,11 @@ protected:
private Q_SLOTS: private Q_SLOTS:
void loadThemeSettings(); void loadThemeSettings();
void slotKGlobalSettingsNotifyChange(int type, int arg);
private: private:
void updateTheme(const QString &name, int size); void updateTheme(const QString &name, int size);
void loadThemeFromKConfig();
QPoint m_pos; QPoint m_pos;
int m_mousePollingCounter; int m_mousePollingCounter;
int m_cursorTrackingCounter; int m_cursorTrackingCounter;