Merge lp:~fourdollars/ubuntu/trusty/gnome-desktop3/fix-lowest-brightness into lp:ubuntu/trusty-proposed/gnome-desktop3
- Trusty (14.04)
- fix-lowest-brightness
- Merge into trusty-proposed
Proposed by
Shih-Yuan Lee
Status: | Merged |
---|---|
Merge reported by: | Martin Pitt |
Merged at revision: | not available |
Proposed branch: | lp:~fourdollars/ubuntu/trusty/gnome-desktop3/fix-lowest-brightness |
Merge into: | lp:ubuntu/trusty-proposed/gnome-desktop3 |
Diff against target: |
2705 lines (+2659/-0) 6 files modified
.pc/applied-patches (+1/-0) .pc/fix_lowest_brightness.patch/libgnome-desktop/gnome-rr.c (+2624/-0) debian/changelog (+7/-0) debian/patches/fix_lowest_brightness.patch (+21/-0) debian/patches/series (+1/-0) libgnome-desktop/gnome-rr.c (+5/-0) |
To merge this branch: | bzr merge lp:~fourdollars/ubuntu/trusty/gnome-desktop3/fix-lowest-brightness |
Related bugs: |
Reviewer | Review Type | Date Requested | Status |
---|---|---|---|
Martin Pitt | Approve | ||
Review via email: mp+278110@code.launchpad.net |
Commit message
Apply the similar method from the power plugin in unity-settings-
Description of the change
Please help to review this change.
This change has been applied in xenial.
I am backporting it into trusty.
To post a comment you must log in.
Preview Diff
[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1 | === modified file '.pc/applied-patches' | |||
2 | --- .pc/applied-patches 2015-03-31 10:59:01 +0000 | |||
3 | +++ .pc/applied-patches 2015-11-20 08:10:07 +0000 | |||
4 | @@ -8,3 +8,4 @@ | |||
5 | 8 | ignore_errors_with_primary_outputs.patch | 8 | ignore_errors_with_primary_outputs.patch |
6 | 9 | backlight-property-name.patch | 9 | backlight-property-name.patch |
7 | 10 | idletime_sanity_checks.patch | 10 | idletime_sanity_checks.patch |
8 | 11 | fix_lowest_brightness.patch | ||
9 | 11 | 12 | ||
10 | === added directory '.pc/fix_lowest_brightness.patch' | |||
11 | === added directory '.pc/fix_lowest_brightness.patch/libgnome-desktop' | |||
12 | === added file '.pc/fix_lowest_brightness.patch/libgnome-desktop/gnome-rr.c' | |||
13 | --- .pc/fix_lowest_brightness.patch/libgnome-desktop/gnome-rr.c 1970-01-01 00:00:00 +0000 | |||
14 | +++ .pc/fix_lowest_brightness.patch/libgnome-desktop/gnome-rr.c 2015-11-20 08:10:07 +0000 | |||
15 | @@ -0,0 +1,2624 @@ | |||
16 | 1 | /* gnome-rr.c | ||
17 | 2 | * | ||
18 | 3 | * Copyright 2007, 2008, Red Hat, Inc. | ||
19 | 4 | * | ||
20 | 5 | * This file is part of the Gnome Library. | ||
21 | 6 | * | ||
22 | 7 | * The Gnome Library is free software; you can redistribute it and/or | ||
23 | 8 | * modify it under the terms of the GNU Library General Public License as | ||
24 | 9 | * published by the Free Software Foundation; either version 2 of the | ||
25 | 10 | * License, or (at your option) any later version. | ||
26 | 11 | * | ||
27 | 12 | * The Gnome Library is distributed in the hope that it will be useful, | ||
28 | 13 | * but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
29 | 14 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | ||
30 | 15 | * Library General Public License for more details. | ||
31 | 16 | * | ||
32 | 17 | * You should have received a copy of the GNU Library General Public | ||
33 | 18 | * License along with the Gnome Library; see the file COPYING.LIB. If not, | ||
34 | 19 | * write to the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, | ||
35 | 20 | * Boston, MA 02110-1301, USA. | ||
36 | 21 | * | ||
37 | 22 | * Author: Soren Sandmann <sandmann@redhat.com> | ||
38 | 23 | */ | ||
39 | 24 | |||
40 | 25 | #define GNOME_DESKTOP_USE_UNSTABLE_API | ||
41 | 26 | |||
42 | 27 | #include <config.h> | ||
43 | 28 | #include <glib/gi18n-lib.h> | ||
44 | 29 | #include <string.h> | ||
45 | 30 | #include <X11/Xlib.h> | ||
46 | 31 | |||
47 | 32 | #include <X11/extensions/Xrandr.h> | ||
48 | 33 | |||
49 | 34 | #include <gtk/gtk.h> | ||
50 | 35 | #include <gdk/gdkx.h> | ||
51 | 36 | #include <X11/Xatom.h> | ||
52 | 37 | #include <X11/extensions/dpms.h> | ||
53 | 38 | |||
54 | 39 | #undef GNOME_DISABLE_DEPRECATED | ||
55 | 40 | #include "gnome-rr.h" | ||
56 | 41 | #include "gnome-rr-config.h" | ||
57 | 42 | |||
58 | 43 | #include "edid.h" | ||
59 | 44 | #include "gnome-rr-private.h" | ||
60 | 45 | |||
61 | 46 | #define DISPLAY(o) ((o)->info->screen->priv->xdisplay) | ||
62 | 47 | |||
63 | 48 | #define SERVERS_RANDR_IS_AT_LEAST_1_3(priv) (priv->rr_major_version > 1 || (priv->rr_major_version == 1 && priv->rr_minor_version >= 3)) | ||
64 | 49 | |||
65 | 50 | enum { | ||
66 | 51 | SCREEN_PROP_0, | ||
67 | 52 | SCREEN_PROP_GDK_SCREEN, | ||
68 | 53 | SCREEN_PROP_LAST, | ||
69 | 54 | }; | ||
70 | 55 | |||
71 | 56 | enum { | ||
72 | 57 | SCREEN_CHANGED, | ||
73 | 58 | SCREEN_OUTPUT_CONNECTED, | ||
74 | 59 | SCREEN_OUTPUT_DISCONNECTED, | ||
75 | 60 | SCREEN_SIGNAL_LAST, | ||
76 | 61 | }; | ||
77 | 62 | |||
78 | 63 | gint screen_signals[SCREEN_SIGNAL_LAST]; | ||
79 | 64 | |||
80 | 65 | struct GnomeRROutput | ||
81 | 66 | { | ||
82 | 67 | ScreenInfo * info; | ||
83 | 68 | RROutput id; | ||
84 | 69 | |||
85 | 70 | char * name; | ||
86 | 71 | char * display_name; | ||
87 | 72 | GnomeRRCrtc * current_crtc; | ||
88 | 73 | gboolean connected; | ||
89 | 74 | gulong width_mm; | ||
90 | 75 | gulong height_mm; | ||
91 | 76 | GnomeRRCrtc ** possible_crtcs; | ||
92 | 77 | GnomeRROutput ** clones; | ||
93 | 78 | GnomeRRMode ** modes; | ||
94 | 79 | int n_preferred; | ||
95 | 80 | guint8 * edid_data; | ||
96 | 81 | gsize edid_size; | ||
97 | 82 | char * connector_type; | ||
98 | 83 | gint backlight_min; | ||
99 | 84 | gint backlight_max; | ||
100 | 85 | }; | ||
101 | 86 | |||
102 | 87 | struct GnomeRROutputWrap | ||
103 | 88 | { | ||
104 | 89 | RROutput id; | ||
105 | 90 | }; | ||
106 | 91 | |||
107 | 92 | struct GnomeRRCrtc | ||
108 | 93 | { | ||
109 | 94 | ScreenInfo * info; | ||
110 | 95 | RRCrtc id; | ||
111 | 96 | |||
112 | 97 | GnomeRRMode * current_mode; | ||
113 | 98 | GnomeRROutput ** current_outputs; | ||
114 | 99 | GnomeRROutput ** possible_outputs; | ||
115 | 100 | int x; | ||
116 | 101 | int y; | ||
117 | 102 | |||
118 | 103 | GnomeRRRotation current_rotation; | ||
119 | 104 | GnomeRRRotation rotations; | ||
120 | 105 | int gamma_size; | ||
121 | 106 | }; | ||
122 | 107 | |||
123 | 108 | struct GnomeRRMode | ||
124 | 109 | { | ||
125 | 110 | ScreenInfo * info; | ||
126 | 111 | RRMode id; | ||
127 | 112 | char * name; | ||
128 | 113 | int width; | ||
129 | 114 | int height; | ||
130 | 115 | int freq; /* in mHz */ | ||
131 | 116 | }; | ||
132 | 117 | |||
133 | 118 | /* GnomeRRCrtc */ | ||
134 | 119 | static GnomeRRCrtc * crtc_new (ScreenInfo *info, | ||
135 | 120 | RRCrtc id); | ||
136 | 121 | static GnomeRRCrtc * crtc_copy (const GnomeRRCrtc *from); | ||
137 | 122 | static void crtc_free (GnomeRRCrtc *crtc); | ||
138 | 123 | |||
139 | 124 | static gboolean crtc_initialize (GnomeRRCrtc *crtc, | ||
140 | 125 | XRRScreenResources *res, | ||
141 | 126 | GError **error); | ||
142 | 127 | |||
143 | 128 | /* GnomeRROutput */ | ||
144 | 129 | static GnomeRROutput *output_new (ScreenInfo *info, | ||
145 | 130 | RROutput id); | ||
146 | 131 | |||
147 | 132 | static gboolean output_initialize (GnomeRROutput *output, | ||
148 | 133 | XRRScreenResources *res, | ||
149 | 134 | GError **error); | ||
150 | 135 | |||
151 | 136 | static GnomeRROutput *output_copy (const GnomeRROutput *from); | ||
152 | 137 | static void output_free (GnomeRROutput *output); | ||
153 | 138 | |||
154 | 139 | /* GnomeRRMode */ | ||
155 | 140 | static GnomeRRMode * mode_new (ScreenInfo *info, | ||
156 | 141 | RRMode id); | ||
157 | 142 | |||
158 | 143 | static void mode_initialize (GnomeRRMode *mode, | ||
159 | 144 | XRRModeInfo *info); | ||
160 | 145 | |||
161 | 146 | static GnomeRRMode * mode_copy (const GnomeRRMode *from); | ||
162 | 147 | static void mode_free (GnomeRRMode *mode); | ||
163 | 148 | |||
164 | 149 | static void gnome_rr_screen_finalize (GObject*); | ||
165 | 150 | static void gnome_rr_screen_set_property (GObject*, guint, const GValue*, GParamSpec*); | ||
166 | 151 | static void gnome_rr_screen_get_property (GObject*, guint, GValue*, GParamSpec*); | ||
167 | 152 | static gboolean gnome_rr_screen_initable_init (GInitable*, GCancellable*, GError**); | ||
168 | 153 | static void gnome_rr_screen_initable_iface_init (GInitableIface *iface); | ||
169 | 154 | G_DEFINE_TYPE_WITH_CODE (GnomeRRScreen, gnome_rr_screen, G_TYPE_OBJECT, | ||
170 | 155 | G_IMPLEMENT_INTERFACE (G_TYPE_INITABLE, gnome_rr_screen_initable_iface_init)) | ||
171 | 156 | |||
172 | 157 | G_DEFINE_BOXED_TYPE (GnomeRRCrtc, gnome_rr_crtc, crtc_copy, crtc_free) | ||
173 | 158 | G_DEFINE_BOXED_TYPE (GnomeRROutput, gnome_rr_output, output_copy, output_free) | ||
174 | 159 | G_DEFINE_BOXED_TYPE (GnomeRRMode, gnome_rr_mode, mode_copy, mode_free) | ||
175 | 160 | |||
176 | 161 | /* Errors */ | ||
177 | 162 | |||
178 | 163 | /** | ||
179 | 164 | * gnome_rr_error_quark: | ||
180 | 165 | * | ||
181 | 166 | * Returns the #GQuark that will be used for #GError values returned by the | ||
182 | 167 | * GnomeRR API. | ||
183 | 168 | * | ||
184 | 169 | * Return value: a #GQuark used to identify errors coming from the GnomeRR API. | ||
185 | 170 | */ | ||
186 | 171 | GQuark | ||
187 | 172 | gnome_rr_error_quark (void) | ||
188 | 173 | { | ||
189 | 174 | return g_quark_from_static_string ("gnome-rr-error-quark"); | ||
190 | 175 | } | ||
191 | 176 | |||
192 | 177 | /* Screen */ | ||
193 | 178 | static GnomeRROutput * | ||
194 | 179 | gnome_rr_output_by_id (ScreenInfo *info, RROutput id) | ||
195 | 180 | { | ||
196 | 181 | GnomeRROutput **output; | ||
197 | 182 | |||
198 | 183 | g_assert (info != NULL); | ||
199 | 184 | |||
200 | 185 | for (output = info->outputs; *output; ++output) | ||
201 | 186 | { | ||
202 | 187 | if ((*output)->id == id) | ||
203 | 188 | return *output; | ||
204 | 189 | } | ||
205 | 190 | |||
206 | 191 | return NULL; | ||
207 | 192 | } | ||
208 | 193 | |||
209 | 194 | static GnomeRRCrtc * | ||
210 | 195 | crtc_by_id (ScreenInfo *info, RRCrtc id) | ||
211 | 196 | { | ||
212 | 197 | GnomeRRCrtc **crtc; | ||
213 | 198 | |||
214 | 199 | if (!info) | ||
215 | 200 | return NULL; | ||
216 | 201 | |||
217 | 202 | for (crtc = info->crtcs; *crtc; ++crtc) | ||
218 | 203 | { | ||
219 | 204 | if ((*crtc)->id == id) | ||
220 | 205 | return *crtc; | ||
221 | 206 | } | ||
222 | 207 | |||
223 | 208 | return NULL; | ||
224 | 209 | } | ||
225 | 210 | |||
226 | 211 | static GnomeRRMode * | ||
227 | 212 | mode_by_id (ScreenInfo *info, RRMode id) | ||
228 | 213 | { | ||
229 | 214 | GnomeRRMode **mode; | ||
230 | 215 | |||
231 | 216 | g_assert (info != NULL); | ||
232 | 217 | |||
233 | 218 | for (mode = info->modes; *mode; ++mode) | ||
234 | 219 | { | ||
235 | 220 | if ((*mode)->id == id) | ||
236 | 221 | return *mode; | ||
237 | 222 | } | ||
238 | 223 | |||
239 | 224 | return NULL; | ||
240 | 225 | } | ||
241 | 226 | |||
242 | 227 | static void | ||
243 | 228 | screen_info_free (ScreenInfo *info) | ||
244 | 229 | { | ||
245 | 230 | GnomeRROutput **output; | ||
246 | 231 | GnomeRRCrtc **crtc; | ||
247 | 232 | GnomeRRMode **mode; | ||
248 | 233 | |||
249 | 234 | g_assert (info != NULL); | ||
250 | 235 | |||
251 | 236 | if (info->resources) | ||
252 | 237 | { | ||
253 | 238 | XRRFreeScreenResources (info->resources); | ||
254 | 239 | |||
255 | 240 | info->resources = NULL; | ||
256 | 241 | } | ||
257 | 242 | |||
258 | 243 | if (info->outputs) | ||
259 | 244 | { | ||
260 | 245 | for (output = info->outputs; *output; ++output) | ||
261 | 246 | output_free (*output); | ||
262 | 247 | g_free (info->outputs); | ||
263 | 248 | } | ||
264 | 249 | |||
265 | 250 | if (info->crtcs) | ||
266 | 251 | { | ||
267 | 252 | for (crtc = info->crtcs; *crtc; ++crtc) | ||
268 | 253 | crtc_free (*crtc); | ||
269 | 254 | g_free (info->crtcs); | ||
270 | 255 | } | ||
271 | 256 | |||
272 | 257 | if (info->modes) | ||
273 | 258 | { | ||
274 | 259 | for (mode = info->modes; *mode; ++mode) | ||
275 | 260 | mode_free (*mode); | ||
276 | 261 | g_free (info->modes); | ||
277 | 262 | } | ||
278 | 263 | |||
279 | 264 | if (info->clone_modes) | ||
280 | 265 | { | ||
281 | 266 | /* The modes themselves were freed above */ | ||
282 | 267 | g_free (info->clone_modes); | ||
283 | 268 | } | ||
284 | 269 | |||
285 | 270 | g_free (info); | ||
286 | 271 | } | ||
287 | 272 | |||
288 | 273 | static gboolean | ||
289 | 274 | has_similar_mode (GnomeRROutput *output, GnomeRRMode *mode) | ||
290 | 275 | { | ||
291 | 276 | int i; | ||
292 | 277 | GnomeRRMode **modes = gnome_rr_output_list_modes (output); | ||
293 | 278 | int width = gnome_rr_mode_get_width (mode); | ||
294 | 279 | int height = gnome_rr_mode_get_height (mode); | ||
295 | 280 | |||
296 | 281 | for (i = 0; modes[i] != NULL; ++i) | ||
297 | 282 | { | ||
298 | 283 | GnomeRRMode *m = modes[i]; | ||
299 | 284 | |||
300 | 285 | if (gnome_rr_mode_get_width (m) == width && | ||
301 | 286 | gnome_rr_mode_get_height (m) == height) | ||
302 | 287 | { | ||
303 | 288 | return TRUE; | ||
304 | 289 | } | ||
305 | 290 | } | ||
306 | 291 | |||
307 | 292 | return FALSE; | ||
308 | 293 | } | ||
309 | 294 | |||
310 | 295 | static void | ||
311 | 296 | gather_clone_modes (ScreenInfo *info) | ||
312 | 297 | { | ||
313 | 298 | int i; | ||
314 | 299 | GPtrArray *result = g_ptr_array_new (); | ||
315 | 300 | |||
316 | 301 | for (i = 0; info->outputs[i] != NULL; ++i) | ||
317 | 302 | { | ||
318 | 303 | int j; | ||
319 | 304 | GnomeRROutput *output1, *output2; | ||
320 | 305 | |||
321 | 306 | output1 = info->outputs[i]; | ||
322 | 307 | |||
323 | 308 | if (!output1->connected) | ||
324 | 309 | continue; | ||
325 | 310 | |||
326 | 311 | for (j = 0; output1->modes[j] != NULL; ++j) | ||
327 | 312 | { | ||
328 | 313 | GnomeRRMode *mode = output1->modes[j]; | ||
329 | 314 | gboolean valid; | ||
330 | 315 | int k; | ||
331 | 316 | |||
332 | 317 | valid = TRUE; | ||
333 | 318 | for (k = 0; info->outputs[k] != NULL; ++k) | ||
334 | 319 | { | ||
335 | 320 | output2 = info->outputs[k]; | ||
336 | 321 | |||
337 | 322 | if (!output2->connected) | ||
338 | 323 | continue; | ||
339 | 324 | |||
340 | 325 | if (!has_similar_mode (output2, mode)) | ||
341 | 326 | { | ||
342 | 327 | valid = FALSE; | ||
343 | 328 | break; | ||
344 | 329 | } | ||
345 | 330 | } | ||
346 | 331 | |||
347 | 332 | if (valid) | ||
348 | 333 | g_ptr_array_add (result, mode); | ||
349 | 334 | } | ||
350 | 335 | } | ||
351 | 336 | |||
352 | 337 | g_ptr_array_add (result, NULL); | ||
353 | 338 | |||
354 | 339 | info->clone_modes = (GnomeRRMode **)g_ptr_array_free (result, FALSE); | ||
355 | 340 | } | ||
356 | 341 | |||
357 | 342 | static gboolean | ||
358 | 343 | fill_screen_info_from_resources (ScreenInfo *info, | ||
359 | 344 | XRRScreenResources *resources, | ||
360 | 345 | GError **error) | ||
361 | 346 | { | ||
362 | 347 | int i; | ||
363 | 348 | GPtrArray *a; | ||
364 | 349 | GnomeRRCrtc **crtc; | ||
365 | 350 | GnomeRROutput **output; | ||
366 | 351 | |||
367 | 352 | info->resources = resources; | ||
368 | 353 | |||
369 | 354 | /* We create all the structures before initializing them, so | ||
370 | 355 | * that they can refer to each other. | ||
371 | 356 | */ | ||
372 | 357 | a = g_ptr_array_new (); | ||
373 | 358 | for (i = 0; i < resources->ncrtc; ++i) | ||
374 | 359 | { | ||
375 | 360 | GnomeRRCrtc *crtc = crtc_new (info, resources->crtcs[i]); | ||
376 | 361 | |||
377 | 362 | g_ptr_array_add (a, crtc); | ||
378 | 363 | } | ||
379 | 364 | g_ptr_array_add (a, NULL); | ||
380 | 365 | info->crtcs = (GnomeRRCrtc **)g_ptr_array_free (a, FALSE); | ||
381 | 366 | |||
382 | 367 | a = g_ptr_array_new (); | ||
383 | 368 | for (i = 0; i < resources->noutput; ++i) | ||
384 | 369 | { | ||
385 | 370 | GnomeRROutput *output = output_new (info, resources->outputs[i]); | ||
386 | 371 | |||
387 | 372 | g_ptr_array_add (a, output); | ||
388 | 373 | } | ||
389 | 374 | g_ptr_array_add (a, NULL); | ||
390 | 375 | info->outputs = (GnomeRROutput **)g_ptr_array_free (a, FALSE); | ||
391 | 376 | |||
392 | 377 | a = g_ptr_array_new (); | ||
393 | 378 | for (i = 0; i < resources->nmode; ++i) | ||
394 | 379 | { | ||
395 | 380 | GnomeRRMode *mode = mode_new (info, resources->modes[i].id); | ||
396 | 381 | |||
397 | 382 | g_ptr_array_add (a, mode); | ||
398 | 383 | } | ||
399 | 384 | g_ptr_array_add (a, NULL); | ||
400 | 385 | info->modes = (GnomeRRMode **)g_ptr_array_free (a, FALSE); | ||
401 | 386 | |||
402 | 387 | /* Initialize */ | ||
403 | 388 | for (crtc = info->crtcs; *crtc; ++crtc) | ||
404 | 389 | { | ||
405 | 390 | if (!crtc_initialize (*crtc, resources, error)) | ||
406 | 391 | return FALSE; | ||
407 | 392 | } | ||
408 | 393 | |||
409 | 394 | for (output = info->outputs; *output; ++output) | ||
410 | 395 | { | ||
411 | 396 | if (!output_initialize (*output, resources, error)) | ||
412 | 397 | return FALSE; | ||
413 | 398 | } | ||
414 | 399 | |||
415 | 400 | for (i = 0; i < resources->nmode; ++i) | ||
416 | 401 | { | ||
417 | 402 | GnomeRRMode *mode = mode_by_id (info, resources->modes[i].id); | ||
418 | 403 | |||
419 | 404 | mode_initialize (mode, &(resources->modes[i])); | ||
420 | 405 | } | ||
421 | 406 | |||
422 | 407 | gather_clone_modes (info); | ||
423 | 408 | |||
424 | 409 | return TRUE; | ||
425 | 410 | } | ||
426 | 411 | |||
427 | 412 | static gboolean | ||
428 | 413 | fill_out_screen_info (Display *xdisplay, | ||
429 | 414 | Window xroot, | ||
430 | 415 | ScreenInfo *info, | ||
431 | 416 | gboolean needs_reprobe, | ||
432 | 417 | GError **error) | ||
433 | 418 | { | ||
434 | 419 | XRRScreenResources *resources; | ||
435 | 420 | GnomeRRScreenPrivate *priv; | ||
436 | 421 | |||
437 | 422 | g_assert (xdisplay != NULL); | ||
438 | 423 | g_assert (info != NULL); | ||
439 | 424 | |||
440 | 425 | priv = info->screen->priv; | ||
441 | 426 | |||
442 | 427 | /* First update the screen resources */ | ||
443 | 428 | |||
444 | 429 | if (needs_reprobe) | ||
445 | 430 | resources = XRRGetScreenResources (xdisplay, xroot); | ||
446 | 431 | else | ||
447 | 432 | { | ||
448 | 433 | /* XRRGetScreenResourcesCurrent is less expensive than | ||
449 | 434 | * XRRGetScreenResources, however it is available only | ||
450 | 435 | * in RandR 1.3 or higher | ||
451 | 436 | */ | ||
452 | 437 | if (SERVERS_RANDR_IS_AT_LEAST_1_3 (priv)) | ||
453 | 438 | resources = XRRGetScreenResourcesCurrent (xdisplay, xroot); | ||
454 | 439 | else | ||
455 | 440 | resources = XRRGetScreenResources (xdisplay, xroot); | ||
456 | 441 | } | ||
457 | 442 | |||
458 | 443 | if (resources) | ||
459 | 444 | { | ||
460 | 445 | if (!fill_screen_info_from_resources (info, resources, error)) | ||
461 | 446 | return FALSE; | ||
462 | 447 | } | ||
463 | 448 | else | ||
464 | 449 | { | ||
465 | 450 | g_set_error (error, GNOME_RR_ERROR, GNOME_RR_ERROR_RANDR_ERROR, | ||
466 | 451 | /* Translators: a CRTC is a CRT Controller (this is X terminology). */ | ||
467 | 452 | _("could not get the screen resources (CRTCs, outputs, modes)")); | ||
468 | 453 | return FALSE; | ||
469 | 454 | } | ||
470 | 455 | |||
471 | 456 | /* Then update the screen size range. We do this after XRRGetScreenResources() so that | ||
472 | 457 | * the X server will already have an updated view of the outputs. | ||
473 | 458 | */ | ||
474 | 459 | |||
475 | 460 | if (needs_reprobe) { | ||
476 | 461 | gboolean success; | ||
477 | 462 | |||
478 | 463 | gdk_error_trap_push (); | ||
479 | 464 | success = XRRGetScreenSizeRange (xdisplay, xroot, | ||
480 | 465 | &(info->min_width), | ||
481 | 466 | &(info->min_height), | ||
482 | 467 | &(info->max_width), | ||
483 | 468 | &(info->max_height)); | ||
484 | 469 | gdk_flush (); | ||
485 | 470 | if (gdk_error_trap_pop ()) { | ||
486 | 471 | g_set_error (error, GNOME_RR_ERROR, GNOME_RR_ERROR_UNKNOWN, | ||
487 | 472 | _("unhandled X error while getting the range of screen sizes")); | ||
488 | 473 | return FALSE; | ||
489 | 474 | } | ||
490 | 475 | |||
491 | 476 | if (!success) { | ||
492 | 477 | g_set_error (error, GNOME_RR_ERROR, GNOME_RR_ERROR_RANDR_ERROR, | ||
493 | 478 | _("could not get the range of screen sizes")); | ||
494 | 479 | return FALSE; | ||
495 | 480 | } | ||
496 | 481 | } | ||
497 | 482 | else | ||
498 | 483 | { | ||
499 | 484 | gnome_rr_screen_get_ranges (info->screen, | ||
500 | 485 | &(info->min_width), | ||
501 | 486 | &(info->max_width), | ||
502 | 487 | &(info->min_height), | ||
503 | 488 | &(info->max_height)); | ||
504 | 489 | } | ||
505 | 490 | |||
506 | 491 | info->primary = None; | ||
507 | 492 | if (SERVERS_RANDR_IS_AT_LEAST_1_3 (priv)) { | ||
508 | 493 | gdk_error_trap_push (); | ||
509 | 494 | info->primary = XRRGetOutputPrimary (xdisplay, xroot); | ||
510 | 495 | gdk_error_trap_pop_ignored (); | ||
511 | 496 | } | ||
512 | 497 | |||
513 | 498 | /* can the screen do DPMS? */ | ||
514 | 499 | gdk_error_trap_push (); | ||
515 | 500 | priv->dpms_capable = DPMSCapable (priv->xdisplay); | ||
516 | 501 | gdk_error_trap_pop_ignored (); | ||
517 | 502 | |||
518 | 503 | return TRUE; | ||
519 | 504 | } | ||
520 | 505 | |||
521 | 506 | static ScreenInfo * | ||
522 | 507 | screen_info_new (GnomeRRScreen *screen, gboolean needs_reprobe, GError **error) | ||
523 | 508 | { | ||
524 | 509 | ScreenInfo *info = g_new0 (ScreenInfo, 1); | ||
525 | 510 | GnomeRRScreenPrivate *priv; | ||
526 | 511 | |||
527 | 512 | g_assert (screen != NULL); | ||
528 | 513 | |||
529 | 514 | priv = screen->priv; | ||
530 | 515 | |||
531 | 516 | info->outputs = NULL; | ||
532 | 517 | info->crtcs = NULL; | ||
533 | 518 | info->modes = NULL; | ||
534 | 519 | info->screen = screen; | ||
535 | 520 | |||
536 | 521 | if (fill_out_screen_info (priv->xdisplay, priv->xroot, info, needs_reprobe, error)) | ||
537 | 522 | { | ||
538 | 523 | return info; | ||
539 | 524 | } | ||
540 | 525 | else | ||
541 | 526 | { | ||
542 | 527 | screen_info_free (info); | ||
543 | 528 | return NULL; | ||
544 | 529 | } | ||
545 | 530 | } | ||
546 | 531 | |||
547 | 532 | static GnomeRROutput * | ||
548 | 533 | find_output_by_id (GnomeRROutput **haystack, guint32 id) | ||
549 | 534 | { | ||
550 | 535 | guint i; | ||
551 | 536 | |||
552 | 537 | for (i = 0; haystack[i] != NULL; i++) | ||
553 | 538 | { | ||
554 | 539 | if (gnome_rr_output_get_id (haystack[i]) == id) | ||
555 | 540 | return haystack[i]; | ||
556 | 541 | } | ||
557 | 542 | return NULL; | ||
558 | 543 | } | ||
559 | 544 | |||
560 | 545 | static void | ||
561 | 546 | diff_outputs_and_emit_signals (ScreenInfo *old, ScreenInfo *new) | ||
562 | 547 | { | ||
563 | 548 | guint i; | ||
564 | 549 | guint32 id_old, id_new; | ||
565 | 550 | GnomeRROutput *output_old; | ||
566 | 551 | GnomeRROutput *output_new; | ||
567 | 552 | |||
568 | 553 | /* have any outputs been removed or disconnected */ | ||
569 | 554 | for (i = 0; old->outputs[i] != NULL; i++) | ||
570 | 555 | { | ||
571 | 556 | id_old = gnome_rr_output_get_id (old->outputs[i]); | ||
572 | 557 | output_new = find_output_by_id (new->outputs, id_old); | ||
573 | 558 | if (output_new == NULL) | ||
574 | 559 | { | ||
575 | 560 | /* output removed (and disconnected) */ | ||
576 | 561 | if (gnome_rr_output_is_connected (old->outputs[i])) | ||
577 | 562 | { | ||
578 | 563 | g_signal_emit (G_OBJECT (new->screen), | ||
579 | 564 | screen_signals[SCREEN_OUTPUT_DISCONNECTED], 0, | ||
580 | 565 | old->outputs[i]); | ||
581 | 566 | } | ||
582 | 567 | continue; | ||
583 | 568 | } | ||
584 | 569 | if (gnome_rr_output_is_connected (old->outputs[i]) && | ||
585 | 570 | !gnome_rr_output_is_connected (output_new)) | ||
586 | 571 | { | ||
587 | 572 | /* output disconnected */ | ||
588 | 573 | g_signal_emit (G_OBJECT (new->screen), | ||
589 | 574 | screen_signals[SCREEN_OUTPUT_DISCONNECTED], 0, | ||
590 | 575 | old->outputs[i]); | ||
591 | 576 | } | ||
592 | 577 | } | ||
593 | 578 | |||
594 | 579 | /* have any outputs been created or connected */ | ||
595 | 580 | for (i = 0; new->outputs[i] != NULL; i++) | ||
596 | 581 | { | ||
597 | 582 | id_new = gnome_rr_output_get_id (new->outputs[i]); | ||
598 | 583 | output_old = find_output_by_id (old->outputs, id_new); | ||
599 | 584 | if (output_old == NULL) | ||
600 | 585 | { | ||
601 | 586 | /* output created */ | ||
602 | 587 | if (gnome_rr_output_is_connected (new->outputs[i])) | ||
603 | 588 | { | ||
604 | 589 | g_signal_emit (G_OBJECT (new->screen), | ||
605 | 590 | screen_signals[SCREEN_OUTPUT_CONNECTED], 0, | ||
606 | 591 | new->outputs[i]); | ||
607 | 592 | } | ||
608 | 593 | continue; | ||
609 | 594 | } | ||
610 | 595 | if (!gnome_rr_output_is_connected (output_old) && | ||
611 | 596 | gnome_rr_output_is_connected (new->outputs[i])) | ||
612 | 597 | { | ||
613 | 598 | /* output connected */ | ||
614 | 599 | g_signal_emit (G_OBJECT (new->screen), | ||
615 | 600 | screen_signals[SCREEN_OUTPUT_CONNECTED], 0, | ||
616 | 601 | new->outputs[i]); | ||
617 | 602 | } | ||
618 | 603 | } | ||
619 | 604 | } | ||
620 | 605 | |||
621 | 606 | static gboolean | ||
622 | 607 | screen_update (GnomeRRScreen *screen, gboolean force_callback, gboolean needs_reprobe, GError **error) | ||
623 | 608 | { | ||
624 | 609 | ScreenInfo *info; | ||
625 | 610 | gboolean changed = FALSE; | ||
626 | 611 | |||
627 | 612 | g_assert (screen != NULL); | ||
628 | 613 | |||
629 | 614 | info = screen_info_new (screen, needs_reprobe, error); | ||
630 | 615 | if (!info) | ||
631 | 616 | return FALSE; | ||
632 | 617 | |||
633 | 618 | if (info->resources->configTimestamp != screen->priv->info->resources->configTimestamp) | ||
634 | 619 | changed = TRUE; | ||
635 | 620 | |||
636 | 621 | /* work out if any outputs have changed connected state */ | ||
637 | 622 | diff_outputs_and_emit_signals (screen->priv->info, info); | ||
638 | 623 | |||
639 | 624 | screen_info_free (screen->priv->info); | ||
640 | 625 | |||
641 | 626 | screen->priv->info = info; | ||
642 | 627 | |||
643 | 628 | if (changed || force_callback) | ||
644 | 629 | g_signal_emit (G_OBJECT (screen), screen_signals[SCREEN_CHANGED], 0); | ||
645 | 630 | |||
646 | 631 | return changed; | ||
647 | 632 | } | ||
648 | 633 | |||
649 | 634 | static GdkFilterReturn | ||
650 | 635 | screen_on_event (GdkXEvent *xevent, | ||
651 | 636 | GdkEvent *event, | ||
652 | 637 | gpointer data) | ||
653 | 638 | { | ||
654 | 639 | GnomeRRScreen *screen = data; | ||
655 | 640 | GnomeRRScreenPrivate *priv = screen->priv; | ||
656 | 641 | XEvent *e = xevent; | ||
657 | 642 | int event_num; | ||
658 | 643 | |||
659 | 644 | if (!e) | ||
660 | 645 | return GDK_FILTER_CONTINUE; | ||
661 | 646 | |||
662 | 647 | event_num = e->type - priv->randr_event_base; | ||
663 | 648 | |||
664 | 649 | if (event_num == RRScreenChangeNotify) { | ||
665 | 650 | /* We don't reprobe the hardware; we just fetch the X server's latest | ||
666 | 651 | * state. The server already knows the new state of the outputs; that's | ||
667 | 652 | * why it sent us an event! | ||
668 | 653 | */ | ||
669 | 654 | screen_update (screen, TRUE, FALSE, NULL); /* NULL-GError */ | ||
670 | 655 | #if 0 | ||
671 | 656 | /* Enable this code to get a dialog showing the RANDR timestamps, for debugging purposes */ | ||
672 | 657 | { | ||
673 | 658 | GtkWidget *dialog; | ||
674 | 659 | XRRScreenChangeNotifyEvent *rr_event; | ||
675 | 660 | static int dialog_num; | ||
676 | 661 | |||
677 | 662 | rr_event = (XRRScreenChangeNotifyEvent *) e; | ||
678 | 663 | |||
679 | 664 | dialog = gtk_message_dialog_new (NULL, | ||
680 | 665 | 0, | ||
681 | 666 | GTK_MESSAGE_INFO, | ||
682 | 667 | GTK_BUTTONS_CLOSE, | ||
683 | 668 | "RRScreenChangeNotify timestamps (%d):\n" | ||
684 | 669 | "event change: %u\n" | ||
685 | 670 | "event config: %u\n" | ||
686 | 671 | "event serial: %lu\n" | ||
687 | 672 | "----------------------" | ||
688 | 673 | "screen change: %u\n" | ||
689 | 674 | "screen config: %u\n", | ||
690 | 675 | dialog_num++, | ||
691 | 676 | (guint32) rr_event->timestamp, | ||
692 | 677 | (guint32) rr_event->config_timestamp, | ||
693 | 678 | rr_event->serial, | ||
694 | 679 | (guint32) priv->info->resources->timestamp, | ||
695 | 680 | (guint32) priv->info->resources->configTimestamp); | ||
696 | 681 | g_signal_connect (dialog, "response", | ||
697 | 682 | G_CALLBACK (gtk_widget_destroy), NULL); | ||
698 | 683 | gtk_widget_show (dialog); | ||
699 | 684 | } | ||
700 | 685 | #endif | ||
701 | 686 | } | ||
702 | 687 | #if 0 | ||
703 | 688 | /* WHY THIS CODE IS DISABLED: | ||
704 | 689 | * | ||
705 | 690 | * Note that in gnome_rr_screen_new(), we only select for | ||
706 | 691 | * RRScreenChangeNotifyMask. We used to select for other values in | ||
707 | 692 | * RR*NotifyMask, but we weren't really doing anything useful with those | ||
708 | 693 | * events. We only care about "the screens changed in some way or another" | ||
709 | 694 | * for now. | ||
710 | 695 | * | ||
711 | 696 | * If we ever run into a situtation that could benefit from processing more | ||
712 | 697 | * detailed events, we can enable this code again. | ||
713 | 698 | * | ||
714 | 699 | * Note that the X server sends RRScreenChangeNotify in conjunction with the | ||
715 | 700 | * more detailed events from RANDR 1.2 - see xserver/randr/randr.c:TellChanged(). | ||
716 | 701 | */ | ||
717 | 702 | else if (event_num == RRNotify) | ||
718 | 703 | { | ||
719 | 704 | /* Other RandR events */ | ||
720 | 705 | |||
721 | 706 | XRRNotifyEvent *event = (XRRNotifyEvent *)e; | ||
722 | 707 | |||
723 | 708 | /* Here we can distinguish between RRNotify events supported | ||
724 | 709 | * since RandR 1.2 such as RRNotify_OutputProperty. For now, we | ||
725 | 710 | * don't have anything special to do for particular subevent types, so | ||
726 | 711 | * we leave this as an empty switch(). | ||
727 | 712 | */ | ||
728 | 713 | switch (event->subtype) | ||
729 | 714 | { | ||
730 | 715 | default: | ||
731 | 716 | break; | ||
732 | 717 | } | ||
733 | 718 | |||
734 | 719 | /* No need to reprobe hardware here */ | ||
735 | 720 | screen_update (screen, TRUE, FALSE, NULL); /* NULL-GError */ | ||
736 | 721 | } | ||
737 | 722 | #endif | ||
738 | 723 | |||
739 | 724 | /* Pass the event on to GTK+ */ | ||
740 | 725 | return GDK_FILTER_CONTINUE; | ||
741 | 726 | } | ||
742 | 727 | |||
743 | 728 | static gboolean | ||
744 | 729 | gnome_rr_screen_initable_init (GInitable *initable, GCancellable *canc, GError **error) | ||
745 | 730 | { | ||
746 | 731 | GnomeRRScreen *self = GNOME_RR_SCREEN (initable); | ||
747 | 732 | GnomeRRScreenPrivate *priv = self->priv; | ||
748 | 733 | Display *dpy = GDK_SCREEN_XDISPLAY (self->priv->gdk_screen); | ||
749 | 734 | int event_base; | ||
750 | 735 | int ignore; | ||
751 | 736 | |||
752 | 737 | priv->connector_type_atom = XInternAtom (dpy, "ConnectorType", FALSE); | ||
753 | 738 | |||
754 | 739 | if (XRRQueryExtension (dpy, &event_base, &ignore)) | ||
755 | 740 | { | ||
756 | 741 | priv->randr_event_base = event_base; | ||
757 | 742 | |||
758 | 743 | XRRQueryVersion (dpy, &priv->rr_major_version, &priv->rr_minor_version); | ||
759 | 744 | if (priv->rr_major_version < 1 || (priv->rr_major_version == 1 && priv->rr_minor_version < 2)) { | ||
760 | 745 | g_set_error (error, GNOME_RR_ERROR, GNOME_RR_ERROR_NO_RANDR_EXTENSION, | ||
761 | 746 | "RANDR extension is too old (must be at least 1.2)"); | ||
762 | 747 | return FALSE; | ||
763 | 748 | } | ||
764 | 749 | |||
765 | 750 | priv->info = screen_info_new (self, TRUE, error); | ||
766 | 751 | |||
767 | 752 | if (!priv->info) { | ||
768 | 753 | return FALSE; | ||
769 | 754 | } | ||
770 | 755 | |||
771 | 756 | XRRSelectInput (priv->xdisplay, | ||
772 | 757 | priv->xroot, | ||
773 | 758 | RRScreenChangeNotifyMask); | ||
774 | 759 | gdk_x11_register_standard_event_type (gdk_screen_get_display (priv->gdk_screen), | ||
775 | 760 | event_base, | ||
776 | 761 | RRNotify + 1); | ||
777 | 762 | gdk_window_add_filter (priv->gdk_root, screen_on_event, self); | ||
778 | 763 | |||
779 | 764 | return TRUE; | ||
780 | 765 | } | ||
781 | 766 | else | ||
782 | 767 | { | ||
783 | 768 | g_set_error (error, GNOME_RR_ERROR, GNOME_RR_ERROR_NO_RANDR_EXTENSION, | ||
784 | 769 | _("RANDR extension is not present")); | ||
785 | 770 | |||
786 | 771 | return FALSE; | ||
787 | 772 | } | ||
788 | 773 | } | ||
789 | 774 | |||
790 | 775 | void | ||
791 | 776 | gnome_rr_screen_initable_iface_init (GInitableIface *iface) | ||
792 | 777 | { | ||
793 | 778 | iface->init = gnome_rr_screen_initable_init; | ||
794 | 779 | } | ||
795 | 780 | |||
796 | 781 | void | ||
797 | 782 | gnome_rr_screen_finalize (GObject *gobject) | ||
798 | 783 | { | ||
799 | 784 | GnomeRRScreen *screen = GNOME_RR_SCREEN (gobject); | ||
800 | 785 | |||
801 | 786 | gdk_window_remove_filter (screen->priv->gdk_root, screen_on_event, screen); | ||
802 | 787 | |||
803 | 788 | if (screen->priv->info) | ||
804 | 789 | screen_info_free (screen->priv->info); | ||
805 | 790 | |||
806 | 791 | G_OBJECT_CLASS (gnome_rr_screen_parent_class)->finalize (gobject); | ||
807 | 792 | } | ||
808 | 793 | |||
809 | 794 | void | ||
810 | 795 | gnome_rr_screen_set_property (GObject *gobject, guint property_id, const GValue *value, GParamSpec *property) | ||
811 | 796 | { | ||
812 | 797 | GnomeRRScreen *self = GNOME_RR_SCREEN (gobject); | ||
813 | 798 | GnomeRRScreenPrivate *priv = self->priv; | ||
814 | 799 | |||
815 | 800 | switch (property_id) | ||
816 | 801 | { | ||
817 | 802 | case SCREEN_PROP_GDK_SCREEN: | ||
818 | 803 | priv->gdk_screen = g_value_get_object (value); | ||
819 | 804 | priv->gdk_root = gdk_screen_get_root_window (priv->gdk_screen); | ||
820 | 805 | priv->xroot = gdk_x11_window_get_xid (priv->gdk_root); | ||
821 | 806 | priv->xdisplay = GDK_SCREEN_XDISPLAY (priv->gdk_screen); | ||
822 | 807 | priv->xscreen = gdk_x11_screen_get_xscreen (priv->gdk_screen); | ||
823 | 808 | return; | ||
824 | 809 | default: | ||
825 | 810 | G_OBJECT_WARN_INVALID_PROPERTY_ID (gobject, property_id, property); | ||
826 | 811 | return; | ||
827 | 812 | } | ||
828 | 813 | } | ||
829 | 814 | |||
830 | 815 | void | ||
831 | 816 | gnome_rr_screen_get_property (GObject *gobject, guint property_id, GValue *value, GParamSpec *property) | ||
832 | 817 | { | ||
833 | 818 | GnomeRRScreen *self = GNOME_RR_SCREEN (gobject); | ||
834 | 819 | GnomeRRScreenPrivate *priv = self->priv; | ||
835 | 820 | |||
836 | 821 | switch (property_id) | ||
837 | 822 | { | ||
838 | 823 | case SCREEN_PROP_GDK_SCREEN: | ||
839 | 824 | g_value_set_object (value, priv->gdk_screen); | ||
840 | 825 | return; | ||
841 | 826 | default: | ||
842 | 827 | G_OBJECT_WARN_INVALID_PROPERTY_ID (gobject, property_id, property); | ||
843 | 828 | return; | ||
844 | 829 | } | ||
845 | 830 | } | ||
846 | 831 | |||
847 | 832 | void | ||
848 | 833 | gnome_rr_screen_class_init (GnomeRRScreenClass *klass) | ||
849 | 834 | { | ||
850 | 835 | GObjectClass *gobject_class = G_OBJECT_CLASS (klass); | ||
851 | 836 | g_type_class_add_private (klass, sizeof (GnomeRRScreenPrivate)); | ||
852 | 837 | |||
853 | 838 | bindtextdomain (GETTEXT_PACKAGE, GNOMELOCALEDIR); | ||
854 | 839 | bind_textdomain_codeset (GETTEXT_PACKAGE, "UTF-8"); | ||
855 | 840 | |||
856 | 841 | gobject_class->set_property = gnome_rr_screen_set_property; | ||
857 | 842 | gobject_class->get_property = gnome_rr_screen_get_property; | ||
858 | 843 | gobject_class->finalize = gnome_rr_screen_finalize; | ||
859 | 844 | |||
860 | 845 | g_object_class_install_property( | ||
861 | 846 | gobject_class, | ||
862 | 847 | SCREEN_PROP_GDK_SCREEN, | ||
863 | 848 | g_param_spec_object ( | ||
864 | 849 | "gdk-screen", | ||
865 | 850 | "GDK Screen", | ||
866 | 851 | "The GDK Screen represented by this GnomeRRScreen", | ||
867 | 852 | GDK_TYPE_SCREEN, | ||
868 | 853 | G_PARAM_READWRITE | | ||
869 | 854 | G_PARAM_CONSTRUCT_ONLY | | ||
870 | 855 | G_PARAM_STATIC_STRINGS) | ||
871 | 856 | ); | ||
872 | 857 | |||
873 | 858 | screen_signals[SCREEN_CHANGED] = g_signal_new("changed", | ||
874 | 859 | G_TYPE_FROM_CLASS (gobject_class), | ||
875 | 860 | G_SIGNAL_RUN_FIRST | G_SIGNAL_NO_RECURSE | G_SIGNAL_NO_HOOKS, | ||
876 | 861 | G_STRUCT_OFFSET (GnomeRRScreenClass, changed), | ||
877 | 862 | NULL, | ||
878 | 863 | NULL, | ||
879 | 864 | g_cclosure_marshal_VOID__VOID, | ||
880 | 865 | G_TYPE_NONE, | ||
881 | 866 | 0); | ||
882 | 867 | |||
883 | 868 | /** | ||
884 | 869 | * GnomeRRScreen::output-connected: | ||
885 | 870 | * @screen: the #GnomeRRScreen that emitted the signal | ||
886 | 871 | * @output: the #GnomeRROutput that was connected | ||
887 | 872 | * | ||
888 | 873 | * This signal is emitted when a display device is connected to a | ||
889 | 874 | * port, or a port is hotplugged with an active output. The latter | ||
890 | 875 | * can happen if a laptop is docked, and the dock provides a new | ||
891 | 876 | * active output. | ||
892 | 877 | * | ||
893 | 878 | * The @output value is not a #GObject. The returned @output value can | ||
894 | 879 | * only assume to be valid during the emission of the signal (i.e. within | ||
895 | 880 | * your signal handler only), as it may change later when the @screen | ||
896 | 881 | * is modified due to an event from the X server, or due to another | ||
897 | 882 | * place in the application modifying the @screen and the @output. | ||
898 | 883 | * Therefore, deal with changes to the @output right in your signal | ||
899 | 884 | * handler, instead of keeping the @output reference for an async or | ||
900 | 885 | * idle function. | ||
901 | 886 | **/ | ||
902 | 887 | screen_signals[SCREEN_OUTPUT_CONNECTED] = g_signal_new("output-connected", | ||
903 | 888 | G_TYPE_FROM_CLASS (gobject_class), | ||
904 | 889 | G_SIGNAL_RUN_FIRST | G_SIGNAL_NO_RECURSE | G_SIGNAL_NO_HOOKS, | ||
905 | 890 | G_STRUCT_OFFSET (GnomeRRScreenClass, output_connected), | ||
906 | 891 | NULL, | ||
907 | 892 | NULL, | ||
908 | 893 | g_cclosure_marshal_VOID__POINTER, | ||
909 | 894 | G_TYPE_NONE, | ||
910 | 895 | 1, G_TYPE_POINTER); | ||
911 | 896 | |||
912 | 897 | /** | ||
913 | 898 | * GnomeRRScreen::output-disconnected: | ||
914 | 899 | * @screen: the #GnomeRRScreen that emitted the signal | ||
915 | 900 | * @output: the #GnomeRROutput that was disconnected | ||
916 | 901 | * | ||
917 | 902 | * This signal is emitted when a display device is disconnected from | ||
918 | 903 | * a port, or a port output is hot-unplugged. The latter can happen | ||
919 | 904 | * if a laptop is undocked, and the dock provided the output. | ||
920 | 905 | * | ||
921 | 906 | * The @output value is not a #GObject. The returned @output value can | ||
922 | 907 | * only assume to be valid during the emission of the signal (i.e. within | ||
923 | 908 | * your signal handler only), as it may change later when the @screen | ||
924 | 909 | * is modified due to an event from the X server, or due to another | ||
925 | 910 | * place in the application modifying the @screen and the @output. | ||
926 | 911 | * Therefore, deal with changes to the @output right in your signal | ||
927 | 912 | * handler, instead of keeping the @output reference for an async or | ||
928 | 913 | * idle function. | ||
929 | 914 | **/ | ||
930 | 915 | screen_signals[SCREEN_OUTPUT_DISCONNECTED] = g_signal_new("output-disconnected", | ||
931 | 916 | G_TYPE_FROM_CLASS (gobject_class), | ||
932 | 917 | G_SIGNAL_RUN_FIRST | G_SIGNAL_NO_RECURSE | G_SIGNAL_NO_HOOKS, | ||
933 | 918 | G_STRUCT_OFFSET (GnomeRRScreenClass, output_disconnected), | ||
934 | 919 | NULL, | ||
935 | 920 | NULL, | ||
936 | 921 | g_cclosure_marshal_VOID__POINTER, | ||
937 | 922 | G_TYPE_NONE, | ||
938 | 923 | 1, G_TYPE_POINTER); | ||
939 | 924 | } | ||
940 | 925 | |||
941 | 926 | void | ||
942 | 927 | gnome_rr_screen_init (GnomeRRScreen *self) | ||
943 | 928 | { | ||
944 | 929 | GnomeRRScreenPrivate *priv = G_TYPE_INSTANCE_GET_PRIVATE (self, GNOME_TYPE_RR_SCREEN, GnomeRRScreenPrivate); | ||
945 | 930 | self->priv = priv; | ||
946 | 931 | |||
947 | 932 | priv->gdk_screen = NULL; | ||
948 | 933 | priv->gdk_root = NULL; | ||
949 | 934 | priv->xdisplay = NULL; | ||
950 | 935 | priv->xroot = None; | ||
951 | 936 | priv->xscreen = NULL; | ||
952 | 937 | priv->info = NULL; | ||
953 | 938 | priv->rr_major_version = 0; | ||
954 | 939 | priv->rr_minor_version = 0; | ||
955 | 940 | } | ||
956 | 941 | |||
957 | 942 | /* Weak reference callback set in gnome_rr_screen_new(); we remove the GObject data from the GdkScreen. */ | ||
958 | 943 | static void | ||
959 | 944 | rr_screen_weak_notify_cb (gpointer data, GObject *where_the_object_was) | ||
960 | 945 | { | ||
961 | 946 | GdkScreen *screen = GDK_SCREEN (data); | ||
962 | 947 | |||
963 | 948 | g_object_set_data (G_OBJECT (screen), "GnomeRRScreen", NULL); | ||
964 | 949 | } | ||
965 | 950 | |||
966 | 951 | /** | ||
967 | 952 | * gnome_rr_screen_new: | ||
968 | 953 | * @screen: the #GdkScreen on which to operate | ||
969 | 954 | * @error: will be set if XRandR is not supported | ||
970 | 955 | * | ||
971 | 956 | * Creates a unique #GnomeRRScreen instance for the specified @screen. | ||
972 | 957 | * | ||
973 | 958 | * Returns: a unique #GnomeRRScreen instance, specific to the @screen, or NULL | ||
974 | 959 | * if this could not be created, for instance if the driver does not support | ||
975 | 960 | * Xrandr 1.2. Each #GdkScreen thus has a single instance of #GnomeRRScreen. | ||
976 | 961 | */ | ||
977 | 962 | GnomeRRScreen * | ||
978 | 963 | gnome_rr_screen_new (GdkScreen *screen, | ||
979 | 964 | GError **error) | ||
980 | 965 | { | ||
981 | 966 | GnomeRRScreen *rr_screen; | ||
982 | 967 | |||
983 | 968 | g_return_val_if_fail (GDK_IS_SCREEN (screen), NULL); | ||
984 | 969 | g_return_val_if_fail (error == NULL || *error == NULL, NULL); | ||
985 | 970 | |||
986 | 971 | rr_screen = g_object_get_data (G_OBJECT (screen), "GnomeRRScreen"); | ||
987 | 972 | if (rr_screen) | ||
988 | 973 | g_object_ref (rr_screen); | ||
989 | 974 | else { | ||
990 | 975 | rr_screen = g_initable_new (GNOME_TYPE_RR_SCREEN, NULL, error, "gdk-screen", screen, NULL); | ||
991 | 976 | if (rr_screen) { | ||
992 | 977 | g_object_set_data (G_OBJECT (screen), "GnomeRRScreen", rr_screen); | ||
993 | 978 | g_object_weak_ref (G_OBJECT (rr_screen), rr_screen_weak_notify_cb, screen); | ||
994 | 979 | } | ||
995 | 980 | } | ||
996 | 981 | |||
997 | 982 | return rr_screen; | ||
998 | 983 | } | ||
999 | 984 | |||
1000 | 985 | void | ||
1001 | 986 | gnome_rr_screen_set_size (GnomeRRScreen *screen, | ||
1002 | 987 | int width, | ||
1003 | 988 | int height, | ||
1004 | 989 | int mm_width, | ||
1005 | 990 | int mm_height) | ||
1006 | 991 | { | ||
1007 | 992 | g_return_if_fail (GNOME_IS_RR_SCREEN (screen)); | ||
1008 | 993 | |||
1009 | 994 | gdk_error_trap_push (); | ||
1010 | 995 | XRRSetScreenSize (screen->priv->xdisplay, screen->priv->xroot, | ||
1011 | 996 | width, height, mm_width, mm_height); | ||
1012 | 997 | gdk_error_trap_pop_ignored (); | ||
1013 | 998 | } | ||
1014 | 999 | |||
1015 | 1000 | /** | ||
1016 | 1001 | * gnome_rr_screen_get_ranges: | ||
1017 | 1002 | * @screen: a #GnomeRRScreen | ||
1018 | 1003 | * @min_width: (out): the minimum width | ||
1019 | 1004 | * @max_width: (out): the maximum width | ||
1020 | 1005 | * @min_height: (out): the minimum height | ||
1021 | 1006 | * @max_height: (out): the maximum height | ||
1022 | 1007 | * | ||
1023 | 1008 | * Get the ranges of the screen | ||
1024 | 1009 | */ | ||
1025 | 1010 | void | ||
1026 | 1011 | gnome_rr_screen_get_ranges (GnomeRRScreen *screen, | ||
1027 | 1012 | int *min_width, | ||
1028 | 1013 | int *max_width, | ||
1029 | 1014 | int *min_height, | ||
1030 | 1015 | int *max_height) | ||
1031 | 1016 | { | ||
1032 | 1017 | GnomeRRScreenPrivate *priv; | ||
1033 | 1018 | |||
1034 | 1019 | g_return_if_fail (GNOME_IS_RR_SCREEN (screen)); | ||
1035 | 1020 | |||
1036 | 1021 | priv = screen->priv; | ||
1037 | 1022 | |||
1038 | 1023 | if (min_width) | ||
1039 | 1024 | *min_width = priv->info->min_width; | ||
1040 | 1025 | |||
1041 | 1026 | if (max_width) | ||
1042 | 1027 | *max_width = priv->info->max_width; | ||
1043 | 1028 | |||
1044 | 1029 | if (min_height) | ||
1045 | 1030 | *min_height = priv->info->min_height; | ||
1046 | 1031 | |||
1047 | 1032 | if (max_height) | ||
1048 | 1033 | *max_height = priv->info->max_height; | ||
1049 | 1034 | } | ||
1050 | 1035 | |||
1051 | 1036 | /** | ||
1052 | 1037 | * gnome_rr_screen_get_timestamps: | ||
1053 | 1038 | * @screen: a #GnomeRRScreen | ||
1054 | 1039 | * @change_timestamp_ret: (out): Location in which to store the timestamp at which the RANDR configuration was last changed | ||
1055 | 1040 | * @config_timestamp_ret: (out): Location in which to store the timestamp at which the RANDR configuration was last obtained | ||
1056 | 1041 | * | ||
1057 | 1042 | * Queries the two timestamps that the X RANDR extension maintains. The X | ||
1058 | 1043 | * server will prevent change requests for stale configurations, those whose | ||
1059 | 1044 | * timestamp is not equal to that of the latest request for configuration. The | ||
1060 | 1045 | * X server will also prevent change requests that have an older timestamp to | ||
1061 | 1046 | * the latest change request. | ||
1062 | 1047 | */ | ||
1063 | 1048 | void | ||
1064 | 1049 | gnome_rr_screen_get_timestamps (GnomeRRScreen *screen, | ||
1065 | 1050 | guint32 *change_timestamp_ret, | ||
1066 | 1051 | guint32 *config_timestamp_ret) | ||
1067 | 1052 | { | ||
1068 | 1053 | GnomeRRScreenPrivate *priv; | ||
1069 | 1054 | |||
1070 | 1055 | g_return_if_fail (GNOME_IS_RR_SCREEN (screen)); | ||
1071 | 1056 | |||
1072 | 1057 | priv = screen->priv; | ||
1073 | 1058 | |||
1074 | 1059 | if (change_timestamp_ret) | ||
1075 | 1060 | *change_timestamp_ret = priv->info->resources->timestamp; | ||
1076 | 1061 | |||
1077 | 1062 | if (config_timestamp_ret) | ||
1078 | 1063 | *config_timestamp_ret = priv->info->resources->configTimestamp; | ||
1079 | 1064 | } | ||
1080 | 1065 | |||
1081 | 1066 | static gboolean | ||
1082 | 1067 | force_timestamp_update (GnomeRRScreen *screen) | ||
1083 | 1068 | { | ||
1084 | 1069 | GnomeRRScreenPrivate *priv = screen->priv; | ||
1085 | 1070 | GnomeRRCrtc *crtc; | ||
1086 | 1071 | XRRCrtcInfo *current_info; | ||
1087 | 1072 | Status status; | ||
1088 | 1073 | gboolean timestamp_updated; | ||
1089 | 1074 | |||
1090 | 1075 | timestamp_updated = FALSE; | ||
1091 | 1076 | |||
1092 | 1077 | crtc = priv->info->crtcs[0]; | ||
1093 | 1078 | |||
1094 | 1079 | if (crtc == NULL) | ||
1095 | 1080 | goto out; | ||
1096 | 1081 | |||
1097 | 1082 | current_info = XRRGetCrtcInfo (priv->xdisplay, | ||
1098 | 1083 | priv->info->resources, | ||
1099 | 1084 | crtc->id); | ||
1100 | 1085 | |||
1101 | 1086 | if (current_info == NULL) | ||
1102 | 1087 | goto out; | ||
1103 | 1088 | |||
1104 | 1089 | gdk_error_trap_push (); | ||
1105 | 1090 | status = XRRSetCrtcConfig (priv->xdisplay, | ||
1106 | 1091 | priv->info->resources, | ||
1107 | 1092 | crtc->id, | ||
1108 | 1093 | current_info->timestamp, | ||
1109 | 1094 | current_info->x, | ||
1110 | 1095 | current_info->y, | ||
1111 | 1096 | current_info->mode, | ||
1112 | 1097 | current_info->rotation, | ||
1113 | 1098 | current_info->outputs, | ||
1114 | 1099 | current_info->noutput); | ||
1115 | 1100 | |||
1116 | 1101 | XRRFreeCrtcInfo (current_info); | ||
1117 | 1102 | |||
1118 | 1103 | gdk_flush (); | ||
1119 | 1104 | if (gdk_error_trap_pop ()) | ||
1120 | 1105 | goto out; | ||
1121 | 1106 | |||
1122 | 1107 | if (status == RRSetConfigSuccess) | ||
1123 | 1108 | timestamp_updated = TRUE; | ||
1124 | 1109 | out: | ||
1125 | 1110 | return timestamp_updated; | ||
1126 | 1111 | } | ||
1127 | 1112 | |||
1128 | 1113 | /** | ||
1129 | 1114 | * gnome_rr_screen_refresh: | ||
1130 | 1115 | * @screen: a #GnomeRRScreen | ||
1131 | 1116 | * @error: location to store error, or %NULL | ||
1132 | 1117 | * | ||
1133 | 1118 | * Refreshes the screen configuration, and calls the screen's callback if it | ||
1134 | 1119 | * exists and if the screen's configuration changed. | ||
1135 | 1120 | * | ||
1136 | 1121 | * Return value: TRUE if the screen's configuration changed; otherwise, the | ||
1137 | 1122 | * function returns FALSE and a NULL error if the configuration didn't change, | ||
1138 | 1123 | * or FALSE and a non-NULL error if there was an error while refreshing the | ||
1139 | 1124 | * configuration. | ||
1140 | 1125 | */ | ||
1141 | 1126 | gboolean | ||
1142 | 1127 | gnome_rr_screen_refresh (GnomeRRScreen *screen, | ||
1143 | 1128 | GError **error) | ||
1144 | 1129 | { | ||
1145 | 1130 | gboolean refreshed; | ||
1146 | 1131 | |||
1147 | 1132 | g_return_val_if_fail (error == NULL || *error == NULL, FALSE); | ||
1148 | 1133 | |||
1149 | 1134 | gdk_x11_display_grab (gdk_screen_get_display (screen->priv->gdk_screen)); | ||
1150 | 1135 | |||
1151 | 1136 | refreshed = screen_update (screen, FALSE, TRUE, error); | ||
1152 | 1137 | force_timestamp_update (screen); /* this is to keep other clients from thinking that the X server re-detected things by itself - bgo#621046 */ | ||
1153 | 1138 | |||
1154 | 1139 | gdk_x11_display_ungrab (gdk_screen_get_display (screen->priv->gdk_screen)); | ||
1155 | 1140 | |||
1156 | 1141 | return refreshed; | ||
1157 | 1142 | } | ||
1158 | 1143 | |||
1159 | 1144 | /** | ||
1160 | 1145 | * gnome_rr_screen_get_dpms_mode: | ||
1161 | 1146 | * @mode: (out): The current #GnomeRRDpmsMode of this screen | ||
1162 | 1147 | **/ | ||
1163 | 1148 | gboolean | ||
1164 | 1149 | gnome_rr_screen_get_dpms_mode (GnomeRRScreen *screen, | ||
1165 | 1150 | GnomeRRDpmsMode *mode, | ||
1166 | 1151 | GError **error) | ||
1167 | 1152 | { | ||
1168 | 1153 | BOOL enabled = FALSE; | ||
1169 | 1154 | CARD16 state; | ||
1170 | 1155 | gboolean ret = FALSE; | ||
1171 | 1156 | |||
1172 | 1157 | g_return_val_if_fail (error == NULL || *error == NULL, FALSE); | ||
1173 | 1158 | g_return_val_if_fail (mode != NULL, FALSE); | ||
1174 | 1159 | |||
1175 | 1160 | if (!screen->priv->dpms_capable) { | ||
1176 | 1161 | g_set_error_literal (error, | ||
1177 | 1162 | GNOME_RR_ERROR, | ||
1178 | 1163 | GNOME_RR_ERROR_NO_DPMS_EXTENSION, | ||
1179 | 1164 | "Display is not DPMS capable"); | ||
1180 | 1165 | goto out; | ||
1181 | 1166 | } | ||
1182 | 1167 | |||
1183 | 1168 | if (!DPMSInfo (screen->priv->xdisplay, | ||
1184 | 1169 | &state, | ||
1185 | 1170 | &enabled)) { | ||
1186 | 1171 | g_set_error_literal (error, | ||
1187 | 1172 | GNOME_RR_ERROR, | ||
1188 | 1173 | GNOME_RR_ERROR_UNKNOWN, | ||
1189 | 1174 | "Unable to get DPMS state"); | ||
1190 | 1175 | goto out; | ||
1191 | 1176 | } | ||
1192 | 1177 | |||
1193 | 1178 | /* DPMS not enabled is a valid mode */ | ||
1194 | 1179 | if (!enabled) { | ||
1195 | 1180 | *mode = GNOME_RR_DPMS_DISABLED; | ||
1196 | 1181 | ret = TRUE; | ||
1197 | 1182 | goto out; | ||
1198 | 1183 | } | ||
1199 | 1184 | |||
1200 | 1185 | switch (state) { | ||
1201 | 1186 | case DPMSModeOn: | ||
1202 | 1187 | *mode = GNOME_RR_DPMS_ON; | ||
1203 | 1188 | break; | ||
1204 | 1189 | case DPMSModeStandby: | ||
1205 | 1190 | *mode = GNOME_RR_DPMS_STANDBY; | ||
1206 | 1191 | break; | ||
1207 | 1192 | case DPMSModeSuspend: | ||
1208 | 1193 | *mode = GNOME_RR_DPMS_SUSPEND; | ||
1209 | 1194 | break; | ||
1210 | 1195 | case DPMSModeOff: | ||
1211 | 1196 | *mode = GNOME_RR_DPMS_OFF; | ||
1212 | 1197 | break; | ||
1213 | 1198 | default: | ||
1214 | 1199 | g_assert_not_reached (); | ||
1215 | 1200 | break; | ||
1216 | 1201 | } | ||
1217 | 1202 | ret = TRUE; | ||
1218 | 1203 | out: | ||
1219 | 1204 | return ret; | ||
1220 | 1205 | } | ||
1221 | 1206 | |||
1222 | 1207 | /** | ||
1223 | 1208 | * gnome_rr_screen_clear_dpms_timeouts: | ||
1224 | 1209 | **/ | ||
1225 | 1210 | static gboolean | ||
1226 | 1211 | gnome_rr_screen_clear_dpms_timeouts (GnomeRRScreen *screen, | ||
1227 | 1212 | GError **error) | ||
1228 | 1213 | { | ||
1229 | 1214 | gdk_error_trap_push (); | ||
1230 | 1215 | /* DPMSSetTimeouts() return value is often a lie, so ignore it */ | ||
1231 | 1216 | DPMSSetTimeouts (screen->priv->xdisplay, 0, 0, 0); | ||
1232 | 1217 | if (gdk_error_trap_pop ()) { | ||
1233 | 1218 | g_set_error_literal (error, | ||
1234 | 1219 | GNOME_RR_ERROR, | ||
1235 | 1220 | GNOME_RR_ERROR_UNKNOWN, | ||
1236 | 1221 | "Could not set DPMS timeouts"); | ||
1237 | 1222 | return FALSE; | ||
1238 | 1223 | } | ||
1239 | 1224 | return TRUE; | ||
1240 | 1225 | } | ||
1241 | 1226 | |||
1242 | 1227 | /** | ||
1243 | 1228 | * gnome_rr_screen_set_dpms_mode: | ||
1244 | 1229 | * | ||
1245 | 1230 | * This method also disables the DPMS timeouts. | ||
1246 | 1231 | **/ | ||
1247 | 1232 | gboolean | ||
1248 | 1233 | gnome_rr_screen_set_dpms_mode (GnomeRRScreen *screen, | ||
1249 | 1234 | GnomeRRDpmsMode mode, | ||
1250 | 1235 | GError **error) | ||
1251 | 1236 | { | ||
1252 | 1237 | CARD16 state = 0; | ||
1253 | 1238 | gboolean ret; | ||
1254 | 1239 | GnomeRRDpmsMode current_mode; | ||
1255 | 1240 | |||
1256 | 1241 | g_return_val_if_fail (error == NULL || *error == NULL, FALSE); | ||
1257 | 1242 | |||
1258 | 1243 | /* set, if the new mode is different */ | ||
1259 | 1244 | ret = gnome_rr_screen_get_dpms_mode (screen, ¤t_mode, error); | ||
1260 | 1245 | if (!ret) | ||
1261 | 1246 | goto out; | ||
1262 | 1247 | if (current_mode == mode) { | ||
1263 | 1248 | ret = gnome_rr_screen_clear_dpms_timeouts (screen, error); | ||
1264 | 1249 | goto out; | ||
1265 | 1250 | } | ||
1266 | 1251 | |||
1267 | 1252 | switch (mode) { | ||
1268 | 1253 | case GNOME_RR_DPMS_ON: | ||
1269 | 1254 | state = DPMSModeOn; | ||
1270 | 1255 | break; | ||
1271 | 1256 | case GNOME_RR_DPMS_STANDBY: | ||
1272 | 1257 | state = DPMSModeStandby; | ||
1273 | 1258 | break; | ||
1274 | 1259 | case GNOME_RR_DPMS_SUSPEND: | ||
1275 | 1260 | state = DPMSModeSuspend; | ||
1276 | 1261 | break; | ||
1277 | 1262 | case GNOME_RR_DPMS_OFF: | ||
1278 | 1263 | state = DPMSModeOff; | ||
1279 | 1264 | break; | ||
1280 | 1265 | default: | ||
1281 | 1266 | g_assert_not_reached (); | ||
1282 | 1267 | break; | ||
1283 | 1268 | } | ||
1284 | 1269 | |||
1285 | 1270 | gdk_error_trap_push (); | ||
1286 | 1271 | /* DPMSForceLevel() return value is often a lie, so ignore it */ | ||
1287 | 1272 | DPMSForceLevel (screen->priv->xdisplay, state); | ||
1288 | 1273 | XSync (screen->priv->xdisplay, False); | ||
1289 | 1274 | if (gdk_error_trap_pop ()) { | ||
1290 | 1275 | ret = FALSE; | ||
1291 | 1276 | g_set_error_literal (error, | ||
1292 | 1277 | GNOME_RR_ERROR, | ||
1293 | 1278 | GNOME_RR_ERROR_UNKNOWN, | ||
1294 | 1279 | "Could not change DPMS mode"); | ||
1295 | 1280 | goto out; | ||
1296 | 1281 | } | ||
1297 | 1282 | |||
1298 | 1283 | ret = gnome_rr_screen_clear_dpms_timeouts (screen, error); | ||
1299 | 1284 | if (!ret) | ||
1300 | 1285 | goto out; | ||
1301 | 1286 | out: | ||
1302 | 1287 | return ret; | ||
1303 | 1288 | } | ||
1304 | 1289 | |||
1305 | 1290 | /** | ||
1306 | 1291 | * gnome_rr_screen_list_modes: | ||
1307 | 1292 | * | ||
1308 | 1293 | * List available XRandR modes | ||
1309 | 1294 | * | ||
1310 | 1295 | * Returns: (array zero-terminated=1) (transfer none): | ||
1311 | 1296 | */ | ||
1312 | 1297 | GnomeRRMode ** | ||
1313 | 1298 | gnome_rr_screen_list_modes (GnomeRRScreen *screen) | ||
1314 | 1299 | { | ||
1315 | 1300 | g_return_val_if_fail (GNOME_IS_RR_SCREEN (screen), NULL); | ||
1316 | 1301 | g_return_val_if_fail (screen->priv->info != NULL, NULL); | ||
1317 | 1302 | |||
1318 | 1303 | return screen->priv->info->modes; | ||
1319 | 1304 | } | ||
1320 | 1305 | |||
1321 | 1306 | /** | ||
1322 | 1307 | * gnome_rr_screen_list_clone_modes: | ||
1323 | 1308 | * | ||
1324 | 1309 | * List available XRandR clone modes | ||
1325 | 1310 | * | ||
1326 | 1311 | * Returns: (array zero-terminated=1) (transfer none): | ||
1327 | 1312 | */ | ||
1328 | 1313 | GnomeRRMode ** | ||
1329 | 1314 | gnome_rr_screen_list_clone_modes (GnomeRRScreen *screen) | ||
1330 | 1315 | { | ||
1331 | 1316 | g_return_val_if_fail (GNOME_IS_RR_SCREEN (screen), NULL); | ||
1332 | 1317 | g_return_val_if_fail (screen->priv->info != NULL, NULL); | ||
1333 | 1318 | |||
1334 | 1319 | return screen->priv->info->clone_modes; | ||
1335 | 1320 | } | ||
1336 | 1321 | |||
1337 | 1322 | /** | ||
1338 | 1323 | * gnome_rr_screen_list_crtcs: | ||
1339 | 1324 | * | ||
1340 | 1325 | * List all CRTCs | ||
1341 | 1326 | * | ||
1342 | 1327 | * Returns: (array zero-terminated=1) (transfer none): | ||
1343 | 1328 | */ | ||
1344 | 1329 | GnomeRRCrtc ** | ||
1345 | 1330 | gnome_rr_screen_list_crtcs (GnomeRRScreen *screen) | ||
1346 | 1331 | { | ||
1347 | 1332 | g_return_val_if_fail (GNOME_IS_RR_SCREEN (screen), NULL); | ||
1348 | 1333 | g_return_val_if_fail (screen->priv->info != NULL, NULL); | ||
1349 | 1334 | |||
1350 | 1335 | return screen->priv->info->crtcs; | ||
1351 | 1336 | } | ||
1352 | 1337 | |||
1353 | 1338 | /** | ||
1354 | 1339 | * gnome_rr_screen_list_outputs: | ||
1355 | 1340 | * | ||
1356 | 1341 | * List all outputs | ||
1357 | 1342 | * | ||
1358 | 1343 | * Returns: (array zero-terminated=1) (transfer none): | ||
1359 | 1344 | */ | ||
1360 | 1345 | GnomeRROutput ** | ||
1361 | 1346 | gnome_rr_screen_list_outputs (GnomeRRScreen *screen) | ||
1362 | 1347 | { | ||
1363 | 1348 | g_return_val_if_fail (GNOME_IS_RR_SCREEN (screen), NULL); | ||
1364 | 1349 | g_return_val_if_fail (screen->priv->info != NULL, NULL); | ||
1365 | 1350 | |||
1366 | 1351 | return screen->priv->info->outputs; | ||
1367 | 1352 | } | ||
1368 | 1353 | |||
1369 | 1354 | /** | ||
1370 | 1355 | * gnome_rr_screen_get_crtc_by_id: | ||
1371 | 1356 | * | ||
1372 | 1357 | * Returns: (transfer none): the CRTC identified by @id | ||
1373 | 1358 | */ | ||
1374 | 1359 | GnomeRRCrtc * | ||
1375 | 1360 | gnome_rr_screen_get_crtc_by_id (GnomeRRScreen *screen, | ||
1376 | 1361 | guint32 id) | ||
1377 | 1362 | { | ||
1378 | 1363 | GnomeRRCrtc **crtcs; | ||
1379 | 1364 | int i; | ||
1380 | 1365 | |||
1381 | 1366 | g_return_val_if_fail (GNOME_IS_RR_SCREEN (screen), NULL); | ||
1382 | 1367 | g_return_val_if_fail (screen->priv->info != NULL, NULL); | ||
1383 | 1368 | |||
1384 | 1369 | crtcs = screen->priv->info->crtcs; | ||
1385 | 1370 | |||
1386 | 1371 | for (i = 0; crtcs[i] != NULL; ++i) | ||
1387 | 1372 | { | ||
1388 | 1373 | if (crtcs[i]->id == id) | ||
1389 | 1374 | return crtcs[i]; | ||
1390 | 1375 | } | ||
1391 | 1376 | |||
1392 | 1377 | return NULL; | ||
1393 | 1378 | } | ||
1394 | 1379 | |||
1395 | 1380 | /** | ||
1396 | 1381 | * gnome_rr_screen_get_output_by_id: | ||
1397 | 1382 | * | ||
1398 | 1383 | * Returns: (transfer none): the output identified by @id | ||
1399 | 1384 | */ | ||
1400 | 1385 | GnomeRROutput * | ||
1401 | 1386 | gnome_rr_screen_get_output_by_id (GnomeRRScreen *screen, | ||
1402 | 1387 | guint32 id) | ||
1403 | 1388 | { | ||
1404 | 1389 | GnomeRROutput **outputs; | ||
1405 | 1390 | int i; | ||
1406 | 1391 | |||
1407 | 1392 | g_return_val_if_fail (GNOME_IS_RR_SCREEN (screen), NULL); | ||
1408 | 1393 | g_return_val_if_fail (screen->priv->info != NULL, NULL); | ||
1409 | 1394 | |||
1410 | 1395 | outputs = screen->priv->info->outputs; | ||
1411 | 1396 | |||
1412 | 1397 | for (i = 0; outputs[i] != NULL; ++i) | ||
1413 | 1398 | { | ||
1414 | 1399 | if (outputs[i]->id == id) | ||
1415 | 1400 | return outputs[i]; | ||
1416 | 1401 | } | ||
1417 | 1402 | |||
1418 | 1403 | return NULL; | ||
1419 | 1404 | } | ||
1420 | 1405 | |||
1421 | 1406 | /* GnomeRROutput */ | ||
1422 | 1407 | static GnomeRROutput * | ||
1423 | 1408 | output_new (ScreenInfo *info, RROutput id) | ||
1424 | 1409 | { | ||
1425 | 1410 | GnomeRROutput *output = g_slice_new0 (GnomeRROutput); | ||
1426 | 1411 | |||
1427 | 1412 | output->id = id; | ||
1428 | 1413 | output->info = info; | ||
1429 | 1414 | |||
1430 | 1415 | return output; | ||
1431 | 1416 | } | ||
1432 | 1417 | |||
1433 | 1418 | static guint8 * | ||
1434 | 1419 | get_property (Display *dpy, | ||
1435 | 1420 | RROutput output, | ||
1436 | 1421 | Atom atom, | ||
1437 | 1422 | gsize *len) | ||
1438 | 1423 | { | ||
1439 | 1424 | unsigned char *prop; | ||
1440 | 1425 | int actual_format; | ||
1441 | 1426 | unsigned long nitems, bytes_after; | ||
1442 | 1427 | Atom actual_type; | ||
1443 | 1428 | guint8 *result; | ||
1444 | 1429 | |||
1445 | 1430 | XRRGetOutputProperty (dpy, output, atom, | ||
1446 | 1431 | 0, 100, False, False, | ||
1447 | 1432 | AnyPropertyType, | ||
1448 | 1433 | &actual_type, &actual_format, | ||
1449 | 1434 | &nitems, &bytes_after, &prop); | ||
1450 | 1435 | |||
1451 | 1436 | if (actual_type == XA_INTEGER && actual_format == 8) | ||
1452 | 1437 | { | ||
1453 | 1438 | result = g_memdup (prop, nitems); | ||
1454 | 1439 | if (len) | ||
1455 | 1440 | *len = nitems; | ||
1456 | 1441 | } | ||
1457 | 1442 | else | ||
1458 | 1443 | { | ||
1459 | 1444 | result = NULL; | ||
1460 | 1445 | } | ||
1461 | 1446 | |||
1462 | 1447 | XFree (prop); | ||
1463 | 1448 | |||
1464 | 1449 | return result; | ||
1465 | 1450 | } | ||
1466 | 1451 | |||
1467 | 1452 | static guint8 * | ||
1468 | 1453 | read_edid_data (GnomeRROutput *output, gsize *len) | ||
1469 | 1454 | { | ||
1470 | 1455 | Atom edid_atom; | ||
1471 | 1456 | guint8 *result; | ||
1472 | 1457 | |||
1473 | 1458 | edid_atom = XInternAtom (DISPLAY (output), "EDID", FALSE); | ||
1474 | 1459 | result = get_property (DISPLAY (output), | ||
1475 | 1460 | output->id, edid_atom, len); | ||
1476 | 1461 | |||
1477 | 1462 | if (!result) | ||
1478 | 1463 | { | ||
1479 | 1464 | edid_atom = XInternAtom (DISPLAY (output), "EDID_DATA", FALSE); | ||
1480 | 1465 | result = get_property (DISPLAY (output), | ||
1481 | 1466 | output->id, edid_atom, len); | ||
1482 | 1467 | } | ||
1483 | 1468 | |||
1484 | 1469 | if (!result) | ||
1485 | 1470 | { | ||
1486 | 1471 | edid_atom = XInternAtom (DISPLAY (output), "XFree86_DDC_EDID1_RAWDATA", FALSE); | ||
1487 | 1472 | result = get_property (DISPLAY (output), | ||
1488 | 1473 | output->id, edid_atom, len); | ||
1489 | 1474 | } | ||
1490 | 1475 | |||
1491 | 1476 | if (result) | ||
1492 | 1477 | { | ||
1493 | 1478 | if (*len % 128 == 0) | ||
1494 | 1479 | return result; | ||
1495 | 1480 | else | ||
1496 | 1481 | g_free (result); | ||
1497 | 1482 | } | ||
1498 | 1483 | |||
1499 | 1484 | return NULL; | ||
1500 | 1485 | } | ||
1501 | 1486 | |||
1502 | 1487 | static char * | ||
1503 | 1488 | get_connector_type_string (GnomeRROutput *output) | ||
1504 | 1489 | { | ||
1505 | 1490 | char *result; | ||
1506 | 1491 | unsigned char *prop; | ||
1507 | 1492 | int actual_format; | ||
1508 | 1493 | unsigned long nitems, bytes_after; | ||
1509 | 1494 | Atom actual_type; | ||
1510 | 1495 | Atom connector_type; | ||
1511 | 1496 | char *connector_type_str; | ||
1512 | 1497 | |||
1513 | 1498 | result = NULL; | ||
1514 | 1499 | |||
1515 | 1500 | if (XRRGetOutputProperty (DISPLAY (output), output->id, output->info->screen->priv->connector_type_atom, | ||
1516 | 1501 | 0, 100, False, False, | ||
1517 | 1502 | AnyPropertyType, | ||
1518 | 1503 | &actual_type, &actual_format, | ||
1519 | 1504 | &nitems, &bytes_after, &prop) != Success) | ||
1520 | 1505 | return NULL; | ||
1521 | 1506 | |||
1522 | 1507 | if (!(actual_type == XA_ATOM && actual_format == 32 && nitems == 1)) | ||
1523 | 1508 | goto out; | ||
1524 | 1509 | |||
1525 | 1510 | connector_type = *((Atom *) prop); | ||
1526 | 1511 | |||
1527 | 1512 | connector_type_str = XGetAtomName (DISPLAY (output), connector_type); | ||
1528 | 1513 | if (connector_type_str) { | ||
1529 | 1514 | result = g_strdup (connector_type_str); /* so the caller can g_free() it */ | ||
1530 | 1515 | XFree (connector_type_str); | ||
1531 | 1516 | } | ||
1532 | 1517 | |||
1533 | 1518 | out: | ||
1534 | 1519 | |||
1535 | 1520 | XFree (prop); | ||
1536 | 1521 | |||
1537 | 1522 | return result; | ||
1538 | 1523 | } | ||
1539 | 1524 | |||
1540 | 1525 | static void | ||
1541 | 1526 | update_brightness_limits (GnomeRROutput *output) | ||
1542 | 1527 | { | ||
1543 | 1528 | gint rc; | ||
1544 | 1529 | Atom atom; | ||
1545 | 1530 | XRRPropertyInfo *info; | ||
1546 | 1531 | |||
1547 | 1532 | gdk_error_trap_push (); | ||
1548 | 1533 | atom = XInternAtom (DISPLAY (output), "Backlight", FALSE); | ||
1549 | 1534 | info = XRRQueryOutputProperty (DISPLAY (output), output->id, atom); | ||
1550 | 1535 | rc = gdk_error_trap_pop (); | ||
1551 | 1536 | if (rc != Success) | ||
1552 | 1537 | { | ||
1553 | 1538 | if (rc != BadName) | ||
1554 | 1539 | g_warning ("could not get output property for %s, rc: %i", | ||
1555 | 1540 | output->name, rc); | ||
1556 | 1541 | goto out; | ||
1557 | 1542 | } | ||
1558 | 1543 | if (info == NULL) | ||
1559 | 1544 | { | ||
1560 | 1545 | g_warning ("could not get output property for %s", | ||
1561 | 1546 | output->name); | ||
1562 | 1547 | goto out; | ||
1563 | 1548 | } | ||
1564 | 1549 | if (!info->range || info->num_values != 2) | ||
1565 | 1550 | { | ||
1566 | 1551 | g_debug ("backlight %s was not range", output->name); | ||
1567 | 1552 | goto out; | ||
1568 | 1553 | } | ||
1569 | 1554 | output->backlight_min = info->values[0]; | ||
1570 | 1555 | output->backlight_max = info->values[1]; | ||
1571 | 1556 | out: | ||
1572 | 1557 | if (info != NULL) | ||
1573 | 1558 | { | ||
1574 | 1559 | XFree (info); | ||
1575 | 1560 | } | ||
1576 | 1561 | } | ||
1577 | 1562 | |||
1578 | 1563 | static gboolean | ||
1579 | 1564 | output_initialize (GnomeRROutput *output, XRRScreenResources *res, GError **error) | ||
1580 | 1565 | { | ||
1581 | 1566 | XRROutputInfo *info = XRRGetOutputInfo ( | ||
1582 | 1567 | DISPLAY (output), res, output->id); | ||
1583 | 1568 | GPtrArray *a; | ||
1584 | 1569 | int i; | ||
1585 | 1570 | |||
1586 | 1571 | #if 0 | ||
1587 | 1572 | g_print ("Output %lx Timestamp: %u\n", output->id, (guint32)info->timestamp); | ||
1588 | 1573 | #endif | ||
1589 | 1574 | |||
1590 | 1575 | if (!info || !output->info) | ||
1591 | 1576 | { | ||
1592 | 1577 | /* FIXME: see the comment in crtc_initialize() */ | ||
1593 | 1578 | /* Translators: here, an "output" is a video output */ | ||
1594 | 1579 | g_set_error (error, GNOME_RR_ERROR, GNOME_RR_ERROR_RANDR_ERROR, | ||
1595 | 1580 | _("could not get information about output %d"), | ||
1596 | 1581 | (int) output->id); | ||
1597 | 1582 | return FALSE; | ||
1598 | 1583 | } | ||
1599 | 1584 | |||
1600 | 1585 | output->name = g_strdup (info->name); /* FIXME: what is nameLen used for? */ | ||
1601 | 1586 | output->display_name = NULL; /* set first time the getter is used */ | ||
1602 | 1587 | output->current_crtc = crtc_by_id (output->info, info->crtc); | ||
1603 | 1588 | output->width_mm = info->mm_width; | ||
1604 | 1589 | output->height_mm = info->mm_height; | ||
1605 | 1590 | output->connected = (info->connection == RR_Connected); | ||
1606 | 1591 | output->connector_type = get_connector_type_string (output); | ||
1607 | 1592 | |||
1608 | 1593 | /* Possible crtcs */ | ||
1609 | 1594 | a = g_ptr_array_new (); | ||
1610 | 1595 | |||
1611 | 1596 | for (i = 0; i < info->ncrtc; ++i) | ||
1612 | 1597 | { | ||
1613 | 1598 | GnomeRRCrtc *crtc = crtc_by_id (output->info, info->crtcs[i]); | ||
1614 | 1599 | |||
1615 | 1600 | if (crtc) | ||
1616 | 1601 | g_ptr_array_add (a, crtc); | ||
1617 | 1602 | } | ||
1618 | 1603 | g_ptr_array_add (a, NULL); | ||
1619 | 1604 | output->possible_crtcs = (GnomeRRCrtc **)g_ptr_array_free (a, FALSE); | ||
1620 | 1605 | |||
1621 | 1606 | /* Clones */ | ||
1622 | 1607 | a = g_ptr_array_new (); | ||
1623 | 1608 | for (i = 0; i < info->nclone; ++i) | ||
1624 | 1609 | { | ||
1625 | 1610 | GnomeRROutput *gnome_rr_output = gnome_rr_output_by_id (output->info, info->clones[i]); | ||
1626 | 1611 | |||
1627 | 1612 | if (gnome_rr_output) | ||
1628 | 1613 | g_ptr_array_add (a, gnome_rr_output); | ||
1629 | 1614 | } | ||
1630 | 1615 | g_ptr_array_add (a, NULL); | ||
1631 | 1616 | output->clones = (GnomeRROutput **)g_ptr_array_free (a, FALSE); | ||
1632 | 1617 | |||
1633 | 1618 | /* Modes */ | ||
1634 | 1619 | a = g_ptr_array_new (); | ||
1635 | 1620 | for (i = 0; i < info->nmode; ++i) | ||
1636 | 1621 | { | ||
1637 | 1622 | GnomeRRMode *mode = mode_by_id (output->info, info->modes[i]); | ||
1638 | 1623 | |||
1639 | 1624 | if (mode) | ||
1640 | 1625 | g_ptr_array_add (a, mode); | ||
1641 | 1626 | } | ||
1642 | 1627 | g_ptr_array_add (a, NULL); | ||
1643 | 1628 | output->modes = (GnomeRRMode **)g_ptr_array_free (a, FALSE); | ||
1644 | 1629 | |||
1645 | 1630 | output->n_preferred = info->npreferred; | ||
1646 | 1631 | |||
1647 | 1632 | /* Edid data */ | ||
1648 | 1633 | output->edid_data = read_edid_data (output, &output->edid_size); | ||
1649 | 1634 | |||
1650 | 1635 | /* brightness data */ | ||
1651 | 1636 | if (output->connected) | ||
1652 | 1637 | update_brightness_limits (output); | ||
1653 | 1638 | |||
1654 | 1639 | XRRFreeOutputInfo (info); | ||
1655 | 1640 | |||
1656 | 1641 | return TRUE; | ||
1657 | 1642 | } | ||
1658 | 1643 | |||
1659 | 1644 | static GnomeRROutput* | ||
1660 | 1645 | output_copy (const GnomeRROutput *from) | ||
1661 | 1646 | { | ||
1662 | 1647 | GPtrArray *array; | ||
1663 | 1648 | GnomeRRCrtc **p_crtc; | ||
1664 | 1649 | GnomeRROutput **p_output; | ||
1665 | 1650 | GnomeRRMode **p_mode; | ||
1666 | 1651 | GnomeRROutput *output = g_slice_new0 (GnomeRROutput); | ||
1667 | 1652 | |||
1668 | 1653 | output->id = from->id; | ||
1669 | 1654 | output->info = from->info; | ||
1670 | 1655 | output->name = g_strdup (from->name); | ||
1671 | 1656 | output->current_crtc = from->current_crtc; | ||
1672 | 1657 | output->width_mm = from->width_mm; | ||
1673 | 1658 | output->height_mm = from->height_mm; | ||
1674 | 1659 | output->connected = from->connected; | ||
1675 | 1660 | output->n_preferred = from->n_preferred; | ||
1676 | 1661 | output->connector_type = g_strdup (from->connector_type); | ||
1677 | 1662 | output->backlight_min = -1; | ||
1678 | 1663 | output->backlight_max = -1; | ||
1679 | 1664 | |||
1680 | 1665 | array = g_ptr_array_new (); | ||
1681 | 1666 | for (p_crtc = from->possible_crtcs; *p_crtc != NULL; p_crtc++) | ||
1682 | 1667 | { | ||
1683 | 1668 | g_ptr_array_add (array, *p_crtc); | ||
1684 | 1669 | } | ||
1685 | 1670 | output->possible_crtcs = (GnomeRRCrtc**) g_ptr_array_free (array, FALSE); | ||
1686 | 1671 | |||
1687 | 1672 | array = g_ptr_array_new (); | ||
1688 | 1673 | for (p_output = from->clones; *p_output != NULL; p_output++) | ||
1689 | 1674 | { | ||
1690 | 1675 | g_ptr_array_add (array, *p_output); | ||
1691 | 1676 | } | ||
1692 | 1677 | output->clones = (GnomeRROutput**) g_ptr_array_free (array, FALSE); | ||
1693 | 1678 | |||
1694 | 1679 | array = g_ptr_array_new (); | ||
1695 | 1680 | for (p_mode = from->modes; *p_mode != NULL; p_mode++) | ||
1696 | 1681 | { | ||
1697 | 1682 | g_ptr_array_add (array, *p_mode); | ||
1698 | 1683 | } | ||
1699 | 1684 | output->modes = (GnomeRRMode**) g_ptr_array_free (array, FALSE); | ||
1700 | 1685 | |||
1701 | 1686 | output->edid_size = from->edid_size; | ||
1702 | 1687 | output->edid_data = g_memdup (from->edid_data, from->edid_size); | ||
1703 | 1688 | |||
1704 | 1689 | return output; | ||
1705 | 1690 | } | ||
1706 | 1691 | |||
1707 | 1692 | static void | ||
1708 | 1693 | output_free (GnomeRROutput *output) | ||
1709 | 1694 | { | ||
1710 | 1695 | g_free (output->clones); | ||
1711 | 1696 | g_free (output->modes); | ||
1712 | 1697 | g_free (output->possible_crtcs); | ||
1713 | 1698 | g_free (output->edid_data); | ||
1714 | 1699 | g_free (output->name); | ||
1715 | 1700 | g_free (output->display_name); | ||
1716 | 1701 | g_free (output->connector_type); | ||
1717 | 1702 | g_slice_free (GnomeRROutput, output); | ||
1718 | 1703 | } | ||
1719 | 1704 | |||
1720 | 1705 | guint32 | ||
1721 | 1706 | gnome_rr_output_get_id (GnomeRROutput *output) | ||
1722 | 1707 | { | ||
1723 | 1708 | g_assert(output != NULL); | ||
1724 | 1709 | |||
1725 | 1710 | return output->id; | ||
1726 | 1711 | } | ||
1727 | 1712 | |||
1728 | 1713 | const guint8 * | ||
1729 | 1714 | gnome_rr_output_get_edid_data (GnomeRROutput *output, gsize *size) | ||
1730 | 1715 | { | ||
1731 | 1716 | g_return_val_if_fail (output != NULL, NULL); | ||
1732 | 1717 | if (size) | ||
1733 | 1718 | *size = output->edid_size; | ||
1734 | 1719 | return output->edid_data; | ||
1735 | 1720 | } | ||
1736 | 1721 | |||
1737 | 1722 | /** | ||
1738 | 1723 | * gnome_rr_output_get_ids_from_edid: | ||
1739 | 1724 | * @output: a #GnomeRROutput | ||
1740 | 1725 | * @vendor: (out) (allow-none): | ||
1741 | 1726 | * @product: (out) (allow-none): | ||
1742 | 1727 | * @serial: (out) (allow-none): | ||
1743 | 1728 | */ | ||
1744 | 1729 | gboolean | ||
1745 | 1730 | gnome_rr_output_get_ids_from_edid (GnomeRROutput *output, | ||
1746 | 1731 | char **vendor, | ||
1747 | 1732 | int *product, | ||
1748 | 1733 | int *serial) | ||
1749 | 1734 | { | ||
1750 | 1735 | MonitorInfo *info; | ||
1751 | 1736 | |||
1752 | 1737 | g_return_val_if_fail (output != NULL, FALSE); | ||
1753 | 1738 | |||
1754 | 1739 | if (!output->edid_data) | ||
1755 | 1740 | return FALSE; | ||
1756 | 1741 | info = decode_edid (output->edid_data); | ||
1757 | 1742 | if (!info) | ||
1758 | 1743 | return FALSE; | ||
1759 | 1744 | if (vendor) | ||
1760 | 1745 | *vendor = g_memdup (info->manufacturer_code, 4); | ||
1761 | 1746 | if (product) | ||
1762 | 1747 | *product = info->product_code; | ||
1763 | 1748 | if (serial) | ||
1764 | 1749 | *serial = info->serial_number; | ||
1765 | 1750 | |||
1766 | 1751 | g_free (info); | ||
1767 | 1752 | |||
1768 | 1753 | return TRUE; | ||
1769 | 1754 | |||
1770 | 1755 | } | ||
1771 | 1756 | |||
1772 | 1757 | static void | ||
1773 | 1758 | ensure_display_name (GnomeRROutput *output) | ||
1774 | 1759 | { | ||
1775 | 1760 | if (output->display_name != NULL) | ||
1776 | 1761 | return; | ||
1777 | 1762 | |||
1778 | 1763 | if (gnome_rr_output_is_laptop (output)) | ||
1779 | 1764 | output->display_name = g_strdup (_("Built-in Display")); | ||
1780 | 1765 | |||
1781 | 1766 | if (output->display_name == NULL | ||
1782 | 1767 | && output->edid_data != NULL) { | ||
1783 | 1768 | MonitorInfo *info; | ||
1784 | 1769 | |||
1785 | 1770 | info = decode_edid (output->edid_data); | ||
1786 | 1771 | if (info != NULL) | ||
1787 | 1772 | output->display_name = make_display_name (info); | ||
1788 | 1773 | |||
1789 | 1774 | g_free (info); | ||
1790 | 1775 | } | ||
1791 | 1776 | |||
1792 | 1777 | if (output->display_name == NULL) { | ||
1793 | 1778 | char *inches; | ||
1794 | 1779 | inches = make_display_size_string (output->width_mm, output->height_mm); | ||
1795 | 1780 | if (inches != NULL) { | ||
1796 | 1781 | /* Translators: %s is the size of the monitor in inches */ | ||
1797 | 1782 | output->display_name = g_strdup_printf (_("%s Display"), inches); | ||
1798 | 1783 | } | ||
1799 | 1784 | g_free (inches); | ||
1800 | 1785 | } | ||
1801 | 1786 | |||
1802 | 1787 | /* last chance on the stairway */ | ||
1803 | 1788 | if (output->display_name == NULL) { | ||
1804 | 1789 | output->display_name = g_strdup (_("Unknown Display")); | ||
1805 | 1790 | } | ||
1806 | 1791 | } | ||
1807 | 1792 | |||
1808 | 1793 | const char * | ||
1809 | 1794 | gnome_rr_output_get_display_name (GnomeRROutput *output) | ||
1810 | 1795 | { | ||
1811 | 1796 | g_return_val_if_fail (output != NULL, NULL); | ||
1812 | 1797 | |||
1813 | 1798 | ensure_display_name (output); | ||
1814 | 1799 | |||
1815 | 1800 | return output->display_name; | ||
1816 | 1801 | } | ||
1817 | 1802 | |||
1818 | 1803 | /** | ||
1819 | 1804 | * gnome_rr_output_get_backlight_min: | ||
1820 | 1805 | * | ||
1821 | 1806 | * Returns: The mimimum backlight value, or -1 if not supported | ||
1822 | 1807 | */ | ||
1823 | 1808 | gint | ||
1824 | 1809 | gnome_rr_output_get_backlight_min (GnomeRROutput *output) | ||
1825 | 1810 | { | ||
1826 | 1811 | g_return_val_if_fail (output != NULL, -1); | ||
1827 | 1812 | return output->backlight_min; | ||
1828 | 1813 | } | ||
1829 | 1814 | |||
1830 | 1815 | /** | ||
1831 | 1816 | * gnome_rr_output_get_backlight_max: | ||
1832 | 1817 | * | ||
1833 | 1818 | * Returns: The maximum backlight value, or -1 if not supported | ||
1834 | 1819 | */ | ||
1835 | 1820 | gint | ||
1836 | 1821 | gnome_rr_output_get_backlight_max (GnomeRROutput *output) | ||
1837 | 1822 | { | ||
1838 | 1823 | g_return_val_if_fail (output != NULL, -1); | ||
1839 | 1824 | return output->backlight_max; | ||
1840 | 1825 | } | ||
1841 | 1826 | |||
1842 | 1827 | /** | ||
1843 | 1828 | * gnome_rr_output_get_backlight: | ||
1844 | 1829 | * | ||
1845 | 1830 | * Returns: The currently set backlight brightness | ||
1846 | 1831 | */ | ||
1847 | 1832 | gint | ||
1848 | 1833 | gnome_rr_output_get_backlight (GnomeRROutput *output, GError **error) | ||
1849 | 1834 | { | ||
1850 | 1835 | guint now = -1; | ||
1851 | 1836 | unsigned long nitems; | ||
1852 | 1837 | unsigned long bytes_after; | ||
1853 | 1838 | guint *prop; | ||
1854 | 1839 | Atom atom; | ||
1855 | 1840 | Atom actual_type; | ||
1856 | 1841 | int actual_format; | ||
1857 | 1842 | gint retval; | ||
1858 | 1843 | |||
1859 | 1844 | g_return_val_if_fail (output != NULL, -1); | ||
1860 | 1845 | |||
1861 | 1846 | gdk_error_trap_push (); | ||
1862 | 1847 | atom = XInternAtom (DISPLAY (output), "Backlight", FALSE); | ||
1863 | 1848 | retval = XRRGetOutputProperty (DISPLAY (output), output->id, atom, | ||
1864 | 1849 | 0, 4, False, False, None, | ||
1865 | 1850 | &actual_type, &actual_format, | ||
1866 | 1851 | &nitems, &bytes_after, ((unsigned char **)&prop)); | ||
1867 | 1852 | gdk_flush (); | ||
1868 | 1853 | if (gdk_error_trap_pop ()) | ||
1869 | 1854 | { | ||
1870 | 1855 | g_set_error_literal (error, | ||
1871 | 1856 | GNOME_RR_ERROR, | ||
1872 | 1857 | GNOME_RR_ERROR_UNKNOWN, | ||
1873 | 1858 | "unhandled X error while getting the range of backlight values"); | ||
1874 | 1859 | goto out; | ||
1875 | 1860 | } | ||
1876 | 1861 | |||
1877 | 1862 | if (retval != Success) { | ||
1878 | 1863 | g_set_error_literal (error, | ||
1879 | 1864 | GNOME_RR_ERROR, | ||
1880 | 1865 | GNOME_RR_ERROR_RANDR_ERROR, | ||
1881 | 1866 | "could not get the range of backlight values"); | ||
1882 | 1867 | goto out; | ||
1883 | 1868 | } | ||
1884 | 1869 | if (actual_type == XA_INTEGER && | ||
1885 | 1870 | nitems == 1 && | ||
1886 | 1871 | actual_format == 32) | ||
1887 | 1872 | { | ||
1888 | 1873 | memcpy (&now, prop, sizeof (guint)); | ||
1889 | 1874 | } | ||
1890 | 1875 | else | ||
1891 | 1876 | { | ||
1892 | 1877 | g_set_error (error, | ||
1893 | 1878 | GNOME_RR_ERROR, | ||
1894 | 1879 | GNOME_RR_ERROR_RANDR_ERROR, | ||
1895 | 1880 | "failed to get correct property type, got %lu,%i", | ||
1896 | 1881 | nitems, actual_format); | ||
1897 | 1882 | } | ||
1898 | 1883 | out: | ||
1899 | 1884 | XFree (prop); | ||
1900 | 1885 | return now; | ||
1901 | 1886 | } | ||
1902 | 1887 | |||
1903 | 1888 | /** | ||
1904 | 1889 | * gnome_rr_output_set_backlight: | ||
1905 | 1890 | * @value: the absolute value which is min >= this <= max | ||
1906 | 1891 | * | ||
1907 | 1892 | * Returns: %TRUE for success | ||
1908 | 1893 | */ | ||
1909 | 1894 | gboolean | ||
1910 | 1895 | gnome_rr_output_set_backlight (GnomeRROutput *output, gint value, GError **error) | ||
1911 | 1896 | { | ||
1912 | 1897 | gboolean ret = FALSE; | ||
1913 | 1898 | Atom atom; | ||
1914 | 1899 | |||
1915 | 1900 | g_return_val_if_fail (output != NULL, FALSE); | ||
1916 | 1901 | |||
1917 | 1902 | /* check this is sane */ | ||
1918 | 1903 | if (value < output->backlight_min || | ||
1919 | 1904 | value > output->backlight_max) | ||
1920 | 1905 | { | ||
1921 | 1906 | g_set_error (error, | ||
1922 | 1907 | GNOME_RR_ERROR, | ||
1923 | 1908 | GNOME_RR_ERROR_BOUNDS_ERROR, | ||
1924 | 1909 | "out of brightness range: %i, has to be %i -> %i", | ||
1925 | 1910 | value, | ||
1926 | 1911 | output->backlight_max, output->backlight_min); | ||
1927 | 1912 | goto out; | ||
1928 | 1913 | } | ||
1929 | 1914 | |||
1930 | 1915 | /* don't abort on error */ | ||
1931 | 1916 | gdk_error_trap_push (); | ||
1932 | 1917 | atom = XInternAtom (DISPLAY (output), "Backlight", FALSE); | ||
1933 | 1918 | XRRChangeOutputProperty (DISPLAY (output), output->id, atom, | ||
1934 | 1919 | XA_INTEGER, 32, PropModeReplace, | ||
1935 | 1920 | (unsigned char *) &value, 1); | ||
1936 | 1921 | if (gdk_error_trap_pop ()) | ||
1937 | 1922 | { | ||
1938 | 1923 | g_set_error_literal (error, | ||
1939 | 1924 | GNOME_RR_ERROR, | ||
1940 | 1925 | GNOME_RR_ERROR_UNKNOWN, | ||
1941 | 1926 | "unhandled X error while setting the backlight values"); | ||
1942 | 1927 | goto out; | ||
1943 | 1928 | } | ||
1944 | 1929 | |||
1945 | 1930 | /* we assume this succeeded as there's no return value */ | ||
1946 | 1931 | ret = TRUE; | ||
1947 | 1932 | out: | ||
1948 | 1933 | return ret; | ||
1949 | 1934 | } | ||
1950 | 1935 | |||
1951 | 1936 | /** | ||
1952 | 1937 | * gnome_rr_screen_get_output_by_name: | ||
1953 | 1938 | * | ||
1954 | 1939 | * Returns: (transfer none): the output identified by @name | ||
1955 | 1940 | */ | ||
1956 | 1941 | GnomeRROutput * | ||
1957 | 1942 | gnome_rr_screen_get_output_by_name (GnomeRRScreen *screen, | ||
1958 | 1943 | const char *name) | ||
1959 | 1944 | { | ||
1960 | 1945 | int i; | ||
1961 | 1946 | |||
1962 | 1947 | g_return_val_if_fail (GNOME_IS_RR_SCREEN (screen), NULL); | ||
1963 | 1948 | g_return_val_if_fail (screen->priv->info != NULL, NULL); | ||
1964 | 1949 | |||
1965 | 1950 | for (i = 0; screen->priv->info->outputs[i] != NULL; ++i) | ||
1966 | 1951 | { | ||
1967 | 1952 | GnomeRROutput *output = screen->priv->info->outputs[i]; | ||
1968 | 1953 | |||
1969 | 1954 | if (strcmp (output->name, name) == 0) | ||
1970 | 1955 | return output; | ||
1971 | 1956 | } | ||
1972 | 1957 | |||
1973 | 1958 | return NULL; | ||
1974 | 1959 | } | ||
1975 | 1960 | |||
1976 | 1961 | GnomeRRCrtc * | ||
1977 | 1962 | gnome_rr_output_get_crtc (GnomeRROutput *output) | ||
1978 | 1963 | { | ||
1979 | 1964 | g_return_val_if_fail (output != NULL, NULL); | ||
1980 | 1965 | |||
1981 | 1966 | return output->current_crtc; | ||
1982 | 1967 | } | ||
1983 | 1968 | |||
1984 | 1969 | /* Returns NULL if the ConnectorType property is not available */ | ||
1985 | 1970 | const char * | ||
1986 | 1971 | gnome_rr_output_get_connector_type (GnomeRROutput *output) | ||
1987 | 1972 | { | ||
1988 | 1973 | g_return_val_if_fail (output != NULL, NULL); | ||
1989 | 1974 | |||
1990 | 1975 | return output->connector_type; | ||
1991 | 1976 | } | ||
1992 | 1977 | |||
1993 | 1978 | gboolean | ||
1994 | 1979 | _gnome_rr_output_name_is_laptop (const char *name) | ||
1995 | 1980 | { | ||
1996 | 1981 | if (!name) | ||
1997 | 1982 | return FALSE; | ||
1998 | 1983 | |||
1999 | 1984 | if (strstr (name, "lvds") || /* Most drivers use an "LVDS" prefix... */ | ||
2000 | 1985 | strstr (name, "LVDS") || | ||
2001 | 1986 | strstr (name, "Lvds") || | ||
2002 | 1987 | strstr (name, "LCD") || /* ... but fglrx uses "LCD" in some versions. Shoot me now, kthxbye. */ | ||
2003 | 1988 | strstr (name, "eDP") || /* eDP is for internal laptop panel connections */ | ||
2004 | 1989 | strstr (name, "default")) /* Finally, NVidia and all others that don't bother to do RANDR properly */ | ||
2005 | 1990 | return TRUE; | ||
2006 | 1991 | |||
2007 | 1992 | return FALSE; | ||
2008 | 1993 | } | ||
2009 | 1994 | |||
2010 | 1995 | gboolean | ||
2011 | 1996 | gnome_rr_output_is_laptop (GnomeRROutput *output) | ||
2012 | 1997 | { | ||
2013 | 1998 | g_return_val_if_fail (output != NULL, FALSE); | ||
2014 | 1999 | |||
2015 | 2000 | if (!output->connected) | ||
2016 | 2001 | return FALSE; | ||
2017 | 2002 | |||
2018 | 2003 | /* The ConnectorType property is present in RANDR 1.3 and greater */ | ||
2019 | 2004 | if (g_strcmp0 (output->connector_type, GNOME_RR_CONNECTOR_TYPE_PANEL) == 0) | ||
2020 | 2005 | return TRUE; | ||
2021 | 2006 | |||
2022 | 2007 | /* Older versions of RANDR - this is a best guess, as @#$% RANDR doesn't have standard output names, | ||
2023 | 2008 | * so drivers can use whatever they like. | ||
2024 | 2009 | */ | ||
2025 | 2010 | if (_gnome_rr_output_name_is_laptop (output->name)) | ||
2026 | 2011 | return TRUE; | ||
2027 | 2012 | |||
2028 | 2013 | return FALSE; | ||
2029 | 2014 | } | ||
2030 | 2015 | |||
2031 | 2016 | GnomeRRMode * | ||
2032 | 2017 | gnome_rr_output_get_current_mode (GnomeRROutput *output) | ||
2033 | 2018 | { | ||
2034 | 2019 | GnomeRRCrtc *crtc; | ||
2035 | 2020 | |||
2036 | 2021 | g_return_val_if_fail (output != NULL, NULL); | ||
2037 | 2022 | |||
2038 | 2023 | if ((crtc = gnome_rr_output_get_crtc (output))) | ||
2039 | 2024 | return gnome_rr_crtc_get_current_mode (crtc); | ||
2040 | 2025 | |||
2041 | 2026 | return NULL; | ||
2042 | 2027 | } | ||
2043 | 2028 | |||
2044 | 2029 | /** | ||
2045 | 2030 | * gnome_rr_output_get_position: | ||
2046 | 2031 | * @output: a #GnomeRROutput | ||
2047 | 2032 | * @x: (out) (allow-none): | ||
2048 | 2033 | * @y: (out) (allow-none): | ||
2049 | 2034 | */ | ||
2050 | 2035 | void | ||
2051 | 2036 | gnome_rr_output_get_position (GnomeRROutput *output, | ||
2052 | 2037 | int *x, | ||
2053 | 2038 | int *y) | ||
2054 | 2039 | { | ||
2055 | 2040 | GnomeRRCrtc *crtc; | ||
2056 | 2041 | |||
2057 | 2042 | g_return_if_fail (output != NULL); | ||
2058 | 2043 | |||
2059 | 2044 | if ((crtc = gnome_rr_output_get_crtc (output))) | ||
2060 | 2045 | gnome_rr_crtc_get_position (crtc, x, y); | ||
2061 | 2046 | } | ||
2062 | 2047 | |||
2063 | 2048 | const char * | ||
2064 | 2049 | gnome_rr_output_get_name (GnomeRROutput *output) | ||
2065 | 2050 | { | ||
2066 | 2051 | g_assert (output != NULL); | ||
2067 | 2052 | return output->name; | ||
2068 | 2053 | } | ||
2069 | 2054 | |||
2070 | 2055 | int | ||
2071 | 2056 | gnome_rr_output_get_width_mm (GnomeRROutput *output) | ||
2072 | 2057 | { | ||
2073 | 2058 | g_assert (output != NULL); | ||
2074 | 2059 | return output->width_mm; | ||
2075 | 2060 | } | ||
2076 | 2061 | |||
2077 | 2062 | int | ||
2078 | 2063 | gnome_rr_output_get_height_mm (GnomeRROutput *output) | ||
2079 | 2064 | { | ||
2080 | 2065 | g_assert (output != NULL); | ||
2081 | 2066 | return output->height_mm; | ||
2082 | 2067 | } | ||
2083 | 2068 | |||
2084 | 2069 | GnomeRRMode * | ||
2085 | 2070 | gnome_rr_output_get_preferred_mode (GnomeRROutput *output) | ||
2086 | 2071 | { | ||
2087 | 2072 | g_return_val_if_fail (output != NULL, NULL); | ||
2088 | 2073 | if (output->n_preferred) | ||
2089 | 2074 | return output->modes[0]; | ||
2090 | 2075 | |||
2091 | 2076 | return NULL; | ||
2092 | 2077 | } | ||
2093 | 2078 | |||
2094 | 2079 | GnomeRRMode ** | ||
2095 | 2080 | gnome_rr_output_list_modes (GnomeRROutput *output) | ||
2096 | 2081 | { | ||
2097 | 2082 | g_return_val_if_fail (output != NULL, NULL); | ||
2098 | 2083 | return output->modes; | ||
2099 | 2084 | } | ||
2100 | 2085 | |||
2101 | 2086 | gboolean | ||
2102 | 2087 | gnome_rr_output_is_connected (GnomeRROutput *output) | ||
2103 | 2088 | { | ||
2104 | 2089 | g_return_val_if_fail (output != NULL, FALSE); | ||
2105 | 2090 | return output->connected; | ||
2106 | 2091 | } | ||
2107 | 2092 | |||
2108 | 2093 | gboolean | ||
2109 | 2094 | gnome_rr_output_supports_mode (GnomeRROutput *output, | ||
2110 | 2095 | GnomeRRMode *mode) | ||
2111 | 2096 | { | ||
2112 | 2097 | int i; | ||
2113 | 2098 | |||
2114 | 2099 | g_return_val_if_fail (output != NULL, FALSE); | ||
2115 | 2100 | g_return_val_if_fail (mode != NULL, FALSE); | ||
2116 | 2101 | |||
2117 | 2102 | for (i = 0; output->modes[i] != NULL; ++i) | ||
2118 | 2103 | { | ||
2119 | 2104 | if (output->modes[i] == mode) | ||
2120 | 2105 | return TRUE; | ||
2121 | 2106 | } | ||
2122 | 2107 | |||
2123 | 2108 | return FALSE; | ||
2124 | 2109 | } | ||
2125 | 2110 | |||
2126 | 2111 | gboolean | ||
2127 | 2112 | gnome_rr_output_can_clone (GnomeRROutput *output, | ||
2128 | 2113 | GnomeRROutput *clone) | ||
2129 | 2114 | { | ||
2130 | 2115 | int i; | ||
2131 | 2116 | |||
2132 | 2117 | g_return_val_if_fail (output != NULL, FALSE); | ||
2133 | 2118 | g_return_val_if_fail (clone != NULL, FALSE); | ||
2134 | 2119 | |||
2135 | 2120 | for (i = 0; output->clones[i] != NULL; ++i) | ||
2136 | 2121 | { | ||
2137 | 2122 | if (output->clones[i] == clone) | ||
2138 | 2123 | return TRUE; | ||
2139 | 2124 | } | ||
2140 | 2125 | |||
2141 | 2126 | return FALSE; | ||
2142 | 2127 | } | ||
2143 | 2128 | |||
2144 | 2129 | gboolean | ||
2145 | 2130 | gnome_rr_output_get_is_primary (GnomeRROutput *output) | ||
2146 | 2131 | { | ||
2147 | 2132 | return output->info->primary == output->id; | ||
2148 | 2133 | } | ||
2149 | 2134 | |||
2150 | 2135 | void | ||
2151 | 2136 | gnome_rr_screen_set_primary_output (GnomeRRScreen *screen, | ||
2152 | 2137 | GnomeRROutput *output) | ||
2153 | 2138 | { | ||
2154 | 2139 | GnomeRRScreenPrivate *priv; | ||
2155 | 2140 | RROutput id; | ||
2156 | 2141 | |||
2157 | 2142 | g_return_if_fail (GNOME_IS_RR_SCREEN (screen)); | ||
2158 | 2143 | |||
2159 | 2144 | priv = screen->priv; | ||
2160 | 2145 | |||
2161 | 2146 | if (output) | ||
2162 | 2147 | id = output->id; | ||
2163 | 2148 | else | ||
2164 | 2149 | id = None; | ||
2165 | 2150 | |||
2166 | 2151 | if (SERVERS_RANDR_IS_AT_LEAST_1_3 (priv)) { | ||
2167 | 2152 | gdk_error_trap_push (); | ||
2168 | 2153 | XRRSetOutputPrimary (priv->xdisplay, priv->xroot, id); | ||
2169 | 2154 | gdk_error_trap_pop_ignored (); | ||
2170 | 2155 | } | ||
2171 | 2156 | } | ||
2172 | 2157 | |||
2173 | 2158 | /* GnomeRRCrtc */ | ||
2174 | 2159 | typedef struct | ||
2175 | 2160 | { | ||
2176 | 2161 | Rotation xrot; | ||
2177 | 2162 | GnomeRRRotation rot; | ||
2178 | 2163 | } RotationMap; | ||
2179 | 2164 | |||
2180 | 2165 | static const RotationMap rotation_map[] = | ||
2181 | 2166 | { | ||
2182 | 2167 | { RR_Rotate_0, GNOME_RR_ROTATION_0 }, | ||
2183 | 2168 | { RR_Rotate_90, GNOME_RR_ROTATION_90 }, | ||
2184 | 2169 | { RR_Rotate_180, GNOME_RR_ROTATION_180 }, | ||
2185 | 2170 | { RR_Rotate_270, GNOME_RR_ROTATION_270 }, | ||
2186 | 2171 | { RR_Reflect_X, GNOME_RR_REFLECT_X }, | ||
2187 | 2172 | { RR_Reflect_Y, GNOME_RR_REFLECT_Y }, | ||
2188 | 2173 | }; | ||
2189 | 2174 | |||
2190 | 2175 | static GnomeRRRotation | ||
2191 | 2176 | gnome_rr_rotation_from_xrotation (Rotation r) | ||
2192 | 2177 | { | ||
2193 | 2178 | int i; | ||
2194 | 2179 | GnomeRRRotation result = 0; | ||
2195 | 2180 | |||
2196 | 2181 | for (i = 0; i < G_N_ELEMENTS (rotation_map); ++i) | ||
2197 | 2182 | { | ||
2198 | 2183 | if (r & rotation_map[i].xrot) | ||
2199 | 2184 | result |= rotation_map[i].rot; | ||
2200 | 2185 | } | ||
2201 | 2186 | |||
2202 | 2187 | return result; | ||
2203 | 2188 | } | ||
2204 | 2189 | |||
2205 | 2190 | static Rotation | ||
2206 | 2191 | xrotation_from_rotation (GnomeRRRotation r) | ||
2207 | 2192 | { | ||
2208 | 2193 | int i; | ||
2209 | 2194 | Rotation result = 0; | ||
2210 | 2195 | |||
2211 | 2196 | for (i = 0; i < G_N_ELEMENTS (rotation_map); ++i) | ||
2212 | 2197 | { | ||
2213 | 2198 | if (r & rotation_map[i].rot) | ||
2214 | 2199 | result |= rotation_map[i].xrot; | ||
2215 | 2200 | } | ||
2216 | 2201 | |||
2217 | 2202 | return result; | ||
2218 | 2203 | } | ||
2219 | 2204 | |||
2220 | 2205 | gboolean | ||
2221 | 2206 | gnome_rr_crtc_set_config_with_time (GnomeRRCrtc *crtc, | ||
2222 | 2207 | guint32 timestamp, | ||
2223 | 2208 | int x, | ||
2224 | 2209 | int y, | ||
2225 | 2210 | GnomeRRMode *mode, | ||
2226 | 2211 | GnomeRRRotation rotation, | ||
2227 | 2212 | GnomeRROutput **outputs, | ||
2228 | 2213 | int n_outputs, | ||
2229 | 2214 | GError **error) | ||
2230 | 2215 | { | ||
2231 | 2216 | ScreenInfo *info; | ||
2232 | 2217 | GArray *output_ids; | ||
2233 | 2218 | Status status; | ||
2234 | 2219 | gboolean result; | ||
2235 | 2220 | int i; | ||
2236 | 2221 | |||
2237 | 2222 | g_return_val_if_fail (crtc != NULL, FALSE); | ||
2238 | 2223 | g_return_val_if_fail (mode != NULL || outputs == NULL || n_outputs == 0, FALSE); | ||
2239 | 2224 | g_return_val_if_fail (error == NULL || *error == NULL, FALSE); | ||
2240 | 2225 | |||
2241 | 2226 | info = crtc->info; | ||
2242 | 2227 | |||
2243 | 2228 | if (mode) | ||
2244 | 2229 | { | ||
2245 | 2230 | if (x + mode->width > info->max_width | ||
2246 | 2231 | || y + mode->height > info->max_height) | ||
2247 | 2232 | { | ||
2248 | 2233 | g_set_error (error, GNOME_RR_ERROR, GNOME_RR_ERROR_BOUNDS_ERROR, | ||
2249 | 2234 | /* Translators: the "position", "size", and "maximum" | ||
2250 | 2235 | * words here are not keywords; please translate them | ||
2251 | 2236 | * as usual. A CRTC is a CRT Controller (this is X terminology) */ | ||
2252 | 2237 | _("requested position/size for CRTC %d is outside the allowed limit: " | ||
2253 | 2238 | "position=(%d, %d), size=(%d, %d), maximum=(%d, %d)"), | ||
2254 | 2239 | (int) crtc->id, | ||
2255 | 2240 | x, y, | ||
2256 | 2241 | mode->width, mode->height, | ||
2257 | 2242 | info->max_width, info->max_height); | ||
2258 | 2243 | return FALSE; | ||
2259 | 2244 | } | ||
2260 | 2245 | } | ||
2261 | 2246 | |||
2262 | 2247 | output_ids = g_array_new (FALSE, FALSE, sizeof (RROutput)); | ||
2263 | 2248 | |||
2264 | 2249 | if (outputs) | ||
2265 | 2250 | { | ||
2266 | 2251 | for (i = 0; i < n_outputs; ++i) | ||
2267 | 2252 | g_array_append_val (output_ids, outputs[i]->id); | ||
2268 | 2253 | } | ||
2269 | 2254 | |||
2270 | 2255 | gdk_error_trap_push (); | ||
2271 | 2256 | status = XRRSetCrtcConfig (DISPLAY (crtc), info->resources, crtc->id, | ||
2272 | 2257 | timestamp, | ||
2273 | 2258 | x, y, | ||
2274 | 2259 | mode ? mode->id : None, | ||
2275 | 2260 | xrotation_from_rotation (rotation), | ||
2276 | 2261 | (RROutput *)output_ids->data, | ||
2277 | 2262 | output_ids->len); | ||
2278 | 2263 | |||
2279 | 2264 | g_array_free (output_ids, TRUE); | ||
2280 | 2265 | |||
2281 | 2266 | if (gdk_error_trap_pop () || status != RRSetConfigSuccess) { | ||
2282 | 2267 | /* Translators: CRTC is a CRT Controller (this is X terminology). | ||
2283 | 2268 | * It is *very* unlikely that you'll ever get this error, so it is | ||
2284 | 2269 | * only listed for completeness. */ | ||
2285 | 2270 | g_set_error (error, GNOME_RR_ERROR, GNOME_RR_ERROR_RANDR_ERROR, | ||
2286 | 2271 | _("could not set the configuration for CRTC %d"), | ||
2287 | 2272 | (int) crtc->id); | ||
2288 | 2273 | return FALSE; | ||
2289 | 2274 | } else { | ||
2290 | 2275 | result = TRUE; | ||
2291 | 2276 | } | ||
2292 | 2277 | |||
2293 | 2278 | return result; | ||
2294 | 2279 | } | ||
2295 | 2280 | |||
2296 | 2281 | GnomeRRMode * | ||
2297 | 2282 | gnome_rr_crtc_get_current_mode (GnomeRRCrtc *crtc) | ||
2298 | 2283 | { | ||
2299 | 2284 | g_return_val_if_fail (crtc != NULL, NULL); | ||
2300 | 2285 | |||
2301 | 2286 | return crtc->current_mode; | ||
2302 | 2287 | } | ||
2303 | 2288 | |||
2304 | 2289 | guint32 | ||
2305 | 2290 | gnome_rr_crtc_get_id (GnomeRRCrtc *crtc) | ||
2306 | 2291 | { | ||
2307 | 2292 | g_return_val_if_fail (crtc != NULL, 0); | ||
2308 | 2293 | |||
2309 | 2294 | return crtc->id; | ||
2310 | 2295 | } | ||
2311 | 2296 | |||
2312 | 2297 | gboolean | ||
2313 | 2298 | gnome_rr_crtc_can_drive_output (GnomeRRCrtc *crtc, | ||
2314 | 2299 | GnomeRROutput *output) | ||
2315 | 2300 | { | ||
2316 | 2301 | int i; | ||
2317 | 2302 | |||
2318 | 2303 | g_return_val_if_fail (crtc != NULL, FALSE); | ||
2319 | 2304 | g_return_val_if_fail (output != NULL, FALSE); | ||
2320 | 2305 | |||
2321 | 2306 | for (i = 0; crtc->possible_outputs[i] != NULL; ++i) | ||
2322 | 2307 | { | ||
2323 | 2308 | if (crtc->possible_outputs[i] == output) | ||
2324 | 2309 | return TRUE; | ||
2325 | 2310 | } | ||
2326 | 2311 | |||
2327 | 2312 | return FALSE; | ||
2328 | 2313 | } | ||
2329 | 2314 | |||
2330 | 2315 | /* FIXME: merge with get_mode()? */ | ||
2331 | 2316 | /** | ||
2332 | 2317 | * gnome_rr_crtc_get_position: | ||
2333 | 2318 | * @crtc: a #GnomeRRCrtc | ||
2334 | 2319 | * @x: (out) (allow-none): | ||
2335 | 2320 | * @y: (out) (allow-none): | ||
2336 | 2321 | */ | ||
2337 | 2322 | void | ||
2338 | 2323 | gnome_rr_crtc_get_position (GnomeRRCrtc *crtc, | ||
2339 | 2324 | int *x, | ||
2340 | 2325 | int *y) | ||
2341 | 2326 | { | ||
2342 | 2327 | g_return_if_fail (crtc != NULL); | ||
2343 | 2328 | |||
2344 | 2329 | if (x) | ||
2345 | 2330 | *x = crtc->x; | ||
2346 | 2331 | |||
2347 | 2332 | if (y) | ||
2348 | 2333 | *y = crtc->y; | ||
2349 | 2334 | } | ||
2350 | 2335 | |||
2351 | 2336 | /* FIXME: merge with get_mode()? */ | ||
2352 | 2337 | GnomeRRRotation | ||
2353 | 2338 | gnome_rr_crtc_get_current_rotation (GnomeRRCrtc *crtc) | ||
2354 | 2339 | { | ||
2355 | 2340 | g_assert(crtc != NULL); | ||
2356 | 2341 | return crtc->current_rotation; | ||
2357 | 2342 | } | ||
2358 | 2343 | |||
2359 | 2344 | GnomeRRRotation | ||
2360 | 2345 | gnome_rr_crtc_get_rotations (GnomeRRCrtc *crtc) | ||
2361 | 2346 | { | ||
2362 | 2347 | g_assert(crtc != NULL); | ||
2363 | 2348 | return crtc->rotations; | ||
2364 | 2349 | } | ||
2365 | 2350 | |||
2366 | 2351 | gboolean | ||
2367 | 2352 | gnome_rr_crtc_supports_rotation (GnomeRRCrtc * crtc, | ||
2368 | 2353 | GnomeRRRotation rotation) | ||
2369 | 2354 | { | ||
2370 | 2355 | g_return_val_if_fail (crtc != NULL, FALSE); | ||
2371 | 2356 | return (crtc->rotations & rotation); | ||
2372 | 2357 | } | ||
2373 | 2358 | |||
2374 | 2359 | static GnomeRRCrtc * | ||
2375 | 2360 | crtc_new (ScreenInfo *info, RROutput id) | ||
2376 | 2361 | { | ||
2377 | 2362 | GnomeRRCrtc *crtc = g_slice_new0 (GnomeRRCrtc); | ||
2378 | 2363 | |||
2379 | 2364 | crtc->id = id; | ||
2380 | 2365 | crtc->info = info; | ||
2381 | 2366 | |||
2382 | 2367 | return crtc; | ||
2383 | 2368 | } | ||
2384 | 2369 | |||
2385 | 2370 | static GnomeRRCrtc * | ||
2386 | 2371 | crtc_copy (const GnomeRRCrtc *from) | ||
2387 | 2372 | { | ||
2388 | 2373 | GnomeRROutput **p_output; | ||
2389 | 2374 | GPtrArray *array; | ||
2390 | 2375 | GnomeRRCrtc *to = g_slice_new0 (GnomeRRCrtc); | ||
2391 | 2376 | |||
2392 | 2377 | to->info = from->info; | ||
2393 | 2378 | to->id = from->id; | ||
2394 | 2379 | to->current_mode = from->current_mode; | ||
2395 | 2380 | to->x = from->x; | ||
2396 | 2381 | to->y = from->y; | ||
2397 | 2382 | to->current_rotation = from->current_rotation; | ||
2398 | 2383 | to->rotations = from->rotations; | ||
2399 | 2384 | to->gamma_size = from->gamma_size; | ||
2400 | 2385 | |||
2401 | 2386 | array = g_ptr_array_new (); | ||
2402 | 2387 | for (p_output = from->current_outputs; *p_output != NULL; p_output++) | ||
2403 | 2388 | { | ||
2404 | 2389 | g_ptr_array_add (array, *p_output); | ||
2405 | 2390 | } | ||
2406 | 2391 | to->current_outputs = (GnomeRROutput**) g_ptr_array_free (array, FALSE); | ||
2407 | 2392 | |||
2408 | 2393 | array = g_ptr_array_new (); | ||
2409 | 2394 | for (p_output = from->possible_outputs; *p_output != NULL; p_output++) | ||
2410 | 2395 | { | ||
2411 | 2396 | g_ptr_array_add (array, *p_output); | ||
2412 | 2397 | } | ||
2413 | 2398 | to->possible_outputs = (GnomeRROutput**) g_ptr_array_free (array, FALSE); | ||
2414 | 2399 | |||
2415 | 2400 | return to; | ||
2416 | 2401 | } | ||
2417 | 2402 | |||
2418 | 2403 | static gboolean | ||
2419 | 2404 | crtc_initialize (GnomeRRCrtc *crtc, | ||
2420 | 2405 | XRRScreenResources *res, | ||
2421 | 2406 | GError **error) | ||
2422 | 2407 | { | ||
2423 | 2408 | XRRCrtcInfo *info = XRRGetCrtcInfo (DISPLAY (crtc), res, crtc->id); | ||
2424 | 2409 | GPtrArray *a; | ||
2425 | 2410 | int i; | ||
2426 | 2411 | |||
2427 | 2412 | #if 0 | ||
2428 | 2413 | g_print ("CRTC %lx Timestamp: %u\n", crtc->id, (guint32)info->timestamp); | ||
2429 | 2414 | #endif | ||
2430 | 2415 | |||
2431 | 2416 | if (!info) | ||
2432 | 2417 | { | ||
2433 | 2418 | /* FIXME: We need to reaquire the screen resources */ | ||
2434 | 2419 | /* FIXME: can we actually catch BadRRCrtc, and does it make sense to emit that? */ | ||
2435 | 2420 | |||
2436 | 2421 | /* Translators: CRTC is a CRT Controller (this is X terminology). | ||
2437 | 2422 | * It is *very* unlikely that you'll ever get this error, so it is | ||
2438 | 2423 | * only listed for completeness. */ | ||
2439 | 2424 | g_set_error (error, GNOME_RR_ERROR, GNOME_RR_ERROR_RANDR_ERROR, | ||
2440 | 2425 | _("could not get information about CRTC %d"), | ||
2441 | 2426 | (int) crtc->id); | ||
2442 | 2427 | return FALSE; | ||
2443 | 2428 | } | ||
2444 | 2429 | |||
2445 | 2430 | /* GnomeRRMode */ | ||
2446 | 2431 | crtc->current_mode = mode_by_id (crtc->info, info->mode); | ||
2447 | 2432 | |||
2448 | 2433 | crtc->x = info->x; | ||
2449 | 2434 | crtc->y = info->y; | ||
2450 | 2435 | |||
2451 | 2436 | /* Current outputs */ | ||
2452 | 2437 | a = g_ptr_array_new (); | ||
2453 | 2438 | for (i = 0; i < info->noutput; ++i) | ||
2454 | 2439 | { | ||
2455 | 2440 | GnomeRROutput *output = gnome_rr_output_by_id (crtc->info, info->outputs[i]); | ||
2456 | 2441 | |||
2457 | 2442 | if (output) | ||
2458 | 2443 | g_ptr_array_add (a, output); | ||
2459 | 2444 | } | ||
2460 | 2445 | g_ptr_array_add (a, NULL); | ||
2461 | 2446 | crtc->current_outputs = (GnomeRROutput **)g_ptr_array_free (a, FALSE); | ||
2462 | 2447 | |||
2463 | 2448 | /* Possible outputs */ | ||
2464 | 2449 | a = g_ptr_array_new (); | ||
2465 | 2450 | for (i = 0; i < info->npossible; ++i) | ||
2466 | 2451 | { | ||
2467 | 2452 | GnomeRROutput *output = gnome_rr_output_by_id (crtc->info, info->possible[i]); | ||
2468 | 2453 | |||
2469 | 2454 | if (output) | ||
2470 | 2455 | g_ptr_array_add (a, output); | ||
2471 | 2456 | } | ||
2472 | 2457 | g_ptr_array_add (a, NULL); | ||
2473 | 2458 | crtc->possible_outputs = (GnomeRROutput **)g_ptr_array_free (a, FALSE); | ||
2474 | 2459 | |||
2475 | 2460 | /* Rotations */ | ||
2476 | 2461 | crtc->current_rotation = gnome_rr_rotation_from_xrotation (info->rotation); | ||
2477 | 2462 | crtc->rotations = gnome_rr_rotation_from_xrotation (info->rotations); | ||
2478 | 2463 | |||
2479 | 2464 | XRRFreeCrtcInfo (info); | ||
2480 | 2465 | |||
2481 | 2466 | /* get an store gamma size */ | ||
2482 | 2467 | crtc->gamma_size = XRRGetCrtcGammaSize (DISPLAY (crtc), crtc->id); | ||
2483 | 2468 | |||
2484 | 2469 | return TRUE; | ||
2485 | 2470 | } | ||
2486 | 2471 | |||
2487 | 2472 | static void | ||
2488 | 2473 | crtc_free (GnomeRRCrtc *crtc) | ||
2489 | 2474 | { | ||
2490 | 2475 | g_free (crtc->current_outputs); | ||
2491 | 2476 | g_free (crtc->possible_outputs); | ||
2492 | 2477 | g_slice_free (GnomeRRCrtc, crtc); | ||
2493 | 2478 | } | ||
2494 | 2479 | |||
2495 | 2480 | /* GnomeRRMode */ | ||
2496 | 2481 | static GnomeRRMode * | ||
2497 | 2482 | mode_new (ScreenInfo *info, RRMode id) | ||
2498 | 2483 | { | ||
2499 | 2484 | GnomeRRMode *mode = g_slice_new0 (GnomeRRMode); | ||
2500 | 2485 | |||
2501 | 2486 | mode->id = id; | ||
2502 | 2487 | mode->info = info; | ||
2503 | 2488 | |||
2504 | 2489 | return mode; | ||
2505 | 2490 | } | ||
2506 | 2491 | |||
2507 | 2492 | guint32 | ||
2508 | 2493 | gnome_rr_mode_get_id (GnomeRRMode *mode) | ||
2509 | 2494 | { | ||
2510 | 2495 | g_return_val_if_fail (mode != NULL, 0); | ||
2511 | 2496 | return mode->id; | ||
2512 | 2497 | } | ||
2513 | 2498 | |||
2514 | 2499 | guint | ||
2515 | 2500 | gnome_rr_mode_get_width (GnomeRRMode *mode) | ||
2516 | 2501 | { | ||
2517 | 2502 | g_return_val_if_fail (mode != NULL, 0); | ||
2518 | 2503 | return mode->width; | ||
2519 | 2504 | } | ||
2520 | 2505 | |||
2521 | 2506 | int | ||
2522 | 2507 | gnome_rr_mode_get_freq (GnomeRRMode *mode) | ||
2523 | 2508 | { | ||
2524 | 2509 | g_return_val_if_fail (mode != NULL, 0); | ||
2525 | 2510 | return (mode->freq) / 1000; | ||
2526 | 2511 | } | ||
2527 | 2512 | |||
2528 | 2513 | guint | ||
2529 | 2514 | gnome_rr_mode_get_height (GnomeRRMode *mode) | ||
2530 | 2515 | { | ||
2531 | 2516 | g_return_val_if_fail (mode != NULL, 0); | ||
2532 | 2517 | return mode->height; | ||
2533 | 2518 | } | ||
2534 | 2519 | |||
2535 | 2520 | static void | ||
2536 | 2521 | mode_initialize (GnomeRRMode *mode, XRRModeInfo *info) | ||
2537 | 2522 | { | ||
2538 | 2523 | g_assert (mode != NULL); | ||
2539 | 2524 | g_assert (info != NULL); | ||
2540 | 2525 | |||
2541 | 2526 | mode->name = g_strdup (info->name); | ||
2542 | 2527 | mode->width = info->width; | ||
2543 | 2528 | mode->height = info->height; | ||
2544 | 2529 | mode->freq = ((info->dotClock / (double)info->hTotal) / info->vTotal + 0.5) * 1000; | ||
2545 | 2530 | } | ||
2546 | 2531 | |||
2547 | 2532 | static GnomeRRMode * | ||
2548 | 2533 | mode_copy (const GnomeRRMode *from) | ||
2549 | 2534 | { | ||
2550 | 2535 | GnomeRRMode *to = g_slice_new0 (GnomeRRMode); | ||
2551 | 2536 | |||
2552 | 2537 | to->id = from->id; | ||
2553 | 2538 | to->info = from->info; | ||
2554 | 2539 | to->name = g_strdup (from->name); | ||
2555 | 2540 | to->width = from->width; | ||
2556 | 2541 | to->height = from->height; | ||
2557 | 2542 | to->freq = from->freq; | ||
2558 | 2543 | |||
2559 | 2544 | return to; | ||
2560 | 2545 | } | ||
2561 | 2546 | |||
2562 | 2547 | static void | ||
2563 | 2548 | mode_free (GnomeRRMode *mode) | ||
2564 | 2549 | { | ||
2565 | 2550 | g_free (mode->name); | ||
2566 | 2551 | g_slice_free (GnomeRRMode, mode); | ||
2567 | 2552 | } | ||
2568 | 2553 | |||
2569 | 2554 | void | ||
2570 | 2555 | gnome_rr_crtc_set_gamma (GnomeRRCrtc *crtc, int size, | ||
2571 | 2556 | unsigned short *red, | ||
2572 | 2557 | unsigned short *green, | ||
2573 | 2558 | unsigned short *blue) | ||
2574 | 2559 | { | ||
2575 | 2560 | int copy_size; | ||
2576 | 2561 | XRRCrtcGamma *gamma; | ||
2577 | 2562 | |||
2578 | 2563 | g_return_if_fail (crtc != NULL); | ||
2579 | 2564 | g_return_if_fail (red != NULL); | ||
2580 | 2565 | g_return_if_fail (green != NULL); | ||
2581 | 2566 | g_return_if_fail (blue != NULL); | ||
2582 | 2567 | |||
2583 | 2568 | if (size != crtc->gamma_size) | ||
2584 | 2569 | return; | ||
2585 | 2570 | |||
2586 | 2571 | gamma = XRRAllocGamma (crtc->gamma_size); | ||
2587 | 2572 | |||
2588 | 2573 | copy_size = crtc->gamma_size * sizeof (unsigned short); | ||
2589 | 2574 | memcpy (gamma->red, red, copy_size); | ||
2590 | 2575 | memcpy (gamma->green, green, copy_size); | ||
2591 | 2576 | memcpy (gamma->blue, blue, copy_size); | ||
2592 | 2577 | |||
2593 | 2578 | XRRSetCrtcGamma (DISPLAY (crtc), crtc->id, gamma); | ||
2594 | 2579 | XRRFreeGamma (gamma); | ||
2595 | 2580 | } | ||
2596 | 2581 | |||
2597 | 2582 | gboolean | ||
2598 | 2583 | gnome_rr_crtc_get_gamma (GnomeRRCrtc *crtc, int *size, | ||
2599 | 2584 | unsigned short **red, unsigned short **green, | ||
2600 | 2585 | unsigned short **blue) | ||
2601 | 2586 | { | ||
2602 | 2587 | int copy_size; | ||
2603 | 2588 | unsigned short *r, *g, *b; | ||
2604 | 2589 | XRRCrtcGamma *gamma; | ||
2605 | 2590 | |||
2606 | 2591 | g_return_val_if_fail (crtc != NULL, FALSE); | ||
2607 | 2592 | |||
2608 | 2593 | gamma = XRRGetCrtcGamma (DISPLAY (crtc), crtc->id); | ||
2609 | 2594 | if (!gamma) | ||
2610 | 2595 | return FALSE; | ||
2611 | 2596 | |||
2612 | 2597 | copy_size = crtc->gamma_size * sizeof (unsigned short); | ||
2613 | 2598 | |||
2614 | 2599 | if (red) { | ||
2615 | 2600 | r = g_new0 (unsigned short, crtc->gamma_size); | ||
2616 | 2601 | memcpy (r, gamma->red, copy_size); | ||
2617 | 2602 | *red = r; | ||
2618 | 2603 | } | ||
2619 | 2604 | |||
2620 | 2605 | if (green) { | ||
2621 | 2606 | g = g_new0 (unsigned short, crtc->gamma_size); | ||
2622 | 2607 | memcpy (g, gamma->green, copy_size); | ||
2623 | 2608 | *green = g; | ||
2624 | 2609 | } | ||
2625 | 2610 | |||
2626 | 2611 | if (blue) { | ||
2627 | 2612 | b = g_new0 (unsigned short, crtc->gamma_size); | ||
2628 | 2613 | memcpy (b, gamma->blue, copy_size); | ||
2629 | 2614 | *blue = b; | ||
2630 | 2615 | } | ||
2631 | 2616 | |||
2632 | 2617 | XRRFreeGamma (gamma); | ||
2633 | 2618 | |||
2634 | 2619 | if (size) | ||
2635 | 2620 | *size = crtc->gamma_size; | ||
2636 | 2621 | |||
2637 | 2622 | return TRUE; | ||
2638 | 2623 | } | ||
2639 | 2624 | |||
2640 | 0 | 2625 | ||
2641 | === modified file 'debian/changelog' | |||
2642 | --- debian/changelog 2015-03-31 10:59:01 +0000 | |||
2643 | +++ debian/changelog 2015-11-20 08:10:07 +0000 | |||
2644 | @@ -1,3 +1,10 @@ | |||
2645 | 1 | gnome-desktop3 (3.8.4-0ubuntu3.2) trusty-proposed; urgency=medium | ||
2646 | 2 | |||
2647 | 3 | * Apply the similar method from the power plugin in unity-settings-daemon to | ||
2648 | 4 | fix the lowest brightness issue. (LP: #1381625) | ||
2649 | 5 | |||
2650 | 6 | -- Shih-Yuan Lee (FourDollars) <sylee@canonical.com> Fri, 20 Nov 2015 15:35:36 +0800 | ||
2651 | 7 | |||
2652 | 1 | gnome-desktop3 (3.8.4-0ubuntu3.1) trusty; urgency=medium | 8 | gnome-desktop3 (3.8.4-0ubuntu3.1) trusty; urgency=medium |
2653 | 2 | 9 | ||
2654 | 3 | * debian/patches/idletime_sanity_checks.patch: Ensure the argument to | 10 | * debian/patches/idletime_sanity_checks.patch: Ensure the argument to |
2655 | 4 | 11 | ||
2656 | === added file 'debian/patches/fix_lowest_brightness.patch' | |||
2657 | --- debian/patches/fix_lowest_brightness.patch 1970-01-01 00:00:00 +0000 | |||
2658 | +++ debian/patches/fix_lowest_brightness.patch 2015-11-20 08:10:07 +0000 | |||
2659 | @@ -0,0 +1,21 @@ | |||
2660 | 1 | Description: Apply the similar method to fix the lowest brightness issue. (LP: #1381625) | ||
2661 | 2 | Author: Shih-Yuan Lee (FourDollars) <sylee@canonical.com> | ||
2662 | 3 | Bug: https://bugs.launchpad.net/bugs/1381625 | ||
2663 | 4 | --- | ||
2664 | 5 | This patch header follows DEP-3: http://dep.debian.net/deps/dep3/ | ||
2665 | 6 | Index: trusty/libgnome-desktop/gnome-rr.c | ||
2666 | 7 | =================================================================== | ||
2667 | 8 | --- trusty.orig/libgnome-desktop/gnome-rr.c 2015-11-20 15:20:59.316229000 +0800 | ||
2668 | 9 | +++ trusty/libgnome-desktop/gnome-rr.c 2015-11-20 15:30:13.759172830 +0800 | ||
2669 | 10 | @@ -1553,6 +1553,11 @@ | ||
2670 | 11 | } | ||
2671 | 12 | output->backlight_min = info->values[0]; | ||
2672 | 13 | output->backlight_max = info->values[1]; | ||
2673 | 14 | + /* If the interface has more than 99 possible values, it's | ||
2674 | 15 | + * * likely that 0 turns the backlight off so we let 1 be | ||
2675 | 16 | + * * set in that case. */ | ||
2676 | 17 | + if (output->backlight_max > 99 && output->backlight_min == 0) | ||
2677 | 18 | + output->backlight_min = 1; | ||
2678 | 19 | out: | ||
2679 | 20 | if (info != NULL) | ||
2680 | 21 | { | ||
2681 | 0 | 22 | ||
2682 | === modified file 'debian/patches/series' | |||
2683 | --- debian/patches/series 2015-03-31 10:59:01 +0000 | |||
2684 | +++ debian/patches/series 2015-11-20 08:10:07 +0000 | |||
2685 | @@ -9,3 +9,4 @@ | |||
2686 | 9 | ignore_errors_with_primary_outputs.patch | 9 | ignore_errors_with_primary_outputs.patch |
2687 | 10 | backlight-property-name.patch | 10 | backlight-property-name.patch |
2688 | 11 | idletime_sanity_checks.patch | 11 | idletime_sanity_checks.patch |
2689 | 12 | fix_lowest_brightness.patch | ||
2690 | 12 | 13 | ||
2691 | === modified file 'libgnome-desktop/gnome-rr.c' | |||
2692 | --- libgnome-desktop/gnome-rr.c 2014-03-17 17:28:55 +0000 | |||
2693 | +++ libgnome-desktop/gnome-rr.c 2015-11-20 08:10:07 +0000 | |||
2694 | @@ -1553,6 +1553,11 @@ | |||
2695 | 1553 | } | 1553 | } |
2696 | 1554 | output->backlight_min = info->values[0]; | 1554 | output->backlight_min = info->values[0]; |
2697 | 1555 | output->backlight_max = info->values[1]; | 1555 | output->backlight_max = info->values[1]; |
2698 | 1556 | /* If the interface has more than 99 possible values, it's | ||
2699 | 1557 | * * likely that 0 turns the backlight off so we let 1 be | ||
2700 | 1558 | * * set in that case. */ | ||
2701 | 1559 | if (output->backlight_max > 99 && output->backlight_min == 0) | ||
2702 | 1560 | output->backlight_min = 1; | ||
2703 | 1556 | out: | 1561 | out: |
2704 | 1557 | if (info != NULL) | 1562 | if (info != NULL) |
2705 | 1558 | { | 1563 | { |
Uploaded. I didn't merge this into bzr, just grabbed the diff, so closing this manually. Further tracking happens in the SRU bug.
Thank you!