GCC Code Coverage Report


Directory: ./
File: src/client/dpms.h
Date: 2024-01-22 17:25:27
Exec Total Coverage
Lines: 1 1 100.0%
Branches: 3 6 50.0%

Line Branch Exec Source
1 /********************************************************************
2 Copyright 2015 Martin Gräßlin <mgraesslin@kde.org>
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 WRAPLAND_CLIENT_DPMS_H
21 #define WRAPLAND_CLIENT_DPMS_H
22
23 #include <QObject>
24 // STD
25 #include <memory>
26
27 #include <Wrapland/Client/wraplandclient_export.h>
28
29 struct org_kde_kwin_dpms;
30 struct org_kde_kwin_dpms_manager;
31
32 namespace Wrapland
33 {
34 namespace Client
35 {
36
37 class EventQueue;
38 class Dpms;
39 class Output;
40
41 /**
42 * @short This class is a factory for Dpms instances.
43 *
44 * It is a convenience wrapper for the org_kde_kwin_dpms_manager interface.
45 *
46 * To use this class one needs to interact with the Registry. There are two
47 * possible ways to create the DpmsManager interface:
48 * @code
49 * DpmsManager *m = registry->createDpmsManager(name, version);
50 * @endcode
51 *
52 * This creates the DpmsManager and sets it up directly. As an alternative this
53 * can also be done in a more low level way:
54 * @code
55 * DpmsManager *m = new DpmsManager;
56 * m->setup(registry->bindDpmsManager(name, version));
57 * @endcode
58 *
59 * The DpmsManager can be used as a drop-in replacement for any org_kde_kwin_dpms_manager
60 * pointer as it provides matching cast operators.
61 *
62 * @see Registry, Dpms
63 * @since 5.5
64 **/
65 class WRAPLANDCLIENT_EXPORT DpmsManager : public QObject
66 {
67 Q_OBJECT
68 public:
69 /**
70 * Creates a new DpmsManager.
71 * Note: after constructing the DpmsManager it is not yet valid and one needs
72 * to call setup. In order to get a ready to use DpmsManager prefer using
73 * Registry::createDpmsManager.
74 **/
75 explicit DpmsManager(QObject* parent = nullptr);
76 virtual ~DpmsManager();
77
78 /**
79 * @returns @c true if managing a org_kde_kwin_dpms_manager.
80 **/
81 bool isValid() const;
82 /**
83 * Setup this DpmsManager to manage the @p manager.
84 * When using Registry::createDpmsManager there is no need to call this
85 * method.
86 **/
87 void setup(org_kde_kwin_dpms_manager* manager);
88 /**
89 * Releases the org_kde_kwin_dpms_manager interface.
90 * After the interface has been released the DpmsManager instance is no
91 * longer valid and can be setup with another org_kde_kwin_dpms_manager interface.
92 **/
93 void release();
94
95 /**
96 * Sets the @p queue to use for creating a Dpms.
97 **/
98 void setEventQueue(EventQueue* queue);
99 /**
100 * @returns The event queue to use for creating a Dpms.
101 **/
102 EventQueue* eventQueue();
103
104 Dpms* getDpms(Output* output, QObject* parent = nullptr);
105
106 operator org_kde_kwin_dpms_manager*();
107 operator org_kde_kwin_dpms_manager*() const;
108
109 Q_SIGNALS:
110 /**
111 * The corresponding global for this interface on the Registry got removed.
112 *
113 * This signal gets only emitted if the DpmsManager got created by
114 * Registry::createDpmsManager
115 **/
116 void removed();
117
118 private:
119 class Private;
120 std::unique_ptr<Private> d;
121 };
122
123 /**
124 * @short Power management for monitors.
125 *
126 * Display Power Management Signaling allows power management for monitors.
127 * This class is a convenient wrapper for the org_kde_kwin_dpms interface.
128 * To create a Dpms call DpmsManager::getDpms.
129 *
130 * @see DpmsManager
131 **/
132 class WRAPLANDCLIENT_EXPORT Dpms : public QObject
133 {
134 Q_OBJECT
135 public:
136 virtual ~Dpms();
137
138 enum class Mode {
139 On,
140 Standby,
141 Suspend,
142 Off,
143 };
144
145 /**
146 * Setup this Dpms to manage the @p dpms.
147 * When using DpmsManager::createDpms there is no need to call this
148 * method.
149 **/
150 void setup(org_kde_kwin_dpms* dpms);
151 /**
152 * Releases the org_kde_kwin_dpms interface.
153 * After the interface has been released the Dpms instance is no
154 * longer valid and can be setup with another org_kde_kwin_dpms interface.
155 **/
156 void release();
157 /**
158 * Destroys the data held by this Dpms.
159 * This method is supposed to be used when the connection to the Wayland
160 * server goes away. If the connection is not valid anymore, it's not
161 * possible to call release anymore as that calls into the Wayland
162 * connection and the call would fail. This method cleans up the data, so
163 * that the instance can be deleted or set up to a new org_kde_kwin_dpms interface
164 * once there is a new connection available.
165 *
166 * It is suggested to connect this method to ConnectionThread::connectionDied:
167 * @code
168 * connect(connection, &ConnectionThread::connectionDied, source, &Dpms::destroy);
169 * @endcode
170 *
171 * @see release
172 **/
173 void destroy();
174 /**
175 * @returns @c true if managing a org_kde_kwin_dpms.
176 **/
177 bool isValid() const;
178
179 /**
180 * @returns the Output for which this Dpms got created
181 **/
182 QPointer<Output> output() const;
183
184 /**
185 * Whether Dpms is supported for the Output.
186 * Initially set to @c false.
187 * @returns whether Dpms is supported for the Output.
188 * @see supportedChanged
189 **/
190 bool isSupported() const;
191 /**
192 * The current Dpms mode.
193 * Initially set to @c Mode::On.
194 * @returns the current Dpms mode of the Output
195 * @see modeChanged
196 **/
197 Mode mode() const;
198
199 /**
200 * Request to change the Output into Dpms @p mode.
201 * The Wayland compositor is not obliged to honor the request.
202 * If the mode changes the client is notified and @link modeChanged @endlink gets emitted.
203 * @param mode The requested Dpms mode.
204 **/
205 void requestMode(Mode mode);
206
207 operator org_kde_kwin_dpms*();
208 operator org_kde_kwin_dpms*() const;
209
210 Q_SIGNALS:
211 /**
212 * Emitted if the supported state on the Output changes.
213 * @see isSupported
214 **/
215 void supportedChanged();
216 /**
217 * Emitted if the Dpms mode on the Output changes.
218 * @see mode
219 **/
220 void modeChanged();
221
222 private:
223 friend class DpmsManager;
224 explicit Dpms(QPointer<Output> const& o, QObject* parent = nullptr);
225 class Private;
226 std::unique_ptr<Private> d;
227 };
228
229 }
230 }
231
232
3/6
✗ Branch 0 not taken.
✓ Branch 1 taken 1 times.
✓ Branch 2 taken 1 times.
✗ Branch 3 not taken.
✓ Branch 4 taken 1 times.
✗ Branch 5 not taken.
1 Q_DECLARE_METATYPE(Wrapland::Client::Dpms::Mode)
233
234 #endif
235