From 4cd25cf571d5a350b5e62e612a990bfdfa934bff Mon Sep 17 00:00:00 2001 From: Xaver Hugl Date: Mon, 20 Feb 2023 00:35:44 +0100 Subject: [PATCH] cursor: make position, hotspot and size floating point This allows all pixel positions to be used on high dpi screens, and corrects damage tracking with Xwayland cursors CCBUG: 466094 --- .../integration/move_resize_window_test.cpp | 4 +- autotests/integration/pointer_input.cpp | 4 +- autotests/integration/screenedges_test.cpp | 24 +++++------ .../integration/window_selection_test.cpp | 24 +++++------ autotests/integration/x11_window_test.cpp | 8 ++-- .../integration/xdgshellwindow_rules_test.cpp | 10 ++--- autotests/integration/xdgshellwindow_test.cpp | 2 +- src/backends/drm/drm_output.cpp | 22 +++++----- src/backends/drm/drm_output.h | 4 +- src/backends/wayland/wayland_egl_backend.cpp | 5 ++- src/backends/wayland/wayland_output.cpp | 2 +- src/backends/wayland/wayland_output.h | 2 +- .../wayland/wayland_qpainter_backend.cpp | 5 ++- .../x11/standalone/x11_standalone_backend.cpp | 2 +- .../x11/standalone/x11_standalone_backend.h | 2 +- .../x11/standalone/x11_standalone_cursor.cpp | 6 +-- .../x11_standalone_windowselector.cpp | 4 +- .../x11_standalone_windowselector.h | 6 +-- .../x11/windowed/x11_windowed_egl_backend.cpp | 3 +- .../x11/windowed/x11_windowed_output.cpp | 4 +- .../x11/windowed/x11_windowed_output.h | 4 +- .../x11_windowed_qpainter_backend.cpp | 4 +- src/composite.cpp | 6 +-- src/core/output.cpp | 4 +- src/core/output.h | 4 +- src/core/outputlayer.cpp | 8 ++-- src/core/outputlayer.h | 12 +++--- src/core/renderlayer.cpp | 42 ++++++++++++++----- src/core/renderlayer.h | 16 ++++--- src/cursor.cpp | 28 ++++--------- src/cursor.h | 34 +++++---------- src/cursordelegate_opengl.cpp | 6 +-- src/cursordelegate_qpainter.cpp | 4 +- src/cursorsource.cpp | 18 ++++---- src/cursorsource.h | 12 +++--- src/decorations/decoratedclient.cpp | 2 +- src/effects.cpp | 4 +- src/effects.h | 4 +- src/effects/colorpicker/colorpicker.cpp | 8 ++-- src/effects/colorpicker/colorpicker.h | 2 +- src/effects/magiclamp/magiclamp.cpp | 2 +- src/effects/magnifier/magnifier.cpp | 6 +-- src/effects/magnifier/magnifier.h | 4 +- src/effects/mouseclick/mouseclick.cpp | 6 +-- src/effects/mouseclick/mouseclick.h | 2 +- src/effects/mousemark/mousemark.cpp | 10 ++--- src/effects/mousemark/mousemark.h | 8 ++-- .../screenshot/screenshotdbusinterface1.cpp | 6 +-- .../screenshot/screenshotdbusinterface2.cpp | 4 +- .../startupfeedback/startupfeedback.cpp | 4 +- src/effects/startupfeedback/startupfeedback.h | 2 +- src/effects/trackmouse/trackmouse.cpp | 10 ++--- src/effects/trackmouse/trackmouse.h | 2 +- src/effects/zoom/zoom.cpp | 10 ++--- src/effects/zoom/zoom.h | 2 +- src/libkwineffects/kwineffects.cpp | 2 +- src/libkwineffects/kwineffects.h | 10 ++--- src/libkwineffects/kwinglobals.h | 15 +++++-- src/main.cpp | 4 +- src/main.h | 2 +- src/main_x11.cpp | 2 +- src/main_x11.h | 2 +- src/plugins/qpa/platformcursor.cpp | 2 +- src/plugins/screencast/screencastmanager.cpp | 2 +- src/plugins/screencast/screencaststream.cpp | 14 +++---- src/plugins/screencast/screencaststream.h | 8 ++-- src/pointer_input.cpp | 8 ++-- src/screenedge.cpp | 29 ++++++------- src/screenedge.h | 2 +- src/scripting/workspace_wrapper.cpp | 2 +- src/wayland/pointer_interface.cpp | 12 +++--- src/wayland/pointer_interface.h | 2 +- src/window.cpp | 2 +- src/window.h | 2 +- src/workspace.cpp | 9 ++-- 75 files changed, 293 insertions(+), 281 deletions(-) diff --git a/autotests/integration/move_resize_window_test.cpp b/autotests/integration/move_resize_window_test.cpp index 405eb9ed61..898ab7acb2 100644 --- a/autotests/integration/move_resize_window_test.cpp +++ b/autotests/integration/move_resize_window_test.cpp @@ -144,7 +144,7 @@ void MoveResizeWindowTest::testMove() QCOMPARE(window->geometryRestore(), QRect()); // send some key events, not going through input redirection - const QPoint cursorPos = Cursors::self()->mouse()->pos(); + const QPointF cursorPos = Cursors::self()->mouse()->pos(); window->keyPressEvent(Qt::Key_Right); window->updateInteractiveMoveResize(Cursors::self()->mouse()->pos()); QCOMPARE(Cursors::self()->mouse()->pos(), cursorPos + QPoint(8, 0)); @@ -240,7 +240,7 @@ void MoveResizeWindowTest::testResize() QVERIFY(states.testFlag(Test::XdgToplevel::State::Resizing)); // Trigger a change. - const QPoint cursorPos = Cursors::self()->mouse()->pos(); + const QPointF cursorPos = Cursors::self()->mouse()->pos(); window->keyPressEvent(Qt::Key_Right); window->updateInteractiveMoveResize(Cursors::self()->mouse()->pos()); QCOMPARE(Cursors::self()->mouse()->pos(), cursorPos + QPoint(8, 0)); diff --git a/autotests/integration/pointer_input.cpp b/autotests/integration/pointer_input.cpp index 53398fbf49..f882f76b41 100644 --- a/autotests/integration/pointer_input.cpp +++ b/autotests/integration/pointer_input.cpp @@ -1659,7 +1659,7 @@ void PointerInputTest::testResizeCursor() cursorSurface->attachBuffer(Test::waylandShmPool()->createBuffer(arrowCursor.image())); cursorSurface->damage(arrowCursor.image().rect()); cursorSurface->commit(); - pointer->setCursor(cursorSurface.get(), arrowCursor.hotSpot()); + pointer->setCursor(cursorSurface.get(), arrowCursor.hotSpot().toPoint()); QVERIFY(cursorRenderedSpy.wait()); // start resizing the window @@ -1727,7 +1727,7 @@ void PointerInputTest::testMoveCursor() cursorSurface->attachBuffer(Test::waylandShmPool()->createBuffer(arrowCursor.image())); cursorSurface->damage(arrowCursor.image().rect()); cursorSurface->commit(); - pointer->setCursor(cursorSurface.get(), arrowCursor.hotSpot()); + pointer->setCursor(cursorSurface.get(), arrowCursor.hotSpot().toPoint()); QVERIFY(cursorRenderedSpy.wait()); // start moving the window diff --git a/autotests/integration/screenedges_test.cpp b/autotests/integration/screenedges_test.cpp index 6949908ed1..4f7593cb61 100644 --- a/autotests/integration/screenedges_test.cpp +++ b/autotests/integration/screenedges_test.cpp @@ -200,18 +200,18 @@ void ScreenEdgesTest::testPushBack_data() { QTest::addColumn("border"); QTest::addColumn("pushback"); - QTest::addColumn("trigger"); - QTest::addColumn("expected"); + QTest::addColumn("trigger"); + QTest::addColumn("expected"); - QTest::newRow("top-left-3") << ElectricTopLeft << 3 << QPoint(0, 0) << QPoint(3, 3); - QTest::newRow("top-5") << ElectricTop << 5 << QPoint(50, 0) << QPoint(50, 5); - QTest::newRow("top-right-2") << ElectricTopRight << 2 << QPoint(1279, 0) << QPoint(1277, 2); - QTest::newRow("right-10") << ElectricRight << 10 << QPoint(1279, 50) << QPoint(1269, 50); - QTest::newRow("bottom-right-5") << ElectricBottomRight << 5 << QPoint(1279, 1023) << QPoint(1274, 1018); - QTest::newRow("bottom-10") << ElectricBottom << 10 << QPoint(50, 1023) << QPoint(50, 1013); - QTest::newRow("bottom-left-3") << ElectricBottomLeft << 3 << QPoint(0, 1023) << QPoint(3, 1020); - QTest::newRow("left-10") << ElectricLeft << 10 << QPoint(0, 50) << QPoint(10, 50); - QTest::newRow("invalid") << ElectricLeft << 10 << QPoint(50, 0) << QPoint(50, 0); + QTest::newRow("top-left-3") << ElectricTopLeft << 3 << QPointF(0, 0) << QPointF(3, 3); + QTest::newRow("top-5") << ElectricTop << 5 << QPointF(50, 0) << QPointF(50, 5); + QTest::newRow("top-right-2") << ElectricTopRight << 2 << QPointF(1279, 0) << QPointF(1277, 2); + QTest::newRow("right-10") << ElectricRight << 10 << QPointF(1279, 50) << QPointF(1269, 50); + QTest::newRow("bottom-right-5") << ElectricBottomRight << 5 << QPointF(1279, 1023) << QPointF(1274, 1018); + QTest::newRow("bottom-10") << ElectricBottom << 10 << QPointF(50, 1023) << QPointF(50, 1013); + QTest::newRow("bottom-left-3") << ElectricBottomLeft << 3 << QPointF(0, 1023) << QPointF(3, 1020); + QTest::newRow("left-10") << ElectricLeft << 10 << QPointF(0, 50) << QPointF(10, 50); + QTest::newRow("invalid") << ElectricLeft << 10 << QPointF(50, 0) << QPointF(50, 0); } void ScreenEdgesTest::testPushBack() @@ -233,7 +233,7 @@ void ScreenEdgesTest::testPushBack() QFETCH(ElectricBorder, border); s->reserve(border, &callback, "callback"); - QFETCH(QPoint, trigger); + QFETCH(QPointF, trigger); Test::pointerMotion(trigger, 0); QVERIFY(spy.isEmpty()); QTEST(Cursors::self()->mouse()->pos(), "expected"); diff --git a/autotests/integration/window_selection_test.cpp b/autotests/integration/window_selection_test.cpp index 0392820d17..f907afa79c 100644 --- a/autotests/integration/window_selection_test.cpp +++ b/autotests/integration/window_selection_test.cpp @@ -419,14 +419,12 @@ void TestWindowSelection::testSelectPointPointer() QCOMPARE(input()->pointer()->focus(), window); QVERIFY(pointerEnteredSpy.wait()); - QPoint point; - auto callback = [&point](const QPoint &p) { - point = p; - }; - // start the interaction QCOMPARE(input()->isSelectingWindow(), false); - kwinApp()->startInteractivePositionSelection(callback); + QPointF point; + kwinApp()->startInteractivePositionSelection([&point](const QPointF &p) { + point = p; + }); QCOMPARE(input()->isSelectingWindow(), true); QCOMPARE(point, QPoint()); QCOMPARE(keyboardLeftSpy.count(), 0); @@ -438,8 +436,8 @@ void TestWindowSelection::testSelectPointPointer() QCOMPARE(keyboardLeftSpy.count(), 1); // trying again should not be allowed - QPoint point2; - kwinApp()->startInteractivePositionSelection([&point2](const QPoint &p) { + QPointF point2; + kwinApp()->startInteractivePositionSelection([&point2](const QPointF &p) { point2 = p; }); QCOMPARE(point2, QPoint(-1, -1)); @@ -483,14 +481,12 @@ void TestWindowSelection::testSelectPointPointer() void TestWindowSelection::testSelectPointTouch() { // this test verifies point selection through touch works - QPoint point; - auto callback = [&point](const QPoint &p) { - point = p; - }; - // start the interaction QCOMPARE(input()->isSelectingWindow(), false); - kwinApp()->startInteractivePositionSelection(callback); + QPointF point; + kwinApp()->startInteractivePositionSelection([&point](const QPointF &p) { + point = p; + }); QCOMPARE(input()->isSelectingWindow(), true); QCOMPARE(point, QPoint()); diff --git a/autotests/integration/x11_window_test.cpp b/autotests/integration/x11_window_test.cpp index 7b5cd64662..3dc6d5e203 100644 --- a/autotests/integration/x11_window_test.cpp +++ b/autotests/integration/x11_window_test.cpp @@ -130,7 +130,7 @@ void X11WindowTest::testMinimumSize() QCOMPARE(clientStartMoveResizedSpy.count(), 1); QVERIFY(window->isInteractiveResize()); - const QPoint cursorPos = KWin::Cursors::self()->mouse()->pos(); + const QPointF cursorPos = KWin::Cursors::self()->mouse()->pos(); window->keyPressEvent(Qt::Key_Left); window->updateInteractiveMoveResize(KWin::Cursors::self()->mouse()->pos()); @@ -236,7 +236,7 @@ void X11WindowTest::testMaximumSize() QCOMPARE(clientStartMoveResizedSpy.count(), 1); QVERIFY(window->isInteractiveResize()); - const QPoint cursorPos = KWin::Cursors::self()->mouse()->pos(); + const QPointF cursorPos = KWin::Cursors::self()->mouse()->pos(); window->keyPressEvent(Qt::Key_Right); window->updateInteractiveMoveResize(KWin::Cursors::self()->mouse()->pos()); @@ -342,7 +342,7 @@ void X11WindowTest::testResizeIncrements() QCOMPARE(clientStartMoveResizedSpy.count(), 1); QVERIFY(window->isInteractiveResize()); - const QPoint cursorPos = KWin::Cursors::self()->mouse()->pos(); + const QPointF cursorPos = KWin::Cursors::self()->mouse()->pos(); window->keyPressEvent(Qt::Key_Right); window->updateInteractiveMoveResize(KWin::Cursors::self()->mouse()->pos()); @@ -426,7 +426,7 @@ void X11WindowTest::testResizeIncrementsNoBaseSize() QCOMPARE(clientStartMoveResizedSpy.count(), 1); QVERIFY(window->isInteractiveResize()); - const QPoint cursorPos = KWin::Cursors::self()->mouse()->pos(); + const QPointF cursorPos = KWin::Cursors::self()->mouse()->pos(); window->keyPressEvent(Qt::Key_Right); window->updateInteractiveMoveResize(KWin::Cursors::self()->mouse()->pos()); diff --git a/autotests/integration/xdgshellwindow_rules_test.cpp b/autotests/integration/xdgshellwindow_rules_test.cpp index 1c3fcf516c..cf8fd4afa7 100644 --- a/autotests/integration/xdgshellwindow_rules_test.cpp +++ b/autotests/integration/xdgshellwindow_rules_test.cpp @@ -330,7 +330,7 @@ void TestXdgShellWindowRules::testPositionApply() QVERIFY(m_window->isInteractiveMove()); QVERIFY(!m_window->isInteractiveResize()); - const QPoint cursorPos = KWin::Cursors::self()->mouse()->pos(); + const QPointF cursorPos = KWin::Cursors::self()->mouse()->pos(); m_window->keyPressEvent(Qt::Key_Right); m_window->updateInteractiveMoveResize(KWin::Cursors::self()->mouse()->pos()); QCOMPARE(KWin::Cursors::self()->mouse()->pos(), cursorPos + QPoint(8, 0)); @@ -379,7 +379,7 @@ void TestXdgShellWindowRules::testPositionRemember() QVERIFY(m_window->isInteractiveMove()); QVERIFY(!m_window->isInteractiveResize()); - const QPoint cursorPos = KWin::Cursors::self()->mouse()->pos(); + const QPointF cursorPos = KWin::Cursors::self()->mouse()->pos(); m_window->keyPressEvent(Qt::Key_Right); m_window->updateInteractiveMoveResize(KWin::Cursors::self()->mouse()->pos()); QCOMPARE(KWin::Cursors::self()->mouse()->pos(), cursorPos + QPoint(8, 0)); @@ -471,7 +471,7 @@ void TestXdgShellWindowRules::testPositionApplyNow() QVERIFY(m_window->isInteractiveMove()); QVERIFY(!m_window->isInteractiveResize()); - const QPoint cursorPos = KWin::Cursors::self()->mouse()->pos(); + const QPointF cursorPos = KWin::Cursors::self()->mouse()->pos(); m_window->keyPressEvent(Qt::Key_Right); m_window->updateInteractiveMoveResize(KWin::Cursors::self()->mouse()->pos()); QCOMPARE(KWin::Cursors::self()->mouse()->pos(), cursorPos + QPoint(8, 0)); @@ -599,7 +599,7 @@ void TestXdgShellWindowRules::testSizeApply() QVERIFY(states.testFlag(Test::XdgToplevel::State::Resizing)); m_shellSurface->xdgSurface()->ack_configure(m_surfaceConfigureRequestedSpy->last().at(0).value()); - const QPoint cursorPos = KWin::Cursors::self()->mouse()->pos(); + const QPointF cursorPos = KWin::Cursors::self()->mouse()->pos(); m_window->keyPressEvent(Qt::Key_Right); m_window->updateInteractiveMoveResize(KWin::Cursors::self()->mouse()->pos()); QCOMPARE(KWin::Cursors::self()->mouse()->pos(), cursorPos + QPoint(8, 0)); @@ -696,7 +696,7 @@ void TestXdgShellWindowRules::testSizeRemember() QVERIFY(states.testFlag(Test::XdgToplevel::State::Resizing)); m_shellSurface->xdgSurface()->ack_configure(m_surfaceConfigureRequestedSpy->last().at(0).value()); - const QPoint cursorPos = KWin::Cursors::self()->mouse()->pos(); + const QPointF cursorPos = KWin::Cursors::self()->mouse()->pos(); m_window->keyPressEvent(Qt::Key_Right); m_window->updateInteractiveMoveResize(KWin::Cursors::self()->mouse()->pos()); QCOMPARE(KWin::Cursors::self()->mouse()->pos(), cursorPos + QPoint(8, 0)); diff --git a/autotests/integration/xdgshellwindow_test.cpp b/autotests/integration/xdgshellwindow_test.cpp index 0442634369..cff3780c68 100644 --- a/autotests/integration/xdgshellwindow_test.cpp +++ b/autotests/integration/xdgshellwindow_test.cpp @@ -1257,7 +1257,7 @@ void TestXdgShellWindow::testXdgWindowGeometryInteractiveResize() QVERIFY(states.testFlag(Test::XdgToplevel::State::Resizing)); // Go right. - QPoint cursorPos = KWin::Cursors::self()->mouse()->pos(); + QPointF cursorPos = KWin::Cursors::self()->mouse()->pos(); window->keyPressEvent(Qt::Key_Right); window->updateInteractiveMoveResize(KWin::Cursors::self()->mouse()->pos()); QCOMPARE(KWin::Cursors::self()->mouse()->pos(), cursorPos + QPoint(8, 0)); diff --git a/src/backends/drm/drm_output.cpp b/src/backends/drm/drm_output.cpp index 867ea6b8a2..44b42ba2f3 100644 --- a/src/backends/drm/drm_output.cpp +++ b/src/backends/drm/drm_output.cpp @@ -158,9 +158,9 @@ bool DrmOutput::setCursor(CursorSource *source) } bool rendered = false; const QMatrix4x4 monitorMatrix = logicalToNativeMatrix(rect(), scale(), transform()); - const QSize cursorSize = m_cursor.source->size(); - const QRect cursorRect = QRect(m_cursor.position, cursorSize); - const QRect nativeCursorRect = monitorMatrix.mapRect(cursorRect); + const QSizeF cursorSize = m_cursor.source->size(); + const QRectF cursorRect = QRectF(m_cursor.position, cursorSize); + const QRectF nativeCursorRect = monitorMatrix.mapRect(cursorRect); if (nativeCursorRect.width() <= m_gpu->cursorSize().width() && nativeCursorRect.height() <= m_gpu->cursorSize().height()) { if (auto beginInfo = layer->beginFrame()) { RenderTarget *renderTarget = &beginInfo->renderTarget; @@ -186,24 +186,24 @@ bool DrmOutput::setCursor(CursorSource *source) } const QSize layerSize = m_gpu->cursorSize() / scale(); - const QRect layerRect = monitorMatrix.mapRect(QRect(m_cursor.position, layerSize)); + const QRectF layerRect = monitorMatrix.mapRect(QRectF(m_cursor.position, layerSize)); layer->setVisible(cursorRect.intersects(rect())); if (layer->isVisible()) { - m_setCursorSuccessful = m_pipeline->setCursor(logicalToNativeMatrix(QRect(QPoint(), layerRect.size()), scale(), transform()).map(m_cursor.source->hotspot())); + m_setCursorSuccessful = m_pipeline->setCursor(logicalToNativeMatrix(QRectF(QPoint(), layerRect.size()), scale(), transform()).map(m_cursor.source->hotspot()).toPoint()); layer->setVisible(m_setCursorSuccessful); } return m_setCursorSuccessful; } -bool DrmOutput::moveCursor(const QPoint &position) +bool DrmOutput::moveCursor(const QPointF &position) { if (!m_setCursorSuccessful || !m_pipeline->crtc()) { return false; } m_cursor.position = position; - const QSize cursorSize = m_cursor.source ? m_cursor.source->size() : QSize(0, 0); - const QRect cursorRect = QRect(m_cursor.position, cursorSize); + const QSizeF cursorSize = m_cursor.source ? m_cursor.source->size() : QSize(0, 0); + const QRectF cursorRect = QRectF(m_cursor.position, cursorSize); if (!cursorRect.intersects(rect())) { const auto layer = m_pipeline->cursorLayer(); @@ -214,12 +214,12 @@ bool DrmOutput::moveCursor(const QPoint &position) return true; } const QMatrix4x4 monitorMatrix = logicalToNativeMatrix(rect(), scale(), transform()); - const QSize layerSize = m_gpu->cursorSize() / scale(); - const QRect layerRect = monitorMatrix.mapRect(QRect(m_cursor.position, layerSize)); + const QSizeF layerSize = m_gpu->cursorSize() / scale(); + const QRectF layerRect = monitorMatrix.mapRect(QRectF(m_cursor.position, layerSize)); const auto layer = m_pipeline->cursorLayer(); const bool wasVisible = layer->isVisible(); layer->setVisible(true); - layer->setPosition(layerRect.topLeft()); + layer->setPosition(layerRect.topLeft().toPoint()); m_moveCursorSuccessful = m_pipeline->moveCursor(); layer->setVisible(m_moveCursorSuccessful); if (!m_moveCursorSuccessful || !wasVisible) { diff --git a/src/backends/drm/drm_output.h b/src/backends/drm/drm_output.h index b4550f0080..4195dc8fd4 100644 --- a/src/backends/drm/drm_output.h +++ b/src/backends/drm/drm_output.h @@ -51,7 +51,7 @@ public: void updateDpmsMode(DpmsMode dpmsMode); bool setCursor(CursorSource *source) override; - bool moveCursor(const QPoint &position) override; + bool moveCursor(const QPointF &position) override; DrmLease *lease() const; bool addLeaseObjects(QVector &objectList); @@ -76,7 +76,7 @@ private: struct { QPointer source; - QPoint position; + QPointF position; } m_cursor; }; diff --git a/src/backends/wayland/wayland_egl_backend.cpp b/src/backends/wayland/wayland_egl_backend.cpp index 5f8f7df2b0..0fd4ce35e0 100644 --- a/src/backends/wayland/wayland_egl_backend.cpp +++ b/src/backends/wayland/wayland_egl_backend.cpp @@ -242,7 +242,8 @@ std::optional WaylandEglCursorLayer::beginFrame() return std::nullopt; } - const QSize bufferSize = size().expandedTo(QSize(64, 64)); + const auto tmp = size().expandedTo(QSize(64, 64)); + const QSize bufferSize(std::ceil(tmp.width()), std::ceil(tmp.height())); if (!m_swapchain || m_swapchain->size() != bufferSize) { const WaylandLinuxDmabufV1 *dmabuf = m_backend->backend()->display()->linuxDmabuf(); const uint32_t format = DRM_FORMAT_ARGB8888; @@ -266,7 +267,7 @@ bool WaylandEglCursorLayer::endFrame(const QRegion &renderedRegion, const QRegio // Flush rendering commands to the dmabuf. glFlush(); - m_output->cursor()->update(m_buffer->buffer(), scale(), hotspot()); + m_output->cursor()->update(m_buffer->buffer(), scale(), hotspot().toPoint()); m_swapchain->release(m_buffer); return true; diff --git a/src/backends/wayland/wayland_output.cpp b/src/backends/wayland/wayland_output.cpp index 8d91c77a6a..49bdef5c5e 100644 --- a/src/backends/wayland/wayland_output.cpp +++ b/src/backends/wayland/wayland_output.cpp @@ -214,7 +214,7 @@ bool WaylandOutput::setCursor(CursorSource *source) return true; } -bool WaylandOutput::moveCursor(const QPoint &position) +bool WaylandOutput::moveCursor(const QPointF &position) { // The cursor position is controlled by the host compositor. return !m_hasPointerLock; diff --git a/src/backends/wayland/wayland_output.h b/src/backends/wayland/wayland_output.h index eaa2d9215b..3a41113934 100644 --- a/src/backends/wayland/wayland_output.h +++ b/src/backends/wayland/wayland_output.h @@ -66,7 +66,7 @@ public: RenderLoop *renderLoop() const override; bool setCursor(CursorSource *source) override; - bool moveCursor(const QPoint &position) override; + bool moveCursor(const QPointF &position) override; void init(const QSize &pixelSize, qreal scale); diff --git a/src/backends/wayland/wayland_qpainter_backend.cpp b/src/backends/wayland/wayland_qpainter_backend.cpp index d3a9602329..11c59b41cd 100644 --- a/src/backends/wayland/wayland_qpainter_backend.cpp +++ b/src/backends/wayland/wayland_qpainter_backend.cpp @@ -140,7 +140,8 @@ WaylandQPainterCursorLayer::~WaylandQPainterCursorLayer() std::optional WaylandQPainterCursorLayer::beginFrame() { - const QSize bufferSize = size().expandedTo(QSize(64, 64)); + const auto tmp = size().expandedTo(QSize(64, 64)); + const QSize bufferSize(std::ceil(tmp.width()), std::ceil(tmp.height())); if (m_backingStore.size() != bufferSize) { m_backingStore = QImage(bufferSize, QImage::Format_ARGB32_Premultiplied); } @@ -154,7 +155,7 @@ std::optional WaylandQPainterCursorLayer::beginFrame( bool WaylandQPainterCursorLayer::endFrame(const QRegion &renderedRegion, const QRegion &damagedRegion) { KWayland::Client::Buffer::Ptr buffer = m_output->backend()->display()->shmPool()->createBuffer(m_backingStore); - m_output->cursor()->update(*buffer.lock(), scale(), hotspot()); + m_output->cursor()->update(*buffer.lock(), scale(), hotspot().toPoint()); return true; } diff --git a/src/backends/x11/standalone/x11_standalone_backend.cpp b/src/backends/x11/standalone/x11_standalone_backend.cpp index 86c7e0354e..86e837f046 100644 --- a/src/backends/x11/standalone/x11_standalone_backend.cpp +++ b/src/backends/x11/standalone/x11_standalone_backend.cpp @@ -228,7 +228,7 @@ void X11StandaloneBackend::startInteractiveWindowSelection(std::functionstart(callback, cursorName); } -void X11StandaloneBackend::startInteractivePositionSelection(std::function callback) +void X11StandaloneBackend::startInteractivePositionSelection(std::function callback) { if (!m_windowSelector) { m_windowSelector = std::make_unique(); diff --git a/src/backends/x11/standalone/x11_standalone_backend.h b/src/backends/x11/standalone/x11_standalone_backend.h index f8d3314948..0344689762 100644 --- a/src/backends/x11/standalone/x11_standalone_backend.h +++ b/src/backends/x11/standalone/x11_standalone_backend.h @@ -56,7 +56,7 @@ public: std::unique_ptr createScreenEdge(ScreenEdges *parent); void createPlatformCursor(QObject *parent = nullptr); void startInteractiveWindowSelection(std::function callback, const QByteArray &cursorName = QByteArray()); - void startInteractivePositionSelection(std::function callback); + void startInteractivePositionSelection(std::function callback); PlatformCursorImage cursorImage() const; std::unique_ptr createOutline(Outline *outline); void createEffectsHandler(Compositor *compositor, WorkspaceScene *scene); diff --git a/src/backends/x11/standalone/x11_standalone_cursor.cpp b/src/backends/x11/standalone/x11_standalone_cursor.cpp index 73b9dbb014..57e95bec7f 100644 --- a/src/backends/x11/standalone/x11_standalone_cursor.cpp +++ b/src/backends/x11/standalone/x11_standalone_cursor.cpp @@ -52,7 +52,7 @@ X11Cursor::~X11Cursor() void X11Cursor::doSetPos() { - const QPoint &pos = currentPos(); + const QPointF &pos = currentPos(); xcb_warp_pointer(connection(), XCB_WINDOW_NONE, rootWindow(), 0, 0, 0, 0, pos.x(), pos.y()); // call default implementation to emit signal Cursor::doSetPos(); @@ -70,7 +70,7 @@ void X11Cursor::doGetPos() return; } m_buttonMask = pointer->mask; - updatePos(pointer->root_x, pointer->root_y); + updatePos(QPointF(pointer->root_x, pointer->root_y)); m_resetTimeStampTimer.start(0); } @@ -113,7 +113,7 @@ void X11Cursor::doStopCursorTracking() void X11Cursor::mousePolled() { - static QPoint lastPos = currentPos(); + static QPointF lastPos = currentPos(); static uint16_t lastMask = m_buttonMask; doGetPos(); // Update if needed if (lastPos != currentPos() || lastMask != m_buttonMask) { diff --git a/src/backends/x11/standalone/x11_standalone_windowselector.cpp b/src/backends/x11/standalone/x11_standalone_windowselector.cpp index b50313cd5c..128df24ea2 100644 --- a/src/backends/x11/standalone/x11_standalone_windowselector.cpp +++ b/src/backends/x11/standalone/x11_standalone_windowselector.cpp @@ -59,7 +59,7 @@ void WindowSelector::start(std::function callback, const Q m_callback = callback; } -void WindowSelector::start(std::function callback) +void WindowSelector::start(std::function callback) { if (m_active) { callback(QPoint(-1, -1)); @@ -216,7 +216,7 @@ void WindowSelector::release() ungrabXServer(); m_active = false; m_callback = std::function(); - m_pointSelectionFallback = std::function(); + m_pointSelectionFallback = std::function(); } void WindowSelector::selectWindowId(xcb_window_t window_to_select) diff --git a/src/backends/x11/standalone/x11_standalone_windowselector.h b/src/backends/x11/standalone/x11_standalone_windowselector.h index b06e424ebb..be2e6218a1 100644 --- a/src/backends/x11/standalone/x11_standalone_windowselector.h +++ b/src/backends/x11/standalone/x11_standalone_windowselector.h @@ -17,7 +17,7 @@ #include -class QPoint; +class QPointF; namespace KWin { @@ -30,7 +30,7 @@ public: ~WindowSelector() override; void start(std::function callback, const QByteArray &cursorName); - void start(std::function callback); + void start(std::function callback); bool isActive() const { return m_active; @@ -50,7 +50,7 @@ private: void cancelCallback(); bool m_active; std::function m_callback; - std::function m_pointSelectionFallback; + std::function m_pointSelectionFallback; }; } // namespace diff --git a/src/backends/x11/windowed/x11_windowed_egl_backend.cpp b/src/backends/x11/windowed/x11_windowed_egl_backend.cpp index 46f8947eab..9757e268ef 100644 --- a/src/backends/x11/windowed/x11_windowed_egl_backend.cpp +++ b/src/backends/x11/windowed/x11_windowed_egl_backend.cpp @@ -89,7 +89,8 @@ std::optional X11WindowedEglCursorLayer::beginFrame() { eglMakeCurrent(m_backend->eglDisplay(), EGL_NO_SURFACE, EGL_NO_SURFACE, m_backend->context()); - const QSize bufferSize = size().expandedTo(QSize(64, 64)); + const auto tmp = size().expandedTo(QSize(64, 64)); + const QSize bufferSize(std::ceil(tmp.width()), std::ceil(tmp.height())); if (!m_texture || m_texture->size() != bufferSize) { m_texture = std::make_unique(GL_RGBA8, bufferSize); m_framebuffer = std::make_unique(m_texture.get()); diff --git a/src/backends/x11/windowed/x11_windowed_output.cpp b/src/backends/x11/windowed/x11_windowed_output.cpp index 21f90115d6..e480610aa6 100644 --- a/src/backends/x11/windowed/x11_windowed_output.cpp +++ b/src/backends/x11/windowed/x11_windowed_output.cpp @@ -44,7 +44,7 @@ X11WindowedCursor::~X11WindowedCursor() } } -void X11WindowedCursor::update(const QImage &image, const QPoint &hotspot) +void X11WindowedCursor::update(const QImage &image, const QPointF &hotspot) { X11WindowedBackend *backend = m_output->backend(); @@ -314,7 +314,7 @@ bool X11WindowedOutput::setCursor(CursorSource *source) return true; } -bool X11WindowedOutput::moveCursor(const QPoint &position) +bool X11WindowedOutput::moveCursor(const QPointF &position) { // The cursor position is controlled by the host compositor. return true; diff --git a/src/backends/x11/windowed/x11_windowed_output.h b/src/backends/x11/windowed/x11_windowed_output.h index 396c01566e..263d66978a 100644 --- a/src/backends/x11/windowed/x11_windowed_output.h +++ b/src/backends/x11/windowed/x11_windowed_output.h @@ -32,7 +32,7 @@ public: explicit X11WindowedCursor(X11WindowedOutput *output); ~X11WindowedCursor(); - void update(const QImage &image, const QPoint &hotspot); + void update(const QImage &image, const QPointF &hotspot); private: X11WindowedOutput *m_output; @@ -71,7 +71,7 @@ public: QPointF mapFromGlobal(const QPointF &pos) const; bool setCursor(CursorSource *source) override; - bool moveCursor(const QPoint &position) override; + bool moveCursor(const QPointF &position) override; QRegion exposedArea() const; void addExposedArea(const QRect &rect); diff --git a/src/backends/x11/windowed/x11_windowed_qpainter_backend.cpp b/src/backends/x11/windowed/x11_windowed_qpainter_backend.cpp index d86a12e48c..1345f90468 100644 --- a/src/backends/x11/windowed/x11_windowed_qpainter_backend.cpp +++ b/src/backends/x11/windowed/x11_windowed_qpainter_backend.cpp @@ -12,6 +12,7 @@ #include "x11_windowed_output.h" #include +#include #include #include #include @@ -179,7 +180,8 @@ X11WindowedQPainterCursorLayer::X11WindowedQPainterCursorLayer(X11WindowedOutput std::optional X11WindowedQPainterCursorLayer::beginFrame() { - const QSize bufferSize = size().expandedTo(QSize(64, 64)); + const auto tmp = size().expandedTo(QSize(64, 64)); + const QSize bufferSize(std::ceil(tmp.width()), std::ceil(tmp.height())); if (m_buffer.size() != bufferSize) { m_buffer = QImage(bufferSize, QImage::Format_ARGB32_Premultiplied); } diff --git a/src/composite.cpp b/src/composite.cpp index 672e7fb9a4..6cd0ee0722 100644 --- a/src/composite.cpp +++ b/src/composite.cpp @@ -449,7 +449,7 @@ void Compositor::addOutput(Output *output) auto updateCursorLayer = [output, cursorLayer]() { const Cursor *cursor = Cursors::self()->currentCursor(); - const QRect layerRect = output->mapFromGlobal(cursor->geometry()); + const QRectF layerRect = output->mapFromGlobal(cursor->geometry()); bool usesHardwareCursor = false; if (!Cursors::self()->isCursorHidden()) { usesHardwareCursor = output->setCursor(cursor->source()) && output->moveCursor(layerRect.topLeft()); @@ -462,7 +462,7 @@ void Compositor::addOutput(Output *output) }; auto moveCursorLayer = [output, cursorLayer]() { const Cursor *cursor = Cursors::self()->currentCursor(); - const QRect layerRect = output->mapFromGlobal(cursor->geometry()); + const QRectF layerRect = output->mapFromGlobal(cursor->geometry()); const bool usesHardwareCursor = output->moveCursor(layerRect.topLeft()); cursorLayer->setVisible(cursor->isOnOutput(output) && !usesHardwareCursor); cursorLayer->setGeometry(layerRect); @@ -682,7 +682,7 @@ void Compositor::composite(RenderLoop *renderLoop) auto &[renderTarget, repaint] = beginInfo.value(); renderTarget.setDevicePixelRatio(output->scale()); - const QRegion bufferDamage = surfaceDamage.united(repaint).intersected(superLayer->rect()); + const QRegion bufferDamage = surfaceDamage.united(repaint).intersected(superLayer->rect().toAlignedRect()); primaryLayer->aboutToStartPainting(bufferDamage); paintPass(superLayer, &renderTarget, bufferDamage); diff --git a/src/core/output.cpp b/src/core/output.cpp index 11f147315d..92ee9d4512 100644 --- a/src/core/output.cpp +++ b/src/core/output.cpp @@ -321,7 +321,7 @@ Output::DpmsMode Output::dpmsMode() const return m_state.dpmsMode; } -QMatrix4x4 Output::logicalToNativeMatrix(const QRect &rect, qreal scale, Transform transform) +QMatrix4x4 Output::logicalToNativeMatrix(const QRectF &rect, qreal scale, Transform transform) { QMatrix4x4 matrix; matrix.scale(scale); @@ -421,7 +421,7 @@ bool Output::setCursor(CursorSource *source) return false; } -bool Output::moveCursor(const QPoint &position) +bool Output::moveCursor(const QPointF &position) { return false; } diff --git a/src/core/output.h b/src/core/output.h index ac30104855..065f5f9b25 100644 --- a/src/core/output.h +++ b/src/core/output.h @@ -245,7 +245,7 @@ public: /** * Returns a matrix that can translate into the display's coordinates system */ - static QMatrix4x4 logicalToNativeMatrix(const QRect &rect, qreal scale, Transform transform); + static QMatrix4x4 logicalToNativeMatrix(const QRectF &rect, qreal scale, Transform transform); void setVrrPolicy(RenderLoop::VrrPolicy policy); RenderLoop::VrrPolicy vrrPolicy() const; @@ -261,7 +261,7 @@ public: virtual void setColorTransformation(const std::shared_ptr &transformation); virtual bool setCursor(CursorSource *source); - virtual bool moveCursor(const QPoint &position); + virtual bool moveCursor(const QPointF &position); Q_SIGNALS: /** diff --git a/src/core/outputlayer.cpp b/src/core/outputlayer.cpp index 18069c1adb..98bc79ac35 100644 --- a/src/core/outputlayer.cpp +++ b/src/core/outputlayer.cpp @@ -24,22 +24,22 @@ void OutputLayer::setScale(qreal scale) m_scale = scale; } -QPoint OutputLayer::hotspot() const +QPointF OutputLayer::hotspot() const { return m_hotspot; } -void OutputLayer::setHotspot(const QPoint &hotspot) +void OutputLayer::setHotspot(const QPointF &hotspot) { m_hotspot = hotspot; } -QSize OutputLayer::size() const +QSizeF OutputLayer::size() const { return m_size; } -void OutputLayer::setSize(const QSize &size) +void OutputLayer::setSize(const QSizeF &size) { m_size = size; } diff --git a/src/core/outputlayer.h b/src/core/outputlayer.h index 81402baffd..dbc9536db2 100644 --- a/src/core/outputlayer.h +++ b/src/core/outputlayer.h @@ -33,11 +33,11 @@ public: qreal scale() const; void setScale(qreal scale); - QPoint hotspot() const; - void setHotspot(const QPoint &hotspot); + QPointF hotspot() const; + void setHotspot(const QPointF &hotspot); - QSize size() const; - void setSize(const QSize &size); + QSizeF size() const; + void setSize(const QSizeF &size); QRegion repaints() const; void resetRepaints(); @@ -61,8 +61,8 @@ public: private: QRegion m_repaints; - QPoint m_hotspot; - QSize m_size; + QPointF m_hotspot; + QSizeF m_size; qreal m_scale = 1.0; }; diff --git a/src/core/renderlayer.cpp b/src/core/renderlayer.cpp index 06bd06a6ce..cba63b3c96 100644 --- a/src/core/renderlayer.cpp +++ b/src/core/renderlayer.cpp @@ -38,7 +38,7 @@ void RenderLayer::setOutputLayer(OutputLayer *layer) return; } if (m_outputLayer) { - m_outputLayer->addRepaint(mapToGlobal(boundingRect())); + m_outputLayer->addRepaint(mapToGlobal(boundingRect()).toAlignedRect()); } m_outputLayer = layer; for (RenderLayer *sublayer : std::as_const(m_sublayers)) { @@ -101,28 +101,28 @@ void RenderLayer::setDelegate(std::unique_ptr delegate) m_delegate->setLayer(this); } -QRect RenderLayer::rect() const +QRectF RenderLayer::rect() const { return QRect(0, 0, m_geometry.width(), m_geometry.height()); } -QRect RenderLayer::boundingRect() const +QRectF RenderLayer::boundingRect() const { return m_boundingRect; } -QRect RenderLayer::geometry() const +QRectF RenderLayer::geometry() const { return m_geometry; } -void RenderLayer::setGeometry(const QRect &geometry) +void RenderLayer::setGeometry(const QRectF &geometry) { if (m_geometry == geometry) { return; } if (m_effectiveVisible && m_outputLayer) { - m_outputLayer->addRepaint(mapToGlobal(boundingRect())); + m_outputLayer->addRepaint(mapToGlobal(boundingRect()).toAlignedRect()); } m_geometry = geometry; @@ -136,7 +136,7 @@ void RenderLayer::setGeometry(const QRect &geometry) void RenderLayer::updateBoundingRect() { - QRect boundingRect = rect(); + QRectF boundingRect = rect(); for (const RenderLayer *sublayer : std::as_const(m_sublayers)) { boundingRect |= sublayer->boundingRect().translated(sublayer->geometry().topLeft()); } @@ -151,7 +151,7 @@ void RenderLayer::updateBoundingRect() void RenderLayer::addRepaintFull() { - addRepaint(rect()); + addRepaint(rect().toAlignedRect()); } void RenderLayer::addRepaint(int x, int y, int width, int height) @@ -216,7 +216,7 @@ void RenderLayer::updateEffectiveVisibility() addRepaintFull(); } else { if (m_outputLayer) { - m_outputLayer->addRepaint(mapToGlobal(boundingRect())); + m_outputLayer->addRepaint(mapToGlobal(boundingRect()).toAlignedRect()); } } @@ -227,7 +227,12 @@ void RenderLayer::updateEffectiveVisibility() QPoint RenderLayer::mapToGlobal(const QPoint &point) const { - QPoint result = point; + return mapToGlobal(QPointF(point)).toPoint(); +} + +QPointF RenderLayer::mapToGlobal(const QPointF &point) const +{ + QPointF result = point; const RenderLayer *layer = this; while (layer) { result += layer->geometry().topLeft(); @@ -241,6 +246,11 @@ QRect RenderLayer::mapToGlobal(const QRect &rect) const return rect.translated(mapToGlobal(QPoint(0, 0))); } +QRectF RenderLayer::mapToGlobal(const QRectF &rect) const +{ + return rect.translated(mapToGlobal(QPointF(0, 0))); +} + QRegion RenderLayer::mapToGlobal(const QRegion ®ion) const { if (region.isEmpty()) { @@ -251,7 +261,12 @@ QRegion RenderLayer::mapToGlobal(const QRegion ®ion) const QPoint RenderLayer::mapFromGlobal(const QPoint &point) const { - QPoint result = point; + return mapFromGlobal(QPointF(point)).toPoint(); +} + +QPointF RenderLayer::mapFromGlobal(const QPointF &point) const +{ + QPointF result = point; const RenderLayer *layer = this; while (layer) { result -= layer->geometry().topLeft(); @@ -265,6 +280,11 @@ QRect RenderLayer::mapFromGlobal(const QRect &rect) const return rect.translated(mapFromGlobal(QPoint(0, 0))); } +QRectF RenderLayer::mapFromGlobal(const QRectF &rect) const +{ + return rect.translated(mapFromGlobal(QPointF(0, 0))); +} + QRegion RenderLayer::mapFromGlobal(const QRegion ®ion) const { if (region.isEmpty()) { diff --git a/src/core/renderlayer.h b/src/core/renderlayer.h index c3ec33c8db..639afbc2fc 100644 --- a/src/core/renderlayer.h +++ b/src/core/renderlayer.h @@ -55,18 +55,22 @@ public: void setVisible(bool visible); QPoint mapToGlobal(const QPoint &point) const; + QPointF mapToGlobal(const QPointF &point) const; QRegion mapToGlobal(const QRegion ®ion) const; QRect mapToGlobal(const QRect &rect) const; + QRectF mapToGlobal(const QRectF &rect) const; QPoint mapFromGlobal(const QPoint &point) const; + QPointF mapFromGlobal(const QPointF &point) const; QRegion mapFromGlobal(const QRegion ®ion) const; QRect mapFromGlobal(const QRect &rect) const; + QRectF mapFromGlobal(const QRectF &rect) const; - QRect rect() const; - QRect boundingRect() const; + QRectF rect() const; + QRectF boundingRect() const; - QRect geometry() const; - void setGeometry(const QRect &rect); + QRectF geometry() const; + void setGeometry(const QRectF &rect); void addRepaint(const QRegion ®ion); void addRepaint(const QRect &rect); @@ -85,8 +89,8 @@ private: RenderLoop *m_loop; std::unique_ptr m_delegate; QRegion m_repaints; - QRect m_boundingRect; - QRect m_geometry; + QRectF m_boundingRect; + QRectF m_geometry; QPointer m_outputLayer; RenderLayer *m_superlayer = nullptr; QList m_sublayers; diff --git a/src/cursor.cpp b/src/cursor.cpp index fc8d099d10..3561a9bb75 100644 --- a/src/cursor.cpp +++ b/src/cursor.cpp @@ -45,7 +45,7 @@ void Cursors::addCursor(Cursor *cursor) Q_ASSERT(!m_cursors.contains(cursor)); m_cursors += cursor; - connect(cursor, &Cursor::posChanged, this, [this, cursor](const QPoint &pos) { + connect(cursor, &Cursor::posChanged, this, [this, cursor](const QPointF &pos) { setCurrentCursor(cursor); Q_EMIT positionChanged(cursor, pos); }); @@ -186,40 +186,35 @@ QImage Cursor::image() const return m_source->image(); } -QPoint Cursor::hotspot() const +QPointF Cursor::hotspot() const { if (Q_UNLIKELY(!m_source)) { - return QPoint(); + return QPointF(); } return m_source->hotspot(); } -QRect Cursor::geometry() const +QRectF Cursor::geometry() const { return rect().translated(m_pos - hotspot()); } -QRect Cursor::rect() const +QRectF Cursor::rect() const { if (Q_UNLIKELY(!m_source)) { - return QRect(); + return QRectF(); } else { - return QRect(QPoint(0, 0), m_source->size()); + return QRectF(QPointF(0, 0), m_source->size()); } } -QPoint Cursor::pos() +QPointF Cursor::pos() { doGetPos(); return m_pos; } void Cursor::setPos(const QPointF &pos) -{ - setPos(pos.toPoint()); -} - -void Cursor::setPos(const QPoint &pos) { // first query the current pos to not warp to the already existing pos if (pos == m_pos) { @@ -229,11 +224,6 @@ void Cursor::setPos(const QPoint &pos) doSetPos(); } -void Cursor::setPos(int x, int y) -{ - setPos(QPoint(x, y)); -} - void Cursor::markAsRendered(std::chrono::milliseconds timestamp) { Q_EMIT rendered(timestamp); @@ -288,7 +278,7 @@ void Cursor::doGetPos() { } -void Cursor::updatePos(const QPoint &pos) +void Cursor::updatePos(const QPointF &pos) { if (m_pos == pos) { return; diff --git a/src/cursor.h b/src/cursor.h index 4a751579f7..3eec5912f8 100644 --- a/src/cursor.h +++ b/src/cursor.h @@ -156,17 +156,11 @@ public: * Implementing subclasses should prefer to use currentPos which is not performing a check * for update. */ - QPoint pos(); + QPointF pos(); /** * Warps the mouse cursor to new @p pos. - * Values will be rounded to an integer */ void setPos(const QPointF &pos); - /** - * Warps the mouse cursor to new @p pos. - */ - void setPos(const QPoint &pos); - void setPos(int x, int y); xcb_cursor_t x11Cursor(CursorShape shape); /** * Notice: if available always use the CursorShape variant to avoid cache duplicates for @@ -175,9 +169,9 @@ public: xcb_cursor_t x11Cursor(const QByteArray &name); QImage image() const; - QPoint hotspot() const; - QRect geometry() const; - QRect rect() const; + QPointF hotspot() const; + QRectF geometry() const; + QRectF rect() const; CursorSource *source() const; void setSource(CursorSource *source); @@ -190,8 +184,8 @@ public: void markAsRendered(std::chrono::milliseconds timestamp); Q_SIGNALS: - void posChanged(const QPoint &pos); - void mouseChanged(const QPoint &pos, const QPoint &oldpos, + void posChanged(const QPointF &pos); + void mouseChanged(const QPointF &pos, const QPointF &oldpos, Qt::MouseButtons buttons, Qt::MouseButtons oldbuttons, Qt::KeyboardModifiers modifiers, Qt::KeyboardModifiers oldmodifiers); /** @@ -242,13 +236,12 @@ protected: * access to the cursor position this method should be used instead of the static @ref pos, as * the static method syncs with the underlying system's cursor. */ - const QPoint ¤tPos() const; + const QPointF ¤tPos() const; /** * Updates the internal position to @p pos without warping the pointer as * setPos does. */ - void updatePos(const QPoint &pos); - void updatePos(int x, int y); + void updatePos(const QPointF &pos); private Q_SLOTS: void loadThemeSettings(); @@ -259,7 +252,7 @@ private: void loadThemeFromKConfig(); CursorSource *m_source = nullptr; QHash m_cursors; - QPoint m_pos; + QPointF m_pos; int m_mousePollingCounter; int m_cursorTrackingCounter; QString m_themeName; @@ -303,7 +296,7 @@ public: Q_SIGNALS: void currentCursorChanged(Cursor *cursor); void hiddenChanged(); - void positionChanged(Cursor *cursor, const QPoint &position); + void positionChanged(Cursor *cursor, const QPointF &position); private: void emitCurrentCursorChanged(); @@ -337,16 +330,11 @@ private: static InputConfig *s_self; }; -inline const QPoint &Cursor::currentPos() const +inline const QPointF &Cursor::currentPos() const { return m_pos; } -inline void Cursor::updatePos(int x, int y) -{ - updatePos(QPoint(x, y)); -} - inline const QString &Cursor::themeName() const { return m_themeName; diff --git a/src/cursordelegate_opengl.cpp b/src/cursordelegate_opengl.cpp index e4ba065da8..9401de066f 100644 --- a/src/cursordelegate_opengl.cpp +++ b/src/cursordelegate_opengl.cpp @@ -24,12 +24,12 @@ CursorDelegateOpenGL::~CursorDelegateOpenGL() void CursorDelegateOpenGL::paint(RenderTarget *renderTarget, const QRegion ®ion) { - if (!region.intersects(layer()->mapToGlobal(layer()->rect()))) { + if (!region.intersects(layer()->mapToGlobal(layer()->rect()).toAlignedRect())) { return; } // Render the cursor scene in an offscreen render target. - const QSize bufferSize = Cursors::self()->currentCursor()->rect().size() * renderTarget->devicePixelRatio(); + const QSize bufferSize = (Cursors::self()->currentCursor()->rect().size() * renderTarget->devicePixelRatio()).toSize(); if (!m_texture || m_texture->size() != bufferSize) { m_texture = std::make_unique(GL_RGBA8, bufferSize); m_framebuffer = std::make_unique(m_texture.get()); @@ -45,7 +45,7 @@ void CursorDelegateOpenGL::paint(RenderTarget *renderTarget, const QRegion ®i renderLayer.delegate()->postPaint(); // Show the rendered cursor scene on the screen. - const QRect cursorRect = layer()->mapToGlobal(layer()->rect()); + const QRectF cursorRect = layer()->mapToGlobal(layer()->rect()); const qreal scale = renderTarget->devicePixelRatio(); QMatrix4x4 mvp; diff --git a/src/cursordelegate_qpainter.cpp b/src/cursordelegate_qpainter.cpp index ab22acc325..ef1c5dc34c 100644 --- a/src/cursordelegate_qpainter.cpp +++ b/src/cursordelegate_qpainter.cpp @@ -18,7 +18,7 @@ namespace KWin void CursorDelegateQPainter::paint(RenderTarget *renderTarget, const QRegion ®ion) { - if (!region.intersects(layer()->mapToGlobal(layer()->rect()))) { + if (!region.intersects(layer()->mapToGlobal(layer()->rect()).toAlignedRect())) { return; } @@ -27,7 +27,7 @@ void CursorDelegateQPainter::paint(RenderTarget *renderTarget, const QRegion &re return; } - const QSize bufferSize = Cursors::self()->currentCursor()->rect().size() * renderTarget->devicePixelRatio(); + const QSize bufferSize = (Cursors::self()->currentCursor()->rect().size() * renderTarget->devicePixelRatio()).toSize(); if (m_buffer.size() != bufferSize) { m_buffer = QImage(bufferSize, QImage::Format_ARGB32_Premultiplied); } diff --git a/src/cursorsource.cpp b/src/cursorsource.cpp index e82f4db913..9ade0a2778 100644 --- a/src/cursorsource.cpp +++ b/src/cursorsource.cpp @@ -23,12 +23,12 @@ QImage CursorSource::image() const return m_image; } -QSize CursorSource::size() const +QSizeF CursorSource::size() const { return m_size; } -QPoint CursorSource::hotspot() const +QPointF CursorSource::hotspot() const { return m_hotspot; } @@ -38,10 +38,10 @@ ImageCursorSource::ImageCursorSource(QObject *parent) { } -void ImageCursorSource::update(const QImage &image, const QPoint &hotspot) +void ImageCursorSource::update(const QImage &image, const QPointF &hotspot) { m_image = image; - m_size = image.size() / image.devicePixelRatio(); + m_size = QSizeF(image.size()) / image.devicePixelRatio(); m_hotspot = hotspot; Q_EMIT changed(); } @@ -118,7 +118,7 @@ void ShapeCursorSource::selectSprite(int index) const KXcursorSprite &sprite = m_sprites[index]; m_currentSprite = index; m_image = sprite.data(); - m_size = m_image.size() / m_image.devicePixelRatio(); + m_size = QSizeF(m_image.size()) / m_image.devicePixelRatio(); m_hotspot = sprite.hotspot(); if (sprite.delay().count() && m_sprites.size() > 1) { m_delayTimer.start(sprite.delay()); @@ -136,12 +136,12 @@ KWaylandServer::SurfaceInterface *SurfaceCursorSource::surface() const return m_surface; } -void SurfaceCursorSource::update(KWaylandServer::SurfaceInterface *surface, const QPoint &hotspot) +void SurfaceCursorSource::update(KWaylandServer::SurfaceInterface *surface, const QPointF &hotspot) { if (!surface) { m_image = QImage(); - m_size = QSize(0, 0); - m_hotspot = QPoint(); + m_size = QSizeF(0, 0); + m_hotspot = QPointF(); m_surface = nullptr; } else { // TODO Plasma 6: once Xwayland cursor scaling can be done correctly, remove this @@ -155,7 +155,7 @@ void SurfaceCursorSource::update(KWaylandServer::SurfaceInterface *surface, cons } else { m_image = QImage(); } - m_size = (surface->size() * surface->client()->scaleOverride()).toSize(); + m_size = surface->size() * surface->client()->scaleOverride(); m_hotspot = hotspot; m_surface = surface; } diff --git a/src/cursorsource.h b/src/cursorsource.h index 9fe65a2896..dd231e6256 100644 --- a/src/cursorsource.h +++ b/src/cursorsource.h @@ -33,16 +33,16 @@ public: explicit CursorSource(QObject *parent = nullptr); QImage image() const; - QSize size() const; - QPoint hotspot() const; + QSizeF size() const; + QPointF hotspot() const; Q_SIGNALS: void changed(); protected: QImage m_image; - QSize m_size = QSize(0, 0); - QPoint m_hotspot; + QSizeF m_size = QSizeF(0, 0); + QPointF m_hotspot; }; /** @@ -56,7 +56,7 @@ public: explicit ImageCursorSource(QObject *parent = nullptr); public Q_SLOTS: - void update(const QImage &image, const QPoint &hotspot); + void update(const QImage &image, const QPointF &hotspot); }; /** @@ -101,7 +101,7 @@ public: KWaylandServer::SurfaceInterface *surface() const; public Q_SLOTS: - void update(KWaylandServer::SurfaceInterface *surface, const QPoint &hotspot); + void update(KWaylandServer::SurfaceInterface *surface, const QPointF &hotspot); private: QPointer m_surface; diff --git a/src/decorations/decoratedclient.cpp b/src/decorations/decoratedclient.cpp index e64f51bac8..a9bba76190 100644 --- a/src/decorations/decoratedclient.cpp +++ b/src/decorations/decoratedclient.cpp @@ -79,7 +79,7 @@ DecoratedClientImpl::DecoratedClientImpl(Window *window, KDecoration2::Decorated int fallAsleepDelay = QApplication::style()->styleHint(QStyle::SH_ToolTip_FallAsleepDelay); this->m_toolTipFallAsleep.setRemainingTime(fallAsleepDelay); - QToolTip::showText(Cursors::self()->mouse()->pos(), this->m_toolTipText); + QToolTip::showText(Cursors::self()->mouse()->pos().toPoint(), this->m_toolTipText); m_toolTipShowing = true; }); } diff --git a/src/effects.cpp b/src/effects.cpp index 81f2df5b51..b06bc70b42 100644 --- a/src/effects.cpp +++ b/src/effects.cpp @@ -1359,7 +1359,7 @@ void EffectsHandlerImpl::doCheckInputWindowStacking() { } -QPoint EffectsHandlerImpl::cursorPos() const +QPointF EffectsHandlerImpl::cursorPos() const { return Cursors::self()->mouse()->pos(); } @@ -1696,7 +1696,7 @@ void EffectsHandlerImpl::startInteractiveWindowSelection(std::function callback) +void EffectsHandlerImpl::startInteractivePositionSelection(std::function callback) { kwinApp()->startInteractivePositionSelection(callback); } diff --git a/src/effects.h b/src/effects.h index 63fdcc95f3..06086b7049 100644 --- a/src/effects.h +++ b/src/effects.h @@ -93,7 +93,7 @@ public: QString desktopName(int desktop) const override; bool optionRollOverDesktops() const override; - QPoint cursorPos() const override; + QPointF cursorPos() const override; bool grabKeyboard(Effect *effect) override; void ungrabKeyboard() override; // not performing XGrabPointer @@ -203,7 +203,7 @@ public: void showCursor() override; void startInteractiveWindowSelection(std::function callback) override; - void startInteractivePositionSelection(std::function callback) override; + void startInteractivePositionSelection(std::function callback) override; void showOnScreenMessage(const QString &message, const QString &iconName = QString()) override; void hideOnScreenMessage(OnScreenMessageHideFlags flags = OnScreenMessageHideFlags()) override; diff --git a/src/effects/colorpicker/colorpicker.cpp b/src/effects/colorpicker/colorpicker.cpp index dd99229723..eb53e81c1a 100644 --- a/src/effects/colorpicker/colorpicker.cpp +++ b/src/effects/colorpicker/colorpicker.cpp @@ -54,8 +54,8 @@ void ColorPickerEffect::paintScreen(int mask, const QRegion ®ion, ScreenPaint { effects->paintScreen(mask, region, data); - const QRect geo = effects->renderTargetRect(); - if (m_scheduledPosition != QPoint(-1, -1) && geo.contains(m_scheduledPosition)) { + const QRectF geo = effects->renderTargetRect(); + if (m_scheduledPosition != QPoint(-1, -1) && exclusiveContains(geo, m_scheduledPosition)) { uint8_t data[4]; constexpr GLsizei PIXEL_SIZE = 1; const QPoint screenPosition(m_scheduledPosition.x() - geo.x(), m_scheduledPosition.y() - geo.y()); @@ -82,9 +82,9 @@ QColor ColorPickerEffect::pick() setDelayedReply(true); showInfoMessage(); effects->startInteractivePositionSelection( - [this](const QPoint &p) { + [this](const QPointF &p) { hideInfoMessage(); - if (p == QPoint(-1, -1)) { + if (p == QPointF(-1, -1)) { // error condition QDBusConnection::sessionBus().send(m_replyMessage.createErrorReply(QStringLiteral("org.kde.kwin.ColorPicker.Error.Cancelled"), "Color picking got cancelled")); m_picking = false; diff --git a/src/effects/colorpicker/colorpicker.h b/src/effects/colorpicker/colorpicker.h index 6bf3fae858..56d805084c 100644 --- a/src/effects/colorpicker/colorpicker.h +++ b/src/effects/colorpicker/colorpicker.h @@ -43,7 +43,7 @@ private: void hideInfoMessage(); QDBusMessage m_replyMessage; - QPoint m_scheduledPosition; + QPointF m_scheduledPosition; bool m_picking = false; }; diff --git a/src/effects/magiclamp/magiclamp.cpp b/src/effects/magiclamp/magiclamp.cpp index 09edd56fd1..99284f12c7 100644 --- a/src/effects/magiclamp/magiclamp.cpp +++ b/src/effects/magiclamp/magiclamp.cpp @@ -84,7 +84,7 @@ void MagicLampEffect::apply(EffectWindow *w, int mask, WindowPaintData &data, Wi // If there's no icon geometry, minimize to the center of the screen if (!icon.isValid()) { QRect extG = geo; - QPoint pt = cursorPos(); + QPoint pt = cursorPos().toPoint(); // focussing inside the window is no good, leads to ugly artefacts, find nearest border if (extG.contains(pt)) { const int d[2][2] = {{pt.x() - extG.x(), extG.right() - pt.x()}, diff --git a/src/effects/magnifier/magnifier.cpp b/src/effects/magnifier/magnifier.cpp index 7321534f46..f92ad06fb5 100644 --- a/src/effects/magnifier/magnifier.cpp +++ b/src/effects/magnifier/magnifier.cpp @@ -115,7 +115,7 @@ void MagnifierEffect::paintScreen(int mask, const QRegion ®ion, ScreenPaintDa if (m_zoom != 1.0) { // get the right area from the current rendered screen const QRect area = magnifierArea(); - const QPoint cursor = cursorPos(); + const QPointF cursor = cursorPos(); const auto scale = effects->renderTargetScale(); QRectF srcArea(cursor.x() - (double)area.width() / (m_zoom * 2), @@ -187,7 +187,7 @@ void MagnifierEffect::postPaintScreen() effects->postPaintScreen(); } -QRect MagnifierEffect::magnifierArea(QPoint pos) const +QRect MagnifierEffect::magnifierArea(QPointF pos) const { return QRect(pos.x() - m_magnifierSize.width() / 2, pos.y() - m_magnifierSize.height() / 2, m_magnifierSize.width(), m_magnifierSize.height()); @@ -253,7 +253,7 @@ void MagnifierEffect::toggle() effects->addRepaint(magnifierArea().adjusted(-FRAME_WIDTH, -FRAME_WIDTH, FRAME_WIDTH, FRAME_WIDTH)); } -void MagnifierEffect::slotMouseChanged(const QPoint &pos, const QPoint &old, +void MagnifierEffect::slotMouseChanged(const QPointF &pos, const QPointF &old, Qt::MouseButtons, Qt::MouseButtons, Qt::KeyboardModifiers, Qt::KeyboardModifiers) { if (pos != old && m_zoom != 1) { diff --git a/src/effects/magnifier/magnifier.h b/src/effects/magnifier/magnifier.h index 2efd6254b9..bf0db559d4 100644 --- a/src/effects/magnifier/magnifier.h +++ b/src/effects/magnifier/magnifier.h @@ -40,13 +40,13 @@ private Q_SLOTS: void zoomIn(); void zoomOut(); void toggle(); - void slotMouseChanged(const QPoint &pos, const QPoint &old, + void slotMouseChanged(const QPointF &pos, const QPointF &old, Qt::MouseButtons buttons, Qt::MouseButtons oldbuttons, Qt::KeyboardModifiers modifiers, Qt::KeyboardModifiers oldmodifiers); void slotWindowDamaged(); private: - QRect magnifierArea(QPoint pos = cursorPos()) const; + QRect magnifierArea(QPointF pos = cursorPos()) const; double m_zoom; double m_targetZoom; bool m_polling; // Mouse polling diff --git a/src/effects/mouseclick/mouseclick.cpp b/src/effects/mouseclick/mouseclick.cpp index fc00296895..05fabb1e08 100644 --- a/src/effects/mouseclick/mouseclick.cpp +++ b/src/effects/mouseclick/mouseclick.cpp @@ -146,7 +146,7 @@ float MouseClickEffect::computeAlpha(const MouseEvent *click, int ring) return (m_ringLife - (float)click->m_time - ringDistance * (ring)) / m_ringLife; } -void MouseClickEffect::slotMouseChanged(const QPoint &pos, const QPoint &, +void MouseClickEffect::slotMouseChanged(const QPointF &pos, const QPointF &, Qt::MouseButtons buttons, Qt::MouseButtons oldButtons, Qt::KeyboardModifiers, Qt::KeyboardModifiers) { @@ -159,11 +159,11 @@ void MouseClickEffect::slotMouseChanged(const QPoint &pos, const QPoint &, while (--i >= 0) { MouseButton *b = m_buttons[i].get(); if (isPressed(b->m_button, buttons, oldButtons)) { - m = std::make_unique(i, pos, 0, createEffectFrame(pos, b->m_labelDown), true); + m = std::make_unique(i, pos.toPoint(), 0, createEffectFrame(pos.toPoint(), b->m_labelDown), true); break; } else if (isReleased(b->m_button, buttons, oldButtons) && (!b->m_isPressed || b->m_time > m_ringLife)) { // we might miss a press, thus also check !b->m_isPressed, bug #314762 - m = std::make_unique(i, pos, 0, createEffectFrame(pos, b->m_labelUp), false); + m = std::make_unique(i, pos.toPoint(), 0, createEffectFrame(pos.toPoint(), b->m_labelUp), false); break; } b->setPressed(b->m_button & buttons); diff --git a/src/effects/mouseclick/mouseclick.h b/src/effects/mouseclick/mouseclick.h index dae17b3e20..67c1d04a61 100644 --- a/src/effects/mouseclick/mouseclick.h +++ b/src/effects/mouseclick/mouseclick.h @@ -117,7 +117,7 @@ public: private Q_SLOTS: void toggleEnabled(); - void slotMouseChanged(const QPoint &pos, const QPoint &old, + void slotMouseChanged(const QPointF &pos, const QPointF &old, Qt::MouseButtons buttons, Qt::MouseButtons oldbuttons, Qt::KeyboardModifiers modifiers, Qt::KeyboardModifiers oldmodifiers); diff --git a/src/effects/mousemark/mousemark.cpp b/src/effects/mousemark/mousemark.cpp index e1a9b889aa..15d93c188a 100644 --- a/src/effects/mousemark/mousemark.cpp +++ b/src/effects/mousemark/mousemark.cpp @@ -95,7 +95,7 @@ void MouseMarkEffect::paintScreen(int mask, const QRegion ®ion, ScreenPaintDa for (const Mark &mark : std::as_const(marks)) { verts.clear(); verts.reserve(mark.size() * 2); - for (const QPoint &p : std::as_const(mark)) { + for (const QPointF &p : std::as_const(mark)) { verts << p.x() * scale << p.y() * scale; } vbo->setData(verts.size() / 2, 2, verts.data(), nullptr); @@ -104,7 +104,7 @@ void MouseMarkEffect::paintScreen(int mask, const QRegion ®ion, ScreenPaintDa if (!drawing.isEmpty()) { verts.clear(); verts.reserve(drawing.size() * 2); - for (const QPoint &p : std::as_const(drawing)) { + for (const QPointF &p : std::as_const(drawing)) { verts << p.x() * scale << p.y() * scale; } vbo->setData(verts.size() / 2, 2, verts.data(), nullptr); @@ -139,7 +139,7 @@ void MouseMarkEffect::drawMark(QPainter *painter, const Mark &mark) } } -void MouseMarkEffect::slotMouseChanged(const QPoint &pos, const QPoint &, +void MouseMarkEffect::slotMouseChanged(const QPointF &pos, const QPointF &, Qt::MouseButtons, Qt::MouseButtons, Qt::KeyboardModifiers modifiers, Qt::KeyboardModifiers) { @@ -164,7 +164,7 @@ void MouseMarkEffect::slotMouseChanged(const QPoint &pos, const QPoint &, if (drawing.last() == pos) { return; } - QPoint pos2 = drawing.last(); + QPointF pos2 = drawing.last(); drawing.append(pos); QRect repaint = QRect(std::min(pos.x(), pos2.x()), std::min(pos.y(), pos2.y()), std::max(pos.x(), pos2.x()), std::max(pos.y(), pos2.y())); @@ -196,7 +196,7 @@ void MouseMarkEffect::clearLast() } } -MouseMarkEffect::Mark MouseMarkEffect::createArrow(QPoint arrow_start, QPoint arrow_end) +MouseMarkEffect::Mark MouseMarkEffect::createArrow(QPointF arrow_start, QPointF arrow_end) { Mark ret; double angle = atan2((double)(arrow_end.y() - arrow_start.y()), (double)(arrow_end.x() - arrow_start.x())); diff --git a/src/effects/mousemark/mousemark.h b/src/effects/mousemark/mousemark.h index 2aa8d118ed..324eee1e73 100644 --- a/src/effects/mousemark/mousemark.h +++ b/src/effects/mousemark/mousemark.h @@ -41,18 +41,18 @@ public: private Q_SLOTS: void clear(); void clearLast(); - void slotMouseChanged(const QPoint &pos, const QPoint &old, + void slotMouseChanged(const QPointF &pos, const QPointF &old, Qt::MouseButtons buttons, Qt::MouseButtons oldbuttons, Qt::KeyboardModifiers modifiers, Qt::KeyboardModifiers oldmodifiers); void screenLockingChanged(bool locked); private: - typedef QVector Mark; + typedef QVector Mark; void drawMark(QPainter *painter, const Mark &mark); - static Mark createArrow(QPoint arrow_start, QPoint arrow_end); + static Mark createArrow(QPointF arrow_start, QPointF arrow_end); QVector marks; Mark drawing; - QPoint arrow_start; + QPointF arrow_start; int width; QColor color; }; diff --git a/src/effects/screenshot/screenshotdbusinterface1.cpp b/src/effects/screenshot/screenshotdbusinterface1.cpp index 251b43f870..4d0cf93417 100644 --- a/src/effects/screenshot/screenshotdbusinterface1.cpp +++ b/src/effects/screenshot/screenshotdbusinterface1.cpp @@ -541,7 +541,7 @@ void ScreenShotDBusInterface1::screenshotWindowUnderCursor(int mask) EffectWindow *hoveredWindow = nullptr; - const QPoint cursor = effects->cursorPos(); + const QPointF cursor = effects->cursorPos(); EffectWindowList order = effects->stackingOrder(); EffectWindowList::const_iterator it = order.constEnd(), first = order.constBegin(); while (it != first) { @@ -709,12 +709,12 @@ void ScreenShotDBusInterface1::screenshotScreen(QDBusUnixFileDescriptor fd, bool flags |= ScreenShotIncludeCursor; } - effects->startInteractivePositionSelection([this, fileDescriptor, flags](const QPoint &p) { + effects->startInteractivePositionSelection([this, fileDescriptor, flags](const QPointF &p) { hideInfoMessage(); if (p == QPoint(-1, -1)) { close(fileDescriptor); } else { - EffectScreen *screen = effects->screenAt(p); + EffectScreen *screen = effects->screenAt(p.toPoint()); if (!screen) { close(fileDescriptor); return; diff --git a/src/effects/screenshot/screenshotdbusinterface2.cpp b/src/effects/screenshot/screenshotdbusinterface2.cpp index d771f0e5bb..48ce0e23f3 100644 --- a/src/effects/screenshot/screenshotdbusinterface2.cpp +++ b/src/effects/screenshot/screenshotdbusinterface2.cpp @@ -478,7 +478,7 @@ QVariantMap ScreenShotDBusInterface2::CaptureInteractive(uint kind, "Escape or right click to cancel."), QStringLiteral("spectacle")); } else { - effects->startInteractivePositionSelection([=, this](const QPoint &point) { + effects->startInteractivePositionSelection([=, this](const QPointF &point) { effects->hideOnScreenMessage(EffectsHandler::OnScreenMessageHideFlag::SkipsCloseAnimation); if (point == QPoint(-1, -1)) { @@ -487,7 +487,7 @@ QVariantMap ScreenShotDBusInterface2::CaptureInteractive(uint kind, QDBusConnection bus = QDBusConnection::sessionBus(); bus.send(replyMessage.createErrorReply(s_errorCancelled, s_errorCancelledMessage)); } else { - EffectScreen *screen = effects->screenAt(point); + EffectScreen *screen = effects->screenAt(point.toPoint()); takeScreenShot(screen, screenShotFlagsFromOptions(options), new ScreenShotSinkPipe2(fileDescriptor, replyMessage)); } diff --git a/src/effects/startupfeedback/startupfeedback.cpp b/src/effects/startupfeedback/startupfeedback.cpp index 8138f91c19..a6f26b7273 100644 --- a/src/effects/startupfeedback/startupfeedback.cpp +++ b/src/effects/startupfeedback/startupfeedback.cpp @@ -242,7 +242,7 @@ void StartupFeedbackEffect::postPaintScreen() effects->postPaintScreen(); } -void StartupFeedbackEffect::slotMouseChanged(const QPoint &pos, const QPoint &oldpos, Qt::MouseButtons buttons, +void StartupFeedbackEffect::slotMouseChanged(const QPointF &pos, const QPointF &oldpos, Qt::MouseButtons buttons, Qt::MouseButtons oldbuttons, Qt::KeyboardModifiers modifiers, Qt::KeyboardModifiers oldmodifiers) { if (m_active) { @@ -416,7 +416,7 @@ QRect StartupFeedbackEffect::feedbackRect() const // nothing break; } - const QPoint cursorPos = effects->cursorPos() + QPoint(xDiff, yDiff + yOffset); + const QPoint cursorPos = effects->cursorPos().toPoint() + QPoint(xDiff, yDiff + yOffset); QRect rect; if (texture) { rect = QRect(cursorPos, texture->size()); diff --git a/src/effects/startupfeedback/startupfeedback.h b/src/effects/startupfeedback/startupfeedback.h index e28fe7cc3b..1e599c2e91 100644 --- a/src/effects/startupfeedback/startupfeedback.h +++ b/src/effects/startupfeedback/startupfeedback.h @@ -53,7 +53,7 @@ private Q_SLOTS: void gotNewStartup(const QString &id, const QIcon &icon); void gotRemoveStartup(const QString &id); void gotStartupChange(const QString &id, const QIcon &icon); - void slotMouseChanged(const QPoint &pos, const QPoint &oldpos, Qt::MouseButtons buttons, Qt::MouseButtons oldbuttons, Qt::KeyboardModifiers modifiers, Qt::KeyboardModifiers oldmodifiers); + void slotMouseChanged(const QPointF &pos, const QPointF &oldpos, Qt::MouseButtons buttons, Qt::MouseButtons oldbuttons, Qt::KeyboardModifiers modifiers, Qt::KeyboardModifiers oldmodifiers); private: enum FeedbackType { diff --git a/src/effects/trackmouse/trackmouse.cpp b/src/effects/trackmouse/trackmouse.cpp index 2e2d374f7e..d1010410ef 100644 --- a/src/effects/trackmouse/trackmouse.cpp +++ b/src/effects/trackmouse/trackmouse.cpp @@ -90,8 +90,8 @@ void TrackMouseEffect::prePaintScreen(ScreenPrePaintData &data, std::chrono::mil { QTime t = QTime::currentTime(); m_angle = ((t.second() % 4) * m_angleBase) + (t.msec() / 1000.0 * m_angleBase); - m_lastRect[0].moveCenter(cursorPos()); - m_lastRect[1].moveCenter(cursorPos()); + m_lastRect[0].moveCenter(cursorPos().toPoint()); + m_lastRect[1].moveCenter(cursorPos().toPoint()); data.paint |= m_lastRect[0].adjusted(-1, -1, 1, 1); effects->prePaintScreen(data, presentTime); @@ -155,8 +155,8 @@ bool TrackMouseEffect::init() return false; } } - m_lastRect[0].moveCenter(cursorPos()); - m_lastRect[1].moveCenter(cursorPos()); + m_lastRect[0].moveCenter(cursorPos().toPoint()); + m_lastRect[1].moveCenter(cursorPos().toPoint()); m_angle = 0; return true; } @@ -187,7 +187,7 @@ void TrackMouseEffect::toggle() effects->addRepaint(m_lastRect[0].adjusted(-1, -1, 1, 1)); } -void TrackMouseEffect::slotMouseChanged(const QPoint &, const QPoint &, +void TrackMouseEffect::slotMouseChanged(const QPointF &, const QPointF &, Qt::MouseButtons, Qt::MouseButtons, Qt::KeyboardModifiers modifiers, Qt::KeyboardModifiers) { diff --git a/src/effects/trackmouse/trackmouse.h b/src/effects/trackmouse/trackmouse.h index e69489d486..ba8b583dca 100644 --- a/src/effects/trackmouse/trackmouse.h +++ b/src/effects/trackmouse/trackmouse.h @@ -45,7 +45,7 @@ public: } private Q_SLOTS: void toggle(); - void slotMouseChanged(const QPoint &pos, const QPoint &old, + void slotMouseChanged(const QPointF &pos, const QPointF &old, Qt::MouseButtons buttons, Qt::MouseButtons oldbuttons, Qt::KeyboardModifiers modifiers, Qt::KeyboardModifiers oldmodifiers); diff --git a/src/effects/zoom/zoom.cpp b/src/effects/zoom/zoom.cpp index f46fd88c1a..676e80099f 100644 --- a/src/effects/zoom/zoom.cpp +++ b/src/effects/zoom/zoom.cpp @@ -396,7 +396,7 @@ void ZoomEffect::paintScreen(int mask, const QRegion ®ion, ScreenPaintData &d cursorSize *= zoom; } - const QPoint p = (effects->cursorPos() - cursor.hotSpot()) * zoom + QPoint(xTranslation, yTranslation); + const QPointF p = (effects->cursorPos() - cursor.hotSpot()) * zoom + QPoint(xTranslation, yTranslation); cursorTexture->bind(); glEnable(GL_BLEND); @@ -439,7 +439,7 @@ void ZoomEffect::zoomIn(double to) polling = true; effects->startMousePolling(); } - cursorPoint = effects->cursorPos(); + cursorPoint = effects->cursorPos().toPoint(); if (mouseTracking == MouseTrackingDisabled) { prevPoint = cursorPoint; } @@ -458,7 +458,7 @@ void ZoomEffect::zoomOut() } } if (mouseTracking == MouseTrackingDisabled) { - prevPoint = effects->cursorPos(); + prevPoint = effects->cursorPos().toPoint(); } effects->addRepaintFull(); } @@ -540,13 +540,13 @@ void ZoomEffect::moveMouseToCenter() QCursor::setPos(r.x() + r.width() / 2, r.y() + r.height() / 2); } -void ZoomEffect::slotMouseChanged(const QPoint &pos, const QPoint &old, Qt::MouseButtons, +void ZoomEffect::slotMouseChanged(const QPointF &pos, const QPointF &old, Qt::MouseButtons, Qt::MouseButtons, Qt::KeyboardModifiers, Qt::KeyboardModifiers) { if (zoom == 1.0) { return; } - cursorPoint = pos; + cursorPoint = pos.toPoint(); if (pos != old) { lastMouseEvent = QTime::currentTime(); effects->addRepaintFull(); diff --git a/src/effects/zoom/zoom.h b/src/effects/zoom/zoom.h index 02abef1c6b..0ded11df61 100644 --- a/src/effects/zoom/zoom.h +++ b/src/effects/zoom/zoom.h @@ -73,7 +73,7 @@ private Q_SLOTS: void moveMouseToCenter(); void timelineFrameChanged(int frame); void moveFocus(const QPoint &point); - void slotMouseChanged(const QPoint &pos, const QPoint &old, + void slotMouseChanged(const QPointF &pos, const QPointF &old, Qt::MouseButtons buttons, Qt::MouseButtons oldbuttons, Qt::KeyboardModifiers modifiers, Qt::KeyboardModifiers oldmodifiers); void slotWindowDamaged(); diff --git a/src/libkwineffects/kwineffects.cpp b/src/libkwineffects/kwineffects.cpp index 708467bb05..cf6f5b2921 100644 --- a/src/libkwineffects/kwineffects.cpp +++ b/src/libkwineffects/kwineffects.cpp @@ -548,7 +548,7 @@ void Effect::setPositionTransformations(WindowPaintData &data, QRect ®ion, Ef data.setYTranslation(y - w->y()); } -QPoint Effect::cursorPos() +QPointF Effect::cursorPos() { return effects->cursorPos(); } diff --git a/src/libkwineffects/kwineffects.h b/src/libkwineffects/kwineffects.h index 2dea3ce4d9..76c673533c 100644 --- a/src/libkwineffects/kwineffects.h +++ b/src/libkwineffects/kwineffects.h @@ -627,7 +627,7 @@ public: */ virtual bool tabletPadRingEvent(int number, int position, bool isFinger, void *tabletPadId); - static QPoint cursorPos(); + static QPointF cursorPos(); /** * Read animation time from the configuration and possibly adjust using animationTimeFactor(). @@ -819,7 +819,7 @@ class KWINEFFECTS_EXPORT EffectsHandler : public QObject */ Q_PROPERTY(bool decorationsHaveAlpha READ decorationsHaveAlpha) Q_PROPERTY(CompositingType compositingType READ compositingType CONSTANT) - Q_PROPERTY(QPoint cursorPos READ cursorPos) + Q_PROPERTY(QPointF cursorPos READ cursorPos) Q_PROPERTY(QSize virtualScreenSize READ virtualScreenSize NOTIFY virtualScreenSizeChanged) Q_PROPERTY(QRect virtualScreenGeometry READ virtualScreenGeometry NOTIFY virtualScreenGeometryChanged) Q_PROPERTY(bool hasActiveFullScreenEffect READ hasActiveFullScreenEffect NOTIFY hasActiveFullScreenEffectChanged) @@ -855,7 +855,7 @@ public: * @since 4.11 */ virtual void defineCursor(Qt::CursorShape shape) = 0; - virtual QPoint cursorPos() const = 0; + virtual QPointF cursorPos() const = 0; virtual bool grabKeyboard(Effect *effect) = 0; virtual void ungrabKeyboard() = 0; /** @@ -1332,7 +1332,7 @@ public: * @param callback The function to invoke once the interactive position selection ends * @since 5.9 */ - virtual void startInteractivePositionSelection(std::function callback) = 0; + virtual void startInteractivePositionSelection(std::function callback) = 0; /** * Shows an on-screen-message. To hide it again use hideOnScreenMessage. @@ -1730,7 +1730,7 @@ Q_SIGNALS: * @see startMousePolling * @since 4.7 */ - void mouseChanged(const QPoint &pos, const QPoint &oldpos, + void mouseChanged(const QPointF &pos, const QPointF &oldpos, Qt::MouseButtons buttons, Qt::MouseButtons oldbuttons, Qt::KeyboardModifiers modifiers, Qt::KeyboardModifiers oldmodifiers); /** diff --git a/src/libkwineffects/kwinglobals.h b/src/libkwineffects/kwinglobals.h index 973a022f63..02e54d3f39 100644 --- a/src/libkwineffects/kwinglobals.h +++ b/src/libkwineffects/kwinglobals.h @@ -225,7 +225,7 @@ public: , m_hotSpot() { } - explicit PlatformCursorImage(const QImage &image, const QPoint &hotSpot) + explicit PlatformCursorImage(const QImage &image, const QPointF &hotSpot) : m_image(image) , m_hotSpot(hotSpot) { @@ -240,14 +240,14 @@ public: { return m_image; } - QPoint hotSpot() const + QPointF hotSpot() const { return m_hotSpot; } private: QImage m_image; - QPoint m_hotSpot; + QPointF m_hotSpot; }; /** @@ -259,6 +259,15 @@ inline KWIN_EXPORT QRect infiniteRegion() return QRect(INT_MIN / 2, INT_MIN / 2, INT_MAX, INT_MAX); } +/** + * @returns if @a point is contained in @a rect, including the left and top borders + * but excluding the right and bottom borders + */ +static inline bool exclusiveContains(const QRectF &rect, const QPointF &point) +{ + return point.x() >= rect.x() && point.y() >= rect.y() && point.x() < (rect.x() + rect.width()) && point.y() < (rect.y() + rect.height()); +} + } // namespace Q_DECLARE_METATYPE(std::chrono::nanoseconds) diff --git a/src/main.cpp b/src/main.cpp index 744571b77b..cece92c3b7 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -672,10 +672,10 @@ void Application::startInteractiveWindowSelection(std::functionstartInteractiveWindowSelection(callback, cursorName); } -void Application::startInteractivePositionSelection(std::function callback) +void Application::startInteractivePositionSelection(std::function callback) { if (!input()) { - callback(QPoint(-1, -1)); + callback(QPointF(-1, -1)); return; } input()->startInteractivePositionSelection(callback); diff --git a/src/main.h b/src/main.h index 1e6489944f..5d36810d61 100644 --- a/src/main.h +++ b/src/main.h @@ -299,7 +299,7 @@ public: * * @param callback The function to invoke once the interactive position selection ends */ - virtual void startInteractivePositionSelection(std::function callback); + virtual void startInteractivePositionSelection(std::function callback); /** * Returns a PlatformCursorImage. By default this is created by softwareCursor and diff --git a/src/main_x11.cpp b/src/main_x11.cpp index 1442e42718..42442f032d 100644 --- a/src/main_x11.cpp +++ b/src/main_x11.cpp @@ -227,7 +227,7 @@ void ApplicationX11::startInteractiveWindowSelection(std::function(outputBackend())->startInteractiveWindowSelection(callback, cursorName); } -void ApplicationX11::startInteractivePositionSelection(std::function callback) +void ApplicationX11::startInteractivePositionSelection(std::function callback) { static_cast(outputBackend())->startInteractivePositionSelection(callback); } diff --git a/src/main_x11.h b/src/main_x11.h index 1ddb277ab3..b0cf7368a3 100644 --- a/src/main_x11.h +++ b/src/main_x11.h @@ -28,7 +28,7 @@ public: std::unique_ptr createOutline(Outline *outline) override; void createEffectsHandler(Compositor *compositor, WorkspaceScene *scene) override; void startInteractiveWindowSelection(std::function callback, const QByteArray &cursorName = QByteArray()) override; - void startInteractivePositionSelection(std::function callback) override; + void startInteractivePositionSelection(std::function callback) override; PlatformCursorImage cursorImage() const override; protected: diff --git a/src/plugins/qpa/platformcursor.cpp b/src/plugins/qpa/platformcursor.cpp index 2359fc91ad..fc337e07ef 100644 --- a/src/plugins/qpa/platformcursor.cpp +++ b/src/plugins/qpa/platformcursor.cpp @@ -23,7 +23,7 @@ PlatformCursor::~PlatformCursor() = default; QPoint PlatformCursor::pos() const { - return Cursors::self()->mouse()->pos(); + return Cursors::self()->mouse()->pos().toPoint(); } void PlatformCursor::setPos(const QPoint &pos) diff --git a/src/plugins/screencast/screencastmanager.cpp b/src/plugins/screencast/screencastmanager.cpp index 5c869abd68..e34d96cf9c 100644 --- a/src/plugins/screencast/screencastmanager.cpp +++ b/src/plugins/screencast/screencastmanager.cpp @@ -108,7 +108,7 @@ void ScreencastManager::streamWindow(KWaylandServer::ScreencastStreamV1Interface } auto stream = new WindowStream(window, this); - stream->setCursorMode(mode, 1, window->clientGeometry().toRect()); + stream->setCursorMode(mode, 1, window->clientGeometry()); if (mode != KWaylandServer::ScreencastV1Interface::CursorMode::Hidden) { connect(window, &Window::clientGeometryChanged, stream, [window, stream, mode]() { stream->setCursorMode(mode, 1, window->clientGeometry().toRect()); diff --git a/src/plugins/screencast/screencaststream.cpp b/src/plugins/screencast/screencaststream.cpp index bab5b2e481..1672b13f49 100644 --- a/src/plugins/screencast/screencaststream.cpp +++ b/src/plugins/screencast/screencaststream.cpp @@ -446,7 +446,7 @@ void ScreenCastStream::recordFrame(const QRegion &_damagedRegion) if (m_cursor.mode == KWaylandServer::ScreencastV1Interface::Embedded && m_cursor.viewport.contains(cursor->pos())) { QPainter painter(&dest); const auto position = (cursor->pos() - m_cursor.viewport.topLeft() - cursor->hotspot()) * m_cursor.scale; - painter.drawImage(QRect{position, cursor->image().size()}, cursor->image()); + painter.drawImage(QRect{position.toPoint(), cursor->image().size()}, cursor->image()); } } else { auto &buf = m_dmabufDataForPwBuffer[buffer]; @@ -493,10 +493,10 @@ void ScreenCastStream::recordFrame(const QRegion &_damagedRegion) ShaderManager::instance()->popShader(); GLFramebuffer::popFramebuffer(); - damagedRegion += QRegion{m_cursor.lastRect} | cursorRect; + damagedRegion += QRegion{m_cursor.lastRect.toAlignedRect()} | cursorRect.toAlignedRect(); m_cursor.lastRect = cursorRect; } else { - damagedRegion |= m_cursor.lastRect; + damagedRegion |= m_cursor.lastRect.toAlignedRect(); m_cursor.lastRect = {}; } } @@ -692,14 +692,14 @@ spa_pod *ScreenCastStream::buildFormat(struct spa_pod_builder *b, enum spa_video return (spa_pod *)spa_pod_builder_pop(b, &f[0]); } -QRect ScreenCastStream::cursorGeometry(Cursor *cursor) const +QRectF ScreenCastStream::cursorGeometry(Cursor *cursor) const { if (!m_cursor.texture) { return {}; } const auto position = (cursor->pos() - m_cursor.viewport.topLeft() - cursor->hotspot()) * m_cursor.scale; - return QRect{position, m_cursor.texture->size()}; + return QRectF{position, m_cursor.texture->size()}; } void ScreenCastStream::sendCursorData(Cursor *cursor, spa_meta_cursor *spa_meta_cursor) @@ -736,7 +736,7 @@ void ScreenCastStream::sendCursorData(Cursor *cursor, spa_meta_cursor *spa_meta_ m_cursor.lastKey = image.cacheKey(); spa_meta_cursor->bitmap_offset = sizeof(struct spa_meta_cursor); - const QSize targetSize = cursor->rect().size() * m_cursor.scale; + const QSize targetSize = (cursor->rect().size() * m_cursor.scale).toSize(); struct spa_meta_bitmap *spa_meta_bitmap = SPA_MEMBER(spa_meta_cursor, spa_meta_cursor->bitmap_offset, @@ -761,7 +761,7 @@ void ScreenCastStream::sendCursorData(Cursor *cursor, spa_meta_cursor *spa_meta_ } } -void ScreenCastStream::setCursorMode(KWaylandServer::ScreencastV1Interface::CursorMode mode, qreal scale, const QRect &viewport) +void ScreenCastStream::setCursorMode(KWaylandServer::ScreencastV1Interface::CursorMode mode, qreal scale, const QRectF &viewport) { m_cursor.mode = mode; m_cursor.scale = scale; diff --git a/src/plugins/screencast/screencaststream.h b/src/plugins/screencast/screencaststream.h index 0de382152e..57311efb58 100644 --- a/src/plugins/screencast/screencaststream.h +++ b/src/plugins/screencast/screencaststream.h @@ -59,7 +59,7 @@ public: */ void recordFrame(const QRegion &damagedRegion); - void setCursorMode(KWaylandServer::ScreencastV1Interface::CursorMode mode, qreal scale, const QRect &viewport); + void setCursorMode(KWaylandServer::ScreencastV1Interface::CursorMode mode, qreal scale, const QRectF &viewport); public Q_SLOTS: void recordCursor(); @@ -112,13 +112,13 @@ private: KWaylandServer::ScreencastV1Interface::CursorMode mode = KWaylandServer::ScreencastV1Interface::Hidden; const QSize bitmapSize = QSize(256, 256); qreal scale = 1; - QRect viewport; + QRectF viewport; qint64 lastKey = 0; - QRect lastRect; + QRectF lastRect; std::unique_ptr texture; bool visible = false; } m_cursor; - QRect cursorGeometry(Cursor *cursor) const; + QRectF cursorGeometry(Cursor *cursor) const; QHash> m_dmabufDataForPwBuffer; diff --git a/src/pointer_input.cpp b/src/pointer_input.cpp index b807f59af8..180b546d4a 100644 --- a/src/pointer_input.cpp +++ b/src/pointer_input.cpp @@ -1180,9 +1180,9 @@ void InputRedirectionCursor::doSetPos() void InputRedirectionCursor::slotPosChanged(const QPointF &pos) { - const QPoint oldPos = currentPos(); - updatePos(pos.toPoint()); - Q_EMIT mouseChanged(pos.toPoint(), oldPos, m_currentButtons, m_currentButtons, + const QPointF oldPos = currentPos(); + updatePos(pos); + Q_EMIT mouseChanged(pos, oldPos, m_currentButtons, m_currentButtons, input()->keyboardModifiers(), input()->keyboardModifiers()); } @@ -1195,7 +1195,7 @@ void InputRedirectionCursor::slotPointerButtonChanged() { const Qt::MouseButtons oldButtons = m_currentButtons; m_currentButtons = input()->qtButtonStates(); - const QPoint pos = currentPos(); + const QPointF pos = currentPos(); Q_EMIT mouseChanged(pos, pos, m_currentButtons, oldButtons, input()->keyboardModifiers(), input()->keyboardModifiers()); } diff --git a/src/screenedge.cpp b/src/screenedge.cpp index 5e93cb8b7f..dec4fd3825 100644 --- a/src/screenedge.cpp +++ b/src/screenedge.cpp @@ -516,7 +516,7 @@ void Edge::pushCursorBack(const QPoint &cursorPos) if (isBottom()) { y -= distance.height(); } - Cursors::self()->mouse()->setPos(x, y); + Cursors::self()->mouse()->setPos(QPoint(x, y)); } void Edge::setGeometry(const QRect &geometry) @@ -648,46 +648,47 @@ void Edge::doStopApproaching() { } -void Edge::updateApproaching(const QPoint &point) +void Edge::updateApproaching(const QPointF &point) { - if (approachGeometry().contains(point)) { + if (exclusiveContains(approachGeometry(), point)) { int factor = 0; const int edgeDistance = m_edges->cornerOffset(); - auto cornerDistance = [=](const QPoint &corner) { + auto cornerDistance = [=](const QPointF &corner) { return std::max(std::abs(corner.x() - point.x()), std::abs(corner.y() - point.y())); }; + constexpr double factorScale = 256; switch (border()) { case ElectricTopLeft: - factor = (cornerDistance(approachGeometry().topLeft()) << 8) / edgeDistance; + factor = (cornerDistance(approachGeometry().topLeft()) * factorScale) / edgeDistance; break; case ElectricTopRight: - factor = (cornerDistance(approachGeometry().topRight()) << 8) / edgeDistance; + factor = (cornerDistance(approachGeometry().topRight()) * factorScale) / edgeDistance; break; case ElectricBottomRight: - factor = (cornerDistance(approachGeometry().bottomRight()) << 8) / edgeDistance; + factor = (cornerDistance(approachGeometry().bottomRight()) * factorScale) / edgeDistance; break; case ElectricBottomLeft: - factor = (cornerDistance(approachGeometry().bottomLeft()) << 8) / edgeDistance; + factor = (cornerDistance(approachGeometry().bottomLeft()) * factorScale) / edgeDistance; break; case ElectricTop: - factor = (std::abs(point.y() - approachGeometry().y()) << 8) / edgeDistance; + factor = (std::abs(point.y() - approachGeometry().y()) * factorScale) / edgeDistance; break; case ElectricRight: - factor = (std::abs(point.x() - approachGeometry().right()) << 8) / edgeDistance; + factor = (std::abs(point.x() - approachGeometry().right()) * factorScale) / edgeDistance; break; case ElectricBottom: - factor = (std::abs(point.y() - approachGeometry().bottom()) << 8) / edgeDistance; + factor = (std::abs(point.y() - approachGeometry().bottom()) * factorScale) / edgeDistance; break; case ElectricLeft: - factor = (std::abs(point.x() - approachGeometry().x()) << 8) / edgeDistance; + factor = (std::abs(point.x() - approachGeometry().x()) * factorScale) / edgeDistance; break; default: break; } - factor = 256 - factor; + factor = factorScale - factor; if (m_lastApproachingFactor != factor) { m_lastApproachingFactor = factor; - Q_EMIT approaching(border(), m_lastApproachingFactor / 256.0f, m_approachGeometry); + Q_EMIT approaching(border(), m_lastApproachingFactor / factorScale, m_approachGeometry); } } else { stopApproaching(); diff --git a/src/screenedge.h b/src/screenedge.h index 6e018220e3..8195a9804f 100644 --- a/src/screenedge.h +++ b/src/screenedge.h @@ -112,7 +112,7 @@ public Q_SLOTS: void setBorder(ElectricBorder border); void setAction(ElectricBorderAction action); void setGeometry(const QRect &geometry); - void updateApproaching(const QPoint &point); + void updateApproaching(const QPointF &point); void checkBlocking(); Q_SIGNALS: void approaching(ElectricBorder border, qreal factor, const QRect &geometry); diff --git a/src/scripting/workspace_wrapper.cpp b/src/scripting/workspace_wrapper.cpp index 74f9f12910..1a46bb894e 100644 --- a/src/scripting/workspace_wrapper.cpp +++ b/src/scripting/workspace_wrapper.cpp @@ -108,7 +108,7 @@ QStringList WorkspaceWrapper::activityList() const QPoint WorkspaceWrapper::cursorPos() const { - return Cursors::self()->mouse()->pos(); + return Cursors::self()->mouse()->pos().toPoint(); } #define SLOTWRAPPER(name) \ diff --git a/src/wayland/pointer_interface.cpp b/src/wayland/pointer_interface.cpp index fb1c868c57..3bd032c0de 100644 --- a/src/wayland/pointer_interface.cpp +++ b/src/wayland/pointer_interface.cpp @@ -28,10 +28,10 @@ public: Cursor *q; PointerInterface *pointer; quint32 enteredSerial = 0; - QPoint hotspot; + QPointF hotspot; QPointer surface; - void update(SurfaceInterface *surface, quint32 serial, const QPoint &hotspot); + void update(SurfaceInterface *surface, quint32 serial, const QPointF &hotspot); }; PointerInterfacePrivate *PointerInterfacePrivate::get(PointerInterface *pointer) @@ -86,11 +86,11 @@ void PointerInterfacePrivate::pointer_set_cursor(Resource *resource, uint32_t se if (!cursor) { // TODO: Assign the cursor surface role. cursor = new Cursor(q); - cursor->d->update(surface, serial, QPoint(hotspot_x, hotspot_y)); + cursor->d->update(surface, serial, QPointF(hotspot_x, hotspot_y) / focusedSurface->client()->scaleOverride()); QObject::connect(cursor, &Cursor::changed, q, &PointerInterface::cursorChanged); Q_EMIT q->cursorChanged(); } else { - cursor->d->update(surface, serial, QPoint(hotspot_x, hotspot_y)); + cursor->d->update(surface, serial, QPointF(hotspot_x, hotspot_y) / focusedSurface->client()->scaleOverride()); } } @@ -372,7 +372,7 @@ CursorPrivate::CursorPrivate(Cursor *q, PointerInterface *pointer) { } -void CursorPrivate::update(SurfaceInterface *s, quint32 serial, const QPoint &p) +void CursorPrivate::update(SurfaceInterface *s, quint32 serial, const QPointF &p) { bool emitChanged = false; if (enteredSerial != serial) { @@ -416,7 +416,7 @@ quint32 Cursor::enteredSerial() const return d->enteredSerial; } -QPoint Cursor::hotspot() const +QPointF Cursor::hotspot() const { return d->hotspot; } diff --git a/src/wayland/pointer_interface.h b/src/wayland/pointer_interface.h index 07d628404f..f3535347db 100644 --- a/src/wayland/pointer_interface.h +++ b/src/wayland/pointer_interface.h @@ -93,7 +93,7 @@ public: /** * The hotspot of the cursor image in surface-relative coordinates. */ - QPoint hotspot() const; + QPointF hotspot() const; /** * The entered serial when the Cursor got set. */ diff --git a/src/window.cpp b/src/window.cpp index 2ecde92a9c..6a53189931 100644 --- a/src/window.cpp +++ b/src/window.cpp @@ -1817,7 +1817,7 @@ void Window::handleInteractiveMoveResize(const QPointF &local, const QPointF &gl } } -void Window::handleInteractiveMoveResize(int x, int y, int x_root, int y_root) +void Window::handleInteractiveMoveResize(qreal x, qreal y, qreal x_root, qreal y_root) { if (isWaitingForInteractiveMoveResizeSync()) { return; // we're still waiting for the client or the timeout diff --git a/src/window.h b/src/window.h index 3341d10e4e..7364c689eb 100644 --- a/src/window.h +++ b/src/window.h @@ -1835,7 +1835,7 @@ protected: * Default implementation does nothing. */ virtual void doInteractiveResizeSync(const QRectF &rect); - void handleInteractiveMoveResize(int x, int y, int x_root, int y_root); + void handleInteractiveMoveResize(qreal x, qreal y, qreal x_root, qreal y_root); void handleInteractiveMoveResize(const QPointF &local, const QPointF &global); void dontInteractiveMoveResize(); diff --git a/src/workspace.cpp b/src/workspace.cpp index 5f71da7135..c317ac3732 100644 --- a/src/workspace.cpp +++ b/src/workspace.cpp @@ -1353,8 +1353,7 @@ Window *Workspace::findWindowToActivateOnDesktop(VirtualDesktop *desktop) continue; } - // port to hit test - if (window->frameGeometry().toRect().contains(Cursors::self()->mouse()->pos())) { + if (window->hitTest(Cursors::self()->mouse()->pos())) { if (!window->isDesktop()) { return window; } @@ -2439,15 +2438,15 @@ void Workspace::desktopResized() // 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()); + return exclusiveContains(geometry, Cursors::self()->mouse()->pos()); }); if (oldCursorOutput != m_oldScreenGeometries.cend()) { 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())); + const QPointF relativePosition = Cursors::self()->mouse()->pos() - oldGeometry.topLeft(); + const QPointF newRelativePosition(newGeometry.width() * relativePosition.x() / float(oldGeometry.width()), newGeometry.height() * relativePosition.y() / float(oldGeometry.height())); Cursors::self()->mouse()->setPos(newGeometry.topLeft() + newRelativePosition); } }