Commit 64b7cc3c authored by Vlad Zahorodnii's avatar Vlad Zahorodnii
Browse files

wayland: Fix drag-and-drop cursors with hidpi

QImage::rect() returns a rect in the native pixels, however we need a
rect that is in the device independent pixels.

CCBUG: 424589
parent 2ac86115
...@@ -1155,6 +1155,7 @@ void CursorImage::updateDragCursor() ...@@ -1155,6 +1155,7 @@ void CursorImage::updateDragCursor()
if (auto dragIcon = ddi->icon()) { if (auto dragIcon = ddi->icon()) {
if (auto buffer = dragIcon->buffer()) { if (auto buffer = dragIcon->buffer()) {
additionalIcon = buffer->data().copy(); additionalIcon = buffer->data().copy();
additionalIcon.setDevicePixelRatio(dragIcon->bufferScale());
additionalIcon.setOffset(dragIcon->offset()); additionalIcon.setOffset(dragIcon->offset());
} }
} }
...@@ -1187,32 +1188,39 @@ void CursorImage::updateDragCursor() ...@@ -1187,32 +1188,39 @@ void CursorImage::updateDragCursor()
} }
return; return;
} }
m_drag.cursor.hotspot = c->hotspot();
QImage cursorImage = buffer->data();
cursorImage.setDevicePixelRatio(cursorSurface->bufferScale());
if (additionalIcon.isNull()) { if (additionalIcon.isNull()) {
m_drag.cursor.image = buffer->data().copy(); m_drag.cursor.image = cursorImage.copy();
m_drag.cursor.image.setDevicePixelRatio(cursorSurface->bufferScale()); m_drag.cursor.hotspot = c->hotspot();
} else { } else {
QRect cursorRect = buffer->data().rect(); QRect cursorRect(QPoint(0, 0), cursorImage.size() / cursorImage.devicePixelRatio());
QRect iconRect = additionalIcon.rect(); QRect iconRect(QPoint(0, 0), additionalIcon.size() / additionalIcon.devicePixelRatio());
if (-m_drag.cursor.hotspot.x() < additionalIcon.offset().x()) { if (-c->hotspot().x() < additionalIcon.offset().x()) {
iconRect.moveLeft(m_drag.cursor.hotspot.x() - additionalIcon.offset().x()); iconRect.moveLeft(c->hotspot().x() - additionalIcon.offset().x());
} else { } else {
cursorRect.moveLeft(-additionalIcon.offset().x() - m_drag.cursor.hotspot.x()); cursorRect.moveLeft(-additionalIcon.offset().x() - c->hotspot().x());
} }
if (-m_drag.cursor.hotspot.y() < additionalIcon.offset().y()) { if (-c->hotspot().y() < additionalIcon.offset().y()) {
iconRect.moveTop(m_drag.cursor.hotspot.y() - additionalIcon.offset().y()); iconRect.moveTop(c->hotspot().y() - additionalIcon.offset().y());
} else { } else {
cursorRect.moveTop(-additionalIcon.offset().y() - m_drag.cursor.hotspot.y()); cursorRect.moveTop(-additionalIcon.offset().y() - c->hotspot().y());
} }
m_drag.cursor.image = QImage(cursorRect.united(iconRect).size(), QImage::Format_ARGB32_Premultiplied); const QRect viewport = cursorRect.united(iconRect);
m_drag.cursor.image.setDevicePixelRatio(cursorSurface->bufferScale()); const qreal scale = cursorSurface->bufferScale();
m_drag.cursor.image = QImage(viewport.size() * scale, QImage::Format_ARGB32_Premultiplied);
m_drag.cursor.image.setDevicePixelRatio(scale);
m_drag.cursor.image.fill(Qt::transparent); m_drag.cursor.image.fill(Qt::transparent);
m_drag.cursor.hotspot = cursorRect.topLeft() + c->hotspot();
QPainter p(&m_drag.cursor.image); QPainter p(&m_drag.cursor.image);
p.drawImage(iconRect, additionalIcon); p.drawImage(iconRect, additionalIcon);
p.drawImage(cursorRect, buffer->data()); p.drawImage(cursorRect, cursorImage);
p.end(); p.end();
} }
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment