workspace: restore cursor position after output changes

This commit is contained in:
Xaver Hugl 2022-08-21 15:02:40 +02:00
parent a32869594e
commit d54aaf5aaa

View file

@ -2210,6 +2210,22 @@ void Workspace::desktopResized()
} }
updateClientArea(); 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 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 // TODO: emit a signal instead and remove the deep function calls into edges and effects