1/****************************************************************************
2**
3** Copyright (C) 2017-2015 Pier Luigi Fiorini <pierluigi.fiorini@gmail.com>
4** Copyright (C) 2017 The Qt Company Ltd.
5** Contact: https://www.qt.io/licensing/
6**
7** This file is part of the QtWaylandCompositor module of the Qt Toolkit.
8**
9** $QT_BEGIN_LICENSE:LGPL$
10** Commercial License Usage
11** Licensees holding valid commercial Qt licenses may use this file in
12** accordance with the commercial license agreement provided with the
13** Software or, alternatively, in accordance with the terms contained in
14** a written agreement between you and The Qt Company. For licensing terms
15** and conditions see https://www.qt.io/terms-conditions. For further
16** information use the contact form at https://www.qt.io/contact-us.
17**
18** GNU Lesser General Public License Usage
19** Alternatively, this file may be used under the terms of the GNU Lesser
20** General Public License version 3 as published by the Free Software
21** Foundation and appearing in the file LICENSE.LGPL3 included in the
22** packaging of this file. Please review the following information to
23** ensure the GNU Lesser General Public License version 3 requirements
24** will be met: https://www.gnu.org/licenses/lgpl-3.0.html.
25**
26** GNU General Public License Usage
27** Alternatively, this file may be used under the terms of the GNU
28** General Public License version 2.0 or (at your option) the GNU General
29** Public license version 3 or any later version approved by the KDE Free
30** Qt Foundation. The licenses are as published by the Free Software
31** Foundation and appearing in the file LICENSE.GPL2 and LICENSE.GPL3
32** included in the packaging of this file. Please review the following
33** information to ensure the GNU General Public License requirements will
34** be met: https://www.gnu.org/licenses/gpl-2.0.html and
35** https://www.gnu.org/licenses/gpl-3.0.html.
36**
37** $QT_END_LICENSE$
38**
39****************************************************************************/
40
41#ifndef QWAYLANDSURFACE_H
42#define QWAYLANDSURFACE_H
43
44#include <QtWaylandCompositor/qtwaylandcompositorglobal.h>
45#include <QtWaylandCompositor/qwaylandcompositorextension.h>
46#include <QtWaylandCompositor/qwaylandclient.h>
47
48#include <QtCore/QScopedPointer>
49#include <QtGui/QImage>
50#include <QtGui/QWindow>
51#include <QtCore/QVariantMap>
52
53struct wl_client;
54struct wl_resource;
55
56QT_BEGIN_NAMESPACE
57
58class QTouchEvent;
59class QWaylandClient;
60class QWaylandSurfacePrivate;
61class QWaylandCompositor;
62class QWaylandBufferRef;
63class QWaylandView;
64class QWaylandSurfaceOp;
65class QWaylandInputMethodControl;
66class QWaylandDrag;
67
68class QWaylandSurfaceRole
69{
70public:
71 QWaylandSurfaceRole(const QByteArray &n) : m_name(n) {}
72
73 const QByteArray name() { return m_name; }
74
75private:
76 QByteArray m_name;
77};
78
79class Q_WAYLAND_COMPOSITOR_EXPORT QWaylandSurface : public QWaylandObject
80{
81 Q_OBJECT
82 Q_DECLARE_PRIVATE(QWaylandSurface)
83 Q_PROPERTY(QWaylandClient *client READ client CONSTANT)
84 Q_PROPERTY(QRectF sourceGeometry READ sourceGeometry NOTIFY sourceGeometryChanged REVISION 13)
85 Q_PROPERTY(QSize destinationSize READ destinationSize NOTIFY destinationSizeChanged REVISION 13)
86 Q_PROPERTY(QSize bufferSize READ bufferSize NOTIFY bufferSizeChanged REVISION 13)
87#if QT_DEPRECATED_SINCE(5, 13)
88 Q_PROPERTY(QSize size READ size NOTIFY sizeChanged) // Qt 6: Remove
89#endif
90 Q_PROPERTY(int bufferScale READ bufferScale NOTIFY bufferScaleChanged)
91 Q_PROPERTY(Qt::ScreenOrientation contentOrientation READ contentOrientation NOTIFY contentOrientationChanged)
92 Q_PROPERTY(QWaylandSurface::Origin origin READ origin NOTIFY originChanged)
93 Q_PROPERTY(bool hasContent READ hasContent NOTIFY hasContentChanged)
94 Q_PROPERTY(bool cursorSurface READ isCursorSurface WRITE markAsCursorSurface NOTIFY cursorSurfaceChanged)
95
96public:
97 enum Origin {
98 OriginTopLeft,
99 OriginBottomLeft
100 };
101 Q_ENUM(Origin)
102
103 QWaylandSurface();
104 QWaylandSurface(QWaylandCompositor *compositor, QWaylandClient *client, uint id, int version);
105 ~QWaylandSurface() override;
106
107 Q_INVOKABLE void initialize(QWaylandCompositor *compositor, QWaylandClient *client, uint id, int version);
108 bool isInitialized() const;
109
110 QWaylandClient *client() const;
111 ::wl_client *waylandClient() const;
112
113 bool setRole(QWaylandSurfaceRole *role, wl_resource *errorResource, uint32_t errorCode);
114 QWaylandSurfaceRole *role() const;
115
116 bool hasContent() const;
117
118 QRectF sourceGeometry() const;
119 QSize destinationSize() const;
120#if QT_DEPRECATED_SINCE(5, 13)
121 QT_DEPRECATED QSize size() const;
122#endif
123 QSize bufferSize() const;
124 int bufferScale() const;
125
126 Qt::ScreenOrientation contentOrientation() const;
127
128 Origin origin() const;
129
130 QWaylandCompositor *compositor() const;
131
132 bool inputRegionContains(const QPoint &p) const;
133
134 Q_INVOKABLE void destroy();
135 Q_INVOKABLE bool isDestroyed() const;
136
137 Q_INVOKABLE void frameStarted();
138 Q_INVOKABLE void sendFrameCallbacks();
139
140 QWaylandView *primaryView() const;
141 void setPrimaryView(QWaylandView *view);
142
143 QList<QWaylandView *> views() const;
144
145 static QWaylandSurface *fromResource(::wl_resource *resource);
146 struct wl_resource *resource() const;
147
148 void markAsCursorSurface(bool cursorSurface);
149 bool isCursorSurface() const;
150
151#if QT_CONFIG(im)
152 QWaylandInputMethodControl *inputMethodControl() const;
153#endif
154
155public Q_SLOTS:
156#if QT_CONFIG(clipboard)
157 void updateSelection();
158#endif
159
160protected:
161 QWaylandSurface(QWaylandSurfacePrivate &dptr);
162
163Q_SIGNALS:
164 void hasContentChanged();
165 void damaged(const QRegion &rect);
166 void parentChanged(QWaylandSurface *newParent, QWaylandSurface *oldParent);
167 void childAdded(QWaylandSurface *child);
168 Q_REVISION(13) void sourceGeometryChanged();
169 Q_REVISION(13) void destinationSizeChanged();
170#if QT_DEPRECATED_SINCE(5, 13)
171 QT_DEPRECATED void sizeChanged();
172#endif
173 Q_REVISION(13) void bufferSizeChanged();
174 void bufferScaleChanged();
175 void offsetForNextFrame(const QPoint &offset);
176 void contentOrientationChanged();
177 void surfaceDestroyed();
178 void originChanged();
179 void subsurfacePositionChanged(const QPoint &position);
180 void subsurfacePlaceAbove(QWaylandSurface *sibling);
181 void subsurfacePlaceBelow(QWaylandSurface *sibling);
182 void dragStarted(QWaylandDrag *drag);
183 void cursorSurfaceChanged();
184
185 void configure(bool hasBuffer);
186 void redraw();
187};
188
189QT_END_NAMESPACE
190
191#endif // QWAYLANDSURFACE_H
192