diff options
author | Johan Klokkhammer Helsing <johan.helsing@qt.io> | 2018-12-06 12:00:55 +0100 |
---|---|---|
committer | Johan Helsing <johan.helsing@qt.io> | 2019-02-15 09:12:35 +0000 |
commit | 15b3afd621a5c0e8d1dd1cd9d5ae816e15aa4a1a (patch) | |
tree | efe8e2944f983d1b263ce44efeb2a3eeee6ef0bb /src/client/qwaylandinputdevice_p.h | |
parent | 8073af6668cbcf308c83359ef2797d85d971946f (diff) |
Client: Refactor cursors and fix various bugs
This patch is mostly a cleanup to prepare for implementations of
xcursor-configuration, but also fixes a couple of issues.
Most of the logic has now been moved out of QWaylandDisplay and QWaylandCursor
and into QWaylandInputDevice and QWaylandInputDevice::Pointer. QWaylandDisplay
now only contains mechanisms for avoiding loading the same theme multiple
times.
There is now only one setCursor method on QWaylandInputDevice, accepting a
QCursor and storing its values so changing scale factor doesn't require calling
setCursor again. QWaylandInputDevice::Pointer::updateCursor() is called
instead.
Cursor buffer scale is now set according to enter/leave events of the cursor
surface itself instead of the current window, this fixes incorrect buffer
scales for cursors on windows that span multiple outputs. The window buffer
scale can still be passed into the seat as a fallback until the first enter
event is received.
This also fixes a bug where the QWaylandBuffer of a bitmap cursor could be
deleted while it was being used as a cursor.
[ChangeLog][QPA plugin] Fixed a bug where the DPI of bitmap cursors were not
sent to the compositor, leading to the compositor incorrectly scaling the
cursor up or down.
[ChangeLog][QPA plugin] Fixed a bug where bitmap cursor hotspots were off when
the screen scale factor was different from the bitmap cursor device pixel
ratio.
Task-number: QTBUG-68571
Change-Id: I747a47ffff01b7b5f6a0ede3552ab37884c4fa60
Reviewed-by: Paul Olav Tvete <paul.tvete@qt.io>
Diffstat (limited to 'src/client/qwaylandinputdevice_p.h')
-rw-r--r-- | src/client/qwaylandinputdevice_p.h | 45 |
1 files changed, 32 insertions, 13 deletions
diff --git a/src/client/qwaylandinputdevice_p.h b/src/client/qwaylandinputdevice_p.h index c2fd57bb0..e57d7f4fd 100644 --- a/src/client/qwaylandinputdevice_p.h +++ b/src/client/qwaylandinputdevice_p.h @@ -88,6 +88,10 @@ class QWaylandWindow; class QWaylandDisplay; class QWaylandDataDevice; class QWaylandTextInput; +#if QT_CONFIG(cursor) +class QWaylandCursorTheme; +class CursorSurface; +#endif class Q_WAYLAND_CLIENT_EXPORT QWaylandInputDevice : public QObject @@ -107,10 +111,7 @@ public: struct ::wl_seat *wl_seat() { return QtWayland::wl_seat::object(); } #if QT_CONFIG(cursor) - void setCursor(const QCursor &cursor, QWaylandScreen *screen); - void setCursor(struct wl_buffer *buffer, struct ::wl_cursor_image *image, int bufferScale); - void setCursor(struct wl_buffer *buffer, const QPoint &hotSpot, const QSize &size, int bufferScale); - void setCursor(const QSharedPointer<QWaylandBuffer> &buffer, const QPoint &hotSpot, int bufferScale); + void setCursor(const QCursor *cursor, const QSharedPointer<QWaylandBuffer> &cachedBuffer = {}, int fallbackOutputScale = 1); #endif void handleWindowDestroyed(QWaylandWindow *window); void handleEndDrag(); @@ -134,22 +135,27 @@ public: Qt::KeyboardModifiers modifiers() const; uint32_t serial() const; - uint32_t cursorSerial() const; virtual Keyboard *createKeyboard(QWaylandInputDevice *device); virtual Pointer *createPointer(QWaylandInputDevice *device); virtual Touch *createTouch(QWaylandInputDevice *device); private: - void setCursor(Qt::CursorShape cursor, QWaylandScreen *screen); - QWaylandDisplay *mQDisplay = nullptr; struct wl_display *mDisplay = nullptr; int mVersion; uint32_t mCaps = 0; - struct wl_surface *pointerSurface = nullptr; +#if QT_CONFIG(cursor) + struct CursorState { + QSharedPointer<QWaylandBuffer> bitmapBuffer; // not used with shape cursors + int bitmapScale = 1; + Qt::CursorShape shape = Qt::ArrowCursor; + int fallbackOutputScale = 1; + QPoint hotspot; + } mCursor; +#endif #if QT_CONFIG(wayland_datadevice) QWaylandDataDevice *mDataDevice = nullptr; @@ -169,8 +175,6 @@ private: QTouchDevice *mTouchDevice = nullptr; - QSharedPointer<QWaylandBuffer> mPixmapCursor; - friend class QWaylandTouchExtension; friend class QWaylandQtKeyExtension; }; @@ -247,11 +251,20 @@ private: class Q_WAYLAND_CLIENT_EXPORT QWaylandInputDevice::Pointer : public QtWayland::wl_pointer { - public: - Pointer(QWaylandInputDevice *p); + explicit Pointer(QWaylandInputDevice *seat); ~Pointer() override; +#if QT_CONFIG(cursor) + QString cursorThemeName() const; + int cursorSize() const; // in surface coordinates + int idealCursorScale() const; + void updateCursorTheme(); + void updateCursor(); + CursorSurface *getOrCreateCursorSurface(); +#endif + QWaylandInputDevice *seat() const { return mParent; } +protected: void pointer_enter(uint32_t serial, struct wl_surface *surface, wl_fixed_t sx, wl_fixed_t sy) override; void pointer_leave(uint32_t time, struct wl_surface *surface) override; @@ -263,13 +276,19 @@ public: uint32_t axis, wl_fixed_t value) override; +public: void releaseButtons(); QWaylandInputDevice *mParent = nullptr; QPointer<QWaylandWindow> mFocus; uint32_t mEnterSerial = 0; #if QT_CONFIG(cursor) - uint32_t mCursorSerial = 0; + struct { + uint32_t serial = 0; + QWaylandCursorTheme *theme = nullptr; + int themeBufferScale = 0; + QScopedPointer<CursorSurface> surface; + } mCursor; #endif QPointF mSurfacePos; QPointF mGlobalPos; |