diff --git a/src/pointer_input.cpp b/src/pointer_input.cpp index 69a47516cc..adf084acc4 100644 --- a/src/pointer_input.cpp +++ b/src/pointer_input.cpp @@ -99,7 +99,7 @@ void PointerInputRedirection::init() connect(Cursors::self()->mouse(), &Cursor::rendered, m_cursor, &CursorImage::markAsRendered); connect(m_cursor, &CursorImage::changed, Cursors::self()->mouse(), [this] { Cursors::self()->mouse()->setSource(m_cursor->source()); - updateCursorOutputs(); + m_cursor->updateCursorOutputs(m_pos); }); Q_EMIT m_cursor->changed(); @@ -769,32 +769,11 @@ void PointerInputRedirection::updatePosition(const QPointF &pos) m_pos = p; workspace()->setActiveCursorOutput(m_pos); - updateCursorOutputs(); + m_cursor->updateCursorOutputs(m_pos); Q_EMIT input()->globalPointerChanged(m_pos); } -void PointerInputRedirection::updateCursorOutputs() -{ - KWaylandServer::PointerInterface *pointer = waylandServer()->seat()->pointer(); - if (!pointer) { - return; - } - - KWaylandServer::Cursor *cursor = pointer->cursor(); - if (!cursor) { - return; - } - - KWaylandServer::SurfaceInterface *surface = cursor->surface(); - if (!surface) { - return; - } - - const QRectF cursorGeometry(m_pos - m_cursor->source()->hotspot(), surface->size()); - surface->setOutputs(waylandServer()->display()->outputsIntersecting(cursorGeometry.toAlignedRect())); -} - void PointerInputRedirection::updateButton(uint32_t button, InputRedirection::PointerButtonState state) { m_buttons[button] = state; @@ -934,24 +913,25 @@ CursorImage::CursorImage(PointerInputRedirection *parent) CursorImage::~CursorImage() = default; +void CursorImage::updateCursorOutputs(const QPointF &pos) +{ + if (m_currentSource == m_serverCursor.cursor.get()) { + auto cursorSurface = m_serverCursor.cursor->surface(); + if (cursorSurface) { + const QRectF cursorGeometry(pos - m_currentSource->hotspot(), m_currentSource->size()); + cursorSurface->setOutputs(waylandServer()->display()->outputsIntersecting(cursorGeometry.toAlignedRect())); + } + } +} + void CursorImage::markAsRendered(std::chrono::milliseconds timestamp) { - if (m_currentSource != m_serverCursor.cursor.get()) { - return; + if (m_currentSource == m_serverCursor.cursor.get()) { + auto cursorSurface = m_serverCursor.cursor->surface(); + if (cursorSurface) { + cursorSurface->frameRendered(timestamp.count()); + } } - auto p = waylandServer()->seat()->pointer(); - if (!p) { - return; - } - auto c = p->cursor(); - if (!c) { - return; - } - auto cursorSurface = c->surface(); - if (!cursorSurface) { - return; - } - cursorSurface->frameRendered(timestamp.count()); } void CursorImage::handleFocusedSurfaceChanged() @@ -998,17 +978,10 @@ void CursorImage::updateMoveResize() reevaluteSource(); } -void CursorImage::updateServerCursor() +void CursorImage::updateServerCursor(KWaylandServer::Cursor *cursor) { + m_serverCursor.cursor->update(cursor->surface(), cursor->hotspot()); reevaluteSource(); - auto p = waylandServer()->seat()->pointer(); - if (!p) { - return; - } - auto c = p->cursor(); - if (c) { - m_serverCursor.cursor->update(c->surface(), c->hotspot()); - } } void CursorImage::setEffectsOverrideCursor(Qt::CursorShape shape) diff --git a/src/pointer_input.h b/src/pointer_input.h index fefe834da0..09cb36a4d9 100644 --- a/src/pointer_input.h +++ b/src/pointer_input.h @@ -23,6 +23,7 @@ class QWindow; namespace KWaylandServer { +class Cursor; class SurfaceInterface; } @@ -72,7 +73,6 @@ public: void removeWindowSelectionCursor(); void updatePointerConstraints(); - void updateCursorOutputs(); void setEnableConstraints(bool set); @@ -214,6 +214,8 @@ public: KXcursorTheme theme() const; CursorSource *source() const; void setSource(CursorSource *source); + + void updateCursorOutputs(const QPointF &pos); void markAsRendered(std::chrono::milliseconds timestamp); Q_SIGNALS: @@ -221,7 +223,7 @@ Q_SIGNALS: private: void reevaluteSource(); - void updateServerCursor(); + void updateServerCursor(KWaylandServer::Cursor *cursor); void updateDecoration(); void updateDecorationCursor(); void updateMoveResize(); diff --git a/src/wayland/autotests/client/test_wayland_seat.cpp b/src/wayland/autotests/client/test_wayland_seat.cpp index 9f5ba4b82b..880ba22c7a 100644 --- a/src/wayland/autotests/client/test_wayland_seat.cpp +++ b/src/wayland/autotests/client/test_wayland_seat.cpp @@ -1321,14 +1321,13 @@ void TestWaylandSeat::testCursor() QVERIFY(enteredSpy.wait()); QCOMPARE_GT(enteredSpy.first().first().value(), serial); QVERIFY(m_seatInterface->focusedPointerSurface()); - QVERIFY(!m_seatInterface->pointer()->cursor()); QSignalSpy cursorChangedSpy(m_seatInterface->pointer(), &KWaylandServer::PointerInterface::cursorChanged); // just remove the pointer p->setCursor(nullptr); QVERIFY(cursorChangedSpy.wait()); QCOMPARE(cursorChangedSpy.count(), 1); - auto cursor = m_seatInterface->pointer()->cursor(); + auto cursor = cursorChangedSpy.last().first().value(); QVERIFY(cursor); QVERIFY(!cursor->surface()); QCOMPARE(cursor->hotspot(), QPoint()); diff --git a/src/wayland/pointer_interface.cpp b/src/wayland/pointer_interface.cpp index 7312f28183..0b1a37cb02 100644 --- a/src/wayland/pointer_interface.cpp +++ b/src/wayland/pointer_interface.cpp @@ -86,7 +86,7 @@ void PointerInterfacePrivate::pointer_set_cursor(Resource *resource, uint32_t se cursor->d->hotspot = QPointF(hotspot_x, hotspot_y) / focusedSurface->client()->scaleOverride(); cursor->d->surface = surface; - Q_EMIT q->cursorChanged(); + Q_EMIT q->cursorChanged(cursor.get()); } void PointerInterfacePrivate::pointer_release(Resource *resource) @@ -344,11 +344,6 @@ void PointerInterface::sendFrame() } } -Cursor *PointerInterface::cursor() const -{ - return d->cursor.get(); -} - SeatInterface *PointerInterface::seat() const { return d->seat; diff --git a/src/wayland/pointer_interface.h b/src/wayland/pointer_interface.h index f29e0a6b46..8e1321ac33 100644 --- a/src/wayland/pointer_interface.h +++ b/src/wayland/pointer_interface.h @@ -43,8 +43,6 @@ public: */ SurfaceInterface *focusedSurface() const; - Cursor *cursor() const; - /** * Returns the seat to which this pointer belongs to. */ @@ -67,7 +65,7 @@ Q_SIGNALS: * This signal is emitted whenever the cursor surface changes. As long as there is no * any focused surface, the cursor cannot be changed. */ - void cursorChanged(); + void cursorChanged(KWaylandServer::Cursor *cursor); /** * This signal is emitted whenever the focused pointer surface changes. */