From fc1901b4b34d29df79be1b9b1c1d3f5a127eaa59 Mon Sep 17 00:00:00 2001 From: Giulio Camuffo Date: Sat, 19 Nov 2016 08:58:17 +0100 Subject: Don't reset the cursor at every mouse move Change-Id: I67f9a0d171da403ebb124ab584c2510891da80fc Reviewed-by: Paul Olav Tvete --- src/client/qwaylandinputdevice.cpp | 14 ++++++++++++++ src/client/qwaylandinputdevice_p.h | 5 ++++- src/client/qwaylandwindow.cpp | 6 +----- src/client/qwaylandwindow_p.h | 1 - 4 files changed, 19 insertions(+), 7 deletions(-) diff --git a/src/client/qwaylandinputdevice.cpp b/src/client/qwaylandinputdevice.cpp index 94316bafc..de0520890 100644 --- a/src/client/qwaylandinputdevice.cpp +++ b/src/client/qwaylandinputdevice.cpp @@ -147,6 +147,8 @@ QWaylandInputDevice::Pointer::Pointer(QWaylandInputDevice *p) , mEnterSerial(0) , mCursorSerial(0) , mButtons(0) + , mCursorBuffer(nullptr) + , mCursorShape(Qt::BitmapCursor) { } @@ -362,6 +364,10 @@ void QWaylandInputDevice::setCursor(Qt::CursorShape newShape, QWaylandScreen *sc void QWaylandInputDevice::setCursor(const QCursor &cursor, QWaylandScreen *screen) { + if (cursor.shape() != Qt::BitmapCursor && cursor.shape() == mPointer->mCursorShape) + return; + + mPointer->mCursorShape = cursor.shape(); if (cursor.shape() == Qt::BitmapCursor) { setCursor(screen->waylandCursor()->cursorBitmapImage(&cursor), cursor.hotSpot()); return; @@ -379,8 +385,16 @@ void QWaylandInputDevice::setCursor(struct wl_buffer *buffer, struct wl_cursor_i void QWaylandInputDevice::setCursor(struct wl_buffer *buffer, const QPoint &hotSpot, const QSize &size) { if (mCaps & WL_SEAT_CAPABILITY_POINTER) { + bool force = mPointer->mEnterSerial > mPointer->mCursorSerial; + + if (!force && mPointer->mCursorBuffer == buffer) + return; + mPixmapCursor.clear(); mPointer->mCursorSerial = mPointer->mEnterSerial; + + mPointer->mCursorBuffer = buffer; + /* Hide cursor */ if (!buffer) { diff --git a/src/client/qwaylandinputdevice_p.h b/src/client/qwaylandinputdevice_p.h index 2f39bc547..d41bde564 100644 --- a/src/client/qwaylandinputdevice_p.h +++ b/src/client/qwaylandinputdevice_p.h @@ -99,7 +99,6 @@ public: struct ::wl_seat *wl_seat() { return QtWayland::wl_seat::object(); } - void setCursor(Qt::CursorShape cursor, QWaylandScreen *screen); void setCursor(const QCursor &cursor, QWaylandScreen *screen); void setCursor(struct wl_buffer *buffer, struct ::wl_cursor_image *image); void setCursor(struct wl_buffer *buffer, const QPoint &hotSpot, const QSize &size); @@ -129,6 +128,8 @@ public: virtual Touch *createTouch(QWaylandInputDevice *device); private: + void setCursor(Qt::CursorShape cursor, QWaylandScreen *screen); + QWaylandDisplay *mQDisplay; struct wl_display *mDisplay; @@ -249,6 +250,8 @@ public: QPointF mSurfacePos; QPointF mGlobalPos; Qt::MouseButtons mButtons; + wl_buffer *mCursorBuffer; + Qt::CursorShape mCursorShape; }; class Q_WAYLAND_CLIENT_EXPORT QWaylandInputDevice::Touch : public QtWayland::wl_touch diff --git a/src/client/qwaylandwindow.cpp b/src/client/qwaylandwindow.cpp index 1ff6686f6..8e40f3b37 100644 --- a/src/client/qwaylandwindow.cpp +++ b/src/client/qwaylandwindow.cpp @@ -81,7 +81,6 @@ QWaylandWindow::QWaylandWindow(QWindow *window) , mWindowDecoration(0) , mMouseEventsInContentArea(false) , mMousePressedInContentArea(Qt::NoButton) - , m_cursor(Qt::ArrowCursor) , mWaitingForFrameSync(false) , mFrameCallback(nullptr) , mRequestResizeSent(false) @@ -780,10 +779,7 @@ void QWaylandWindow::handleMouseEventWithDecoration(QWaylandInputDevice *inputDe void QWaylandWindow::setMouseCursor(QWaylandInputDevice *device, const QCursor &cursor) { - if (device->serial() >= device->cursorSerial()) { - device->setCursor(cursor, mScreen); - m_cursor = cursor; - } + device->setCursor(cursor, mScreen); } void QWaylandWindow::restoreMouseCursor(QWaylandInputDevice *device) diff --git a/src/client/qwaylandwindow_p.h b/src/client/qwaylandwindow_p.h index 7e7078fcf..f5988fbd1 100644 --- a/src/client/qwaylandwindow_p.h +++ b/src/client/qwaylandwindow_p.h @@ -217,7 +217,6 @@ protected: QWaylandAbstractDecoration *mWindowDecoration; bool mMouseEventsInContentArea; Qt::MouseButtons mMousePressedInContentArea; - QCursor m_cursor; WId mWindowId; bool mWaitingForFrameSync; -- cgit v1.2.3