1 | /**************************************************************************** |
2 | ** |
3 | ** Copyright (C) 2017 The Qt Company Ltd. |
4 | ** Contact: https://www.qt.io/licensing/ |
5 | ** |
6 | ** This file is part of the QtWaylandCompositor module of the Qt Toolkit. |
7 | ** |
8 | ** $QT_BEGIN_LICENSE:GPL$ |
9 | ** Commercial License Usage |
10 | ** Licensees holding valid commercial Qt licenses may use this file in |
11 | ** accordance with the commercial license agreement provided with the |
12 | ** Software or, alternatively, in accordance with the terms contained in |
13 | ** a written agreement between you and The Qt Company. For licensing terms |
14 | ** and conditions see https://www.qt.io/terms-conditions. For further |
15 | ** information use the contact form at https://www.qt.io/contact-us. |
16 | ** |
17 | ** GNU General Public License Usage |
18 | ** Alternatively, this file may be used under the terms of the GNU |
19 | ** General Public License version 3 or (at your option) any later version |
20 | ** approved by the KDE Free Qt Foundation. The licenses are as published by |
21 | ** the Free Software Foundation and appearing in the file LICENSE.GPL3 |
22 | ** included in the packaging of this file. Please review the following |
23 | ** information to ensure the GNU General Public License requirements will |
24 | ** be met: https://www.gnu.org/licenses/gpl-3.0.html. |
25 | ** |
26 | ** $QT_END_LICENSE$ |
27 | ** |
28 | ****************************************************************************/ |
29 | |
30 | #ifndef QWAYLANDSURFACEITEM_H |
31 | #define QWAYLANDSURFACEITEM_H |
32 | |
33 | #include <QtWaylandCompositor/qtwaylandcompositorglobal.h> |
34 | |
35 | #include <QtQuick/QQuickItem> |
36 | #include <QtQuick/qsgtexture.h> |
37 | |
38 | #include <QtQuick/qsgtextureprovider.h> |
39 | |
40 | #include <QtWaylandCompositor/qwaylandview.h> |
41 | #include <QtWaylandCompositor/qwaylandquicksurface.h> |
42 | |
43 | Q_DECLARE_METATYPE(QWaylandQuickSurface*) |
44 | |
45 | QT_BEGIN_NAMESPACE |
46 | |
47 | class QWaylandSeat; |
48 | class QWaylandQuickItemPrivate; |
49 | |
50 | class Q_WAYLAND_COMPOSITOR_EXPORT QWaylandQuickItem : public QQuickItem |
51 | { |
52 | Q_OBJECT |
53 | Q_DECLARE_PRIVATE(QWaylandQuickItem) |
54 | Q_PROPERTY(QWaylandCompositor *compositor READ compositor NOTIFY compositorChanged) |
55 | Q_PROPERTY(QWaylandSurface *surface READ surface WRITE setSurface NOTIFY surfaceChanged) |
56 | Q_PROPERTY(bool paintEnabled READ paintEnabled WRITE setPaintEnabled NOTIFY paintEnabledChanged) |
57 | Q_PROPERTY(bool touchEventsEnabled READ touchEventsEnabled WRITE setTouchEventsEnabled NOTIFY touchEventsEnabledChanged) |
58 | Q_PROPERTY(QWaylandSurface::Origin origin READ origin NOTIFY originChanged) |
59 | Q_PROPERTY(bool inputEventsEnabled READ inputEventsEnabled WRITE setInputEventsEnabled NOTIFY inputEventsEnabledChanged) |
60 | Q_PROPERTY(bool focusOnClick READ focusOnClick WRITE setFocusOnClick NOTIFY focusOnClickChanged) |
61 | Q_PROPERTY(bool sizeFollowsSurface READ sizeFollowsSurface WRITE setSizeFollowsSurface NOTIFY sizeFollowsSurfaceChanged) |
62 | Q_PROPERTY(QObject *subsurfaceHandler READ subsurfaceHandler WRITE setSubsurfaceHandler NOTIFY subsurfaceHandlerChanged) |
63 | Q_PROPERTY(QWaylandOutput *output READ output WRITE setOutput NOTIFY outputChanged) |
64 | Q_PROPERTY(bool bufferLocked READ isBufferLocked WRITE setBufferLocked NOTIFY bufferLockedChanged) |
65 | Q_PROPERTY(bool allowDiscardFrontBuffer READ allowDiscardFrontBuffer WRITE setAllowDiscardFrontBuffer NOTIFY allowDiscardFrontBufferChanged) |
66 | public: |
67 | QWaylandQuickItem(QQuickItem *parent = nullptr); |
68 | ~QWaylandQuickItem() override; |
69 | |
70 | QWaylandCompositor *compositor() const; |
71 | QWaylandView *view() const; |
72 | |
73 | QWaylandSurface *surface() const; |
74 | void setSurface(QWaylandSurface *surface); |
75 | |
76 | QWaylandSurface::Origin origin() const; |
77 | |
78 | bool isTextureProvider() const override; |
79 | QSGTextureProvider *textureProvider() const override; |
80 | |
81 | bool paintEnabled() const; |
82 | bool touchEventsEnabled() const; |
83 | |
84 | void setTouchEventsEnabled(bool enabled); |
85 | |
86 | bool inputEventsEnabled() const; |
87 | void setInputEventsEnabled(bool enabled); |
88 | |
89 | bool focusOnClick() const; |
90 | void setFocusOnClick(bool focus); |
91 | |
92 | bool inputRegionContains(const QPointF &localPosition) const; |
93 | bool inputRegionContains(const QPointF &localPosition); |
94 | Q_INVOKABLE QPointF mapToSurface(const QPointF &point) const; |
95 | Q_REVISION(13) Q_INVOKABLE QPointF mapFromSurface(const QPointF &point) const; |
96 | |
97 | bool sizeFollowsSurface() const; |
98 | void setSizeFollowsSurface(bool sizeFollowsSurface); |
99 | |
100 | #if QT_CONFIG(im) |
101 | QVariant inputMethodQuery(Qt::InputMethodQuery query) const override; |
102 | Q_INVOKABLE QVariant inputMethodQuery(Qt::InputMethodQuery query, QVariant argument) const; |
103 | #endif |
104 | |
105 | QObject *subsurfaceHandler() const; |
106 | void setSubsurfaceHandler(QObject*); |
107 | |
108 | QWaylandOutput *output() const; |
109 | void setOutput(QWaylandOutput *output); |
110 | |
111 | bool isBufferLocked() const; |
112 | void setBufferLocked(bool locked); |
113 | |
114 | bool allowDiscardFrontBuffer() const; |
115 | void setAllowDiscardFrontBuffer(bool discard); |
116 | |
117 | Q_INVOKABLE void setPrimary(); |
118 | |
119 | protected: |
120 | void mousePressEvent(QMouseEvent *event) override; |
121 | void mouseMoveEvent(QMouseEvent *event) override; |
122 | void mouseReleaseEvent(QMouseEvent *event) override; |
123 | void hoverEnterEvent(QHoverEvent *event) override; |
124 | void hoverMoveEvent(QHoverEvent *event) override; |
125 | void hoverLeaveEvent(QHoverEvent *event) override; |
126 | #if QT_CONFIG(wheelevent) |
127 | void wheelEvent(QWheelEvent *event) override; |
128 | #endif |
129 | |
130 | void keyPressEvent(QKeyEvent *event) override; |
131 | void keyReleaseEvent(QKeyEvent *event) override; |
132 | |
133 | void touchEvent(QTouchEvent *event) override; |
134 | void touchUngrabEvent() override; |
135 | |
136 | #if QT_CONFIG(im) |
137 | void inputMethodEvent(QInputMethodEvent *event) override; |
138 | #endif |
139 | |
140 | virtual void surfaceChangedEvent(QWaylandSurface *newSurface, QWaylandSurface *oldSurface); |
141 | public Q_SLOTS: |
142 | virtual void takeFocus(QWaylandSeat *device = nullptr); |
143 | void setPaintEnabled(bool paintEnabled); |
144 | void raise(); |
145 | void lower(); |
146 | void sendMouseMoveEvent(const QPointF &position, QWaylandSeat *seat = nullptr); |
147 | |
148 | private Q_SLOTS: |
149 | void surfaceMappedChanged(); |
150 | void handleSurfaceChanged(); |
151 | void parentChanged(QWaylandSurface *newParent, QWaylandSurface *oldParent); |
152 | void updateSize(); |
153 | void updateBuffer(bool hasBuffer); |
154 | void updateWindow(); |
155 | void updateOutput(); |
156 | void beforeSync(); |
157 | void handleSubsurfaceAdded(QWaylandSurface *childSurface); |
158 | void handleSubsurfacePosition(const QPoint &pos); |
159 | void handlePlaceAbove(QWaylandSurface *referenceSurface); |
160 | void handlePlaceBelow(QWaylandSurface *referenceSurface); |
161 | #if QT_CONFIG(draganddrop) |
162 | void handleDragStarted(QWaylandDrag *drag); |
163 | #endif |
164 | #if QT_CONFIG(im) |
165 | void updateInputMethod(Qt::InputMethodQueries queries); |
166 | #endif |
167 | |
168 | Q_SIGNALS: |
169 | void surfaceChanged(); |
170 | void compositorChanged(); |
171 | void paintEnabledChanged(); |
172 | void touchEventsEnabledChanged(); |
173 | void originChanged(); |
174 | void surfaceDestroyed(); |
175 | void inputEventsEnabledChanged(); |
176 | void focusOnClickChanged(); |
177 | void mouseMove(const QPointF &windowPosition); |
178 | void mouseRelease(); |
179 | void sizeFollowsSurfaceChanged(); |
180 | void subsurfaceHandlerChanged(); |
181 | void outputChanged(); |
182 | void bufferLockedChanged(); |
183 | void allowDiscardFrontBufferChanged(); |
184 | protected: |
185 | QSGNode *updatePaintNode(QSGNode *oldNode, UpdatePaintNodeData *data) override; |
186 | |
187 | QWaylandQuickItem(QWaylandQuickItemPrivate &dd, QQuickItem *parent = nullptr); |
188 | }; |
189 | |
190 | QT_END_NAMESPACE |
191 | |
192 | #endif |
193 | |