1 | // Copyright (C) 2017 The Qt Company Ltd. |
2 | // SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only |
3 | |
4 | #ifndef QWAYLANDSURFACEITEM_H |
5 | #define QWAYLANDSURFACEITEM_H |
6 | |
7 | #include <QtWaylandCompositor/qtwaylandcompositorglobal.h> |
8 | |
9 | #include <QtQuick/QQuickItem> |
10 | #include <QtQuick/qsgtexture.h> |
11 | |
12 | #include <QtQuick/qsgtextureprovider.h> |
13 | |
14 | #include <QtWaylandCompositor/qwaylandview.h> |
15 | #include <QtWaylandCompositor/qwaylandquicksurface.h> |
16 | |
17 | Q_DECLARE_METATYPE(QWaylandQuickSurface*) |
18 | |
19 | QT_REQUIRE_CONFIG(wayland_compositor_quick); |
20 | |
21 | QT_BEGIN_NAMESPACE |
22 | |
23 | class QWaylandSeat; |
24 | class QWaylandQuickItemPrivate; |
25 | |
26 | class Q_WAYLANDCOMPOSITOR_EXPORT QWaylandQuickItem : public QQuickItem |
27 | { |
28 | Q_OBJECT |
29 | Q_DECLARE_PRIVATE(QWaylandQuickItem) |
30 | Q_PROPERTY(QWaylandCompositor *compositor READ compositor NOTIFY compositorChanged) |
31 | Q_PROPERTY(QWaylandSurface *surface READ surface WRITE setSurface NOTIFY surfaceChanged) |
32 | Q_PROPERTY(bool paintEnabled READ isPaintEnabled WRITE setPaintEnabled NOTIFY paintEnabledChanged) |
33 | Q_PROPERTY(bool touchEventsEnabled READ touchEventsEnabled WRITE setTouchEventsEnabled NOTIFY touchEventsEnabledChanged) |
34 | Q_PROPERTY(QWaylandSurface::Origin origin READ origin NOTIFY originChanged) |
35 | Q_PROPERTY(bool inputEventsEnabled READ inputEventsEnabled WRITE setInputEventsEnabled NOTIFY inputEventsEnabledChanged) |
36 | Q_PROPERTY(bool focusOnClick READ focusOnClick WRITE setFocusOnClick NOTIFY focusOnClickChanged) |
37 | Q_PROPERTY(QObject *subsurfaceHandler READ subsurfaceHandler WRITE setSubsurfaceHandler NOTIFY subsurfaceHandlerChanged) |
38 | Q_PROPERTY(QWaylandOutput *output READ output WRITE setOutput NOTIFY outputChanged) |
39 | Q_PROPERTY(bool bufferLocked READ isBufferLocked WRITE setBufferLocked NOTIFY bufferLockedChanged) |
40 | Q_PROPERTY(bool allowDiscardFrontBuffer READ allowDiscardFrontBuffer WRITE setAllowDiscardFrontBuffer NOTIFY allowDiscardFrontBufferChanged) |
41 | Q_MOC_INCLUDE("qwaylandcompositor.h" ) |
42 | Q_MOC_INCLUDE("qwaylandseat.h" ) |
43 | Q_MOC_INCLUDE("qwaylanddrag.h" ) |
44 | QML_NAMED_ELEMENT(WaylandQuickItem) |
45 | QML_ADDED_IN_VERSION(1, 0) |
46 | public: |
47 | QWaylandQuickItem(QQuickItem *parent = nullptr); |
48 | ~QWaylandQuickItem() override; |
49 | |
50 | QWaylandCompositor *compositor() const; |
51 | QWaylandView *view() const; |
52 | |
53 | QWaylandSurface *surface() const; |
54 | void setSurface(QWaylandSurface *surface); |
55 | |
56 | QWaylandSurface::Origin origin() const; |
57 | |
58 | bool isTextureProvider() const override; |
59 | QSGTextureProvider *textureProvider() const override; |
60 | |
61 | bool isPaintEnabled() const; |
62 | bool touchEventsEnabled() const; |
63 | |
64 | void setTouchEventsEnabled(bool enabled); |
65 | |
66 | bool inputEventsEnabled() const; |
67 | void setInputEventsEnabled(bool enabled); |
68 | |
69 | bool focusOnClick() const; |
70 | void setFocusOnClick(bool focus); |
71 | |
72 | bool inputRegionContains(const QPointF &localPosition) const; |
73 | Q_INVOKABLE QPointF mapToSurface(const QPointF &point) const; |
74 | Q_REVISION(1, 13) Q_INVOKABLE QPointF mapFromSurface(const QPointF &point) const; |
75 | |
76 | #if QT_CONFIG(im) |
77 | QVariant inputMethodQuery(Qt::InputMethodQuery query) const override; |
78 | Q_INVOKABLE QVariant inputMethodQuery(Qt::InputMethodQuery query, QVariant argument) const; |
79 | #endif |
80 | |
81 | QObject *subsurfaceHandler() const; |
82 | void setSubsurfaceHandler(QObject*); |
83 | |
84 | QWaylandOutput *output() const; |
85 | void setOutput(QWaylandOutput *output); |
86 | |
87 | bool isBufferLocked() const; |
88 | void setBufferLocked(bool locked); |
89 | |
90 | bool allowDiscardFrontBuffer() const; |
91 | void setAllowDiscardFrontBuffer(bool discard); |
92 | |
93 | Q_INVOKABLE void setPrimary(); |
94 | |
95 | protected: |
96 | void mousePressEvent(QMouseEvent *event) override; |
97 | void mouseMoveEvent(QMouseEvent *event) override; |
98 | void mouseReleaseEvent(QMouseEvent *event) override; |
99 | void hoverEnterEvent(QHoverEvent *event) override; |
100 | void hoverMoveEvent(QHoverEvent *event) override; |
101 | void hoverLeaveEvent(QHoverEvent *event) override; |
102 | #if QT_CONFIG(wheelevent) |
103 | void wheelEvent(QWheelEvent *event) override; |
104 | #endif |
105 | |
106 | void keyPressEvent(QKeyEvent *event) override; |
107 | void keyReleaseEvent(QKeyEvent *event) override; |
108 | |
109 | void touchEvent(QTouchEvent *event) override; |
110 | void touchUngrabEvent() override; |
111 | |
112 | #if QT_CONFIG(im) |
113 | void inputMethodEvent(QInputMethodEvent *event) override; |
114 | #endif |
115 | |
116 | virtual void surfaceChangedEvent(QWaylandSurface *newSurface, QWaylandSurface *oldSurface); |
117 | public Q_SLOTS: |
118 | virtual void takeFocus(QWaylandSeat *device = nullptr); |
119 | void setPaintEnabled(bool paintEnabled); |
120 | void raise(); |
121 | void lower(); |
122 | void sendMouseMoveEvent(const QPointF &position, QWaylandSeat *seat = nullptr); |
123 | |
124 | private Q_SLOTS: |
125 | void surfaceMappedChanged(); |
126 | void handleSurfaceChanged(); |
127 | void parentChanged(QWaylandSurface *newParent, QWaylandSurface *oldParent); |
128 | void updateSize(); |
129 | void updateBuffer(bool hasBuffer); |
130 | void updateWindow(); |
131 | void updateOutput(); |
132 | void beforeSync(); |
133 | void handleSubsurfaceAdded(QWaylandSurface *childSurface); |
134 | void handleSubsurfacePosition(const QPoint &pos); |
135 | void handlePlaceAbove(QWaylandSurface *referenceSurface); |
136 | void handlePlaceBelow(QWaylandSurface *referenceSurface); |
137 | #if QT_CONFIG(draganddrop) |
138 | void handleDragStarted(QWaylandDrag *drag); |
139 | #endif |
140 | #if QT_CONFIG(im) |
141 | void updateInputMethod(Qt::InputMethodQueries queries); |
142 | #endif |
143 | void updateFocus(); |
144 | |
145 | Q_SIGNALS: |
146 | void surfaceChanged(); |
147 | void compositorChanged(); |
148 | void paintEnabledChanged(); |
149 | void touchEventsEnabledChanged(); |
150 | void originChanged(); |
151 | void surfaceDestroyed(); |
152 | void inputEventsEnabledChanged(); |
153 | void focusOnClickChanged(); |
154 | void mouseMove(const QPointF &windowPosition); |
155 | void mouseRelease(); |
156 | void subsurfaceHandlerChanged(); |
157 | void outputChanged(); |
158 | void bufferLockedChanged(); |
159 | void allowDiscardFrontBufferChanged(); |
160 | protected: |
161 | QSGNode *updatePaintNode(QSGNode *oldNode, UpdatePaintNodeData *data) override; |
162 | |
163 | QWaylandQuickItem(QWaylandQuickItemPrivate &dd, QQuickItem *parent = nullptr); |
164 | }; |
165 | |
166 | QT_END_NAMESPACE |
167 | |
168 | #endif |
169 | |