GCC Code Coverage Report


Directory: ./
File: lib/output.h
Date: 2023-04-20 22:59:23
Exec Total Coverage
Lines: 1 1 100.0%
Branches: 4 10 40.0%

Line Branch Exec Source
1 /*************************************************************************************
2 * Copyright (C) 2012 by Alejandro Fiestas Olivares <afiestas@kde.org> *
3 * Copyright (C) 2014 by Daniel Vrátil <dvratil@redhat.com> *
4 * Copyright © 2020 Roman Gilg <subdiff@gmail.com> *
5 * *
6 * This library is free software; you can redistribute it and/or *
7 * modify it under the terms of the GNU Lesser General Public *
8 * License as published by the Free Software Foundation; either *
9 * version 2.1 of the License, or (at your option) any later version. *
10 * *
11 * This library is distributed in the hope that it will be useful, *
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of *
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU *
14 * Lesser General Public License for more details. *
15 * *
16 * You should have received a copy of the GNU Lesser General Public *
17 * License along with this library; if not, write to the Free Software *
18 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA *
19 *************************************************************************************/
20 #ifndef OUTPUT_CONFIG_H
21 #define OUTPUT_CONFIG_H
22
23 #include "disman_export.h"
24 #include "mode.h"
25 #include "types.h"
26
27 #include <QDebug>
28 #include <QMetaType>
29 #include <QObject>
30 #include <QPoint>
31 #include <QSize>
32
33 #include <string>
34
35 namespace Disman
36 {
37
38 class DISMAN_EXPORT Output : public QObject
39 {
40 Q_OBJECT
41
42 public:
43 Q_ENUMS(Rotation)
44 Q_ENUMS(Type)
45
46 enum Type {
47 Unknown,
48 VGA,
49 DVI,
50 DVII,
51 DVIA,
52 DVID,
53 HDMI,
54 Panel,
55 TV,
56 TVComposite,
57 TVSVideo,
58 TVComponent,
59 TVSCART,
60 TVC4,
61 DisplayPort,
62 };
63
64 enum Rotation {
65 None = 1,
66 Left = 2,
67 Inverted = 4,
68 Right = 8,
69 };
70
71 enum class Retention {
72 Undefined = -1,
73 Global = 0,
74 Individual = 1,
75 };
76 Q_ENUM(Retention)
77
78 Output();
79 ~Output() override;
80
81 OutputPtr clone() const;
82
83 /**
84 * Compares the data of this object with @param output.
85 *
86 * @return true if data is same otherwise false
87 */
88 bool compare(OutputPtr output) const;
89
90 int id() const;
91 void set_id(int id);
92
93 /**
94 * The name of the output uniquely identifies it and usually describes the connector in some way
95 * together with a counter, for example DP-1, DP-2 and HDMI-A-1, HDMI-A-2.
96 */
97 std::string name() const;
98 void set_name(std::string const& name);
99
100 /**
101 * The description of an output is provided by the backend and is meant to be displayed in
102 * UI to identify the output and the display connected to it. It is pre-translated as it is the
103 * responsibility of the backend to translate it to the user session locale.
104 *
105 * Examples are 'Foocorp 11" Display' or 'Virtual X11 output via :1'.
106 */
107 std::string description() const;
108 void set_description(std::string const& description);
109
110 /**
111 * Returns an identifying hex encoded hash for this output.
112 */
113 std::string hash() const;
114
115 /**
116 * Set the output hash by providing a hashable input. The input will be hashed and converted
117 * to hex internally.
118 */
119 void set_hash(std::string const& input);
120
121 /**
122 * Set the output hash by setting a hash directly.
123 */
124 void set_hash_raw(std::string const& hash);
125
126 Type type() const;
127 void setType(Type type);
128
129 ModePtr mode(std::string const& id) const;
130 ModePtr mode(QSize const& resolution, int refresh) const;
131
132 ModeMap modes() const;
133 void set_modes(const ModeMap& modes);
134
135 /**
136 * Sets the mode.
137 *
138 * @see commmanded_mode
139 */
140 void set_mode(ModePtr const& mode);
141 bool set_resolution(QSize const& size);
142 bool set_refresh_rate(int rate);
143
144 void set_to_preferred_mode();
145
146 /**
147 * Returns the mode determined by the set resolution and refresh rate. When received from the
148 * backend this determines the current hardware mode independet of what auto_mode says.
149 *
150 * On the opposite if they are not the same the configuration is not in sync what indicates
151 * a corruption of the output configuration.
152 *
153 * @see commanded_mode
154 * @see set_resolution
155 * @see set_refresh_rate
156 */
157 ModePtr commanded_mode() const;
158
159 /**
160 * Returns a best mode by first selecting the highest available resolution
161 * and for that resolution the mode with the highest refresh rate.
162 */
163 ModePtr best_mode() const;
164
165 /**
166 * Similar to @ref best_mode, tries to return the best mode but considers the current auto
167 * resolution and auto refresh rate settings.
168 *
169 * That means in a first step the highest available resolution is chosen if @ref auto_resolution
170 * is true and otherwise the currently set resolution. In a second step the mode with the
171 * highest refresh rate for this resolution will be returned if @ref auto_refresh_rate is true,
172 * otherwise the mode with the currently set refresh rate. If such a mode does not exist null
173 * is returned.
174 */
175 ModePtr auto_mode() const;
176
177 QSize best_resolution() const;
178 int best_refresh_rate(QSize const& resolution) const;
179
180 void set_preferred_modes(std::vector<std::string> const& modes);
181 std::vector<std::string> const& preferred_modes() const;
182
183 /**
184 * Returns a mode that the hardware marked as preferred and that is the best one in the sense
185 * of @ref best_mode().
186 *
187 * @see best_mode
188 */
189 ModePtr preferred_mode() const;
190
191 Rotation rotation() const;
192 void set_rotation(Rotation rotation);
193
194 /**
195 * Helper that returns true when output is not rotated or is rotated upside down.
196 */
197 bool horizontal() const;
198
199 bool enabled() const;
200 void set_enabled(bool enabled);
201
202 bool adaptive_sync() const;
203 void set_adaptive_sync(bool adapt);
204
205 bool adaptive_sync_toggle_support() const;
206 void set_adaptive_sync_toggle_support(bool support);
207
208 /**
209 * @brief Provides the source for an ongoing replication
210 *
211 * If the returned output id is non-null this output is a replica of the
212 * returned output. If null is returned the output is no replica of any
213 * other output.
214 *
215 * @return Replication source output id of this output
216 */
217 int replication_source() const;
218 /**
219 * @brief Set the replication source.
220 * @param source
221 */
222 void set_replication_source(int source);
223
224 /**
225 * Returns the physical size of the screen in milimeters.
226 *
227 * @note Some broken GPUs or monitors return the size in centimeters instead
228 * of millimeters. Disman at the moment is not sanitizing the values.
229 */
230 QSize physical_size() const;
231 void set_physical_size(const QSize& size);
232
233 /**
234 * Returns if the output needs to be taken account for in the overall compositor/screen
235 * space and if it should be depicted on its own in a graphical view for repositioning.
236 *
237 * @return true if the output is positionable in compositor/screen space.
238 *
239 * @since 5.17
240 */
241 bool positionable() const;
242
243 /**
244 * Returns a rectangle containing the currently set output position and
245 * size.
246 *
247 * The geometry reflects current orientation (i.e. if current mode
248 * is 1920x1080 and orientation is @p Disman::Output::Left, then the
249 * size of the returned rectangle will be 1080x1920.
250 *
251 * The geometry also respects the set scale. But it is not influenced by a replication
252 * source.
253 *
254 * This property contains the current settings stored in the particular
255 * Output object, so it is updated even when user changes current mode
256 * or orientation without applying the whole config.
257 */
258 QRectF geometry() const;
259
260 /**
261 * Force a certain geometry. This function is meant to be used by the backend. Values written
262 * to it by frontend clients have no guarantee to be effective and might corrupt the config.
263 *
264 * @param geo to force
265 */
266 void force_geometry(QRectF const& geo);
267
268 QPointF position() const;
269 void set_position(const QPointF& position);
270
271 double scale() const;
272 void set_scale(double scale);
273
274 /**
275 * @returns whether the mode should be changed to the new preferred mode
276 * once it changes
277 */
278 bool follow_preferred_mode() const;
279
280 /**
281 * Set whether the preferred mode should be followed through @arg follow
282 *
283 * @since 5.15
284 */
285 void set_follow_preferred_mode(bool follow);
286
287 bool auto_resolution() const;
288 void set_auto_resolution(bool auto_res);
289
290 bool auto_refresh_rate() const;
291 void set_auto_refresh_rate(bool auto_rate);
292
293 bool auto_rotate() const;
294 void set_auto_rotate(bool auto_rot);
295
296 bool auto_rotate_only_in_tablet_mode() const;
297 void set_auto_rotate_only_in_tablet_mode(bool only);
298
299 Retention retention() const;
300 void set_retention(Retention retention);
301
302 void apply(const OutputPtr& other);
303
304 struct GlobalData {
305 QSize resolution;
306 int refresh{0};
307 bool adapt_sync{false};
308
309 Rotation rotation;
310 double scale;
311
312 bool auto_resolution{true};
313 bool auto_refresh_rate{true};
314 bool auto_rotate{false};
315 bool auto_rotate_only_in_tablet_mode{true};
316
317 bool valid{false};
318 };
319
320 GlobalData global_data() const;
321 void set_global_data(GlobalData data);
322
323 std::string log() const;
324
325 Q_SIGNALS:
326 /**
327 * An update to the output was applied. Changes to its properties could have occured.
328 */
329 void updated();
330
331 private:
332 Q_DISABLE_COPY(Output)
333
334 class Private;
335 Private* const d;
336
337 Output(Private* dd);
338
339 friend class Generator;
340 };
341
342 }
343
344 DISMAN_EXPORT QDebug operator<<(QDebug dbg, const Disman::OutputPtr& output);
345
346 Q_DECLARE_METATYPE(Disman::OutputMap)
347
4/10
✗ Branch 1 not taken.
✓ Branch 2 taken 1 times.
✓ Branch 7 taken 1 times.
✗ Branch 8 not taken.
✓ Branch 10 taken 1 times.
✗ Branch 11 not taken.
✓ Branch 13 taken 1 times.
✗ Branch 14 not taken.
✗ Branch 18 not taken.
✗ Branch 19 not taken.
1 Q_DECLARE_METATYPE(Disman::Output::Rotation)
348 Q_DECLARE_METATYPE(Disman::Output::Type)
349
350 #endif
351