| 1 | // Copyright (C) 2016 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 QEGLFSKMSGBMCURSOR_H |
| 5 | #define QEGLFSKMSGBMCURSOR_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/QList> |
| 20 | #include <QtGui/QImage> |
| 21 | #include <QtGui/private/qinputdevicemanager_p.h> |
| 22 | |
| 23 | #include <gbm.h> |
| 24 | |
| 25 | QT_BEGIN_NAMESPACE |
| 26 | |
| 27 | class QEglFSKmsGbmScreen; |
| 28 | class QEglFSKmsGbmCursor; |
| 29 | |
| 30 | class QEglFSKmsGbmCursorDeviceListener : public QObject |
| 31 | { |
| 32 | Q_OBJECT |
| 33 | |
| 34 | public: |
| 35 | QEglFSKmsGbmCursorDeviceListener(QEglFSKmsGbmCursor *cursor) : m_cursor(cursor) { } |
| 36 | bool hasMouse() const; |
| 37 | |
| 38 | public slots: |
| 39 | void onDeviceListChanged(QInputDeviceManager::DeviceType type); |
| 40 | |
| 41 | private: |
| 42 | QEglFSKmsGbmCursor *m_cursor; |
| 43 | }; |
| 44 | |
| 45 | class QEglFSKmsGbmCursor : public QPlatformCursor |
| 46 | { |
| 47 | Q_OBJECT |
| 48 | |
| 49 | public: |
| 50 | QEglFSKmsGbmCursor(QEglFSKmsGbmScreen *screen); |
| 51 | ~QEglFSKmsGbmCursor(); |
| 52 | |
| 53 | // input methods |
| 54 | void pointerEvent(const QMouseEvent & event) override; |
| 55 | #ifndef QT_NO_CURSOR |
| 56 | void changeCursor(QCursor * windowCursor, QWindow * window) override; |
| 57 | #endif |
| 58 | QPoint pos() const override; |
| 59 | void setPos(const QPoint &pos) override; |
| 60 | |
| 61 | void updateMouseStatus(); |
| 62 | |
| 63 | void reevaluateVisibilityForScreens() { setPos(pos()); } |
| 64 | |
| 65 | private: |
| 66 | void initCursorAtlas(); |
| 67 | |
| 68 | enum CursorState { |
| 69 | CursorDisabled, |
| 70 | CursorPendingHidden, |
| 71 | CursorHidden, |
| 72 | CursorPendingVisible, |
| 73 | CursorVisible |
| 74 | }; |
| 75 | |
| 76 | QEglFSKmsGbmScreen *m_screen; |
| 77 | QSize m_cursorSize; |
| 78 | gbm_bo *m_bo; |
| 79 | QPoint m_pos; |
| 80 | QPlatformCursorImage m_cursorImage; |
| 81 | CursorState m_state; |
| 82 | QEglFSKmsGbmCursorDeviceListener *m_deviceListener; |
| 83 | |
| 84 | // cursor atlas information |
| 85 | struct CursorAtlas { |
| 86 | CursorAtlas() : cursorsPerRow(0), cursorWidth(0), cursorHeight(0) { } |
| 87 | int cursorsPerRow; |
| 88 | int width, height; // width and height of the atlas |
| 89 | int cursorWidth, cursorHeight; // width and height of cursors inside the atlas |
| 90 | QList<QPoint> hotSpots; |
| 91 | QImage image; |
| 92 | } m_cursorAtlas; |
| 93 | }; |
| 94 | |
| 95 | QT_END_NAMESPACE |
| 96 | |
| 97 | #endif // QEGLFSKMSGBMCURSOR_H |
| 98 | |