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.icc-effect-5.14.5
parent
8b1040f78d
commit
d3c4a46c59
|
@ -49,6 +49,7 @@ target_link_libraries( testClientMachine
|
|||
Qt5::Test
|
||||
Qt5::X11Extras
|
||||
Qt5::Widgets
|
||||
KF5::ConfigCore
|
||||
KF5::WindowSystem
|
||||
XCB::XCB
|
||||
XCB::XFIXES
|
||||
|
|
25
cursor.cpp
25
cursor.cpp
|
@ -24,6 +24,9 @@ along with this program. If not, see <http://www.gnu.org/licenses/>.
|
|||
#include "input.h"
|
||||
#include "main.h"
|
||||
#include "utils.h"
|
||||
// KDE
|
||||
#include <KDE/KConfig>
|
||||
#include <KDE/KConfigGroup>
|
||||
// Qt
|
||||
#include <QTimer>
|
||||
// Xlib
|
||||
|
@ -53,7 +56,13 @@ Cursor::Cursor(QObject *parent)
|
|||
: QObject(parent)
|
||||
, m_mousePollingCounter(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()
|
||||
|
@ -61,6 +70,18 @@ Cursor::~Cursor()
|
|||
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()
|
||||
{
|
||||
s_self->doGetPos();
|
||||
|
@ -269,9 +290,7 @@ xcb_cursor_t X11Cursor::createCursor(Qt::CursorShape shape)
|
|||
return XCB_CURSOR_NONE;
|
||||
}
|
||||
// XCursor is an XLib only lib
|
||||
const char *theme = XcursorGetTheme(display());
|
||||
const int size = XcursorGetDefaultSize(display());
|
||||
XcursorImage *ximg = XcursorLibraryLoadImage(name.constData(), theme, size);
|
||||
XcursorImage *ximg = XcursorLibraryLoadImage(name.constData(), themeName().toUtf8().constData(), themeSize());
|
||||
if (!ximg) {
|
||||
return XCB_CURSOR_NONE;
|
||||
}
|
||||
|
|
29
cursor.h
29
cursor.h
|
@ -87,6 +87,19 @@ public:
|
|||
*/
|
||||
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
|
||||
* needed. It's save to call it multiple times.
|
||||
|
@ -117,6 +130,7 @@ Q_SIGNALS:
|
|||
* @see stopCursorTracking
|
||||
*/
|
||||
void cursorChanged(uint32_t serial);
|
||||
void themeChanged();
|
||||
|
||||
protected:
|
||||
/**
|
||||
|
@ -167,10 +181,15 @@ protected:
|
|||
void updatePos(const QPoint &pos);
|
||||
void updatePos(int x, int y);
|
||||
|
||||
private Q_SLOTS:
|
||||
void loadThemeSettings();
|
||||
|
||||
private:
|
||||
QPoint m_pos;
|
||||
int m_mousePollingCounter;
|
||||
int m_cursorTrackingCounter;
|
||||
QString m_themeName;
|
||||
int m_themeSize;
|
||||
|
||||
KWIN_SINGLETON(Cursor)
|
||||
};
|
||||
|
@ -244,6 +263,16 @@ inline void Cursor::updatePos(int x, int 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
|
||||
|
|
Loading…
Reference in New Issue