@@ -27,7 +27,7 @@ CursorImageProvider *CursorImageProvider::m_instance = nullptr;
28// BuiltInCursorImage
28// BuiltInCursorImage
30−BuiltInCursorImage::BuiltInCursorImage()
30+BuiltInCursorImage::BuiltInCursorImage(int cursorHeight)
32 const char *svgString =
32 const char *svgString =
33 "<?xml version=\"1.0\" encoding=\"UTF-8\" standalone=\"no\"?>"
33 "<?xml version=\"1.0\" encoding=\"UTF-8\" standalone=\"no\"?>"
@@ -42,12 +42,14 @@ BuiltInCursorImage::BuiltInCursorImage()
42 " d=\"M 20.504,50.94931 460.42533,518.14486 266.47603,515.61948 366.48114,719.16522 274.05218,770.68296 172.53185,559.56112 20.504,716.13476 Z\" />"
42 " d=\"M 20.504,50.94931 460.42533,518.14486 266.47603,515.61948 366.48114,719.16522 274.05218,770.68296 172.53185,559.56112 20.504,716.13476 Z\" />"
45+ // NB: Original image dimension is 20x32. Ensure aspect ratio is kept
45− qimage = QImage(20, 32, QImage::Format_ARGB32);
46+ qimage = QImage((20./32.)*cursorHeight, cursorHeight, QImage::Format_ARGB32);
46 qimage.fill(Qt::transparent);
47 qimage.fill(Qt::transparent);
47 QPainter imagePainter(&qimage);
48 QPainter imagePainter(&qimage);
49 frameWidth = qimage.width();
50 frameWidth = qimage.width();
50 frameHeight = qimage.height();
51 frameHeight = qimage.height();
52+ requestedHeight = cursorHeight;
52 QSvgRenderer *svgRenderer = new QSvgRenderer(QByteArray(svgString));
54 QSvgRenderer *svgRenderer = new QSvgRenderer(QByteArray(svgString));
53 svgRenderer->render(&imagePainter);
55 svgRenderer->render(&imagePainter);
@@ -81,11 +83,9 @@ CustomCursorImage::CustomCursorImage(const QCursor &cursor)
82// XCursorImage
84// XCursorImage
84−XCursorImage::XCursorImage(const QString &theme, const QString &file)
86+XCursorImage::XCursorImage(const QString &theme, const QString &file, int preferredCursorHeightPx)
86− // TODO: Consider grid unit value
87− // Hardcoding to a medium size for now
88− int preferredCursorHeightPx = 32;
88+ requestedHeight = preferredCursorHeightPx;
90 XcursorImages *xcursorImages = XcursorLibraryLoadImages(QFile::encodeName(file), QFile::encodeName(theme),
90 XcursorImages *xcursorImages = XcursorLibraryLoadImages(QFile::encodeName(file), QFile::encodeName(theme),
91 preferredCursorHeightPx);
91 preferredCursorHeightPx);
@@ -96,7 +96,7 @@ XCursorImage::XCursorImage(const QString &theme, const QString &file)
96 frameCount = xcursorImages->nimage;
96 frameCount = xcursorImages->nimage;
98 for (int i = 0; i < xcursorImages->nimage; ++i) {
98 for (int i = 0; i < xcursorImages->nimage; ++i) {
99− XcursorImage *xcursorImage = xcursorImages->images[0];
99+ XcursorImage *xcursorImage = xcursorImages->images[i];
100 if (frameWidth < (int)xcursorImage->width) {
100 if (frameWidth < (int)xcursorImage->width) {
101 frameWidth = xcursorImage->width;
101 frameWidth = xcursorImage->width;
@@ -235,34 +235,43 @@ CursorImageProvider::~CursorImageProvider()
235 m_instance = nullptr;
235 m_instance = nullptr;
238−QImage CursorImageProvider::requestImage(const QString &cursorThemeAndName, QSize *size, const QSize & /*requestedSize*/)
238+QImage CursorImageProvider::requestImage(const QString &cursorThemeAndNameAndHeight, QSize *size, const QSize & /*requestedSize*/)
240− CursorImage *cursorImage = fetchCursor(cursorThemeAndName);
240+ CursorImage *cursorImage = fetchCursor(cursorThemeAndNameAndHeight);
241 size->setWidth(cursorImage->qimage.width());
241 size->setWidth(cursorImage->qimage.width());
242 size->setHeight(cursorImage->qimage.height());
242 size->setHeight(cursorImage->qimage.height());
244 return cursorImage->qimage;
244 return cursorImage->qimage;
247−CursorImage *CursorImageProvider::fetchCursor(const QString &cursorThemeAndName)
247+CursorImage *CursorImageProvider::fetchCursor(const QString &cursorThemeAndNameAndHeight)
249 QString themeName;
249 QString themeName;
250 QString cursorName;
250 QString cursorName;
252− QStringList themeAndNameList = cursorThemeAndName.split('/');
253+ QStringList themeAndNameList = cursorThemeAndNameAndHeight.split('/');
253− if (themeAndNameList.size() != 2) {
254+ if (themeAndNameList.size() != 3) {
254 return nullptr;
255 return nullptr;
256 themeName = themeAndNameList[0];
257 themeName = themeAndNameList[0];
257 cursorName = themeAndNameList[1];
258 cursorName = themeAndNameList[1];
261+ cursorHeight = themeAndNameList[2].toInt(&ok);
264+ qWarning().nospace() << "CursorImageProvider: invalid cursor height ("<<themeAndNameList[2]<<")."
265+ " Falling back to "<<cursorHeight<<" pixels";
260− return fetchCursor(themeName, cursorName);
269+ return fetchCursor(themeName, cursorName, cursorHeight);
263−CursorImage *CursorImageProvider::fetchCursor(const QString &themeName, const QString &cursorName)
272+CursorImage *CursorImageProvider::fetchCursor(const QString &themeName, const QString &cursorName, int cursorHeight)
265− CursorImage *cursorImage = fetchCursorHelper(themeName, cursorName);
274+ CursorImage *cursorImage = fetchCursorHelper(themeName, cursorName, cursorHeight);
267 // Try some fallbacks
276 // Try some fallbacks
268 if (cursorImage->qimage.isNull()) {
277 if (cursorImage->qimage.isNull()) {
@@ -271,7 +280,7 @@ CursorImage *CursorImageProvider::fetchCursor(const QString &themeName, const QS
271 int i = 0;
280 int i = 0;
272 while (cursorImage->qimage.isNull() && i < fallbackNames.count()) {
281 while (cursorImage->qimage.isNull() && i < fallbackNames.count()) {
273 qDebug().nospace() << "CursorImageProvider: "<< cursorName <<" not found, trying " << fallbackNames.at(i);
282 qDebug().nospace() << "CursorImageProvider: "<< cursorName <<" not found, trying " << fallbackNames.at(i);
274− cursorImage = fetchCursorHelper(themeName, fallbackNames.at(i));
283+ cursorImage = fetchCursorHelper(themeName, fallbackNames.at(i), cursorHeight);
@@ -281,14 +290,14 @@ CursorImage *CursorImageProvider::fetchCursor(const QString &themeName, const QS
281 if (cursorImage->qimage.isNull() && cursorName != QLatin1String("left_ptr")) {
290 if (cursorImage->qimage.isNull() && cursorName != QLatin1String("left_ptr")) {
282 qDebug() << "CursorImageProvider:" << cursorName
291 qDebug() << "CursorImageProvider:" << cursorName
283 << "not found (nor its fallbacks, if any). Going for \"left_ptr\" as a last resort.";
292 << "not found (nor its fallbacks, if any). Going for \"left_ptr\" as a last resort.";
284− cursorImage = fetchCursorHelper(themeName, QStringLiteral("left_ptr"));
293+ cursorImage = fetchCursorHelper(themeName, QStringLiteral("left_ptr"), cursorHeight);
287 if (cursorImage->qimage.isNull()) {
296 if (cursorImage->qimage.isNull()) {
288 // finally, go for the built-in cursor
297 // finally, go for the built-in cursor
289 qWarning() << "CursorImageProvider: couldn't find any cursors. Using the built-in one";
298 qWarning() << "CursorImageProvider: couldn't find any cursors. Using the built-in one";
290− if (!m_builtInCursorImage) {
299+ if (!m_builtInCursorImage || m_builtInCursorImage->requestedHeight != cursorHeight) {
291− m_builtInCursorImage.reset(new BuiltInCursorImage);
300+ m_builtInCursorImage.reset(new BuiltInCursorImage(cursorHeight));
293 cursorImage = m_builtInCursorImage.data();
302 cursorImage = m_builtInCursorImage.data();
@@ -296,7 +305,7 @@ CursorImage *CursorImageProvider::fetchCursor(const QString &themeName, const QS
296 return cursorImage;
305 return cursorImage;
299−CursorImage *CursorImageProvider::fetchCursorHelper(const QString &themeName, const QString &cursorName)
308+CursorImage *CursorImageProvider::fetchCursorHelper(const QString &themeName, const QString &cursorName, int cursorHeight)
301 if (cursorName == QLatin1String("blank")) {
310 if (cursorName == QLatin1String("blank")) {
302 return &m_blankCursorImage;
311 return &m_blankCursorImage;
@@ -306,7 +315,10 @@ CursorImage *CursorImageProvider::fetchCursorHelper(const QString &themeName, co
306 QMap<QString, CursorImage*> &themeCursors = m_cursors[themeName];
315 QMap<QString, CursorImage*> &themeCursors = m_cursors[themeName];
308 if (!themeCursors.contains(cursorName)) {
317 if (!themeCursors.contains(cursorName)) {
309− themeCursors[cursorName] = new XCursorImage(themeName, cursorName);
318+ themeCursors[cursorName] = new XCursorImage(themeName, cursorName, cursorHeight);
319+ } else if (themeCursors[cursorName]->requestedHeight != cursorHeight) {
320+ delete themeCursors.take(cursorName);
321+ themeCursors[cursorName] = new XCursorImage(themeName, cursorName, cursorHeight);
312 return themeCursors[cursorName];
324 return themeCursors[cursorName];