Line |
Branch |
Exec |
Source |
1 |
|
|
/* |
2 |
|
|
* Copyright (C) 2016 Red Hat, Inc. |
3 |
|
|
* |
4 |
|
|
* This program is free software; you can redistribute it and/or modify |
5 |
|
|
* it under the terms of the GNU General Public License as published by |
6 |
|
|
* the Free Software Foundation; either version 2 of the License, or |
7 |
|
|
* (at your option) any later version. |
8 |
|
|
* |
9 |
|
|
* This program is distributed in the hope that it will be useful, |
10 |
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of |
11 |
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
12 |
|
|
* GNU General Public License for more details. |
13 |
|
|
* |
14 |
|
|
* You should have received a copy of the GNU General Public License |
15 |
|
|
* along with this program; if not, write to the Free Software |
16 |
|
|
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. |
17 |
|
|
* |
18 |
|
|
*/ |
19 |
|
|
|
20 |
|
|
#include <gio/gio.h> |
21 |
|
|
#include <math.h> |
22 |
|
|
#include "cc-display-config.h" |
23 |
|
|
|
24 |
|
|
static const double known_diagonals[] = { |
25 |
|
|
12.1, |
26 |
|
|
13.3, |
27 |
|
|
15.6 |
28 |
|
|
}; |
29 |
|
|
|
30 |
|
|
static char * |
31 |
|
✗ |
diagonal_to_str (double d) |
32 |
|
|
{ |
33 |
|
|
int i; |
34 |
|
|
|
35 |
|
✗ |
for (i = 0; i < G_N_ELEMENTS (known_diagonals); i++) |
36 |
|
|
{ |
37 |
|
|
double delta; |
38 |
|
|
|
39 |
|
✗ |
delta = fabs(known_diagonals[i] - d); |
40 |
|
✗ |
if (delta < 0.1) |
41 |
|
✗ |
return g_strdup_printf ("%0.1lf\"", known_diagonals[i]); |
42 |
|
|
} |
43 |
|
|
|
44 |
|
✗ |
return g_strdup_printf ("%d\"", (int) (d + 0.5)); |
45 |
|
|
} |
46 |
|
|
|
47 |
|
|
static char * |
48 |
|
✗ |
make_display_size_string (int width_mm, |
49 |
|
|
int height_mm) |
50 |
|
|
{ |
51 |
|
✗ |
char *inches = NULL; |
52 |
|
|
|
53 |
|
✗ |
if (width_mm > 0 && height_mm > 0) |
54 |
|
|
{ |
55 |
|
✗ |
double d = sqrt (width_mm * width_mm + height_mm * height_mm); |
56 |
|
|
|
57 |
|
✗ |
inches = diagonal_to_str (d / 25.4); |
58 |
|
|
} |
59 |
|
|
|
60 |
|
✗ |
return inches; |
61 |
|
|
} |
62 |
|
|
|
63 |
|
|
static char * |
64 |
|
✗ |
make_output_ui_name (CcDisplayMonitor *output) |
65 |
|
|
{ |
66 |
|
|
int width_mm, height_mm; |
67 |
|
✗ |
g_autofree char *size = NULL; |
68 |
|
|
|
69 |
|
✗ |
cc_display_monitor_get_physical_size (output, &width_mm, &height_mm); |
70 |
|
✗ |
size = make_display_size_string (width_mm, height_mm); |
71 |
|
✗ |
if (size) |
72 |
|
✗ |
return g_strdup_printf ("%s (%s)", cc_display_monitor_get_display_name (output), size); |
73 |
|
|
else |
74 |
|
✗ |
return g_strdup_printf ("%s", cc_display_monitor_get_display_name (output)); |
75 |
|
|
} |
76 |
|
|
|
77 |
|
|
|
78 |
|
|
|
79 |
|
✗ |
G_DEFINE_TYPE (CcDisplayMode, |
80 |
|
|
cc_display_mode, |
81 |
|
|
G_TYPE_OBJECT) |
82 |
|
|
|
83 |
|
|
static void |
84 |
|
✗ |
cc_display_mode_init (CcDisplayMode *self) |
85 |
|
|
{ |
86 |
|
✗ |
} |
87 |
|
|
|
88 |
|
|
static void |
89 |
|
✗ |
cc_display_mode_class_init (CcDisplayModeClass *klass) |
90 |
|
|
{ |
91 |
|
✗ |
} |
92 |
|
|
|
93 |
|
|
gboolean |
94 |
|
✗ |
cc_display_mode_is_clone_mode (CcDisplayMode *self) |
95 |
|
|
{ |
96 |
|
✗ |
return CC_DISPLAY_MODE_GET_CLASS (self)->is_clone_mode (self); |
97 |
|
|
} |
98 |
|
|
|
99 |
|
|
void |
100 |
|
✗ |
cc_display_mode_get_resolution (CcDisplayMode *self, int *w, int *h) |
101 |
|
|
{ |
102 |
|
✗ |
return CC_DISPLAY_MODE_GET_CLASS (self)->get_resolution (self, w, h); |
103 |
|
|
} |
104 |
|
|
|
105 |
|
|
GArray * |
106 |
|
✗ |
cc_display_mode_get_supported_scales (CcDisplayMode *self) |
107 |
|
|
{ |
108 |
|
✗ |
return CC_DISPLAY_MODE_GET_CLASS (self)->get_supported_scales (self); |
109 |
|
|
} |
110 |
|
|
|
111 |
|
|
double |
112 |
|
✗ |
cc_display_mode_get_preferred_scale (CcDisplayMode *self) |
113 |
|
|
{ |
114 |
|
✗ |
return CC_DISPLAY_MODE_GET_CLASS (self)->get_preferred_scale (self); |
115 |
|
|
} |
116 |
|
|
|
117 |
|
|
CcDisplayModeRefreshRateMode |
118 |
|
✗ |
cc_display_mode_get_refresh_rate_mode (CcDisplayMode *self) |
119 |
|
|
{ |
120 |
|
✗ |
return CC_DISPLAY_MODE_GET_CLASS (self)->get_refresh_rate_mode (self); |
121 |
|
|
} |
122 |
|
|
|
123 |
|
|
gboolean |
124 |
|
✗ |
cc_display_mode_is_interlaced (CcDisplayMode *self) |
125 |
|
|
{ |
126 |
|
✗ |
return CC_DISPLAY_MODE_GET_CLASS (self)->is_interlaced (self); |
127 |
|
|
} |
128 |
|
|
|
129 |
|
|
gboolean |
130 |
|
✗ |
cc_display_mode_is_preferred (CcDisplayMode *self) |
131 |
|
|
{ |
132 |
|
✗ |
return CC_DISPLAY_MODE_GET_CLASS (self)->is_preferred (self); |
133 |
|
|
} |
134 |
|
|
|
135 |
|
|
int |
136 |
|
✗ |
cc_display_mode_get_freq (CcDisplayMode *self) |
137 |
|
|
{ |
138 |
|
✗ |
return CC_DISPLAY_MODE_GET_CLASS (self)->get_freq (self); |
139 |
|
|
} |
140 |
|
|
|
141 |
|
|
double |
142 |
|
✗ |
cc_display_mode_get_freq_f (CcDisplayMode *self) |
143 |
|
|
{ |
144 |
|
✗ |
return CC_DISPLAY_MODE_GET_CLASS (self)->get_freq_f (self); |
145 |
|
|
} |
146 |
|
|
|
147 |
|
|
|
148 |
|
|
struct _CcDisplayMonitorPrivate { |
149 |
|
|
int ui_number; |
150 |
|
|
gchar *ui_name; |
151 |
|
|
gchar *ui_number_name; |
152 |
|
|
gboolean is_usable; |
153 |
|
|
}; |
154 |
|
|
typedef struct _CcDisplayMonitorPrivate CcDisplayMonitorPrivate; |
155 |
|
|
|
156 |
|
✗ |
G_DEFINE_TYPE_WITH_PRIVATE (CcDisplayMonitor, |
157 |
|
|
cc_display_monitor, |
158 |
|
|
G_TYPE_OBJECT) |
159 |
|
|
|
160 |
|
|
static void |
161 |
|
✗ |
cc_display_monitor_init (CcDisplayMonitor *self) |
162 |
|
|
{ |
163 |
|
✗ |
CcDisplayMonitorPrivate *priv = cc_display_monitor_get_instance_private (self); |
164 |
|
|
|
165 |
|
✗ |
priv->ui_number = 0; |
166 |
|
✗ |
priv->ui_name = NULL; |
167 |
|
✗ |
priv->ui_number_name = NULL; |
168 |
|
✗ |
priv->is_usable = TRUE; |
169 |
|
✗ |
} |
170 |
|
|
|
171 |
|
|
static void |
172 |
|
✗ |
cc_display_monitor_finalize (GObject *object) |
173 |
|
|
{ |
174 |
|
✗ |
CcDisplayMonitor *self = CC_DISPLAY_MONITOR (object); |
175 |
|
✗ |
CcDisplayMonitorPrivate *priv = cc_display_monitor_get_instance_private (self); |
176 |
|
|
|
177 |
|
✗ |
g_clear_pointer (&priv->ui_name, g_free); |
178 |
|
✗ |
g_clear_pointer (&priv->ui_number_name, g_free); |
179 |
|
|
|
180 |
|
✗ |
G_OBJECT_CLASS (cc_display_monitor_parent_class)->finalize (object); |
181 |
|
✗ |
} |
182 |
|
|
|
183 |
|
|
static void |
184 |
|
✗ |
cc_display_monitor_class_init (CcDisplayMonitorClass *klass) |
185 |
|
|
{ |
186 |
|
✗ |
GObjectClass *gobject_class = G_OBJECT_CLASS (klass); |
187 |
|
|
|
188 |
|
✗ |
gobject_class->finalize = cc_display_monitor_finalize; |
189 |
|
|
|
190 |
|
✗ |
g_signal_new ("rotation", |
191 |
|
|
CC_TYPE_DISPLAY_MONITOR, |
192 |
|
|
G_SIGNAL_RUN_LAST, |
193 |
|
|
0, NULL, NULL, NULL, |
194 |
|
|
G_TYPE_NONE, 0); |
195 |
|
✗ |
g_signal_new ("mode", |
196 |
|
|
CC_TYPE_DISPLAY_MONITOR, |
197 |
|
|
G_SIGNAL_RUN_LAST, |
198 |
|
|
0, NULL, NULL, NULL, |
199 |
|
|
G_TYPE_NONE, 0); |
200 |
|
✗ |
g_signal_new ("primary", |
201 |
|
|
CC_TYPE_DISPLAY_MONITOR, |
202 |
|
|
G_SIGNAL_RUN_LAST, |
203 |
|
|
0, NULL, NULL, NULL, |
204 |
|
|
G_TYPE_NONE, 0); |
205 |
|
✗ |
g_signal_new ("active", |
206 |
|
|
CC_TYPE_DISPLAY_MONITOR, |
207 |
|
|
G_SIGNAL_RUN_LAST, |
208 |
|
|
0, NULL, NULL, NULL, |
209 |
|
|
G_TYPE_NONE, 0); |
210 |
|
✗ |
g_signal_new ("scale", |
211 |
|
|
CC_TYPE_DISPLAY_MONITOR, |
212 |
|
|
G_SIGNAL_RUN_LAST, |
213 |
|
|
0, NULL, NULL, NULL, |
214 |
|
|
G_TYPE_NONE, 0); |
215 |
|
✗ |
g_signal_new ("position-changed", |
216 |
|
|
CC_TYPE_DISPLAY_MONITOR, |
217 |
|
|
G_SIGNAL_RUN_LAST, |
218 |
|
|
0, NULL, NULL, NULL, |
219 |
|
|
G_TYPE_NONE, 0); |
220 |
|
✗ |
g_signal_new ("is-usable", |
221 |
|
|
CC_TYPE_DISPLAY_MONITOR, |
222 |
|
|
G_SIGNAL_RUN_LAST, |
223 |
|
|
0, NULL, NULL, NULL, |
224 |
|
|
G_TYPE_NONE, 0); |
225 |
|
✗ |
} |
226 |
|
|
|
227 |
|
|
const char * |
228 |
|
✗ |
cc_display_monitor_get_display_name (CcDisplayMonitor *self) |
229 |
|
|
{ |
230 |
|
✗ |
return CC_DISPLAY_MONITOR_GET_CLASS (self)->get_display_name (self); |
231 |
|
|
} |
232 |
|
|
|
233 |
|
|
const char * |
234 |
|
✗ |
cc_display_monitor_get_connector_name (CcDisplayMonitor *self) |
235 |
|
|
{ |
236 |
|
✗ |
return CC_DISPLAY_MONITOR_GET_CLASS (self)->get_connector_name (self); |
237 |
|
|
} |
238 |
|
|
|
239 |
|
|
gboolean |
240 |
|
✗ |
cc_display_monitor_is_builtin (CcDisplayMonitor *self) |
241 |
|
|
{ |
242 |
|
✗ |
return CC_DISPLAY_MONITOR_GET_CLASS (self)->is_builtin (self); |
243 |
|
|
} |
244 |
|
|
|
245 |
|
|
gboolean |
246 |
|
✗ |
cc_display_monitor_is_primary (CcDisplayMonitor *self) |
247 |
|
|
{ |
248 |
|
✗ |
return CC_DISPLAY_MONITOR_GET_CLASS (self)->is_primary (self); |
249 |
|
|
} |
250 |
|
|
|
251 |
|
|
void |
252 |
|
✗ |
cc_display_monitor_set_primary (CcDisplayMonitor *self, gboolean primary) |
253 |
|
|
{ |
254 |
|
✗ |
return CC_DISPLAY_MONITOR_GET_CLASS (self)->set_primary (self, primary); |
255 |
|
|
} |
256 |
|
|
|
257 |
|
|
gboolean |
258 |
|
✗ |
cc_display_monitor_is_active (CcDisplayMonitor *self) |
259 |
|
|
{ |
260 |
|
✗ |
return CC_DISPLAY_MONITOR_GET_CLASS (self)->is_active (self); |
261 |
|
|
} |
262 |
|
|
|
263 |
|
|
void |
264 |
|
✗ |
cc_display_monitor_set_active (CcDisplayMonitor *self, gboolean active) |
265 |
|
|
{ |
266 |
|
✗ |
return CC_DISPLAY_MONITOR_GET_CLASS (self)->set_active (self, active); |
267 |
|
|
} |
268 |
|
|
|
269 |
|
|
CcDisplayRotation |
270 |
|
✗ |
cc_display_monitor_get_rotation (CcDisplayMonitor *self) |
271 |
|
|
{ |
272 |
|
✗ |
return CC_DISPLAY_MONITOR_GET_CLASS (self)->get_rotation (self); |
273 |
|
|
} |
274 |
|
|
|
275 |
|
|
void |
276 |
|
✗ |
cc_display_monitor_set_rotation (CcDisplayMonitor *self, |
277 |
|
|
CcDisplayRotation rotation) |
278 |
|
|
{ |
279 |
|
✗ |
return CC_DISPLAY_MONITOR_GET_CLASS (self)->set_rotation (self, rotation); |
280 |
|
|
} |
281 |
|
|
|
282 |
|
|
gboolean |
283 |
|
✗ |
cc_display_monitor_supports_rotation (CcDisplayMonitor *self, CcDisplayRotation r) |
284 |
|
|
{ |
285 |
|
✗ |
return CC_DISPLAY_MONITOR_GET_CLASS (self)->supports_rotation (self, r); |
286 |
|
|
} |
287 |
|
|
|
288 |
|
|
void |
289 |
|
✗ |
cc_display_monitor_get_physical_size (CcDisplayMonitor *self, int *w, int *h) |
290 |
|
|
{ |
291 |
|
✗ |
return CC_DISPLAY_MONITOR_GET_CLASS (self)->get_physical_size (self, w, h); |
292 |
|
|
} |
293 |
|
|
|
294 |
|
|
void |
295 |
|
✗ |
cc_display_monitor_get_geometry (CcDisplayMonitor *self, int *x, int *y, int *w, int *h) |
296 |
|
|
{ |
297 |
|
✗ |
return CC_DISPLAY_MONITOR_GET_CLASS (self)->get_geometry (self, x, y, w, h); |
298 |
|
|
} |
299 |
|
|
|
300 |
|
|
int |
301 |
|
✗ |
cc_display_monitor_get_min_freq (CcDisplayMonitor *self) |
302 |
|
|
{ |
303 |
|
✗ |
return CC_DISPLAY_MONITOR_GET_CLASS (self)->get_min_freq (self); |
304 |
|
|
} |
305 |
|
|
|
306 |
|
|
CcDisplayMode * |
307 |
|
✗ |
cc_display_monitor_get_mode (CcDisplayMonitor *self) |
308 |
|
|
{ |
309 |
|
✗ |
return CC_DISPLAY_MONITOR_GET_CLASS (self)->get_mode (self); |
310 |
|
|
} |
311 |
|
|
|
312 |
|
|
CcDisplayMode * |
313 |
|
✗ |
cc_display_monitor_get_preferred_mode (CcDisplayMonitor *self) |
314 |
|
|
{ |
315 |
|
✗ |
return CC_DISPLAY_MONITOR_GET_CLASS (self)->get_preferred_mode (self); |
316 |
|
|
} |
317 |
|
|
|
318 |
|
|
guint32 |
319 |
|
✗ |
cc_display_monitor_get_id (CcDisplayMonitor *self) |
320 |
|
|
{ |
321 |
|
✗ |
return CC_DISPLAY_MONITOR_GET_CLASS (self)->get_id (self); |
322 |
|
|
} |
323 |
|
|
|
324 |
|
|
GList * |
325 |
|
✗ |
cc_display_monitor_get_modes (CcDisplayMonitor *self) |
326 |
|
|
{ |
327 |
|
✗ |
return CC_DISPLAY_MONITOR_GET_CLASS (self)->get_modes (self); |
328 |
|
|
} |
329 |
|
|
|
330 |
|
|
gboolean |
331 |
|
✗ |
cc_display_monitor_supports_variable_refresh_rate (CcDisplayMonitor *self) |
332 |
|
|
{ |
333 |
|
✗ |
return CC_DISPLAY_MONITOR_GET_CLASS (self)->supports_variable_refresh_rate (self); |
334 |
|
|
} |
335 |
|
|
|
336 |
|
|
gboolean |
337 |
|
✗ |
cc_display_monitor_supports_underscanning (CcDisplayMonitor *self) |
338 |
|
|
{ |
339 |
|
✗ |
return CC_DISPLAY_MONITOR_GET_CLASS (self)->supports_underscanning (self); |
340 |
|
|
} |
341 |
|
|
|
342 |
|
|
gboolean |
343 |
|
✗ |
cc_display_monitor_get_underscanning (CcDisplayMonitor *self) |
344 |
|
|
{ |
345 |
|
✗ |
return CC_DISPLAY_MONITOR_GET_CLASS (self)->get_underscanning (self); |
346 |
|
|
} |
347 |
|
|
|
348 |
|
|
void |
349 |
|
✗ |
cc_display_monitor_set_underscanning (CcDisplayMonitor *self, |
350 |
|
|
gboolean underscanning) |
351 |
|
|
{ |
352 |
|
✗ |
return CC_DISPLAY_MONITOR_GET_CLASS (self)->set_underscanning (self, underscanning); |
353 |
|
|
} |
354 |
|
|
|
355 |
|
|
CcDisplayMonitorPrivacy |
356 |
|
✗ |
cc_display_monitor_get_privacy (CcDisplayMonitor *self) |
357 |
|
|
{ |
358 |
|
✗ |
return CC_DISPLAY_MONITOR_GET_CLASS (self)->get_privacy (self); |
359 |
|
|
} |
360 |
|
|
|
361 |
|
|
void |
362 |
|
✗ |
cc_display_monitor_set_mode (CcDisplayMonitor *self, CcDisplayMode *m) |
363 |
|
|
{ |
364 |
|
✗ |
return CC_DISPLAY_MONITOR_GET_CLASS (self)->set_mode (self, m); |
365 |
|
|
} |
366 |
|
|
|
367 |
|
|
void |
368 |
|
✗ |
cc_display_monitor_set_compatible_clone_mode (CcDisplayMonitor *self, CcDisplayMode *m) |
369 |
|
|
{ |
370 |
|
✗ |
return CC_DISPLAY_MONITOR_GET_CLASS (self)->set_mode (self, m); |
371 |
|
|
} |
372 |
|
|
|
373 |
|
|
void |
374 |
|
✗ |
cc_display_monitor_set_refresh_rate_mode (CcDisplayMonitor *self, |
375 |
|
|
CcDisplayModeRefreshRateMode refresh_rate_mode) |
376 |
|
|
{ |
377 |
|
✗ |
return CC_DISPLAY_MONITOR_GET_CLASS (self)->set_refresh_rate_mode (self, refresh_rate_mode); |
378 |
|
|
} |
379 |
|
|
|
380 |
|
|
void |
381 |
|
✗ |
cc_display_monitor_set_position (CcDisplayMonitor *self, int x, int y) |
382 |
|
|
{ |
383 |
|
✗ |
return CC_DISPLAY_MONITOR_GET_CLASS (self)->set_position (self, x, y); |
384 |
|
|
} |
385 |
|
|
|
386 |
|
|
double |
387 |
|
✗ |
cc_display_monitor_get_scale (CcDisplayMonitor *self) |
388 |
|
|
{ |
389 |
|
✗ |
return CC_DISPLAY_MONITOR_GET_CLASS (self)->get_scale (self); |
390 |
|
|
} |
391 |
|
|
|
392 |
|
|
void |
393 |
|
✗ |
cc_display_monitor_set_scale (CcDisplayMonitor *self, double s) |
394 |
|
|
{ |
395 |
|
✗ |
return CC_DISPLAY_MONITOR_GET_CLASS (self)->set_scale (self, s); |
396 |
|
|
} |
397 |
|
|
|
398 |
|
|
gboolean |
399 |
|
✗ |
cc_display_monitor_is_useful (CcDisplayMonitor *self) |
400 |
|
|
{ |
401 |
|
✗ |
CcDisplayMonitorPrivate *priv = cc_display_monitor_get_instance_private (self); |
402 |
|
|
|
403 |
|
✗ |
return priv->is_usable && |
404 |
|
✗ |
cc_display_monitor_is_active (self); |
405 |
|
|
} |
406 |
|
|
|
407 |
|
|
gboolean |
408 |
|
✗ |
cc_display_monitor_is_usable (CcDisplayMonitor *self) |
409 |
|
|
{ |
410 |
|
✗ |
CcDisplayMonitorPrivate *priv = cc_display_monitor_get_instance_private (self); |
411 |
|
|
|
412 |
|
✗ |
return priv->is_usable; |
413 |
|
|
} |
414 |
|
|
|
415 |
|
|
void |
416 |
|
✗ |
cc_display_monitor_set_usable (CcDisplayMonitor *self, gboolean is_usable) |
417 |
|
|
{ |
418 |
|
✗ |
CcDisplayMonitorPrivate *priv = cc_display_monitor_get_instance_private (self); |
419 |
|
|
|
420 |
|
✗ |
priv->is_usable = is_usable; |
421 |
|
|
|
422 |
|
✗ |
g_signal_emit_by_name (self, "is-usable"); |
423 |
|
✗ |
} |
424 |
|
|
|
425 |
|
|
gint |
426 |
|
✗ |
cc_display_monitor_get_ui_number (CcDisplayMonitor *self) |
427 |
|
|
{ |
428 |
|
✗ |
CcDisplayMonitorPrivate *priv = cc_display_monitor_get_instance_private (self); |
429 |
|
|
|
430 |
|
✗ |
return priv->ui_number; |
431 |
|
|
} |
432 |
|
|
|
433 |
|
|
const char * |
434 |
|
✗ |
cc_display_monitor_get_ui_name (CcDisplayMonitor *self) |
435 |
|
|
{ |
436 |
|
✗ |
CcDisplayMonitorPrivate *priv = cc_display_monitor_get_instance_private (self); |
437 |
|
|
|
438 |
|
✗ |
return priv->ui_name; |
439 |
|
|
} |
440 |
|
|
|
441 |
|
|
const char * |
442 |
|
✗ |
cc_display_monitor_get_ui_number_name (CcDisplayMonitor *self) |
443 |
|
|
{ |
444 |
|
✗ |
CcDisplayMonitorPrivate *priv = cc_display_monitor_get_instance_private (self); |
445 |
|
|
|
446 |
|
✗ |
return priv->ui_number_name; |
447 |
|
|
} |
448 |
|
|
|
449 |
|
|
char * |
450 |
|
✗ |
cc_display_monitor_dup_ui_number_name (CcDisplayMonitor *self) |
451 |
|
|
{ |
452 |
|
✗ |
CcDisplayMonitorPrivate *priv = cc_display_monitor_get_instance_private (self); |
453 |
|
|
|
454 |
|
✗ |
return g_strdup (priv->ui_number_name); |
455 |
|
|
} |
456 |
|
|
|
457 |
|
|
static void |
458 |
|
✗ |
cc_display_monitor_set_ui_info (CcDisplayMonitor *self, gint ui_number, gchar *ui_name) |
459 |
|
|
{ |
460 |
|
|
|
461 |
|
✗ |
CcDisplayMonitorPrivate *priv = cc_display_monitor_get_instance_private (self); |
462 |
|
|
|
463 |
|
✗ |
priv->ui_number = ui_number; |
464 |
|
✗ |
g_free (priv->ui_name); |
465 |
|
✗ |
priv->ui_name = ui_name; |
466 |
|
✗ |
priv->ui_number_name = g_strdup_printf ("%d\u2003%s", ui_number, ui_name); |
467 |
|
✗ |
} |
468 |
|
|
|
469 |
|
|
struct _CcDisplayConfigPrivate { |
470 |
|
|
GList *ui_sorted_monitors; |
471 |
|
|
}; |
472 |
|
|
typedef struct _CcDisplayConfigPrivate CcDisplayConfigPrivate; |
473 |
|
|
|
474 |
|
✗ |
G_DEFINE_TYPE_WITH_PRIVATE (CcDisplayConfig, |
475 |
|
|
cc_display_config, |
476 |
|
|
G_TYPE_OBJECT) |
477 |
|
|
|
478 |
|
|
static void |
479 |
|
✗ |
cc_display_config_init (CcDisplayConfig *self) |
480 |
|
|
{ |
481 |
|
✗ |
CcDisplayConfigPrivate *priv = cc_display_config_get_instance_private (self); |
482 |
|
|
|
483 |
|
✗ |
priv->ui_sorted_monitors = NULL; |
484 |
|
✗ |
} |
485 |
|
|
|
486 |
|
|
static void |
487 |
|
✗ |
cc_display_config_constructed (GObject *object) |
488 |
|
|
{ |
489 |
|
✗ |
CcDisplayConfig *self = CC_DISPLAY_CONFIG (object); |
490 |
|
✗ |
CcDisplayConfigPrivate *priv = cc_display_config_get_instance_private (self); |
491 |
|
✗ |
GList *monitors = cc_display_config_get_monitors (self); |
492 |
|
|
GList *item; |
493 |
|
|
|
494 |
|
✗ |
for (item = monitors; item != NULL; item = item->next) |
495 |
|
|
{ |
496 |
|
✗ |
CcDisplayMonitor *monitor = item->data; |
497 |
|
|
|
498 |
|
✗ |
if (cc_display_monitor_is_builtin (monitor)) |
499 |
|
✗ |
priv->ui_sorted_monitors = g_list_prepend (priv->ui_sorted_monitors, monitor); |
500 |
|
|
else |
501 |
|
✗ |
priv->ui_sorted_monitors = g_list_append (priv->ui_sorted_monitors, monitor); |
502 |
|
|
} |
503 |
|
|
|
504 |
|
✗ |
cc_display_config_update_ui_numbers_names(self); |
505 |
|
✗ |
} |
506 |
|
|
|
507 |
|
|
static void |
508 |
|
✗ |
cc_display_config_finalize (GObject *object) |
509 |
|
|
{ |
510 |
|
✗ |
CcDisplayConfig *self = CC_DISPLAY_CONFIG (object); |
511 |
|
✗ |
CcDisplayConfigPrivate *priv = cc_display_config_get_instance_private (self); |
512 |
|
|
|
513 |
|
✗ |
g_list_free (priv->ui_sorted_monitors); |
514 |
|
|
|
515 |
|
✗ |
G_OBJECT_CLASS (cc_display_config_parent_class)->finalize (object); |
516 |
|
✗ |
} |
517 |
|
|
|
518 |
|
|
static void |
519 |
|
✗ |
cc_display_config_class_init (CcDisplayConfigClass *klass) |
520 |
|
|
{ |
521 |
|
✗ |
GObjectClass *gobject_class = G_OBJECT_CLASS (klass); |
522 |
|
|
|
523 |
|
✗ |
g_signal_new ("primary", |
524 |
|
|
CC_TYPE_DISPLAY_CONFIG, |
525 |
|
|
G_SIGNAL_RUN_LAST, |
526 |
|
|
0, NULL, NULL, NULL, |
527 |
|
|
G_TYPE_NONE, 0); |
528 |
|
✗ |
g_signal_new ("panel-orientation-managed", |
529 |
|
|
CC_TYPE_DISPLAY_CONFIG, |
530 |
|
|
G_SIGNAL_RUN_LAST, |
531 |
|
|
0, NULL, NULL, NULL, |
532 |
|
|
G_TYPE_NONE, 1, G_TYPE_BOOLEAN); |
533 |
|
|
|
534 |
|
✗ |
gobject_class->constructed = cc_display_config_constructed; |
535 |
|
✗ |
gobject_class->finalize = cc_display_config_finalize; |
536 |
|
✗ |
} |
537 |
|
|
|
538 |
|
|
GList * |
539 |
|
✗ |
cc_display_config_get_monitors (CcDisplayConfig *self) |
540 |
|
|
{ |
541 |
|
✗ |
g_return_val_if_fail (CC_IS_DISPLAY_CONFIG (self), NULL); |
542 |
|
✗ |
return CC_DISPLAY_CONFIG_GET_CLASS (self)->get_monitors (self); |
543 |
|
|
} |
544 |
|
|
|
545 |
|
|
GList * |
546 |
|
✗ |
cc_display_config_get_ui_sorted_monitors (CcDisplayConfig *self) |
547 |
|
|
{ |
548 |
|
✗ |
CcDisplayConfigPrivate *priv = cc_display_config_get_instance_private (self); |
549 |
|
|
|
550 |
|
✗ |
g_return_val_if_fail (CC_IS_DISPLAY_CONFIG (self), NULL); |
551 |
|
✗ |
return priv->ui_sorted_monitors; |
552 |
|
|
} |
553 |
|
|
|
554 |
|
|
int |
555 |
|
✗ |
cc_display_config_count_useful_monitors (CcDisplayConfig *self) |
556 |
|
|
{ |
557 |
|
✗ |
CcDisplayConfigPrivate *priv = cc_display_config_get_instance_private (self); |
558 |
|
|
GList *outputs, *l; |
559 |
|
✗ |
guint count = 0; |
560 |
|
|
|
561 |
|
✗ |
g_return_val_if_fail (CC_IS_DISPLAY_CONFIG (self), 0); |
562 |
|
|
|
563 |
|
✗ |
outputs = priv->ui_sorted_monitors; |
564 |
|
✗ |
for (l = outputs; l != NULL; l = l->next) |
565 |
|
|
{ |
566 |
|
✗ |
CcDisplayMonitor *output = l->data; |
567 |
|
✗ |
if (!cc_display_monitor_is_useful (output)) |
568 |
|
✗ |
continue; |
569 |
|
|
else |
570 |
|
✗ |
count++; |
571 |
|
|
} |
572 |
|
✗ |
return count; |
573 |
|
|
|
574 |
|
|
} |
575 |
|
|
|
576 |
|
|
gboolean |
577 |
|
✗ |
cc_display_config_is_applicable (CcDisplayConfig *self) |
578 |
|
|
{ |
579 |
|
✗ |
g_return_val_if_fail (CC_IS_DISPLAY_CONFIG (self), FALSE); |
580 |
|
✗ |
return CC_DISPLAY_CONFIG_GET_CLASS (self)->is_applicable (self); |
581 |
|
|
} |
582 |
|
|
|
583 |
|
|
void |
584 |
|
✗ |
cc_display_config_set_mode_on_all_outputs (CcDisplayConfig *config, |
585 |
|
|
CcDisplayMode *clone_mode) |
586 |
|
|
{ |
587 |
|
|
GList *outputs, *l; |
588 |
|
|
|
589 |
|
✗ |
g_return_if_fail (CC_IS_DISPLAY_CONFIG (config)); |
590 |
|
✗ |
g_return_if_fail (cc_display_mode_is_clone_mode (clone_mode)); |
591 |
|
|
|
592 |
|
✗ |
outputs = cc_display_config_get_monitors (config); |
593 |
|
✗ |
for (l = outputs; l; l = l->next) |
594 |
|
|
{ |
595 |
|
✗ |
CcDisplayMonitor *output = l->data; |
596 |
|
✗ |
cc_display_monitor_set_compatible_clone_mode (output, clone_mode); |
597 |
|
✗ |
cc_display_monitor_set_position (output, 0, 0); |
598 |
|
|
} |
599 |
|
|
} |
600 |
|
|
|
601 |
|
|
gboolean |
602 |
|
✗ |
cc_display_config_equal (CcDisplayConfig *self, |
603 |
|
|
CcDisplayConfig *other) |
604 |
|
|
{ |
605 |
|
✗ |
g_return_val_if_fail (CC_IS_DISPLAY_CONFIG (self), FALSE); |
606 |
|
✗ |
g_return_val_if_fail (CC_IS_DISPLAY_CONFIG (other), FALSE); |
607 |
|
|
|
608 |
|
✗ |
return CC_DISPLAY_CONFIG_GET_CLASS (self)->equal (self, other); |
609 |
|
|
} |
610 |
|
|
|
611 |
|
|
gboolean |
612 |
|
✗ |
cc_display_config_apply (CcDisplayConfig *self, |
613 |
|
|
GError **error) |
614 |
|
|
{ |
615 |
|
✗ |
if (!CC_IS_DISPLAY_CONFIG (self)) |
616 |
|
|
{ |
617 |
|
✗ |
g_warning ("Cannot apply invalid configuration"); |
618 |
|
✗ |
g_set_error (error, |
619 |
|
|
G_IO_ERROR, |
620 |
|
|
G_IO_ERROR_FAILED, |
621 |
|
|
"Cannot apply invalid configuration"); |
622 |
|
✗ |
return FALSE; |
623 |
|
|
} |
624 |
|
|
|
625 |
|
✗ |
return CC_DISPLAY_CONFIG_GET_CLASS (self)->apply (self, error); |
626 |
|
|
} |
627 |
|
|
|
628 |
|
|
gboolean |
629 |
|
✗ |
cc_display_config_is_cloning (CcDisplayConfig *self) |
630 |
|
|
{ |
631 |
|
✗ |
g_return_val_if_fail (CC_IS_DISPLAY_CONFIG (self), FALSE); |
632 |
|
✗ |
return CC_DISPLAY_CONFIG_GET_CLASS (self)->is_cloning (self); |
633 |
|
|
} |
634 |
|
|
|
635 |
|
|
void |
636 |
|
✗ |
cc_display_config_set_cloning (CcDisplayConfig *self, |
637 |
|
|
gboolean clone) |
638 |
|
|
{ |
639 |
|
✗ |
g_return_if_fail (CC_IS_DISPLAY_CONFIG (self)); |
640 |
|
✗ |
return CC_DISPLAY_CONFIG_GET_CLASS (self)->set_cloning (self, clone); |
641 |
|
|
} |
642 |
|
|
|
643 |
|
|
GList * |
644 |
|
✗ |
cc_display_config_generate_cloning_modes (CcDisplayConfig *self) |
645 |
|
|
{ |
646 |
|
✗ |
g_return_val_if_fail (CC_IS_DISPLAY_CONFIG (self), NULL); |
647 |
|
✗ |
return CC_DISPLAY_CONFIG_GET_CLASS (self)->generate_cloning_modes (self); |
648 |
|
|
} |
649 |
|
|
|
650 |
|
|
gboolean |
651 |
|
✗ |
cc_display_config_is_layout_logical (CcDisplayConfig *self) |
652 |
|
|
{ |
653 |
|
✗ |
g_return_val_if_fail (CC_IS_DISPLAY_CONFIG (self), FALSE); |
654 |
|
✗ |
return CC_DISPLAY_CONFIG_GET_CLASS (self)->is_layout_logical (self); |
655 |
|
|
} |
656 |
|
|
|
657 |
|
|
void |
658 |
|
✗ |
cc_display_config_set_minimum_size (CcDisplayConfig *self, |
659 |
|
|
int width, |
660 |
|
|
int height) |
661 |
|
|
{ |
662 |
|
✗ |
g_return_if_fail (CC_IS_DISPLAY_CONFIG (self)); |
663 |
|
✗ |
CC_DISPLAY_CONFIG_GET_CLASS (self)->set_minimum_size (self, width, height); |
664 |
|
|
} |
665 |
|
|
|
666 |
|
|
gboolean |
667 |
|
✗ |
cc_display_config_is_scaled_mode_valid (CcDisplayConfig *self, |
668 |
|
|
CcDisplayMode *mode, |
669 |
|
|
double scale) |
670 |
|
|
{ |
671 |
|
✗ |
g_return_val_if_fail (CC_IS_DISPLAY_CONFIG (self), FALSE); |
672 |
|
✗ |
g_return_val_if_fail (CC_IS_DISPLAY_MODE (mode), FALSE); |
673 |
|
✗ |
return CC_DISPLAY_CONFIG_GET_CLASS (self)->is_scaled_mode_valid (self, mode, scale); |
674 |
|
|
} |
675 |
|
|
|
676 |
|
|
gboolean |
677 |
|
✗ |
cc_display_config_get_panel_orientation_managed (CcDisplayConfig *self) |
678 |
|
|
{ |
679 |
|
✗ |
return CC_DISPLAY_CONFIG_GET_CLASS (self)->get_panel_orientation_managed (self); |
680 |
|
|
} |
681 |
|
|
|
682 |
|
|
void |
683 |
|
✗ |
cc_display_config_update_ui_numbers_names (CcDisplayConfig *self) |
684 |
|
|
{ |
685 |
|
✗ |
CcDisplayConfigPrivate *priv = cc_display_config_get_instance_private (self); |
686 |
|
|
GList *item; |
687 |
|
✗ |
gint ui_number = 1; |
688 |
|
✗ |
for (item = priv->ui_sorted_monitors; item != NULL; item = item->next) |
689 |
|
|
{ |
690 |
|
✗ |
CcDisplayMonitor *monitor = item->data; |
691 |
|
|
char *ui_name; |
692 |
|
✗ |
gint current_ui_number = 0; |
693 |
|
|
|
694 |
|
✗ |
ui_name = make_output_ui_name (monitor); |
695 |
|
|
|
696 |
|
|
/* Prevents gaps in monitor numbering. Monitors |
697 |
|
|
* with number 0 will not be visible in the UI. |
698 |
|
|
*/ |
699 |
|
✗ |
if (cc_display_monitor_is_usable (monitor)) |
700 |
|
|
{ |
701 |
|
✗ |
current_ui_number = ui_number; |
702 |
|
✗ |
ui_number += 1; |
703 |
|
|
} |
704 |
|
|
|
705 |
|
✗ |
cc_display_monitor_set_ui_info (monitor, current_ui_number, ui_name); |
706 |
|
|
} |
707 |
|
✗ |
} |
708 |
|
|
|