From 916944807b8c54e887959eef63c542d2f16afab1 Mon Sep 17 00:00:00 2001 From: Johan Klokkhammer Helsing Date: Tue, 15 May 2018 16:24:37 +0200 Subject: Client: Move cursor theme logic into its own class, QWaylandCursorTheme ...and out of QWaylandCursor. Encapsulates the ugly details of wayland cursor themes, and presents a simple interface. A theme is created with a given size and theme name. wl_cursor_images for a theme can be acquired through: wl_cursor_image *QWaylandCursorTheme::cursorImage(Qt::CursorShape shape); Change-Id: Ia6fc6f2997133ca25c1610ecdf075ecb5c4edbfa Reviewed-by: Paul Olav Tvete --- src/client/qwaylandcursor_p.h | 41 +++++++++++++++++++++++++++-------------- 1 file changed, 27 insertions(+), 14 deletions(-) (limited to 'src/client/qwaylandcursor_p.h') diff --git a/src/client/qwaylandcursor_p.h b/src/client/qwaylandcursor_p.h index 532e46c19..71f9cd1b8 100644 --- a/src/client/qwaylandcursor_p.h +++ b/src/client/qwaylandcursor_p.h @@ -68,19 +68,15 @@ namespace QtWaylandClient { class QWaylandBuffer; class QWaylandDisplay; class QWaylandScreen; +class QWaylandShm; -class Q_WAYLAND_CLIENT_EXPORT QWaylandCursor : public QPlatformCursor +class Q_WAYLAND_CLIENT_EXPORT QWaylandCursorTheme { public: - QWaylandCursor(QWaylandScreen *screen); - - void changeCursor(QCursor *cursor, QWindow *window) override; - void pointerEvent(const QMouseEvent &event) override; - QPoint pos() const override; - void setPos(const QPoint &pos) override; - + static QWaylandCursorTheme *create(QWaylandShm *shm, int size); + static QWaylandCursorTheme *create(QWaylandShm *shm, int size, const QString &themeName); + ~QWaylandCursorTheme(); struct wl_cursor_image *cursorImage(Qt::CursorShape shape); - QSharedPointer cursorBitmapImage(const QCursor *cursor); private: enum WaylandCursor { @@ -106,6 +102,7 @@ private: DragCopyCursor, DragMoveCursor, DragLinkCursor, + // The following are used for cursors that don't have equivalents in Qt ResizeNorthCursor = Qt::CustomCursor + 1, ResizeSouthCursor, ResizeEastCursor, @@ -116,13 +113,29 @@ private: ResizeSouthWestCursor }; - struct wl_cursor* requestCursor(WaylandCursor shape); - void initCursorMap(); + explicit QWaylandCursorTheme(struct ::wl_cursor_theme *theme) : m_theme(theme) {} + struct ::wl_cursor *requestCursor(WaylandCursor shape); + struct ::wl_cursor_theme *m_theme = nullptr; + QMap m_cursors; +}; + +class Q_WAYLAND_CLIENT_EXPORT QWaylandCursor : public QPlatformCursor +{ +public: + QWaylandCursor(QWaylandScreen *screen); + + void changeCursor(QCursor *cursor, QWindow *window) override; + void pointerEvent(const QMouseEvent &event) override; + QPoint pos() const override; + void setPos(const QPoint &pos) override; + + QSharedPointer cursorBitmapImage(const QCursor *cursor); + struct wl_cursor_image *cursorImage(Qt::CursorShape shape); + +private: QWaylandDisplay *mDisplay = nullptr; - struct wl_cursor_theme *mCursorTheme = nullptr; + QWaylandCursorTheme *mCursorTheme = nullptr; QPoint mLastPos; - QMap mCursors; - QMultiMap mCursorNamesMap; }; } -- cgit v1.2.3