From baebfb7f7e0bd7c03adc4585710483eaaa6274f9 Mon Sep 17 00:00:00 2001 From: Marco Martin Date: Thu, 6 Feb 2020 13:24:07 +0100 Subject: [PATCH] actually draw drag icons in the mouse cursor during drags Summary: paint together the cursor image and the extra dnd image if available on X11 with QDrag::setHotspot is possible to control their relative position, which doesn't seem to have a wayland protocol correspondence so their relative position are controlled just by the hotspot of the cursor itself Test Plan: folder graphics from dolphin is painted correctly {F8086937} Reviewers: #plasma, #kwin, davidedmundson Reviewed By: #plasma, #kwin, davidedmundson Subscribers: davidedmundson, kwin Tags: #kwin Differential Revision: https://phabricator.kde.org/D27174 --- pointer_input.cpp | 29 ++++++++++++++++++++++++++++- 1 file changed, 28 insertions(+), 1 deletion(-) diff --git a/pointer_input.cpp b/pointer_input.cpp index 64d7558312..a2dfdac05e 100644 --- a/pointer_input.cpp +++ b/pointer_input.cpp @@ -51,6 +51,7 @@ along with this program. If not, see . #include #include +#include // Wayland #include @@ -1221,6 +1222,7 @@ void CursorImage::updateDragCursor() if (auto dragIcon = ddi->icon()) { if (auto buffer = dragIcon->buffer()) { additionalIcon = buffer->data().copy(); + additionalIcon.setOffset(dragIcon->offset()); } } } @@ -1253,7 +1255,32 @@ void CursorImage::updateDragCursor() return; } m_drag.cursor.hotSpot = c->hotspot(); - m_drag.cursor.image = buffer->data().copy(); + + if (additionalIcon.isNull()) { + m_drag.cursor.image = buffer->data().copy(); + } else { + QRect cursorRect = buffer->data().rect(); + QRect iconRect = additionalIcon.rect(); + + if (-m_drag.cursor.hotSpot.x() < additionalIcon.offset().x()) { + iconRect.moveLeft(m_drag.cursor.hotSpot.x() - additionalIcon.offset().x()); + } else { + cursorRect.moveLeft(-additionalIcon.offset().x() - m_drag.cursor.hotSpot.x()); + } + if (-m_drag.cursor.hotSpot.y() < additionalIcon.offset().y()) { + iconRect.moveTop(m_drag.cursor.hotSpot.y() - additionalIcon.offset().y()); + } else { + cursorRect.moveTop(-additionalIcon.offset().y() - m_drag.cursor.hotSpot.y()); + } + + m_drag.cursor.image = QImage(cursorRect.united(iconRect).size(), QImage::Format_ARGB32_Premultiplied); + m_drag.cursor.image.fill(Qt::transparent); + QPainter p(&m_drag.cursor.image); + p.drawImage(iconRect, additionalIcon); + p.drawImage(cursorRect, buffer->data()); + p.end(); + } + if (needsEmit) { emit changed(); }