From d54aaf5aaac9bc3b3a1781b8ce1abd729cccae93 Mon Sep 17 00:00:00 2001 From: Xaver Hugl Date: Sun, 21 Aug 2022 15:02:40 +0200 Subject: [PATCH] workspace: restore cursor position after output changes --- src/workspace.cpp | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) diff --git a/src/workspace.cpp b/src/workspace.cpp index 7ddce8eb9d..cb5712d561 100644 --- a/src/workspace.cpp +++ b/src/workspace.cpp @@ -2210,6 +2210,22 @@ void Workspace::desktopResized() } updateClientArea(); + + // restore cursor position + const auto oldCursorOutput = std::find_if(m_oldScreenGeometries.cbegin(), m_oldScreenGeometries.cend(), [](const auto &geometry) { + return geometry.contains(Cursors::self()->mouse()->pos()); + }); + if (oldCursorOutput != m_oldScreenGeometries.end()) { + const Output *cursorOutput = oldCursorOutput.key(); + if (std::find(m_outputs.cbegin(), m_outputs.cend(), cursorOutput) != m_outputs.cend()) { + const QRect oldGeometry = oldCursorOutput.value(); + const QRect newGeometry = cursorOutput->geometry(); + const QPoint relativePosition = Cursors::self()->mouse()->pos() - oldGeometry.topLeft(); + const QPoint newRelativePosition(newGeometry.width() * relativePosition.x() / float(oldGeometry.width()), newGeometry.height() * relativePosition.y() / float(oldGeometry.height())); + Cursors::self()->mouse()->setPos(newGeometry.topLeft() + newRelativePosition); + } + } + saveOldScreenSizes(); // after updateClientArea(), so that one still uses the previous one // TODO: emit a signal instead and remove the deep function calls into edges and effects