GCC Code Coverage Report


Directory: ./
File: lib/config.h
Date: 2023-04-20 22:59:23
Exec Total Coverage
Lines: 1 1 100.0%
Branches: 0 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 * *
5 * This library is free software; you can redistribute it and/or *
6 * modify it under the terms of the GNU Lesser General Public *
7 * License as published by the Free Software Foundation; either *
8 * version 2.1 of the License, or (at your option) any later version. *
9 * *
10 * This library is distributed in the hope that it will be useful, *
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of *
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU *
13 * Lesser General Public License for more details. *
14 * *
15 * You should have received a copy of the GNU Lesser General Public *
16 * License along with this library; if not, write to the Free Software *
17 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA *
18 *************************************************************************************/
19 #ifndef DISMAN_CONFIG_H
20 #define DISMAN_CONFIG_H
21
22 #include "disman_export.h"
23 #include "screen.h"
24 #include "types.h"
25
26 #include <QHash>
27 #include <QMetaType>
28 #include <QObject>
29
30 namespace Disman
31 {
32
33 /**
34 * Represents a (or the) screen configuration.
35 *
36 * This is the main class of Disman, with it you can use
37 * the static methods current() to get the systems config and
38 * setConfig() to apply a config to the system.
39 *
40 * Also, you can instantiate an empty Config, this is usually done
41 * to create a config (with the objective of setting it) from scratch
42 * and for example unserialize a saved config to it.
43 *
44 */
45 class DISMAN_EXPORT Config : public QObject
46 {
47 Q_OBJECT
48
49 public:
50 enum class Cause {
51 unknown,
52 file,
53 generated,
54 interactive,
55 };
56
57 enum class ValidityFlag {
58 None = 0x0,
59 RequireAtLeastOneEnabledScreen = 0x1,
60 };
61 Q_DECLARE_FLAGS(ValidityFlags, ValidityFlag)
62
63 /** This indicates which features the used backend supports.
64 *
65 * @see supported_features
66 * @since 5.7
67 */
68 enum class Feature {
69 None = 0, ///< None of the mentioned features are supported.
70 PrimaryDisplay = 1, ///< The backend knows about the concept of a primary display, this is
71 ///< mostly limited to X11.
72 Writable = 1 << 1, ///< The backend supports setting the config, it's not read-only.
73 PerOutputScaling = 1 << 2, ///< The backend supports scaling each output individually.
74 OutputReplication = 1 << 3, ///< The backend supports replication of outputs.
75 AutoRotation = 1 << 4, ///< The backend supports automatic rotation of outputs.
76 TabletMode = 1 << 5, ///< The backend supports querying if a device is in tablet mode.
77 AdaptiveSync = 1 << 6,
78 };
79 Q_DECLARE_FLAGS(Features, Feature)
80
81 /**
82 * Validates that a config can be applied in the current system
83 *
84 * Each system has different constrains, this method will test
85 * the given config with those constrains to see if it
86 * can be applied.
87 *
88 * @arg config to be checked
89 * @flags enable additional optional checks
90 * @return true if the configuration can be applied, false if not.
91 * @since 5.3.0
92 */
93 static bool can_be_applied(const ConfigPtr& config, ValidityFlags flags);
94
95 /**
96 * Validates that a config can be applied in the current system
97 *
98 * Each system has different constrains, this method will test
99 * the given config with those constrains to see if it
100 * can be applied.
101 *
102 * @arg config to be checked
103 * @return true if the configuration can be applied, false if not.
104 */
105 static bool can_be_applied(const ConfigPtr& config);
106
107 /**
108 * Instantiate an empty config
109 *
110 * Usually you do not want to use this constructor since there are some
111 * values that make no sense to set (for example you want the Screen of
112 * the current systme).
113 *
114 * So usually what you do is call current() and then modify
115 * whatever you need.
116 */
117 Config();
118 explicit Config(Cause cause);
119 ~Config() override;
120
121 /**
122 * Duplicates the config
123 *
124 * @return a new Config instance with same property values
125 */
126 ConfigPtr clone() const;
127
128 /**
129 * Compares the data of this object with @param config.
130 *
131 * @return true if data is same otherwise false
132 */
133 bool compare(ConfigPtr config) const;
134
135 /**
136 * Returns an identifying hash for this config in regards to its
137 * connected outputs.
138 *
139 * The hash is calculated with a sorted combination of all
140 * connected output hashes.
141 *
142 * @return sorted hash combination of all connected outputs
143 * @since 5.15
144 */
145 QString hash() const;
146
147 Cause cause() const;
148 void set_cause(Cause cause);
149
150 ScreenPtr screen() const;
151 void setScreen(const ScreenPtr& screen);
152
153 OutputPtr output(int outputId) const;
154 OutputMap outputs() const;
155
156 OutputPtr primary_output() const;
157 void set_primary_output(const OutputPtr& output);
158
159 void add_output(const OutputPtr& output);
160 void remove_output(int outputId);
161 void set_outputs(OutputMap const& outputs);
162
163 bool valid() const;
164 void set_valid(bool valid);
165
166 void apply(const ConfigPtr& other);
167
168 /** Indicates features supported by the backend. This exists to allow the user
169 * to find out which of the features offered by disman are actually supported
170 * by the backend. Not all backends are writable (QScreen, for example is
171 * read-only, only XRandR, but not KWayland support the primary display, etc.).
172 *
173 * @return Flags for features that are supported for this config, determined by
174 * the backend.
175 * @see set_supported_features
176 * @since 5.7
177 */
178 Features supported_features() const;
179
180 /** Sets the features supported by this backend. This should not be called by the
181 * user, but by the backend.
182 *
183 * @see supported_features
184 * @since 5.7
185 */
186 void set_supported_features(const Features& features);
187
188 /**
189 * Indicates that the device supports switching between a default and a tablet mode. This is
190 * common for convertibles.
191 *
192 * @return true when tablet mode is available, otherwise false
193 * @see set_tablet_mode_available
194 * @since 5.18
195 */
196 bool tablet_mode_available() const;
197
198 /** Sets if the device supports a tablet mode. This should not be called by the
199 * user, but by the backend.
200 *
201 * @see tablet_mode_available
202 * @since 5.18
203 */
204 void set_tablet_mode_available(bool available);
205
206 /**
207 * Indicates that the device is currently in tablet mode.
208 *
209 * @return true when in tablet mode, otherwise false
210 * @see set_tablet_mode_engaged
211 * @since 5.18
212 */
213 bool tablet_mode_engaged() const;
214
215 /**
216 * Sets if the device is currently in tablet mode. This should not be called by the
217 * user, but by the backend.
218 *
219 * @see tabletModeEngaged
220 * @since 5.18
221 */
222 void set_tablet_mode_engaged(bool engaged);
223
224 /**
225 * Returns the Output @param output replicates if @param output is a replica, otherwise null.
226 *
227 * @param output to find replication source for
228 * @return replication source or null
229 */
230 OutputPtr replication_source(OutputPtr const& output);
231
232 std::string log() const;
233
234 Q_SIGNALS:
235 void output_added(const Disman::OutputPtr& output);
236 void output_removed(int outputId);
237 void primary_output_changed(const Disman::OutputPtr& output);
238
239 private:
240 Q_DISABLE_COPY(Config)
241
242 class Private;
243 Private* const d;
244 };
245
246 }
247
248 393 Q_DECLARE_OPERATORS_FOR_FLAGS(Disman::Config::Features)
249
250 DISMAN_EXPORT QDebug operator<<(QDebug dbg, const Disman::ConfigPtr& config);
251
252 #endif
253