| 1 | // Copyright (C) 2019 The Qt Company Ltd. |
| 2 | // SPDX-License-Identifier: LicenseRef-Qt-Commercial OR LGPL-3.0-only OR GPL-2.0-only OR GPL-3.0-only |
| 3 | |
| 4 | #ifndef QWAYLANDCURSOR_H |
| 5 | #define QWAYLANDCURSOR_H |
| 6 | |
| 7 | // |
| 8 | // W A R N I N G |
| 9 | // ------------- |
| 10 | // |
| 11 | // This file is not part of the Qt API. It exists purely as an |
| 12 | // implementation detail. This header file may change from version to |
| 13 | // version without notice, or even be removed. |
| 14 | // |
| 15 | // We mean it. |
| 16 | // |
| 17 | |
| 18 | #include <qpa/qplatformcursor.h> |
| 19 | #include <QtCore/QMap> |
| 20 | #include <QtWaylandClient/qtwaylandclientglobal.h> |
| 21 | #include <QtWaylandClient/private/qwayland-cursor-shape-v1.h> |
| 22 | #include <QtCore/private/qglobal_p.h> |
| 23 | |
| 24 | #if QT_CONFIG(cursor) |
| 25 | |
| 26 | #include <memory> |
| 27 | |
| 28 | struct wl_cursor; |
| 29 | struct wl_cursor_image; |
| 30 | struct wl_cursor_theme; |
| 31 | |
| 32 | QT_BEGIN_NAMESPACE |
| 33 | |
| 34 | namespace QtWaylandClient { |
| 35 | |
| 36 | class QWaylandBuffer; |
| 37 | class QWaylandDisplay; |
| 38 | class QWaylandScreen; |
| 39 | class QWaylandShm; |
| 40 | |
| 41 | class Q_WAYLANDCLIENT_EXPORT QWaylandCursorTheme |
| 42 | { |
| 43 | public: |
| 44 | static std::unique_ptr<QWaylandCursorTheme> create(QWaylandShm *shm, int size, const QString &themeName); |
| 45 | ~QWaylandCursorTheme(); |
| 46 | ::wl_cursor *cursor(Qt::CursorShape shape); |
| 47 | |
| 48 | protected: |
| 49 | enum WaylandCursor { |
| 50 | ArrowCursor = Qt::ArrowCursor, |
| 51 | UpArrowCursor, |
| 52 | CrossCursor, |
| 53 | WaitCursor, |
| 54 | IBeamCursor, |
| 55 | SizeVerCursor, |
| 56 | SizeHorCursor, |
| 57 | SizeBDiagCursor, |
| 58 | SizeFDiagCursor, |
| 59 | SizeAllCursor, |
| 60 | BlankCursor, |
| 61 | SplitVCursor, |
| 62 | SplitHCursor, |
| 63 | PointingHandCursor, |
| 64 | ForbiddenCursor, |
| 65 | WhatsThisCursor, |
| 66 | BusyCursor, |
| 67 | OpenHandCursor, |
| 68 | ClosedHandCursor, |
| 69 | DragCopyCursor, |
| 70 | DragMoveCursor, |
| 71 | DragLinkCursor, |
| 72 | // The following are used for cursors that don't have equivalents in Qt |
| 73 | ResizeNorthCursor = Qt::CustomCursor + 1, |
| 74 | ResizeSouthCursor, |
| 75 | ResizeEastCursor, |
| 76 | ResizeWestCursor, |
| 77 | ResizeNorthWestCursor, |
| 78 | ResizeSouthEastCursor, |
| 79 | ResizeNorthEastCursor, |
| 80 | ResizeSouthWestCursor, |
| 81 | |
| 82 | NumWaylandCursors |
| 83 | }; |
| 84 | |
| 85 | explicit QWaylandCursorTheme(struct ::wl_cursor_theme *theme) : m_theme(theme) {} |
| 86 | struct ::wl_cursor *requestCursor(WaylandCursor shape); |
| 87 | struct ::wl_cursor_theme *m_theme = nullptr; |
| 88 | wl_cursor *m_cursors[NumWaylandCursors] = {}; |
| 89 | }; |
| 90 | |
| 91 | class Q_WAYLANDCLIENT_EXPORT QWaylandCursorShape : public QtWayland::wp_cursor_shape_device_v1 |
| 92 | { |
| 93 | public: |
| 94 | QWaylandCursorShape(struct ::wp_cursor_shape_device_v1 *object); |
| 95 | ~QWaylandCursorShape(); |
| 96 | void setShape(uint32_t serial, Qt::CursorShape shape); |
| 97 | }; |
| 98 | |
| 99 | class Q_WAYLANDCLIENT_EXPORT QWaylandCursor : public QPlatformCursor |
| 100 | { |
| 101 | public: |
| 102 | explicit QWaylandCursor(QWaylandDisplay *display); |
| 103 | |
| 104 | void changeCursor(QCursor *cursor, QWindow *window) override; |
| 105 | void pointerEvent(const QMouseEvent &event) override; |
| 106 | QPoint pos() const override; |
| 107 | void setPos(const QPoint &pos) override; |
| 108 | void setPosFromEnterEvent(const QPoint &pos); |
| 109 | |
| 110 | QSize size() const override; |
| 111 | |
| 112 | static QSharedPointer<QWaylandBuffer> cursorBitmapBuffer(QWaylandDisplay *display, const QCursor *cursor); |
| 113 | |
| 114 | protected: |
| 115 | QWaylandDisplay *mDisplay = nullptr; |
| 116 | QPoint mLastPos; |
| 117 | }; |
| 118 | |
| 119 | } |
| 120 | |
| 121 | QT_END_NAMESPACE |
| 122 | |
| 123 | #endif // cursor |
| 124 | #endif // QWAYLANDCURSOR_H |
| 125 | |