Changeset View
Changeset View
Standalone View
Standalone View
src/client/xdgoutput.h
- This file was added.
1 | /**************************************************************************** | ||||
---|---|---|---|---|---|
2 | Copyright 2018 David Edmundson <kde@davidedmundson.co.uk> | ||||
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 | #ifndef KWAYLAND_CLIENT_XDGOUTPUT_H | ||||
21 | #define KWAYLAND_CLIENT_XDGOUTPUT_H | ||||
22 | | ||||
23 | #include <QObject> | ||||
24 | #include <QSize> | ||||
25 | #include <QPoint> | ||||
26 | | ||||
27 | #include <KWayland/Client/kwaylandclient_export.h> | ||||
28 | | ||||
29 | struct zxdg_output_manager_v1; | ||||
30 | struct zxdg_output_v1; | ||||
31 | | ||||
32 | namespace KWayland | ||||
33 | { | ||||
34 | namespace Client | ||||
35 | { | ||||
36 | | ||||
37 | class EventQueue; | ||||
38 | class XdgOutput; | ||||
39 | class Output; | ||||
40 | | ||||
41 | /** | ||||
42 | * @short Wrapper for the zxdg_output_manager_v1 interface. | ||||
43 | * | ||||
44 | * This class provides a convenient wrapper for the zxdg_output_manager_v1 interface. | ||||
45 | * | ||||
46 | * This provides the logical size of the output. This is useful in case it doesn't match the | ||||
47 | * pixelSize / outputScale. | ||||
48 | * | ||||
49 | * To use this class one needs to interact with the Registry. There are two | ||||
50 | * possible ways to create the XdgOutputManager interface: | ||||
51 | * @code | ||||
52 | * XdgOutputManager *c = registry->createXdgOutputManager(name, version); | ||||
53 | * @endcode | ||||
54 | * | ||||
55 | * This creates the XdgOutputManager and sets it up directly. As an alternative this | ||||
56 | * can also be done in a more low level way: | ||||
57 | * @code | ||||
58 | * XdgOutputManager *c = new XdgOutputManager; | ||||
59 | * c->setup(registry->bindXdgOutputManager(name, version)); | ||||
60 | * @endcode | ||||
61 | * | ||||
62 | * The XdgOutputManager can be used as a drop-in replacement for any zxdg_output_manager_v1 | ||||
63 | * pointer as it provides matching cast operators. | ||||
64 | * | ||||
65 | * @since 5.XDGOUTPUTVERSION | ||||
66 | * | ||||
67 | * @see Registry | ||||
68 | **/ | ||||
69 | class KWAYLANDCLIENT_EXPORT XdgOutputManager : public QObject | ||||
70 | { | ||||
71 | Q_OBJECT | ||||
72 | public: | ||||
73 | /** | ||||
74 | * Creates a new XdgOutputManager. | ||||
75 | * Note: after constructing the XdgOutputManager it is not yet valid and one needs | ||||
76 | * to call setup. In order to get a ready to use XdgOutputManager prefer using | ||||
77 | * Registry::createXdgOutputManager. | ||||
78 | **/ | ||||
79 | explicit XdgOutputManager(QObject *parent = nullptr); | ||||
80 | virtual ~XdgOutputManager(); | ||||
81 | | ||||
82 | /** | ||||
83 | * Setup this XdgOutputManager to manage the @p xdgoutputmanager. | ||||
84 | * When using Registry::createXdgOutputManager there is no need to call this | ||||
85 | * method. | ||||
86 | **/ | ||||
87 | void setup(zxdg_output_manager_v1 *xdgoutputmanager); | ||||
88 | /** | ||||
89 | * @returns @c true if managing a zxdg_output_manager_v1. | ||||
90 | **/ | ||||
91 | bool isValid() const; | ||||
92 | /** | ||||
93 | * Releases the zxdg_output_manager_v1 interface. | ||||
94 | * After the interface has been released the XdgOutputManager instance is no | ||||
95 | * longer valid and can be setup with another zxdg_output_manager_v1 interface. | ||||
96 | **/ | ||||
97 | void release(); | ||||
98 | /** | ||||
99 | * Destroys the data held by this XdgOutputManager. | ||||
100 | * This method is supposed to be used when the connection to the Wayland | ||||
101 | * server goes away. If the connection is not valid anymore, it's not | ||||
102 | * possible to call release anymore as that calls into the Wayland | ||||
103 | * connection and the call would fail. This method cleans up the data, so | ||||
104 | * that the instance can be deleted or set up to a new zxdg_output_manager_v1 interface | ||||
105 | * once there is a new connection available. | ||||
106 | * | ||||
107 | * It is suggested to connect this method to ConnectionThread::connectionDied: | ||||
108 | * @code | ||||
109 | * connect(connection, &ConnectionThread::connectionDied, xdgoutputmanager, &XdgOutputManager::destroy); | ||||
110 | * @endcode | ||||
111 | * | ||||
112 | * @see release | ||||
113 | **/ | ||||
114 | void destroy(); | ||||
115 | | ||||
116 | /** | ||||
117 | * Sets the @p queue to use for creating objects with this XdgOutputManager. | ||||
118 | **/ | ||||
119 | void setEventQueue(EventQueue *queue); | ||||
120 | /** | ||||
121 | * @returns The event queue to use for creating objects with this XdgOutputManager. | ||||
122 | **/ | ||||
123 | EventQueue *eventQueue(); | ||||
124 | | ||||
125 | XdgOutput *getXdgOutput(Output *output, QObject *parent = nullptr); | ||||
126 | | ||||
127 | operator zxdg_output_manager_v1*(); | ||||
128 | operator zxdg_output_manager_v1*() const; | ||||
129 | | ||||
130 | Q_SIGNALS: | ||||
131 | /** | ||||
132 | * The corresponding global for this interface on the Registry got removed. | ||||
133 | * | ||||
134 | * This signal gets only emitted if the XdgOutputManager got created by | ||||
135 | * Registry::createXdgOutputManager | ||||
136 | **/ | ||||
137 | void removed(); | ||||
138 | | ||||
139 | private: | ||||
140 | class Private; | ||||
141 | QScopedPointer<Private> d; | ||||
142 | }; | ||||
143 | | ||||
144 | /** | ||||
145 | * @short Wrapper for the zxdg_output_v1 interface. | ||||
146 | * | ||||
147 | * This class provides a convenient wrapper for the zxdg_output_v1 interface. | ||||
148 | * | ||||
149 | * The XdgOutputManager can be used as a drop-in replacement for any zxdg_output_v1 | ||||
150 | * pointer as it provides matching cast operators. | ||||
151 | * | ||||
152 | * This protocol provides a potentially more correct size and position of the screen | ||||
153 | * than Output with respect to scaling. | ||||
154 | * | ||||
155 | * @see Registry | ||||
156 | **/ | ||||
157 | | ||||
158 | class KWAYLANDCLIENT_EXPORT XdgOutput : public QObject | ||||
159 | { | ||||
160 | Q_OBJECT | ||||
161 | public: | ||||
162 | virtual ~XdgOutput(); | ||||
163 | | ||||
164 | /** | ||||
165 | * Setup this XdgOutput to manage the @p xdgoutput. | ||||
166 | * When using XdgOutputManager::createXdgOutput there is no need to call this | ||||
167 | * method. | ||||
168 | **/ | ||||
169 | void setup(zxdg_output_v1 *xdgoutput); | ||||
170 | /** | ||||
171 | * @returns @c true if managing a zxdg_output_v1. | ||||
172 | **/ | ||||
173 | bool isValid() const; | ||||
174 | /** | ||||
175 | * Releases the zxdg_output_v1 interface. | ||||
176 | * After the interface has been released the XdgOutput instance is no | ||||
177 | * longer valid and can be setup with another zxdg_output_v1 interface. | ||||
178 | **/ | ||||
179 | void release(); | ||||
180 | /** | ||||
181 | * Destroys the data held by this XdgOutput. | ||||
182 | * This method is supposed to be used when the connection to the Wayland | ||||
183 | * server goes away. If the connection is not valid anymore, it's not | ||||
184 | * possible to call release anymore as that calls into the Wayland | ||||
185 | * connection and the call would fail. This method cleans up the data, so | ||||
186 | * that the instance can be deleted or set up to a new zxdg_output_v1 interface | ||||
187 | * once there is a new connection available. | ||||
188 | * | ||||
189 | * It is suggested to connect this method to ConnectionThread::connectionDied: | ||||
190 | * @code | ||||
191 | * connect(connection, &ConnectionThread::connectionDied, xdgoutput, &XdgOutput::destroy); | ||||
192 | * @endcode | ||||
193 | * | ||||
194 | * @see release | ||||
195 | **/ | ||||
196 | void destroy(); | ||||
197 | | ||||
198 | operator zxdg_output_v1*(); | ||||
199 | operator zxdg_output_v1*() const; | ||||
200 | | ||||
201 | /** | ||||
202 | * The top left position of the output in compositor co-ordinates | ||||
203 | */ | ||||
204 | QPoint logicalPosition() const; | ||||
205 | | ||||
206 | /** | ||||
207 | * The size of the output in compositor co-ordinates | ||||
208 | * (i.e pixel size / output scale) | ||||
209 | */ | ||||
210 | QSize logicalSize() const; | ||||
211 | | ||||
212 | Q_SIGNALS: | ||||
213 | /** | ||||
214 | * Emitted when the logical position or size changes | ||||
215 | */ | ||||
216 | void changed(); | ||||
217 | | ||||
218 | private: | ||||
219 | friend class XdgOutputManager; | ||||
220 | explicit XdgOutput(QObject *parent = nullptr); | ||||
221 | class Private; | ||||
222 | QScopedPointer<Private> d; | ||||
223 | }; | ||||
224 | | ||||
225 | | ||||
226 | } | ||||
227 | } | ||||
228 | | ||||
229 | #endif |