Changeset View
Changeset View
Standalone View
Standalone View
src/client/viewporter.h
- This file was added.
1 | /******************************************************************** | ||||
---|---|---|---|---|---|
2 | Copyright © 2019 Roman Gilg <subdiff@gmail.com> | ||||
3 | | ||||
4 | This library is free software; you can redistribute it and/or | ||||
5 | modify it under the terms of the GNU Lesser General Public | ||||
6 | License as published by the Free Software Foundation; either | ||||
7 | version 2.1 of the License, or (at your option) version 3, or any | ||||
8 | later version accepted by the membership of KDE e.V. (or its | ||||
9 | successor approved by the membership of KDE e.V.), which shall | ||||
10 | act as a proxy defined in Section 6 of version 3 of the license. | ||||
11 | | ||||
12 | This library is distributed in the hope that it will be useful, | ||||
13 | but WITHOUT ANY WARRANTY; without even the implied warranty of | ||||
14 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | ||||
15 | Lesser General Public License for more details. | ||||
16 | | ||||
17 | You should have received a copy of the GNU Lesser General Public | ||||
18 | License along with this library. If not, see <http://www.gnu.org/licenses/>. | ||||
19 | *********************************************************************/ | ||||
20 | #pragma once | ||||
21 | | ||||
22 | #include "buffer.h" | ||||
23 | | ||||
24 | #include <QObject> | ||||
25 | #include <QPoint> | ||||
26 | #include <QSize> | ||||
27 | | ||||
28 | #include <KWayland/Client/kwaylandclient_export.h> | ||||
29 | | ||||
30 | struct wl_buffer; | ||||
31 | struct wp_viewport; | ||||
32 | struct wp_viewporter; | ||||
33 | | ||||
34 | class QMarginsF; | ||||
35 | class QWindow; | ||||
36 | | ||||
37 | namespace KWayland | ||||
38 | { | ||||
39 | namespace Client | ||||
40 | { | ||||
41 | | ||||
42 | class EventQueue; | ||||
43 | class Viewport; | ||||
44 | class Surface; | ||||
45 | | ||||
46 | /** | ||||
47 | * @short Wrapper for the wp_viewporter interface. | ||||
48 | * | ||||
49 | * This class provides a convenient wrapper for the wp_viewporter interface. | ||||
50 | * | ||||
51 | * To use this class one needs to interact with the Registry. There are two | ||||
52 | * possible ways to create the Viewporter interface: | ||||
53 | * @code | ||||
54 | * Viewporter *vp = registry->createViewporter(name, version); | ||||
55 | * @endcode | ||||
56 | * | ||||
57 | * This creates the Viewporter and sets it up directly. As an alternative this | ||||
58 | * can also be done in a more low level way: | ||||
59 | * @code | ||||
60 | * Viewporter *vp = new Viewporter; | ||||
61 | * s->setup(registry->bindViewporter(name, version)); | ||||
62 | * @endcode | ||||
63 | * | ||||
64 | * The Viewporter can be used as a drop-in replacement for any wp_viewporter | ||||
65 | * pointer as it provides matching cast operators. | ||||
66 | * | ||||
67 | * @see Registry | ||||
68 | * @since 5.66 | ||||
69 | **/ | ||||
70 | class KWAYLANDCLIENT_EXPORT Viewporter : public QObject | ||||
71 | { | ||||
72 | Q_OBJECT | ||||
73 | public: | ||||
74 | /** | ||||
75 | * Creates a new Viewporter. | ||||
76 | * Note: after constructing the Viewporter it is not yet valid and one needs | ||||
77 | * to call setup. In order to get a ready to use Viewporter prefer using | ||||
78 | * Registry::createViewporter. | ||||
79 | **/ | ||||
80 | explicit Viewporter(QObject *parent = nullptr); | ||||
81 | virtual ~Viewporter(); | ||||
82 | | ||||
83 | /** | ||||
84 | * @returns @c true if managing a wp_viewporter. | ||||
85 | **/ | ||||
86 | bool isValid() const; | ||||
87 | /** | ||||
88 | * Setup this Viewporter to manage the @p viewporter. | ||||
89 | * When using Registry::createViewporter there is no need to call this | ||||
90 | * method. | ||||
91 | **/ | ||||
92 | void setup(wp_viewporter *viewporter); | ||||
93 | /** | ||||
94 | * Releases the wp_viewporter interface. | ||||
95 | * After the interface has been released the Viewporter instance is no | ||||
96 | * longer valid and can be setup with another wp_viewporter interface. | ||||
97 | **/ | ||||
98 | void release(); | ||||
99 | /** | ||||
100 | * Destroys the data held by this Viewporter. | ||||
101 | * This method is supposed to be used when the connection to the Wayland | ||||
102 | * server goes away. If the connection is not valid anymore, it's not | ||||
103 | * possible to call release anymore as that calls into the Wayland | ||||
104 | * connection and the call would fail. This method cleans up the data, so | ||||
105 | * that the instance can be deleted or set up to a new wp_viewporter interface | ||||
106 | * once there is a new connection available. | ||||
107 | * | ||||
108 | * This method is automatically invoked when the Registry which created this | ||||
109 | * Viewporter gets destroyed. | ||||
110 | * | ||||
111 | * @see release | ||||
112 | **/ | ||||
113 | void destroy(); | ||||
114 | | ||||
115 | /** | ||||
116 | * Sets the @p queue to use for creating a Viewport. | ||||
117 | **/ | ||||
118 | void setEventQueue(EventQueue *queue); | ||||
119 | /** | ||||
120 | * @returns The event queue to use for creating a Viewport. | ||||
121 | **/ | ||||
122 | EventQueue *eventQueue(); | ||||
123 | | ||||
124 | /** | ||||
125 | * Creates and setup a new Viewport with @p parent. | ||||
126 | * @param surface The surface to use this Viewport with. | ||||
127 | * @param parent The parent to pass to the Viewport. | ||||
128 | * @returns The new created Viewport | ||||
129 | **/ | ||||
130 | Viewport *createViewport(Surface *surface, QObject *parent = nullptr); | ||||
131 | | ||||
132 | operator wp_viewporter*(); | ||||
133 | operator wp_viewporter*() const; | ||||
134 | | ||||
135 | Q_SIGNALS: | ||||
136 | /** | ||||
137 | * The corresponding global for this interface on the Registry got removed. | ||||
138 | * | ||||
139 | * This signal gets only emitted if the Compositor got created by | ||||
140 | * Registry::createViewporter | ||||
141 | * | ||||
142 | * @since 5.66 | ||||
143 | **/ | ||||
144 | void removed(); | ||||
145 | | ||||
146 | private: | ||||
147 | class Private; | ||||
148 | QScopedPointer<Private> d; | ||||
149 | }; | ||||
150 | | ||||
151 | /** | ||||
152 | * @short Wrapper for the wp_viewport interface. | ||||
153 | * | ||||
154 | * This class is a convenient wrapper for the wp_viewport interface. | ||||
155 | * To create a Viewport call Viewporter::createViewport. | ||||
156 | * | ||||
157 | **/ | ||||
158 | class KWAYLANDCLIENT_EXPORT Viewport : public QObject | ||||
159 | { | ||||
160 | Q_OBJECT | ||||
161 | public: | ||||
162 | ~Viewport() override; | ||||
163 | | ||||
164 | /** | ||||
165 | * Setup this Viewport to manage the @p viewport. | ||||
166 | * When using Viewporter::createViewport there is no need to call this | ||||
167 | * method. | ||||
168 | **/ | ||||
169 | void setup(wp_viewport *viewport); | ||||
170 | /** | ||||
171 | * Releases the wp_viewport interface. | ||||
172 | * After the interface has been released the Viewport instance is no | ||||
173 | * longer valid and can be setup with another wp_viewport interface. | ||||
174 | **/ | ||||
175 | void release(); | ||||
176 | /** | ||||
177 | * Destroys the data held by this Viewport. | ||||
178 | * This method is supposed to be used when the connection to the Wayland | ||||
179 | * server goes away. If the connection is not valid anymore, it's not | ||||
180 | * possible to call release anymore as that calls into the Wayland | ||||
181 | * connection and the call would fail. This method cleans up the data, so | ||||
182 | * that the instance can be deleted or set up to a new wp_viewport interface | ||||
183 | * once there is a new connection available. | ||||
184 | * | ||||
185 | * It is suggested to connect this method to ConnectionThread::connectionDied: | ||||
186 | * @code | ||||
187 | * connect(connection, &ConnectionThread::connectionDied, viewport, &Viewport::destroy); | ||||
188 | * @endcode | ||||
189 | * | ||||
190 | * @see release | ||||
191 | **/ | ||||
192 | void destroy(); | ||||
193 | /** | ||||
194 | * @returns @c true if managing a wp_viewport. | ||||
195 | **/ | ||||
196 | bool isValid() const; | ||||
197 | | ||||
198 | void setSourceRectangle(const QRectF &source); | ||||
199 | void setDestinationSize(const QSize &dest); | ||||
200 | | ||||
201 | operator wp_viewport*(); | ||||
202 | operator wp_viewport*() const; | ||||
203 | | ||||
204 | private: | ||||
205 | friend class Viewporter; | ||||
206 | explicit Viewport(QObject *parent = nullptr); | ||||
207 | class Private; | ||||
208 | QScopedPointer<Private> d; | ||||
209 | }; | ||||
210 | | ||||
211 | } | ||||
212 | } | ||||
213 | |