From 7c70b344f547047849fee06d6a05f3b59e966297 Mon Sep 17 00:00:00 2001 From: Roman Gilg Date: Wed, 11 Dec 2019 21:37:13 +0100 Subject: [PATCH] [platforms/drm] Fix cursor output rotation MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Summary: The calculation of cursor position and orientation on outputs rotations other than 0° and 180° was faulty. This patch fixes both. Test Plan: In live session cursor looks and moves as expected. Reviewers: #kwin Subscribers: kwin Tags: #kwin Differential Revision: https://phabricator.kde.org/D25909 --- plugins/platforms/drm/drm_output.cpp | 18 ++++++++++-------- 1 file changed, 10 insertions(+), 8 deletions(-) diff --git a/plugins/platforms/drm/drm_output.cpp b/plugins/platforms/drm/drm_output.cpp index ef3560b20a..fafda9d4ca 100644 --- a/plugins/platforms/drm/drm_output.cpp +++ b/plugins/platforms/drm/drm_output.cpp @@ -157,7 +157,7 @@ QMatrix4x4 DrmOutput::matrixDisplay(const QSize &s) const const QSize center = s / 2; matrix.translate(center.width(), center.height()); - matrix.rotate(angle, 0, 0, 1); + matrix.rotate(-angle, 0, 0, 1); matrix.translate(-center.width(), -center.height()); } matrix.scale(scale()); @@ -185,7 +185,8 @@ void DrmOutput::moveCursor(const QPoint &globalPos) { const QMatrix4x4 hotspotMatrix = matrixDisplay(m_backend->softwareCursor().size()); - QPoint p = globalPos - AbstractWaylandOutput::globalPos(); + const QPoint localPos = globalPos - AbstractWaylandOutput::globalPos(); + QPoint pos = localPos; // TODO: Do we need to handle the flipped cases differently? switch (transform()) { @@ -194,22 +195,23 @@ void DrmOutput::moveCursor(const QPoint &globalPos) break; case Transform::Rotated90: case Transform::Flipped90: - p = QPoint(p.y(), pixelSize().height() - p.x()); + pos = QPoint(localPos.y(), pixelSize().width() / scale() - localPos.x()); break; case Transform::Rotated270: case Transform::Flipped270: - p = QPoint(pixelSize().width() - p.y(), p.x()); + pos = QPoint(pixelSize().height() / scale() - localPos.y(), localPos.x()); break; case Transform::Rotated180: case Transform::Flipped180: - p = QPoint(pixelSize().width() - p.x(), pixelSize().height() - p.y()); + pos = QPoint(pixelSize().width() / scale() - localPos.x(), + pixelSize().height() / scale() - localPos.y()); break; default: Q_UNREACHABLE(); } - p *= scale(); - p -= hotspotMatrix.map(m_backend->softwareCursorHotspot()); - drmModeMoveCursor(m_backend->fd(), m_crtc->id(), p.x(), p.y()); + pos *= scale(); + pos -= hotspotMatrix.map(m_backend->softwareCursorHotspot()); + drmModeMoveCursor(m_backend->fd(), m_crtc->id(), pos.x(), pos.y()); } static QHash s_connectorNames = {