Track used cursor theme and size in Cursor

Reads the settings from kcminputrc. Unfortunately there is no update when
the settings change. This needs fixing in the cursors KCM first.
This commit is contained in:
Martin Gräßlin 2013-06-27 09:06:16 +02:00
parent 8b1040f78d
commit d3c4a46c59
3 changed files with 52 additions and 3 deletions

View file

@ -49,6 +49,7 @@ target_link_libraries( testClientMachine
Qt5::Test Qt5::Test
Qt5::X11Extras Qt5::X11Extras
Qt5::Widgets Qt5::Widgets
KF5::ConfigCore
KF5::WindowSystem KF5::WindowSystem
XCB::XCB XCB::XCB
XCB::XFIXES XCB::XFIXES

View file

@ -24,6 +24,9 @@ along with this program. If not, see <http://www.gnu.org/licenses/>.
#include "input.h" #include "input.h"
#include "main.h" #include "main.h"
#include "utils.h" #include "utils.h"
// KDE
#include <KDE/KConfig>
#include <KDE/KConfigGroup>
// Qt // Qt
#include <QTimer> #include <QTimer>
// Xlib // Xlib
@ -53,7 +56,13 @@ Cursor::Cursor(QObject *parent)
: QObject(parent) : QObject(parent)
, m_mousePollingCounter(0) , m_mousePollingCounter(0)
, m_cursorTrackingCounter(0) , m_cursorTrackingCounter(0)
, m_themeName("default")
, 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
} }
Cursor::~Cursor() Cursor::~Cursor()
@ -61,6 +70,18 @@ Cursor::~Cursor()
s_self = NULL; s_self = NULL;
} }
void Cursor::loadThemeSettings()
{
KConfigGroup mousecfg(KSharedConfig::openConfig("kcminputrc", KConfig::NoGlobals), "Mouse");
m_themeName = mousecfg.readEntry("cursorTheme", "default");
bool ok = false;
m_themeSize = mousecfg.readEntry("cursorSize", QString("24")).toUInt(&ok);
if (!ok) {
m_themeSize = 24;
}
emit themeChanged();
}
QPoint Cursor::pos() QPoint Cursor::pos()
{ {
s_self->doGetPos(); s_self->doGetPos();
@ -269,9 +290,7 @@ xcb_cursor_t X11Cursor::createCursor(Qt::CursorShape shape)
return XCB_CURSOR_NONE; return XCB_CURSOR_NONE;
} }
// XCursor is an XLib only lib // XCursor is an XLib only lib
const char *theme = XcursorGetTheme(display()); XcursorImage *ximg = XcursorLibraryLoadImage(name.constData(), themeName().toUtf8().constData(), themeSize());
const int size = XcursorGetDefaultSize(display());
XcursorImage *ximg = XcursorLibraryLoadImage(name.constData(), theme, size);
if (!ximg) { if (!ximg) {
return XCB_CURSOR_NONE; return XCB_CURSOR_NONE;
} }

View file

@ -87,6 +87,19 @@ public:
*/ */
void notifyCursorChanged(uint32_t serial); void notifyCursorChanged(uint32_t serial);
/**
* @brief The name of the currently used Cursor theme.
*
* @return const QString&
*/
const QString &themeName() const;
/**
* @brief The size of the currently used Cursor theme.
*
* @return int
*/
int themeSize() const;
/** /**
* Returns the current cursor position. This method does an update of the mouse position if * Returns the current cursor position. This method does an update of the mouse position if
* needed. It's save to call it multiple times. * needed. It's save to call it multiple times.
@ -117,6 +130,7 @@ Q_SIGNALS:
* @see stopCursorTracking * @see stopCursorTracking
*/ */
void cursorChanged(uint32_t serial); void cursorChanged(uint32_t serial);
void themeChanged();
protected: protected:
/** /**
@ -167,10 +181,15 @@ protected:
void updatePos(const QPoint &pos); void updatePos(const QPoint &pos);
void updatePos(int x, int y); void updatePos(int x, int y);
private Q_SLOTS:
void loadThemeSettings();
private: private:
QPoint m_pos; QPoint m_pos;
int m_mousePollingCounter; int m_mousePollingCounter;
int m_cursorTrackingCounter; int m_cursorTrackingCounter;
QString m_themeName;
int m_themeSize;
KWIN_SINGLETON(Cursor) KWIN_SINGLETON(Cursor)
}; };
@ -244,6 +263,16 @@ inline void Cursor::updatePos(int x, int y)
updatePos(QPoint(x, y)); updatePos(QPoint(x, y));
} }
inline const QString& Cursor::themeName() const
{
return m_themeName;
}
inline int Cursor::themeSize() const
{
return m_themeSize;
}
} }
#endif // KWIN_CURSOR_H #endif // KWIN_CURSOR_H