diff --git a/autotests/integration/pointer_input.cpp b/autotests/integration/pointer_input.cpp index 8be420e43c..f773dc4e54 100644 --- a/autotests/integration/pointer_input.cpp +++ b/autotests/integration/pointer_input.cpp @@ -1520,7 +1520,7 @@ void PointerInputTest::testConfineToScreenGeometry_data() QTest::newRow("move right - top screen") << QPoint(1920, 512) << QPoint(2660, 512) << QPoint(2660, 512); QTest::newRow("move bottom-right - top screen") << QPoint(1920, 512) << QPoint(2660, 1124) << QPoint(2660, 1023); QTest::newRow("move bottom - top screen") << QPoint(1920, 512) << QPoint(1920, 1124) << QPoint(1920, 1124); - QTest::newRow("move bottom-left - top screen") << QPoint(1920, 512) << QPoint(1180, 1124) << QPoint(1180, 1023); + QTest::newRow("move bottom-left - top screen") << QPoint(1920, 512) << QPoint(1180, 1124) << QPoint(1280, 1124); QTest::newRow("move left - top screen") << QPoint(1920, 512) << QPoint(1180, 512) << QPoint(1180, 512); QTest::newRow("move top-left - right screen") << QPoint(3200, 512) << QPoint(2460, -100) << QPoint(2460, 0); diff --git a/src/workspace.cpp b/src/workspace.cpp index 0966d4e1e8..734fef1d29 100644 --- a/src/workspace.cpp +++ b/src/workspace.cpp @@ -1231,14 +1231,13 @@ Output *Workspace::outputAt(const QPointF &pos) const qreal minDistance; for (Output *output : std::as_const(m_outputs)) { - const QRect &geo = output->geometry(); - if (geo.contains(pos.toPoint())) { - return output; - } - qreal distance = QPointF(geo.topLeft() - pos).manhattanLength(); - distance = std::min(distance, QPointF(geo.topRight() - pos).manhattanLength()); - distance = std::min(distance, QPointF(geo.bottomRight() - pos).manhattanLength()); - distance = std::min(distance, QPointF(geo.bottomLeft() - pos).manhattanLength()); + const QRectF geo = output->geometry(); + + const QPointF closestPoint(std::clamp(pos.x(), geo.x(), geo.x() + geo.width() - 1), + std::clamp(pos.y(), geo.y(), geo.y() + geo.height() - 1)); + + const QPointF ray = closestPoint - pos; + const qreal distance = ray.x() * ray.x() + ray.y() * ray.y(); if (!bestOutput || distance < minDistance) { minDistance = distance; bestOutput = output;