Merge lp:~robert-ancell/unity-control-center/xrandr into lp:unity-control-center
- xrandr
- Merge into trunk
Status: | Rejected |
---|---|
Rejected by: | Robert Ancell |
Proposed branch: | lp:~robert-ancell/unity-control-center/xrandr |
Merge into: | lp:unity-control-center |
Diff against target: |
8940 lines (+7146/-344) 22 files modified
configure.ac (+4/-0) debian/unity-control-center.install (+1/-0) panels/common/Makefile.am (+29/-1) panels/common/cc-pnp-ids.c (+341/-0) panels/common/cc-pnp-ids.h (+58/-0) panels/common/cc-rr-config.c (+2091/-0) panels/common/cc-rr-config.h (+151/-0) panels/common/cc-rr-output-info.c (+242/-0) panels/common/cc-rr-private.h (+79/-0) panels/common/cc-rr.c (+2622/-0) panels/common/cc-rr.h (+222/-0) panels/common/check_gl_texture_size.c (+86/-0) panels/common/display-name.c (+144/-0) panels/common/edid-parse.c (+540/-0) panels/common/edid.h (+195/-0) panels/display/Makefile.am (+3/-2) panels/display/cc-display-panel.c (+232/-233) panels/display/cc-rr-labeler.c (+19/-19) panels/display/cc-rr-labeler.h (+3/-4) panels/wacom/Makefile.am (+3/-2) panels/wacom/cc-wacom-mapping-panel.c (+14/-15) panels/wacom/gsd-wacom-device.c (+67/-68) |
To merge this branch: | bzr merge lp:~robert-ancell/unity-control-center/xrandr |
Related bugs: |
Reviewer | Review Type | Date Requested | Status |
---|---|---|---|
PS Jenkins bot (community) | continuous-integration | Approve | |
Unity Control Center development team | Pending | ||
Review via email: mp+224547@code.launchpad.net |
Commit message
Move libgnome-desktop RandR code into u-c-c since newer versions remove this unstable API
Description of the change
PS Jenkins bot (ps-jenkins) wrote : | # |
Robert Ancell (robert-ancell) wrote : | # |
See lp:~robert-ancell/unity-settings-daemon/xrandr for associated u-s-d MP.
Sebastien Bacher (seb128) wrote : | # |
That's quite some changes to review, but mostly a copy of existing code, not I don't think it needs a detailled code review. The changes look fine to me on principle but we should give that a proper round of testing, including multimonitor setups and screensaver/idle usecases
Tim Lunn (darkxst) wrote : | # |
This lgtm, lots of cut+paste and a bit of renaming, don't think it will cause any issues
Robert Ancell (robert-ancell) wrote : | # |
This is obsolete and replaced by https:/
Unmerged revisions
- 12784. By Robert Ancell
-
install check_gl_
texture_ size - 12783. By Robert Ancell
-
Fix some renaming
- 12782. By Robert Ancell
-
Move libgnome-desktop RandR code into u-s-c since newer versions remove this unstable API
Preview Diff
1 | === modified file 'configure.ac' | |||
2 | --- configure.ac 2014-02-26 20:00:59 +0000 | |||
3 | +++ configure.ac 2014-06-26 03:13:28 +0000 | |||
4 | @@ -104,6 +104,8 @@ | |||
5 | 104 | CLUTTER_REQUIRED_VERSION=1.11.3 | 104 | CLUTTER_REQUIRED_VERSION=1.11.3 |
6 | 105 | GOA_REQUIRED_VERSION=3.5.90 | 105 | GOA_REQUIRED_VERSION=3.5.90 |
7 | 106 | ACCOUNTSSERVICE_REQUIRED_VERSION=0.6.30 | 106 | ACCOUNTSSERVICE_REQUIRED_VERSION=0.6.30 |
8 | 107 | XRANDR_REQUIRED=1.3 | ||
9 | 108 | XEXT_REQUIRED=1.1 | ||
10 | 107 | 109 | ||
11 | 108 | COMMON_MODULES="gtk+-3.0 >= $GTK_REQUIRED_VERSION | 110 | COMMON_MODULES="gtk+-3.0 >= $GTK_REQUIRED_VERSION |
12 | 109 | glib-2.0 >= $GLIB_REQUIRED_VERSION | 111 | glib-2.0 >= $GLIB_REQUIRED_VERSION |
13 | @@ -115,6 +117,8 @@ | |||
14 | 115 | 117 | ||
15 | 116 | PKG_CHECK_MODULES(LIBUNITY_CONTROL_CENTER, $COMMON_MODULES) | 118 | PKG_CHECK_MODULES(LIBUNITY_CONTROL_CENTER, $COMMON_MODULES) |
16 | 117 | PKG_CHECK_MODULES(LIBLANGUAGE, $COMMON_MODULES gnome-desktop-3.0 fontconfig) | 119 | PKG_CHECK_MODULES(LIBLANGUAGE, $COMMON_MODULES gnome-desktop-3.0 fontconfig) |
17 | 120 | PKG_CHECK_MODULES(LIBRR, $COMMON_MODULES xrandr >= $XRANDR_REQUIRED xext >= $XEXT_REQUIRED) | ||
18 | 121 | PKG_CHECK_MODULES(CHECK_GL_TEXTURE_SIZE, gl x11) | ||
19 | 118 | PKG_CHECK_MODULES(LIBSHORTCUTS, $COMMON_MODULES x11) | 122 | PKG_CHECK_MODULES(LIBSHORTCUTS, $COMMON_MODULES x11) |
20 | 119 | PKG_CHECK_MODULES(SHELL, $COMMON_MODULES libgnome-menu-3.0 gio-unix-2.0 x11) | 123 | PKG_CHECK_MODULES(SHELL, $COMMON_MODULES libgnome-menu-3.0 gio-unix-2.0 x11) |
21 | 120 | PKG_CHECK_MODULES(APPEARANCE_PANEL, $COMMON_MODULES libxml-2.0 gnome-desktop-3.0 | 124 | PKG_CHECK_MODULES(APPEARANCE_PANEL, $COMMON_MODULES libxml-2.0 gnome-desktop-3.0 |
22 | 121 | 125 | ||
23 | === modified file 'debian/unity-control-center.install' | |||
24 | --- debian/unity-control-center.install 2014-02-24 17:28:38 +0000 | |||
25 | +++ debian/unity-control-center.install 2014-06-26 03:13:28 +0000 | |||
26 | @@ -1,5 +1,6 @@ | |||
27 | 1 | etc/xdg/menus | 1 | etc/xdg/menus |
28 | 2 | usr/bin | 2 | usr/bin |
29 | 3 | usr/lib/unity-control-center | ||
30 | 3 | usr/lib/*/unity-control-center-1/panels/*.so | 4 | usr/lib/*/unity-control-center-1/panels/*.so |
31 | 4 | usr/share/applications | 5 | usr/share/applications |
32 | 5 | usr/share/bash-completion | 6 | usr/share/bash-completion |
33 | 6 | 7 | ||
34 | === modified file 'panels/common/Makefile.am' | |||
35 | --- panels/common/Makefile.am 2013-11-29 06:28:37 +0000 | |||
36 | +++ panels/common/Makefile.am 2014-06-26 03:13:28 +0000 | |||
37 | @@ -1,14 +1,17 @@ | |||
38 | 1 | # This is used in PANEL_CFLAGS | 1 | # This is used in PANEL_CFLAGS |
39 | 2 | cappletname = common | 2 | cappletname = common |
40 | 3 | 3 | ||
42 | 4 | noinst_LTLIBRARIES = liblanguage.la | 4 | noinst_LTLIBRARIES = liblanguage.la librr.la |
43 | 5 | noinst_PROGRAMS = list-languages | 5 | noinst_PROGRAMS = list-languages |
44 | 6 | libexec_PROGRAMS = check_gl_texture_size | ||
45 | 6 | 7 | ||
46 | 7 | AM_CPPFLAGS = \ | 8 | AM_CPPFLAGS = \ |
47 | 8 | $(PANEL_CFLAGS) \ | 9 | $(PANEL_CFLAGS) \ |
48 | 9 | $(LIBLANGUAGE_CFLAGS) \ | 10 | $(LIBLANGUAGE_CFLAGS) \ |
49 | 10 | -DDATADIR=\""$(datadir)"\" \ | 11 | -DDATADIR=\""$(datadir)"\" \ |
50 | 12 | -DLIBEXECDIR=\""$(libexecdir)\"" \ | ||
51 | 11 | -DUIDIR=\""$(pkgdatadir)/ui"\" \ | 13 | -DUIDIR=\""$(pkgdatadir)/ui"\" \ |
52 | 14 | -DPNP_IDS=\""$(datadir)/hwdata/pnp.ids"\" \ | ||
53 | 12 | -DLIBLOCALEDIR=\""$(prefix)/lib/locale"\" \ | 15 | -DLIBLOCALEDIR=\""$(prefix)/lib/locale"\" \ |
54 | 13 | -DGNOMELOCALEDIR=\""$(datadir)/locale"\" \ | 16 | -DGNOMELOCALEDIR=\""$(datadir)/locale"\" \ |
55 | 14 | -DUM_PIXMAP_DIR=\""$(pkgdatadir)/pixmaps"\" | 17 | -DUM_PIXMAP_DIR=\""$(pkgdatadir)/pixmaps"\" |
56 | @@ -32,6 +35,31 @@ | |||
57 | 32 | list_languages_LDADD = liblanguage.la | 35 | list_languages_LDADD = liblanguage.la |
58 | 33 | list_languages_CFLAGS = $(LIBLANGUAGE_CFLAGS) | 36 | list_languages_CFLAGS = $(LIBLANGUAGE_CFLAGS) |
59 | 34 | 37 | ||
60 | 38 | librr_la_SOURCES = \ | ||
61 | 39 | cc-pnp-ids.c \ | ||
62 | 40 | cc-pnp-ids.h \ | ||
63 | 41 | cc-rr.c \ | ||
64 | 42 | cc-rr.h \ | ||
65 | 43 | cc-rr-config.c \ | ||
66 | 44 | cc-rr-config.h \ | ||
67 | 45 | cc-rr-output-info.c \ | ||
68 | 46 | cc-rr-private.h \ | ||
69 | 47 | display-name.c \ | ||
70 | 48 | edid-parse.c \ | ||
71 | 49 | edid.h | ||
72 | 50 | |||
73 | 51 | librr_la_LIBADD = \ | ||
74 | 52 | $(PANEL_LIBS) \ | ||
75 | 53 | $(LIBRR_LIBS) | ||
76 | 54 | |||
77 | 55 | librr_la_LDFLAGS = $(PANEL_LDFLAGS) | ||
78 | 56 | |||
79 | 57 | check_gl_texture_size_CPPFLAGS = \ | ||
80 | 58 | $(CHECK_GL_TEXTURE_SIZE_CFLAGS) | ||
81 | 59 | |||
82 | 60 | check_gl_texture_size_LDADD = \ | ||
83 | 61 | $(CHECK_GL_TEXTURE_SIZE_LIBS) | ||
84 | 62 | |||
85 | 35 | uidir = $(pkgdatadir)/ui | 63 | uidir = $(pkgdatadir)/ui |
86 | 36 | 64 | ||
87 | 37 | dist_ui_DATA = \ | 65 | dist_ui_DATA = \ |
88 | 38 | 66 | ||
89 | === added file 'panels/common/cc-pnp-ids.c' | |||
90 | --- panels/common/cc-pnp-ids.c 1970-01-01 00:00:00 +0000 | |||
91 | +++ panels/common/cc-pnp-ids.c 2014-06-26 03:13:28 +0000 | |||
92 | @@ -0,0 +1,341 @@ | |||
93 | 1 | /* -*- Mode: C; tab-width: 8; indent-tabs-mode: t; c-basic-offset: 8 -*- | ||
94 | 2 | * | ||
95 | 3 | * Copyright (C) 2009-2011 Richard Hughes <richard@hughsie.com> | ||
96 | 4 | * | ||
97 | 5 | * This program is free software; you can redistribute it and/or modify | ||
98 | 6 | * it under the terms of the GNU General Public License as published by | ||
99 | 7 | * the Free Software Foundation; either version 2 of the License, or | ||
100 | 8 | * (at your option) any later version. | ||
101 | 9 | * | ||
102 | 10 | * This program is distributed in the hope that it will be useful, | ||
103 | 11 | * but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
104 | 12 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
105 | 13 | * GNU General Public License for more details. | ||
106 | 14 | * | ||
107 | 15 | * You should have received a copy of the GNU General Public License | ||
108 | 16 | * along with this program; if not, write to the Free Software | ||
109 | 17 | * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. | ||
110 | 18 | */ | ||
111 | 19 | |||
112 | 20 | #include "config.h" | ||
113 | 21 | |||
114 | 22 | #include <glib-object.h> | ||
115 | 23 | |||
116 | 24 | #include <cc-pnp-ids.h> | ||
117 | 25 | |||
118 | 26 | static void cc_pnp_ids_finalize (GObject *object); | ||
119 | 27 | |||
120 | 28 | #define CC_PNP_IDS_GET_PRIVATE(o) (G_TYPE_INSTANCE_GET_PRIVATE ((o), CC_TYPE_PNP_IDS, CCPnpIdsPrivate)) | ||
121 | 29 | |||
122 | 30 | struct _CCPnpIdsPrivate | ||
123 | 31 | { | ||
124 | 32 | gchar *table_data; | ||
125 | 33 | GHashTable *pnp_table; | ||
126 | 34 | }; | ||
127 | 35 | |||
128 | 36 | static gpointer cc_pnp_ids_object = NULL; | ||
129 | 37 | |||
130 | 38 | G_DEFINE_TYPE (CCPnpIds, cc_pnp_ids, G_TYPE_OBJECT) | ||
131 | 39 | |||
132 | 40 | typedef struct Vendor Vendor; | ||
133 | 41 | struct Vendor | ||
134 | 42 | { | ||
135 | 43 | const char vendor_id[4]; | ||
136 | 44 | const char vendor_name[28]; | ||
137 | 45 | }; | ||
138 | 46 | |||
139 | 47 | /* This list of vendor codes derived from lshw | ||
140 | 48 | * | ||
141 | 49 | * http://ezix.org/project/wiki/HardwareLiSter | ||
142 | 50 | * | ||
143 | 51 | * Note: we now prefer to use data coming from hwdata (and shipped with | ||
144 | 52 | * gnome-desktop). See | ||
145 | 53 | * http://git.fedorahosted.org/git/?p=hwdata.git;a=blob_plain;f=pnp.ids;hb=HEAD | ||
146 | 54 | * All contributions to the list of vendors should go there. | ||
147 | 55 | */ | ||
148 | 56 | static const struct Vendor vendors[] = | ||
149 | 57 | { | ||
150 | 58 | { "AIC", "AG Neovo" }, | ||
151 | 59 | { "ACR", "Acer" }, | ||
152 | 60 | { "DEL", "DELL" }, | ||
153 | 61 | { "SAM", "SAMSUNG" }, | ||
154 | 62 | { "SNY", "SONY" }, | ||
155 | 63 | { "SEC", "Epson" }, | ||
156 | 64 | { "WAC", "Wacom" }, | ||
157 | 65 | { "NEC", "NEC" }, | ||
158 | 66 | { "CMO", "CMO" }, /* Chi Mei */ | ||
159 | 67 | { "BNQ", "BenQ" }, | ||
160 | 68 | |||
161 | 69 | { "ABP", "Advansys" }, | ||
162 | 70 | { "ACC", "Accton" }, | ||
163 | 71 | { "ACE", "Accton" }, | ||
164 | 72 | { "ADP", "Adaptec" }, | ||
165 | 73 | { "ADV", "AMD" }, | ||
166 | 74 | { "AIR", "AIR" }, | ||
167 | 75 | { "AMI", "AMI" }, | ||
168 | 76 | { "ASU", "ASUS" }, | ||
169 | 77 | { "ATI", "ATI" }, | ||
170 | 78 | { "ATK", "Allied Telesyn" }, | ||
171 | 79 | { "AZT", "Aztech" }, | ||
172 | 80 | { "BAN", "Banya" }, | ||
173 | 81 | { "BRI", "Boca Research" }, | ||
174 | 82 | { "BUS", "Buslogic" }, | ||
175 | 83 | { "CCI", "Cache Computers Inc." }, | ||
176 | 84 | { "CHA", "Chase" }, | ||
177 | 85 | { "CMD", "CMD Technology, Inc." }, | ||
178 | 86 | { "COG", "Cogent" }, | ||
179 | 87 | { "CPQ", "Compaq" }, | ||
180 | 88 | { "CRS", "Crescendo" }, | ||
181 | 89 | { "CSC", "Crystal" }, | ||
182 | 90 | { "CSI", "CSI" }, | ||
183 | 91 | { "CTL", "Creative Labs" }, | ||
184 | 92 | { "DBI", "Digi" }, | ||
185 | 93 | { "DEC", "Digital Equipment" }, | ||
186 | 94 | { "DBK", "Databook" }, | ||
187 | 95 | { "EGL", "Eagle Technology" }, | ||
188 | 96 | { "ELS", "ELSA" }, | ||
189 | 97 | { "ESS", "ESS" }, | ||
190 | 98 | { "FAR", "Farallon" }, | ||
191 | 99 | { "FDC", "Future Domain" }, | ||
192 | 100 | { "HWP", "Hewlett-Packard" }, | ||
193 | 101 | { "IBM", "IBM" }, | ||
194 | 102 | { "INT", "Intel" }, | ||
195 | 103 | { "ISA", "Iomega" }, | ||
196 | 104 | { "LEN", "Lenovo" }, | ||
197 | 105 | { "MDG", "Madge" }, | ||
198 | 106 | { "MDY", "Microdyne" }, | ||
199 | 107 | { "MET", "Metheus" }, | ||
200 | 108 | { "MIC", "Micronics" }, | ||
201 | 109 | { "MLX", "Mylex" }, | ||
202 | 110 | { "NVL", "Novell" }, | ||
203 | 111 | { "OLC", "Olicom" }, | ||
204 | 112 | { "PRO", "Proteon" }, | ||
205 | 113 | { "RII", "Racal" }, | ||
206 | 114 | { "RTL", "Realtek" }, | ||
207 | 115 | { "SCM", "SCM" }, | ||
208 | 116 | { "SKD", "SysKonnect" }, | ||
209 | 117 | { "SGI", "SGI" }, | ||
210 | 118 | { "SMC", "SMC" }, | ||
211 | 119 | { "SNI", "Siemens Nixdorf" }, | ||
212 | 120 | { "STL", "Stallion Technologies" }, | ||
213 | 121 | { "SUN", "Sun" }, | ||
214 | 122 | { "SUP", "SupraExpress" }, | ||
215 | 123 | { "SVE", "SVEC" }, | ||
216 | 124 | { "TCC", "Thomas-Conrad" }, | ||
217 | 125 | { "TCI", "Tulip" }, | ||
218 | 126 | { "TCM", "3Com" }, | ||
219 | 127 | { "TCO", "Thomas-Conrad" }, | ||
220 | 128 | { "TEC", "Tecmar" }, | ||
221 | 129 | { "TRU", "Truevision" }, | ||
222 | 130 | { "TOS", "Toshiba" }, | ||
223 | 131 | { "TYN", "Tyan" }, | ||
224 | 132 | { "UBI", "Ungermann-Bass" }, | ||
225 | 133 | { "USC", "UltraStor" }, | ||
226 | 134 | { "VDM", "Vadem" }, | ||
227 | 135 | { "VMI", "Vermont" }, | ||
228 | 136 | { "WDC", "Western Digital" }, | ||
229 | 137 | { "ZDS", "Zeos" }, | ||
230 | 138 | |||
231 | 139 | /* From http://faydoc.tripod.com/structures/01/0136.htm */ | ||
232 | 140 | { "ACT", "Targa" }, | ||
233 | 141 | { "ADI", "ADI" }, | ||
234 | 142 | { "AOC", "AOC Intl" }, | ||
235 | 143 | { "API", "Acer America" }, | ||
236 | 144 | { "APP", "Apple Computer" }, | ||
237 | 145 | { "ART", "ArtMedia" }, | ||
238 | 146 | { "AST", "AST Research" }, | ||
239 | 147 | { "CPL", "Compal" }, | ||
240 | 148 | { "CTX", "Chuntex Electronic Co." }, | ||
241 | 149 | { "DPC", "Delta Electronics" }, | ||
242 | 150 | { "DWE", "Daewoo" }, | ||
243 | 151 | { "ECS", "ELITEGROUP" }, | ||
244 | 152 | { "EIZ", "EIZO" }, | ||
245 | 153 | { "FCM", "Funai" }, | ||
246 | 154 | { "GSM", "LG Electronics" }, | ||
247 | 155 | { "GWY", "Gateway 2000" }, | ||
248 | 156 | { "HEI", "Hyundai" }, | ||
249 | 157 | { "HIT", "Hitachi" }, | ||
250 | 158 | { "HSL", "Hansol" }, | ||
251 | 159 | { "HTC", "Hitachi" }, | ||
252 | 160 | { "ICL", "Fujitsu ICL" }, | ||
253 | 161 | { "IVM", "Idek Iiyama" }, | ||
254 | 162 | { "KFC", "KFC Computek" }, | ||
255 | 163 | { "LKM", "ADLAS" }, | ||
256 | 164 | { "LNK", "LINK Tech" }, | ||
257 | 165 | { "LTN", "Lite-On" }, | ||
258 | 166 | { "MAG", "MAG InnoVision" }, | ||
259 | 167 | { "MAX", "Maxdata" }, | ||
260 | 168 | { "MEI", "Panasonic" }, | ||
261 | 169 | { "MEL", "Mitsubishi" }, | ||
262 | 170 | { "MIR", "miro" }, | ||
263 | 171 | { "MTC", "MITAC" }, | ||
264 | 172 | { "NAN", "NANAO" }, | ||
265 | 173 | { "NEC", "NEC Tech" }, | ||
266 | 174 | { "NOK", "Nokia" }, | ||
267 | 175 | { "OQI", "OPTIQUEST" }, | ||
268 | 176 | { "PBN", "Packard Bell" }, | ||
269 | 177 | { "PGS", "Princeton" }, | ||
270 | 178 | { "PHL", "Philips" }, | ||
271 | 179 | { "REL", "Relisys" }, | ||
272 | 180 | { "SDI", "Samtron" }, | ||
273 | 181 | { "SMI", "Smile" }, | ||
274 | 182 | { "SPT", "Sceptre" }, | ||
275 | 183 | { "SRC", "Shamrock Technology" }, | ||
276 | 184 | { "STP", "Sceptre" }, | ||
277 | 185 | { "TAT", "Tatung" }, | ||
278 | 186 | { "TRL", "Royal Information Company" }, | ||
279 | 187 | { "TSB", "Toshiba, Inc." }, | ||
280 | 188 | { "UNM", "Unisys" }, | ||
281 | 189 | { "VSC", "ViewSonic" }, | ||
282 | 190 | { "WTC", "Wen Tech" }, | ||
283 | 191 | { "ZCM", "Zenith Data Systems" }, | ||
284 | 192 | |||
285 | 193 | { "???", "Unknown" }, | ||
286 | 194 | }; | ||
287 | 195 | |||
288 | 196 | static gboolean | ||
289 | 197 | cc_pnp_ids_load (CCPnpIds *pnp_ids, GError **error) | ||
290 | 198 | { | ||
291 | 199 | gchar *retval = NULL; | ||
292 | 200 | CCPnpIdsPrivate *priv = pnp_ids->priv; | ||
293 | 201 | guint i; | ||
294 | 202 | |||
295 | 203 | /* load the contents */ | ||
296 | 204 | g_debug ("loading: %s", PNP_IDS); | ||
297 | 205 | if (g_file_get_contents (PNP_IDS, &priv->table_data, NULL, error) == FALSE) | ||
298 | 206 | return FALSE; | ||
299 | 207 | |||
300 | 208 | /* parse into lines */ | ||
301 | 209 | retval = priv->table_data; | ||
302 | 210 | for (i = 0; priv->table_data[i] != '\0'; i++) { | ||
303 | 211 | |||
304 | 212 | /* ignore */ | ||
305 | 213 | if (priv->table_data[i] != '\n') | ||
306 | 214 | continue; | ||
307 | 215 | |||
308 | 216 | /* convert newline to NULL */ | ||
309 | 217 | priv->table_data[i] = '\0'; | ||
310 | 218 | |||
311 | 219 | /* the ID to text is a fixed offset */ | ||
312 | 220 | if (retval[0] && retval[1] && retval[2] && retval[3] == '\t' && retval[4]) { | ||
313 | 221 | retval[3] = '\0'; | ||
314 | 222 | g_hash_table_insert (priv->pnp_table, | ||
315 | 223 | retval, | ||
316 | 224 | retval+4); | ||
317 | 225 | retval = &priv->table_data[i+1]; | ||
318 | 226 | } | ||
319 | 227 | } | ||
320 | 228 | |||
321 | 229 | g_debug ("Added %i items to the vendor hashtable", i); | ||
322 | 230 | |||
323 | 231 | return TRUE; | ||
324 | 232 | } | ||
325 | 233 | |||
326 | 234 | static const char * | ||
327 | 235 | find_vendor (const char *pnp_id) | ||
328 | 236 | { | ||
329 | 237 | guint i; | ||
330 | 238 | |||
331 | 239 | for (i = 0; i < G_N_ELEMENTS (vendors); i++) { | ||
332 | 240 | if (g_strcmp0 (vendors[i].vendor_id, pnp_id) == 0) | ||
333 | 241 | return vendors[i].vendor_name; | ||
334 | 242 | } | ||
335 | 243 | |||
336 | 244 | return NULL; | ||
337 | 245 | } | ||
338 | 246 | |||
339 | 247 | /** | ||
340 | 248 | * cc_pnp_ids_get_pnp_id: | ||
341 | 249 | * @pnp_ids: a #CCPnpIds object | ||
342 | 250 | * @pnp_id: the PNP ID to look for | ||
343 | 251 | * | ||
344 | 252 | * Find the full manufacturer name for the given PNP ID. | ||
345 | 253 | * | ||
346 | 254 | * Returns: (transfer full): a new string representing the manufacturer name, | ||
347 | 255 | * or %NULL when not found. | ||
348 | 256 | */ | ||
349 | 257 | gchar * | ||
350 | 258 | cc_pnp_ids_get_pnp_id (CCPnpIds *pnp_ids, const gchar *pnp_id) | ||
351 | 259 | { | ||
352 | 260 | CCPnpIdsPrivate *priv = pnp_ids->priv; | ||
353 | 261 | const char *found; | ||
354 | 262 | GError *error = NULL; | ||
355 | 263 | guint size; | ||
356 | 264 | |||
357 | 265 | g_return_val_if_fail (CC_IS_PNP_IDS (pnp_ids), NULL); | ||
358 | 266 | g_return_val_if_fail (pnp_id != NULL, NULL); | ||
359 | 267 | |||
360 | 268 | /* if table is empty, try to load it */ | ||
361 | 269 | size = g_hash_table_size (priv->pnp_table); | ||
362 | 270 | if (size == 0) { | ||
363 | 271 | if (cc_pnp_ids_load (pnp_ids, &error) == FALSE) { | ||
364 | 272 | g_warning ("Failed to load PNP ids: %s", error->message); | ||
365 | 273 | g_error_free (error); | ||
366 | 274 | return NULL; | ||
367 | 275 | } | ||
368 | 276 | } | ||
369 | 277 | |||
370 | 278 | /* look this up in the table */ | ||
371 | 279 | found = g_hash_table_lookup (priv->pnp_table, pnp_id); | ||
372 | 280 | if (found == NULL) { | ||
373 | 281 | found = find_vendor (pnp_id); | ||
374 | 282 | if (found == NULL) | ||
375 | 283 | return NULL; | ||
376 | 284 | } | ||
377 | 285 | |||
378 | 286 | return g_strdup (found); | ||
379 | 287 | } | ||
380 | 288 | |||
381 | 289 | static void | ||
382 | 290 | cc_pnp_ids_class_init (CCPnpIdsClass *klass) | ||
383 | 291 | { | ||
384 | 292 | GObjectClass *object_class = G_OBJECT_CLASS (klass); | ||
385 | 293 | object_class->finalize = cc_pnp_ids_finalize; | ||
386 | 294 | g_type_class_add_private (klass, sizeof (CCPnpIdsPrivate)); | ||
387 | 295 | } | ||
388 | 296 | |||
389 | 297 | static void | ||
390 | 298 | cc_pnp_ids_init (CCPnpIds *pnp_ids) | ||
391 | 299 | { | ||
392 | 300 | pnp_ids->priv = CC_PNP_IDS_GET_PRIVATE (pnp_ids); | ||
393 | 301 | |||
394 | 302 | /* we don't keep malloc'd data in the hash; instead we read it | ||
395 | 303 | * out into priv->table_data and then link to it in the hash */ | ||
396 | 304 | pnp_ids->priv->pnp_table = g_hash_table_new_full (g_str_hash, | ||
397 | 305 | g_str_equal, | ||
398 | 306 | NULL, | ||
399 | 307 | NULL); | ||
400 | 308 | } | ||
401 | 309 | |||
402 | 310 | static void | ||
403 | 311 | cc_pnp_ids_finalize (GObject *object) | ||
404 | 312 | { | ||
405 | 313 | CCPnpIds *pnp_ids = CC_PNP_IDS (object); | ||
406 | 314 | CCPnpIdsPrivate *priv = pnp_ids->priv; | ||
407 | 315 | |||
408 | 316 | g_free (priv->table_data); | ||
409 | 317 | g_hash_table_unref (priv->pnp_table); | ||
410 | 318 | |||
411 | 319 | G_OBJECT_CLASS (cc_pnp_ids_parent_class)->finalize (object); | ||
412 | 320 | } | ||
413 | 321 | |||
414 | 322 | /** | ||
415 | 323 | * cc_pnp_ids_new: | ||
416 | 324 | * | ||
417 | 325 | * Returns a reference to a #CCPnpIds object, or creates | ||
418 | 326 | * a new one if none have been created. | ||
419 | 327 | * | ||
420 | 328 | * Returns: (transfer full): a #CCPnpIds object. | ||
421 | 329 | */ | ||
422 | 330 | CCPnpIds * | ||
423 | 331 | cc_pnp_ids_new (void) | ||
424 | 332 | { | ||
425 | 333 | if (cc_pnp_ids_object != NULL) { | ||
426 | 334 | g_object_ref (cc_pnp_ids_object); | ||
427 | 335 | } else { | ||
428 | 336 | cc_pnp_ids_object = g_object_new (CC_TYPE_PNP_IDS, NULL); | ||
429 | 337 | g_object_add_weak_pointer (cc_pnp_ids_object, &cc_pnp_ids_object); | ||
430 | 338 | } | ||
431 | 339 | return CC_PNP_IDS (cc_pnp_ids_object); | ||
432 | 340 | } | ||
433 | 341 | |||
434 | 0 | 342 | ||
435 | === added file 'panels/common/cc-pnp-ids.h' | |||
436 | --- panels/common/cc-pnp-ids.h 1970-01-01 00:00:00 +0000 | |||
437 | +++ panels/common/cc-pnp-ids.h 2014-06-26 03:13:28 +0000 | |||
438 | @@ -0,0 +1,58 @@ | |||
439 | 1 | /* -*- Mode: C; tab-width: 8; indent-tabs-mode: t; c-basic-offset: 8 -*- | ||
440 | 2 | * | ||
441 | 3 | * Copyright (C) 2009-2010 Richard Hughes <richard@hughsie.com> | ||
442 | 4 | * | ||
443 | 5 | * This program is free software; you can redistribute it and/or modify | ||
444 | 6 | * it under the terms of the GNU General Public License as published by | ||
445 | 7 | * the Free Software Foundation; either version 2 of the License, or | ||
446 | 8 | * (at your option) any later version. | ||
447 | 9 | * | ||
448 | 10 | * This program is distributed in the hope that it will be useful, | ||
449 | 11 | * but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
450 | 12 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
451 | 13 | * GNU General Public License for more details. | ||
452 | 14 | * | ||
453 | 15 | * You should have received a copy of the GNU General Public License | ||
454 | 16 | * along with this program; if not, write to the Free Software | ||
455 | 17 | * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. | ||
456 | 18 | */ | ||
457 | 19 | |||
458 | 20 | #ifndef __CC_PNP_IDS_H | ||
459 | 21 | #define __CC_PNP_IDS_H | ||
460 | 22 | |||
461 | 23 | #include <glib-object.h> | ||
462 | 24 | |||
463 | 25 | G_BEGIN_DECLS | ||
464 | 26 | |||
465 | 27 | #define CC_TYPE_PNP_IDS (cc_pnp_ids_get_type ()) | ||
466 | 28 | #define CC_PNP_IDS(o) (G_TYPE_CHECK_INSTANCE_CAST ((o), CC_TYPE_PNP_IDS, CCPnpIds)) | ||
467 | 29 | #define CC_PNP_IDS_CLASS(k) (G_TYPE_CHECK_CLASS_CAST((k), CC_TYPE_PNP_IDS, CCPnpIdsClass)) | ||
468 | 30 | #define CC_IS_PNP_IDS(o) (G_TYPE_CHECK_INSTANCE_TYPE ((o), CC_TYPE_PNP_IDS)) | ||
469 | 31 | #define CC_IS_PNP_IDS_CLASS(k) (G_TYPE_CHECK_CLASS_TYPE ((k), CC_TYPE_PNP_IDS)) | ||
470 | 32 | #define CC_PNP_IDS_GET_CLASS(o) (G_TYPE_INSTANCE_GET_CLASS ((o), CC_TYPE_PNP_IDS, CCPnpIdsClass)) | ||
471 | 33 | #define CC_PNP_IDS_ERROR (cc_pnp_ids_error_quark ()) | ||
472 | 34 | |||
473 | 35 | typedef struct _CCPnpIdsPrivate CCPnpIdsPrivate; | ||
474 | 36 | typedef struct _CCPnpIds CCPnpIds; | ||
475 | 37 | typedef struct _CCPnpIdsClass CCPnpIdsClass; | ||
476 | 38 | |||
477 | 39 | struct _CCPnpIds | ||
478 | 40 | { | ||
479 | 41 | GObject parent; | ||
480 | 42 | CCPnpIdsPrivate *priv; | ||
481 | 43 | }; | ||
482 | 44 | |||
483 | 45 | struct _CCPnpIdsClass | ||
484 | 46 | { | ||
485 | 47 | GObjectClass parent_class; | ||
486 | 48 | }; | ||
487 | 49 | |||
488 | 50 | GType cc_pnp_ids_get_type (void); | ||
489 | 51 | CCPnpIds *cc_pnp_ids_new (void); | ||
490 | 52 | gchar *cc_pnp_ids_get_pnp_id (CCPnpIds *pnp_ids, | ||
491 | 53 | const gchar *pnp_id); | ||
492 | 54 | |||
493 | 55 | G_END_DECLS | ||
494 | 56 | |||
495 | 57 | #endif /* __CC_PNP_IDS_H */ | ||
496 | 58 | |||
497 | 0 | 59 | ||
498 | === added file 'panels/common/cc-rr-config.c' | |||
499 | --- panels/common/cc-rr-config.c 1970-01-01 00:00:00 +0000 | |||
500 | +++ panels/common/cc-rr-config.c 2014-06-26 03:13:28 +0000 | |||
501 | @@ -0,0 +1,2091 @@ | |||
502 | 1 | /* gnome-rr-config.c | ||
503 | 2 | * -*- c-basic-offset: 4 -*- | ||
504 | 3 | * | ||
505 | 4 | * Copyright 2007, 2008, Red Hat, Inc. | ||
506 | 5 | * Copyright 2010 Giovanni Campagna | ||
507 | 6 | * | ||
508 | 7 | * This file is part of the Gnome Library. | ||
509 | 8 | * | ||
510 | 9 | * The Gnome Library is free software; you can redistribute it and/or | ||
511 | 10 | * modify it under the terms of the GNU Library General Public License as | ||
512 | 11 | * published by the Free Software Foundation; either version 2 of the | ||
513 | 12 | * License, or (at your option) any later version. | ||
514 | 13 | * | ||
515 | 14 | * The Gnome Library is distributed in the hope that it will be useful, | ||
516 | 15 | * but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
517 | 16 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | ||
518 | 17 | * Library General Public License for more details. | ||
519 | 18 | * | ||
520 | 19 | * You should have received a copy of the GNU Library General Public | ||
521 | 20 | * License along with the Gnome Library; see the file COPYING.LIB. If not, | ||
522 | 21 | * write to the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, | ||
523 | 22 | * Boston, MA 02110-1301, USA. | ||
524 | 23 | * | ||
525 | 24 | * Author: Soren Sandmann <sandmann@redhat.com> | ||
526 | 25 | */ | ||
527 | 26 | |||
528 | 27 | #include <config.h> | ||
529 | 28 | #include <glib/gi18n-lib.h> | ||
530 | 29 | #include <stdlib.h> | ||
531 | 30 | #include <string.h> | ||
532 | 31 | #include <glib.h> | ||
533 | 32 | #include <glib/gstdio.h> | ||
534 | 33 | |||
535 | 34 | #include <X11/Xlib.h> | ||
536 | 35 | #include <gdk/gdkx.h> | ||
537 | 36 | |||
538 | 37 | #include <unistd.h> | ||
539 | 38 | #include <sys/wait.h> | ||
540 | 39 | #include <signal.h> | ||
541 | 40 | |||
542 | 41 | #include "cc-rr-config.h" | ||
543 | 42 | |||
544 | 43 | #include "edid.h" | ||
545 | 44 | #include "cc-rr-private.h" | ||
546 | 45 | |||
547 | 46 | #define CONFIG_INTENDED_BASENAME "monitors.xml" | ||
548 | 47 | #define CONFIG_BACKUP_BASENAME "monitors.xml.backup" | ||
549 | 48 | |||
550 | 49 | /* Look for DPI_FALLBACK in: | ||
551 | 50 | * http://git.gnome.org/browse/gnome-settings-daemon/tree/plugins/xsettings/gsd-xsettings-manager.c | ||
552 | 51 | * for the reasoning */ | ||
553 | 52 | #define DPI_FALLBACK 96.0 | ||
554 | 53 | |||
555 | 54 | /* In version 0 of the config file format, we had several <configuration> | ||
556 | 55 | * toplevel elements and no explicit version number. So, the filed looked | ||
557 | 56 | * like | ||
558 | 57 | * | ||
559 | 58 | * <configuration> | ||
560 | 59 | * ... | ||
561 | 60 | * </configuration> | ||
562 | 61 | * <configuration> | ||
563 | 62 | * ... | ||
564 | 63 | * </configuration> | ||
565 | 64 | * | ||
566 | 65 | * Since version 1 of the config file, the file has a toplevel <monitors> | ||
567 | 66 | * element to group all the configurations. That element has a "version" | ||
568 | 67 | * attribute which is an integer. So, the file looks like this: | ||
569 | 68 | * | ||
570 | 69 | * <monitors version="1"> | ||
571 | 70 | * <configuration> | ||
572 | 71 | * ... | ||
573 | 72 | * </configuration> | ||
574 | 73 | * <configuration> | ||
575 | 74 | * ... | ||
576 | 75 | * </configuration> | ||
577 | 76 | * </monitors> | ||
578 | 77 | */ | ||
579 | 78 | |||
580 | 79 | /* A helper wrapper around the GMarkup parser stuff */ | ||
581 | 80 | static gboolean parse_file_gmarkup (const gchar *file, | ||
582 | 81 | const GMarkupParser *parser, | ||
583 | 82 | gpointer data, | ||
584 | 83 | GError **err); | ||
585 | 84 | |||
586 | 85 | typedef struct CrtcAssignment CrtcAssignment; | ||
587 | 86 | |||
588 | 87 | static gboolean crtc_assignment_apply (CrtcAssignment *assign, | ||
589 | 88 | guint32 timestamp, | ||
590 | 89 | GError **error); | ||
591 | 90 | static CrtcAssignment *crtc_assignment_new (CCRRScreen *screen, | ||
592 | 91 | CCRROutputInfo **outputs, | ||
593 | 92 | GError **error); | ||
594 | 93 | static void crtc_assignment_free (CrtcAssignment *assign); | ||
595 | 94 | |||
596 | 95 | enum { | ||
597 | 96 | PROP_0, | ||
598 | 97 | PROP_SCREEN, | ||
599 | 98 | PROP_LAST | ||
600 | 99 | }; | ||
601 | 100 | |||
602 | 101 | G_DEFINE_TYPE (CCRRConfig, cc_rr_config, G_TYPE_OBJECT) | ||
603 | 102 | |||
604 | 103 | typedef struct Parser Parser; | ||
605 | 104 | |||
606 | 105 | /* Parser for monitor configurations */ | ||
607 | 106 | struct Parser | ||
608 | 107 | { | ||
609 | 108 | int config_file_version; | ||
610 | 109 | CCRROutputInfo * output; | ||
611 | 110 | CCRRConfig * configuration; | ||
612 | 111 | GPtrArray * outputs; | ||
613 | 112 | GPtrArray * configurations; | ||
614 | 113 | GQueue * stack; | ||
615 | 114 | }; | ||
616 | 115 | |||
617 | 116 | static int | ||
618 | 117 | parse_int (const char *text) | ||
619 | 118 | { | ||
620 | 119 | return strtol (text, NULL, 0); | ||
621 | 120 | } | ||
622 | 121 | |||
623 | 122 | static guint | ||
624 | 123 | parse_uint (const char *text) | ||
625 | 124 | { | ||
626 | 125 | return strtoul (text, NULL, 0); | ||
627 | 126 | } | ||
628 | 127 | |||
629 | 128 | static gboolean | ||
630 | 129 | stack_is (Parser *parser, | ||
631 | 130 | const char *s1, | ||
632 | 131 | ...) | ||
633 | 132 | { | ||
634 | 133 | GList *stack = NULL; | ||
635 | 134 | const char *s; | ||
636 | 135 | GList *l1, *l2; | ||
637 | 136 | va_list args; | ||
638 | 137 | |||
639 | 138 | stack = g_list_prepend (stack, (gpointer)s1); | ||
640 | 139 | |||
641 | 140 | va_start (args, s1); | ||
642 | 141 | |||
643 | 142 | s = va_arg (args, const char *); | ||
644 | 143 | while (s) | ||
645 | 144 | { | ||
646 | 145 | stack = g_list_prepend (stack, (gpointer)s); | ||
647 | 146 | s = va_arg (args, const char *); | ||
648 | 147 | } | ||
649 | 148 | |||
650 | 149 | l1 = stack; | ||
651 | 150 | l2 = parser->stack->head; | ||
652 | 151 | |||
653 | 152 | while (l1 && l2) | ||
654 | 153 | { | ||
655 | 154 | if (strcmp (l1->data, l2->data) != 0) | ||
656 | 155 | { | ||
657 | 156 | g_list_free (stack); | ||
658 | 157 | return FALSE; | ||
659 | 158 | } | ||
660 | 159 | |||
661 | 160 | l1 = l1->next; | ||
662 | 161 | l2 = l2->next; | ||
663 | 162 | } | ||
664 | 163 | |||
665 | 164 | g_list_free (stack); | ||
666 | 165 | |||
667 | 166 | return (!l1 && !l2); | ||
668 | 167 | } | ||
669 | 168 | |||
670 | 169 | static void | ||
671 | 170 | handle_start_element (GMarkupParseContext *context, | ||
672 | 171 | const gchar *name, | ||
673 | 172 | const gchar **attr_names, | ||
674 | 173 | const gchar **attr_values, | ||
675 | 174 | gpointer user_data, | ||
676 | 175 | GError **err) | ||
677 | 176 | { | ||
678 | 177 | Parser *parser = user_data; | ||
679 | 178 | |||
680 | 179 | if (strcmp (name, "output") == 0) | ||
681 | 180 | { | ||
682 | 181 | int i; | ||
683 | 182 | g_assert (parser->output == NULL); | ||
684 | 183 | |||
685 | 184 | parser->output = g_object_new (CC_TYPE_RR_OUTPUT_INFO, NULL); | ||
686 | 185 | parser->output->priv->rotation = 0; | ||
687 | 186 | |||
688 | 187 | for (i = 0; attr_names[i] != NULL; ++i) | ||
689 | 188 | { | ||
690 | 189 | if (strcmp (attr_names[i], "name") == 0) | ||
691 | 190 | { | ||
692 | 191 | parser->output->priv->name = g_strdup (attr_values[i]); | ||
693 | 192 | break; | ||
694 | 193 | } | ||
695 | 194 | } | ||
696 | 195 | |||
697 | 196 | if (!parser->output->priv->name) | ||
698 | 197 | { | ||
699 | 198 | /* This really shouldn't happen, but it's better to make | ||
700 | 199 | * something up than to crash later. | ||
701 | 200 | */ | ||
702 | 201 | g_warning ("Malformed monitor configuration file"); | ||
703 | 202 | |||
704 | 203 | parser->output->priv->name = g_strdup ("default"); | ||
705 | 204 | } | ||
706 | 205 | parser->output->priv->connected = FALSE; | ||
707 | 206 | parser->output->priv->on = FALSE; | ||
708 | 207 | parser->output->priv->primary = FALSE; | ||
709 | 208 | } | ||
710 | 209 | else if (strcmp (name, "configuration") == 0) | ||
711 | 210 | { | ||
712 | 211 | g_assert (parser->configuration == NULL); | ||
713 | 212 | |||
714 | 213 | parser->configuration = g_object_new (CC_TYPE_RR_CONFIG, NULL); | ||
715 | 214 | parser->configuration->priv->clone = FALSE; | ||
716 | 215 | parser->configuration->priv->outputs = NULL; | ||
717 | 216 | } | ||
718 | 217 | else if (strcmp (name, "monitors") == 0) | ||
719 | 218 | { | ||
720 | 219 | int i; | ||
721 | 220 | |||
722 | 221 | for (i = 0; attr_names[i] != NULL; i++) | ||
723 | 222 | { | ||
724 | 223 | if (strcmp (attr_names[i], "version") == 0) | ||
725 | 224 | { | ||
726 | 225 | parser->config_file_version = parse_int (attr_values[i]); | ||
727 | 226 | break; | ||
728 | 227 | } | ||
729 | 228 | } | ||
730 | 229 | } | ||
731 | 230 | |||
732 | 231 | g_queue_push_tail (parser->stack, g_strdup (name)); | ||
733 | 232 | } | ||
734 | 233 | |||
735 | 234 | static void | ||
736 | 235 | handle_end_element (GMarkupParseContext *context, | ||
737 | 236 | const gchar *name, | ||
738 | 237 | gpointer user_data, | ||
739 | 238 | GError **err) | ||
740 | 239 | { | ||
741 | 240 | Parser *parser = user_data; | ||
742 | 241 | |||
743 | 242 | if (strcmp (name, "output") == 0) | ||
744 | 243 | { | ||
745 | 244 | /* If no rotation properties were set, just use CC_RR_ROTATION_0 */ | ||
746 | 245 | if (parser->output->priv->rotation == 0) | ||
747 | 246 | parser->output->priv->rotation = CC_RR_ROTATION_0; | ||
748 | 247 | |||
749 | 248 | g_ptr_array_add (parser->outputs, parser->output); | ||
750 | 249 | |||
751 | 250 | parser->output = NULL; | ||
752 | 251 | } | ||
753 | 252 | else if (strcmp (name, "configuration") == 0) | ||
754 | 253 | { | ||
755 | 254 | g_ptr_array_add (parser->outputs, NULL); | ||
756 | 255 | parser->configuration->priv->outputs = | ||
757 | 256 | (CCRROutputInfo **)g_ptr_array_free (parser->outputs, FALSE); | ||
758 | 257 | parser->outputs = g_ptr_array_new (); | ||
759 | 258 | g_ptr_array_add (parser->configurations, parser->configuration); | ||
760 | 259 | parser->configuration = NULL; | ||
761 | 260 | } | ||
762 | 261 | |||
763 | 262 | g_free (g_queue_pop_tail (parser->stack)); | ||
764 | 263 | } | ||
765 | 264 | |||
766 | 265 | #define TOPLEVEL_ELEMENT (parser->config_file_version > 0 ? "monitors" : NULL) | ||
767 | 266 | |||
768 | 267 | static void | ||
769 | 268 | handle_text (GMarkupParseContext *context, | ||
770 | 269 | const gchar *text, | ||
771 | 270 | gsize text_len, | ||
772 | 271 | gpointer user_data, | ||
773 | 272 | GError **err) | ||
774 | 273 | { | ||
775 | 274 | Parser *parser = user_data; | ||
776 | 275 | |||
777 | 276 | if (stack_is (parser, "vendor", "output", "configuration", TOPLEVEL_ELEMENT, NULL)) | ||
778 | 277 | { | ||
779 | 278 | parser->output->priv->connected = TRUE; | ||
780 | 279 | |||
781 | 280 | strncpy ((gchar*) parser->output->priv->vendor, text, 3); | ||
782 | 281 | parser->output->priv->vendor[3] = 0; | ||
783 | 282 | } | ||
784 | 283 | else if (stack_is (parser, "clone", "configuration", TOPLEVEL_ELEMENT, NULL)) | ||
785 | 284 | { | ||
786 | 285 | if (strcmp (text, "yes") == 0) | ||
787 | 286 | parser->configuration->priv->clone = TRUE; | ||
788 | 287 | } | ||
789 | 288 | else if (stack_is (parser, "product", "output", "configuration", TOPLEVEL_ELEMENT, NULL)) | ||
790 | 289 | { | ||
791 | 290 | parser->output->priv->connected = TRUE; | ||
792 | 291 | |||
793 | 292 | parser->output->priv->product = parse_int (text); | ||
794 | 293 | } | ||
795 | 294 | else if (stack_is (parser, "serial", "output", "configuration", TOPLEVEL_ELEMENT, NULL)) | ||
796 | 295 | { | ||
797 | 296 | parser->output->priv->connected = TRUE; | ||
798 | 297 | |||
799 | 298 | parser->output->priv->serial = parse_uint (text); | ||
800 | 299 | } | ||
801 | 300 | else if (stack_is (parser, "width", "output", "configuration", TOPLEVEL_ELEMENT, NULL)) | ||
802 | 301 | { | ||
803 | 302 | parser->output->priv->on = TRUE; | ||
804 | 303 | |||
805 | 304 | parser->output->priv->width = parse_int (text); | ||
806 | 305 | } | ||
807 | 306 | else if (stack_is (parser, "x", "output", "configuration", TOPLEVEL_ELEMENT, NULL)) | ||
808 | 307 | { | ||
809 | 308 | parser->output->priv->on = TRUE; | ||
810 | 309 | |||
811 | 310 | parser->output->priv->x = parse_int (text); | ||
812 | 311 | } | ||
813 | 312 | else if (stack_is (parser, "y", "output", "configuration", TOPLEVEL_ELEMENT, NULL)) | ||
814 | 313 | { | ||
815 | 314 | parser->output->priv->on = TRUE; | ||
816 | 315 | |||
817 | 316 | parser->output->priv->y = parse_int (text); | ||
818 | 317 | } | ||
819 | 318 | else if (stack_is (parser, "height", "output", "configuration", TOPLEVEL_ELEMENT, NULL)) | ||
820 | 319 | { | ||
821 | 320 | parser->output->priv->on = TRUE; | ||
822 | 321 | |||
823 | 322 | parser->output->priv->height = parse_int (text); | ||
824 | 323 | } | ||
825 | 324 | else if (stack_is (parser, "rate", "output", "configuration", TOPLEVEL_ELEMENT, NULL)) | ||
826 | 325 | { | ||
827 | 326 | parser->output->priv->on = TRUE; | ||
828 | 327 | |||
829 | 328 | parser->output->priv->rate = parse_int (text); | ||
830 | 329 | } | ||
831 | 330 | else if (stack_is (parser, "rotation", "output", "configuration", TOPLEVEL_ELEMENT, NULL)) | ||
832 | 331 | { | ||
833 | 332 | if (strcmp (text, "normal") == 0) | ||
834 | 333 | { | ||
835 | 334 | parser->output->priv->rotation |= CC_RR_ROTATION_0; | ||
836 | 335 | } | ||
837 | 336 | else if (strcmp (text, "left") == 0) | ||
838 | 337 | { | ||
839 | 338 | parser->output->priv->rotation |= CC_RR_ROTATION_90; | ||
840 | 339 | } | ||
841 | 340 | else if (strcmp (text, "upside_down") == 0) | ||
842 | 341 | { | ||
843 | 342 | parser->output->priv->rotation |= CC_RR_ROTATION_180; | ||
844 | 343 | } | ||
845 | 344 | else if (strcmp (text, "right") == 0) | ||
846 | 345 | { | ||
847 | 346 | parser->output->priv->rotation |= CC_RR_ROTATION_270; | ||
848 | 347 | } | ||
849 | 348 | } | ||
850 | 349 | else if (stack_is (parser, "reflect_x", "output", "configuration", TOPLEVEL_ELEMENT, NULL)) | ||
851 | 350 | { | ||
852 | 351 | if (strcmp (text, "yes") == 0) | ||
853 | 352 | { | ||
854 | 353 | parser->output->priv->rotation |= CC_RR_REFLECT_X; | ||
855 | 354 | } | ||
856 | 355 | } | ||
857 | 356 | else if (stack_is (parser, "reflect_y", "output", "configuration", TOPLEVEL_ELEMENT, NULL)) | ||
858 | 357 | { | ||
859 | 358 | if (strcmp (text, "yes") == 0) | ||
860 | 359 | { | ||
861 | 360 | parser->output->priv->rotation |= CC_RR_REFLECT_Y; | ||
862 | 361 | } | ||
863 | 362 | } | ||
864 | 363 | else if (stack_is (parser, "primary", "output", "configuration", TOPLEVEL_ELEMENT, NULL)) | ||
865 | 364 | { | ||
866 | 365 | if (strcmp (text, "yes") == 0) | ||
867 | 366 | { | ||
868 | 367 | parser->output->priv->primary = TRUE; | ||
869 | 368 | } | ||
870 | 369 | } | ||
871 | 370 | else | ||
872 | 371 | { | ||
873 | 372 | /* Ignore other properties so we can expand the format in the future */ | ||
874 | 373 | } | ||
875 | 374 | } | ||
876 | 375 | |||
877 | 376 | static void | ||
878 | 377 | parser_free (Parser *parser) | ||
879 | 378 | { | ||
880 | 379 | int i; | ||
881 | 380 | GList *list; | ||
882 | 381 | |||
883 | 382 | g_assert (parser != NULL); | ||
884 | 383 | |||
885 | 384 | if (parser->output) | ||
886 | 385 | g_object_unref (parser->output); | ||
887 | 386 | |||
888 | 387 | if (parser->configuration) | ||
889 | 388 | g_object_unref (parser->configuration); | ||
890 | 389 | |||
891 | 390 | for (i = 0; i < parser->outputs->len; ++i) | ||
892 | 391 | { | ||
893 | 392 | CCRROutputInfo *output = parser->outputs->pdata[i]; | ||
894 | 393 | |||
895 | 394 | g_object_unref (output); | ||
896 | 395 | } | ||
897 | 396 | |||
898 | 397 | g_ptr_array_free (parser->outputs, TRUE); | ||
899 | 398 | |||
900 | 399 | for (i = 0; i < parser->configurations->len; ++i) | ||
901 | 400 | { | ||
902 | 401 | CCRRConfig *config = parser->configurations->pdata[i]; | ||
903 | 402 | |||
904 | 403 | g_object_unref (config); | ||
905 | 404 | } | ||
906 | 405 | |||
907 | 406 | g_ptr_array_free (parser->configurations, TRUE); | ||
908 | 407 | |||
909 | 408 | for (list = parser->stack->head; list; list = list->next) | ||
910 | 409 | g_free (list->data); | ||
911 | 410 | g_queue_free (parser->stack); | ||
912 | 411 | |||
913 | 412 | g_free (parser); | ||
914 | 413 | } | ||
915 | 414 | |||
916 | 415 | static CCRRConfig ** | ||
917 | 416 | configurations_read_from_file (const gchar *filename, GError **error) | ||
918 | 417 | { | ||
919 | 418 | Parser *parser = g_new0 (Parser, 1); | ||
920 | 419 | CCRRConfig **result; | ||
921 | 420 | GMarkupParser callbacks = { | ||
922 | 421 | handle_start_element, | ||
923 | 422 | handle_end_element, | ||
924 | 423 | handle_text, | ||
925 | 424 | NULL, /* passthrough */ | ||
926 | 425 | NULL, /* error */ | ||
927 | 426 | }; | ||
928 | 427 | |||
929 | 428 | parser->config_file_version = 0; | ||
930 | 429 | parser->configurations = g_ptr_array_new (); | ||
931 | 430 | parser->outputs = g_ptr_array_new (); | ||
932 | 431 | parser->stack = g_queue_new (); | ||
933 | 432 | |||
934 | 433 | if (!parse_file_gmarkup (filename, &callbacks, parser, error)) | ||
935 | 434 | { | ||
936 | 435 | result = NULL; | ||
937 | 436 | |||
938 | 437 | g_assert (parser->outputs); | ||
939 | 438 | goto out; | ||
940 | 439 | } | ||
941 | 440 | |||
942 | 441 | g_assert (parser->outputs); | ||
943 | 442 | |||
944 | 443 | g_ptr_array_add (parser->configurations, NULL); | ||
945 | 444 | result = (CCRRConfig **)g_ptr_array_free (parser->configurations, FALSE); | ||
946 | 445 | parser->configurations = g_ptr_array_new (); | ||
947 | 446 | |||
948 | 447 | g_assert (parser->outputs); | ||
949 | 448 | out: | ||
950 | 449 | parser_free (parser); | ||
951 | 450 | |||
952 | 451 | return result; | ||
953 | 452 | } | ||
954 | 453 | |||
955 | 454 | static void | ||
956 | 455 | cc_rr_config_init (CCRRConfig *self) | ||
957 | 456 | { | ||
958 | 457 | self->priv = G_TYPE_INSTANCE_GET_PRIVATE (self, CC_TYPE_RR_CONFIG, CCRRConfigPrivate); | ||
959 | 458 | |||
960 | 459 | self->priv->clone = FALSE; | ||
961 | 460 | self->priv->screen = NULL; | ||
962 | 461 | self->priv->outputs = NULL; | ||
963 | 462 | } | ||
964 | 463 | |||
965 | 464 | static void | ||
966 | 465 | cc_rr_config_set_property (GObject *gobject, guint property_id, const GValue *value, GParamSpec *property) | ||
967 | 466 | { | ||
968 | 467 | CCRRConfig *self = CC_RR_CONFIG (gobject); | ||
969 | 468 | |||
970 | 469 | switch (property_id) { | ||
971 | 470 | case PROP_SCREEN: | ||
972 | 471 | self->priv->screen = g_value_dup_object (value); | ||
973 | 472 | return; | ||
974 | 473 | default: | ||
975 | 474 | G_OBJECT_WARN_INVALID_PROPERTY_ID (gobject, property_id, property); | ||
976 | 475 | } | ||
977 | 476 | } | ||
978 | 477 | |||
979 | 478 | static void | ||
980 | 479 | cc_rr_config_finalize (GObject *gobject) | ||
981 | 480 | { | ||
982 | 481 | CCRRConfig *self = CC_RR_CONFIG (gobject); | ||
983 | 482 | |||
984 | 483 | if (self->priv->screen) | ||
985 | 484 | g_object_unref (self->priv->screen); | ||
986 | 485 | |||
987 | 486 | if (self->priv->outputs) { | ||
988 | 487 | int i; | ||
989 | 488 | |||
990 | 489 | for (i = 0; self->priv->outputs[i] != NULL; i++) { | ||
991 | 490 | CCRROutputInfo *output = self->priv->outputs[i]; | ||
992 | 491 | g_object_unref (output); | ||
993 | 492 | } | ||
994 | 493 | g_free (self->priv->outputs); | ||
995 | 494 | } | ||
996 | 495 | |||
997 | 496 | G_OBJECT_CLASS (cc_rr_config_parent_class)->finalize (gobject); | ||
998 | 497 | } | ||
999 | 498 | |||
1000 | 499 | gboolean | ||
1001 | 500 | cc_rr_config_load_current (CCRRConfig *config, GError **error) | ||
1002 | 501 | { | ||
1003 | 502 | GPtrArray *a; | ||
1004 | 503 | CCRROutput **rr_outputs; | ||
1005 | 504 | int i; | ||
1006 | 505 | int clone_width = -1; | ||
1007 | 506 | int clone_height = -1; | ||
1008 | 507 | int last_x; | ||
1009 | 508 | |||
1010 | 509 | g_return_val_if_fail (CC_IS_RR_CONFIG (config), FALSE); | ||
1011 | 510 | |||
1012 | 511 | a = g_ptr_array_new (); | ||
1013 | 512 | rr_outputs = cc_rr_screen_list_outputs (config->priv->screen); | ||
1014 | 513 | |||
1015 | 514 | config->priv->clone = FALSE; | ||
1016 | 515 | |||
1017 | 516 | for (i = 0; rr_outputs[i] != NULL; ++i) | ||
1018 | 517 | { | ||
1019 | 518 | CCRROutput *rr_output = rr_outputs[i]; | ||
1020 | 519 | CCRROutputInfo *output = g_object_new (CC_TYPE_RR_OUTPUT_INFO, NULL); | ||
1021 | 520 | CCRRMode *mode = NULL; | ||
1022 | 521 | const guint8 *edid_data = cc_rr_output_get_edid_data (rr_output, NULL); | ||
1023 | 522 | CCRRCrtc *crtc; | ||
1024 | 523 | |||
1025 | 524 | output->priv->name = g_strdup (cc_rr_output_get_name (rr_output)); | ||
1026 | 525 | output->priv->connected = cc_rr_output_is_connected (rr_output); | ||
1027 | 526 | output->priv->display_name = g_strdup (cc_rr_output_get_display_name (rr_output)); | ||
1028 | 527 | |||
1029 | 528 | if (!output->priv->connected) | ||
1030 | 529 | { | ||
1031 | 530 | output->priv->x = -1; | ||
1032 | 531 | output->priv->y = -1; | ||
1033 | 532 | output->priv->width = -1; | ||
1034 | 533 | output->priv->height = -1; | ||
1035 | 534 | output->priv->rate = -1; | ||
1036 | 535 | output->priv->rotation = CC_RR_ROTATION_0; | ||
1037 | 536 | } | ||
1038 | 537 | else | ||
1039 | 538 | { | ||
1040 | 539 | MonitorInfo *info = NULL; | ||
1041 | 540 | |||
1042 | 541 | if (edid_data) | ||
1043 | 542 | info = decode_edid (edid_data); | ||
1044 | 543 | |||
1045 | 544 | if (info) | ||
1046 | 545 | { | ||
1047 | 546 | memcpy (output->priv->vendor, info->manufacturer_code, | ||
1048 | 547 | sizeof (output->priv->vendor)); | ||
1049 | 548 | |||
1050 | 549 | output->priv->product = info->product_code; | ||
1051 | 550 | output->priv->serial = info->serial_number; | ||
1052 | 551 | output->priv->aspect = info->aspect_ratio; | ||
1053 | 552 | } | ||
1054 | 553 | else | ||
1055 | 554 | { | ||
1056 | 555 | strcpy (output->priv->vendor, "???"); | ||
1057 | 556 | output->priv->product = 0; | ||
1058 | 557 | output->priv->serial = 0; | ||
1059 | 558 | } | ||
1060 | 559 | g_free (info); | ||
1061 | 560 | |||
1062 | 561 | crtc = cc_rr_output_get_crtc (rr_output); | ||
1063 | 562 | mode = crtc? cc_rr_crtc_get_current_mode (crtc) : NULL; | ||
1064 | 563 | |||
1065 | 564 | if (crtc && mode) | ||
1066 | 565 | { | ||
1067 | 566 | output->priv->on = TRUE; | ||
1068 | 567 | |||
1069 | 568 | cc_rr_crtc_get_position (crtc, &output->priv->x, &output->priv->y); | ||
1070 | 569 | output->priv->width = cc_rr_mode_get_width (mode); | ||
1071 | 570 | output->priv->height = cc_rr_mode_get_height (mode); | ||
1072 | 571 | output->priv->rate = cc_rr_mode_get_freq (mode); | ||
1073 | 572 | output->priv->rotation = cc_rr_crtc_get_current_rotation (crtc); | ||
1074 | 573 | |||
1075 | 574 | if (output->priv->x == 0 && output->priv->y == 0) { | ||
1076 | 575 | if (clone_width == -1) { | ||
1077 | 576 | clone_width = output->priv->width; | ||
1078 | 577 | clone_height = output->priv->height; | ||
1079 | 578 | } else if (clone_width == output->priv->width && | ||
1080 | 579 | clone_height == output->priv->height) { | ||
1081 | 580 | config->priv->clone = TRUE; | ||
1082 | 581 | } | ||
1083 | 582 | } | ||
1084 | 583 | } | ||
1085 | 584 | else | ||
1086 | 585 | { | ||
1087 | 586 | output->priv->on = FALSE; | ||
1088 | 587 | config->priv->clone = FALSE; | ||
1089 | 588 | } | ||
1090 | 589 | |||
1091 | 590 | /* Get preferred size for the monitor */ | ||
1092 | 591 | mode = cc_rr_output_get_preferred_mode (rr_output); | ||
1093 | 592 | |||
1094 | 593 | if (!mode) | ||
1095 | 594 | { | ||
1096 | 595 | CCRRMode **modes = cc_rr_output_list_modes (rr_output); | ||
1097 | 596 | |||
1098 | 597 | /* FIXME: we should pick the "best" mode here, where best is | ||
1099 | 598 | * sorted wrt | ||
1100 | 599 | * | ||
1101 | 600 | * - closest aspect ratio | ||
1102 | 601 | * - mode area | ||
1103 | 602 | * - refresh rate | ||
1104 | 603 | * - We may want to extend randrwrap so that get_preferred | ||
1105 | 604 | * returns that - although that could also depend on | ||
1106 | 605 | * the crtc. | ||
1107 | 606 | */ | ||
1108 | 607 | if (modes[0]) | ||
1109 | 608 | mode = modes[0]; | ||
1110 | 609 | } | ||
1111 | 610 | |||
1112 | 611 | if (mode) | ||
1113 | 612 | { | ||
1114 | 613 | output->priv->pref_width = cc_rr_mode_get_width (mode); | ||
1115 | 614 | output->priv->pref_height = cc_rr_mode_get_height (mode); | ||
1116 | 615 | } | ||
1117 | 616 | else | ||
1118 | 617 | { | ||
1119 | 618 | /* Pick some random numbers. This should basically never happen */ | ||
1120 | 619 | output->priv->pref_width = 1024; | ||
1121 | 620 | output->priv->pref_height = 768; | ||
1122 | 621 | } | ||
1123 | 622 | } | ||
1124 | 623 | |||
1125 | 624 | output->priv->primary = cc_rr_output_get_is_primary (rr_output); | ||
1126 | 625 | |||
1127 | 626 | g_ptr_array_add (a, output); | ||
1128 | 627 | } | ||
1129 | 628 | |||
1130 | 629 | g_ptr_array_add (a, NULL); | ||
1131 | 630 | |||
1132 | 631 | config->priv->outputs = (CCRROutputInfo **)g_ptr_array_free (a, FALSE); | ||
1133 | 632 | |||
1134 | 633 | /* Walk the outputs computing the right-most edge of all | ||
1135 | 634 | * lit-up displays | ||
1136 | 635 | */ | ||
1137 | 636 | last_x = 0; | ||
1138 | 637 | for (i = 0; config->priv->outputs[i] != NULL; ++i) | ||
1139 | 638 | { | ||
1140 | 639 | CCRROutputInfo *output = config->priv->outputs[i]; | ||
1141 | 640 | |||
1142 | 641 | if (output->priv->on) | ||
1143 | 642 | { | ||
1144 | 643 | last_x = MAX (last_x, output->priv->x + output->priv->width); | ||
1145 | 644 | } | ||
1146 | 645 | } | ||
1147 | 646 | |||
1148 | 647 | /* Now position all off displays to the right of the | ||
1149 | 648 | * on displays | ||
1150 | 649 | */ | ||
1151 | 650 | for (i = 0; config->priv->outputs[i] != NULL; ++i) | ||
1152 | 651 | { | ||
1153 | 652 | CCRROutputInfo *output = config->priv->outputs[i]; | ||
1154 | 653 | |||
1155 | 654 | if (output->priv->connected && !output->priv->on) | ||
1156 | 655 | { | ||
1157 | 656 | output->priv->x = last_x; | ||
1158 | 657 | last_x = output->priv->x + output->priv->width; | ||
1159 | 658 | } | ||
1160 | 659 | } | ||
1161 | 660 | |||
1162 | 661 | g_assert (cc_rr_config_match (config, config)); | ||
1163 | 662 | |||
1164 | 663 | return TRUE; | ||
1165 | 664 | } | ||
1166 | 665 | |||
1167 | 666 | gboolean | ||
1168 | 667 | cc_rr_config_load_filename (CCRRConfig *result, const char *filename, GError **error) | ||
1169 | 668 | { | ||
1170 | 669 | CCRRConfig *current; | ||
1171 | 670 | CCRRConfig **configs; | ||
1172 | 671 | gboolean found = FALSE; | ||
1173 | 672 | |||
1174 | 673 | g_return_val_if_fail (CC_IS_RR_CONFIG (result), FALSE); | ||
1175 | 674 | g_return_val_if_fail (filename != NULL, FALSE); | ||
1176 | 675 | g_return_val_if_fail (error == NULL || *error == NULL, FALSE); | ||
1177 | 676 | |||
1178 | 677 | current = cc_rr_config_new_current (result->priv->screen, error); | ||
1179 | 678 | |||
1180 | 679 | configs = configurations_read_from_file (filename, error); | ||
1181 | 680 | |||
1182 | 681 | if (configs) | ||
1183 | 682 | { | ||
1184 | 683 | int i; | ||
1185 | 684 | |||
1186 | 685 | for (i = 0; configs[i] != NULL; ++i) | ||
1187 | 686 | { | ||
1188 | 687 | if (cc_rr_config_match (configs[i], current)) | ||
1189 | 688 | { | ||
1190 | 689 | int j; | ||
1191 | 690 | GPtrArray *array; | ||
1192 | 691 | result->priv->clone = configs[i]->priv->clone; | ||
1193 | 692 | |||
1194 | 693 | array = g_ptr_array_new (); | ||
1195 | 694 | for (j = 0; configs[i]->priv->outputs[j] != NULL; j++) { | ||
1196 | 695 | g_object_ref (configs[i]->priv->outputs[j]); | ||
1197 | 696 | g_ptr_array_add (array, configs[i]->priv->outputs[j]); | ||
1198 | 697 | } | ||
1199 | 698 | g_ptr_array_add (array, NULL); | ||
1200 | 699 | result->priv->outputs = (CCRROutputInfo **) g_ptr_array_free (array, FALSE); | ||
1201 | 700 | |||
1202 | 701 | found = TRUE; | ||
1203 | 702 | break; | ||
1204 | 703 | } | ||
1205 | 704 | g_object_unref (configs[i]); | ||
1206 | 705 | } | ||
1207 | 706 | g_free (configs); | ||
1208 | 707 | |||
1209 | 708 | if (!found) | ||
1210 | 709 | g_set_error (error, CC_RR_ERROR, CC_RR_ERROR_NO_MATCHING_CONFIG, | ||
1211 | 710 | _("none of the saved display configurations matched the active configuration")); | ||
1212 | 711 | } | ||
1213 | 712 | |||
1214 | 713 | g_object_unref (current); | ||
1215 | 714 | return found; | ||
1216 | 715 | } | ||
1217 | 716 | |||
1218 | 717 | static void | ||
1219 | 718 | cc_rr_config_class_init (CCRRConfigClass *klass) | ||
1220 | 719 | { | ||
1221 | 720 | GObjectClass *gobject_class = G_OBJECT_CLASS (klass); | ||
1222 | 721 | |||
1223 | 722 | g_type_class_add_private (klass, sizeof (CCRROutputInfoPrivate)); | ||
1224 | 723 | |||
1225 | 724 | gobject_class->set_property = cc_rr_config_set_property; | ||
1226 | 725 | gobject_class->finalize = cc_rr_config_finalize; | ||
1227 | 726 | |||
1228 | 727 | g_object_class_install_property (gobject_class, PROP_SCREEN, | ||
1229 | 728 | g_param_spec_object ("screen", "Screen", "The CCRRScreen this config applies to", CC_TYPE_RR_SCREEN, | ||
1230 | 729 | G_PARAM_WRITABLE | G_PARAM_CONSTRUCT_ONLY | G_PARAM_STATIC_NICK | G_PARAM_STATIC_BLURB)); | ||
1231 | 730 | } | ||
1232 | 731 | |||
1233 | 732 | CCRRConfig * | ||
1234 | 733 | cc_rr_config_new_current (CCRRScreen *screen, GError **error) | ||
1235 | 734 | { | ||
1236 | 735 | CCRRConfig *self = g_object_new (CC_TYPE_RR_CONFIG, "screen", screen, NULL); | ||
1237 | 736 | |||
1238 | 737 | if (cc_rr_config_load_current (self, error)) | ||
1239 | 738 | return self; | ||
1240 | 739 | else | ||
1241 | 740 | { | ||
1242 | 741 | g_object_unref (self); | ||
1243 | 742 | return NULL; | ||
1244 | 743 | } | ||
1245 | 744 | } | ||
1246 | 745 | |||
1247 | 746 | CCRRConfig * | ||
1248 | 747 | cc_rr_config_new_stored (CCRRScreen *screen, GError **error) | ||
1249 | 748 | { | ||
1250 | 749 | CCRRConfig *self = g_object_new (CC_TYPE_RR_CONFIG, "screen", screen, NULL); | ||
1251 | 750 | char *filename; | ||
1252 | 751 | gboolean success; | ||
1253 | 752 | |||
1254 | 753 | filename = cc_rr_config_get_intended_filename (); | ||
1255 | 754 | |||
1256 | 755 | success = cc_rr_config_load_filename (self, filename, error); | ||
1257 | 756 | |||
1258 | 757 | g_free (filename); | ||
1259 | 758 | |||
1260 | 759 | if (success) | ||
1261 | 760 | return self; | ||
1262 | 761 | else | ||
1263 | 762 | { | ||
1264 | 763 | g_object_unref (self); | ||
1265 | 764 | return NULL; | ||
1266 | 765 | } | ||
1267 | 766 | } | ||
1268 | 767 | |||
1269 | 768 | static gboolean | ||
1270 | 769 | parse_file_gmarkup (const gchar *filename, | ||
1271 | 770 | const GMarkupParser *parser, | ||
1272 | 771 | gpointer data, | ||
1273 | 772 | GError **err) | ||
1274 | 773 | { | ||
1275 | 774 | GMarkupParseContext *context = NULL; | ||
1276 | 775 | gchar *contents = NULL; | ||
1277 | 776 | gboolean result = TRUE; | ||
1278 | 777 | gsize len; | ||
1279 | 778 | |||
1280 | 779 | if (!g_file_get_contents (filename, &contents, &len, err)) | ||
1281 | 780 | { | ||
1282 | 781 | result = FALSE; | ||
1283 | 782 | goto out; | ||
1284 | 783 | } | ||
1285 | 784 | |||
1286 | 785 | context = g_markup_parse_context_new (parser, 0, data, NULL); | ||
1287 | 786 | |||
1288 | 787 | if (!g_markup_parse_context_parse (context, contents, len, err)) | ||
1289 | 788 | { | ||
1290 | 789 | result = FALSE; | ||
1291 | 790 | goto out; | ||
1292 | 791 | } | ||
1293 | 792 | |||
1294 | 793 | if (!g_markup_parse_context_end_parse (context, err)) | ||
1295 | 794 | { | ||
1296 | 795 | result = FALSE; | ||
1297 | 796 | goto out; | ||
1298 | 797 | } | ||
1299 | 798 | |||
1300 | 799 | out: | ||
1301 | 800 | if (contents) | ||
1302 | 801 | g_free (contents); | ||
1303 | 802 | |||
1304 | 803 | if (context) | ||
1305 | 804 | g_markup_parse_context_free (context); | ||
1306 | 805 | |||
1307 | 806 | return result; | ||
1308 | 807 | } | ||
1309 | 808 | |||
1310 | 809 | static gboolean | ||
1311 | 810 | output_match (CCRROutputInfo *output1, CCRROutputInfo *output2) | ||
1312 | 811 | { | ||
1313 | 812 | g_assert (CC_IS_RR_OUTPUT_INFO (output1)); | ||
1314 | 813 | g_assert (CC_IS_RR_OUTPUT_INFO (output2)); | ||
1315 | 814 | |||
1316 | 815 | if (strcmp (output1->priv->name, output2->priv->name) != 0) | ||
1317 | 816 | return FALSE; | ||
1318 | 817 | |||
1319 | 818 | if (strcmp (output1->priv->vendor, output2->priv->vendor) != 0) | ||
1320 | 819 | return FALSE; | ||
1321 | 820 | |||
1322 | 821 | if (output1->priv->product != output2->priv->product) | ||
1323 | 822 | return FALSE; | ||
1324 | 823 | |||
1325 | 824 | if (output1->priv->serial != output2->priv->serial) | ||
1326 | 825 | return FALSE; | ||
1327 | 826 | |||
1328 | 827 | if (output1->priv->connected != output2->priv->connected) | ||
1329 | 828 | return FALSE; | ||
1330 | 829 | |||
1331 | 830 | return TRUE; | ||
1332 | 831 | } | ||
1333 | 832 | |||
1334 | 833 | static gboolean | ||
1335 | 834 | output_equal (CCRROutputInfo *output1, CCRROutputInfo *output2) | ||
1336 | 835 | { | ||
1337 | 836 | g_assert (CC_IS_RR_OUTPUT_INFO (output1)); | ||
1338 | 837 | g_assert (CC_IS_RR_OUTPUT_INFO (output2)); | ||
1339 | 838 | |||
1340 | 839 | if (!output_match (output1, output2)) | ||
1341 | 840 | return FALSE; | ||
1342 | 841 | |||
1343 | 842 | if (output1->priv->on != output2->priv->on) | ||
1344 | 843 | return FALSE; | ||
1345 | 844 | |||
1346 | 845 | if (output1->priv->on) | ||
1347 | 846 | { | ||
1348 | 847 | if (output1->priv->width != output2->priv->width) | ||
1349 | 848 | return FALSE; | ||
1350 | 849 | |||
1351 | 850 | if (output1->priv->height != output2->priv->height) | ||
1352 | 851 | return FALSE; | ||
1353 | 852 | |||
1354 | 853 | if (output1->priv->rate != output2->priv->rate) | ||
1355 | 854 | return FALSE; | ||
1356 | 855 | |||
1357 | 856 | if (output1->priv->x != output2->priv->x) | ||
1358 | 857 | return FALSE; | ||
1359 | 858 | |||
1360 | 859 | if (output1->priv->y != output2->priv->y) | ||
1361 | 860 | return FALSE; | ||
1362 | 861 | |||
1363 | 862 | if (output1->priv->rotation != output2->priv->rotation) | ||
1364 | 863 | return FALSE; | ||
1365 | 864 | } | ||
1366 | 865 | |||
1367 | 866 | return TRUE; | ||
1368 | 867 | } | ||
1369 | 868 | |||
1370 | 869 | static CCRROutputInfo * | ||
1371 | 870 | find_output (CCRRConfig *config, const char *name) | ||
1372 | 871 | { | ||
1373 | 872 | int i; | ||
1374 | 873 | |||
1375 | 874 | for (i = 0; config->priv->outputs[i] != NULL; ++i) | ||
1376 | 875 | { | ||
1377 | 876 | CCRROutputInfo *output = config->priv->outputs[i]; | ||
1378 | 877 | |||
1379 | 878 | if (strcmp (name, output->priv->name) == 0) | ||
1380 | 879 | return output; | ||
1381 | 880 | } | ||
1382 | 881 | |||
1383 | 882 | return NULL; | ||
1384 | 883 | } | ||
1385 | 884 | |||
1386 | 885 | /* Match means "these configurations apply to the same hardware | ||
1387 | 886 | * setups" | ||
1388 | 887 | */ | ||
1389 | 888 | gboolean | ||
1390 | 889 | cc_rr_config_match (CCRRConfig *c1, CCRRConfig *c2) | ||
1391 | 890 | { | ||
1392 | 891 | int i; | ||
1393 | 892 | g_return_val_if_fail (CC_IS_RR_CONFIG (c1), FALSE); | ||
1394 | 893 | g_return_val_if_fail (CC_IS_RR_CONFIG (c2), FALSE); | ||
1395 | 894 | |||
1396 | 895 | for (i = 0; c1->priv->outputs[i] != NULL; ++i) | ||
1397 | 896 | { | ||
1398 | 897 | CCRROutputInfo *output1 = c1->priv->outputs[i]; | ||
1399 | 898 | CCRROutputInfo *output2; | ||
1400 | 899 | |||
1401 | 900 | output2 = find_output (c2, output1->priv->name); | ||
1402 | 901 | if (!output2 || !output_match (output1, output2)) | ||
1403 | 902 | return FALSE; | ||
1404 | 903 | } | ||
1405 | 904 | |||
1406 | 905 | return TRUE; | ||
1407 | 906 | } | ||
1408 | 907 | |||
1409 | 908 | /* Equal means "the configurations will result in the same | ||
1410 | 909 | * modes being set on the outputs" | ||
1411 | 910 | */ | ||
1412 | 911 | gboolean | ||
1413 | 912 | cc_rr_config_equal (CCRRConfig *c1, | ||
1414 | 913 | CCRRConfig *c2) | ||
1415 | 914 | { | ||
1416 | 915 | int i; | ||
1417 | 916 | g_return_val_if_fail (CC_IS_RR_CONFIG (c1), FALSE); | ||
1418 | 917 | g_return_val_if_fail (CC_IS_RR_CONFIG (c2), FALSE); | ||
1419 | 918 | |||
1420 | 919 | for (i = 0; c1->priv->outputs[i] != NULL; ++i) | ||
1421 | 920 | { | ||
1422 | 921 | CCRROutputInfo *output1 = c1->priv->outputs[i]; | ||
1423 | 922 | CCRROutputInfo *output2; | ||
1424 | 923 | |||
1425 | 924 | output2 = find_output (c2, output1->priv->name); | ||
1426 | 925 | if (!output2 || !output_equal (output1, output2)) | ||
1427 | 926 | return FALSE; | ||
1428 | 927 | } | ||
1429 | 928 | |||
1430 | 929 | return TRUE; | ||
1431 | 930 | } | ||
1432 | 931 | |||
1433 | 932 | static CCRROutputInfo ** | ||
1434 | 933 | make_outputs (CCRRConfig *config) | ||
1435 | 934 | { | ||
1436 | 935 | GPtrArray *outputs; | ||
1437 | 936 | CCRROutputInfo *first_on; | ||
1438 | 937 | int i; | ||
1439 | 938 | |||
1440 | 939 | outputs = g_ptr_array_new (); | ||
1441 | 940 | |||
1442 | 941 | first_on = NULL; | ||
1443 | 942 | |||
1444 | 943 | for (i = 0; config->priv->outputs[i] != NULL; ++i) | ||
1445 | 944 | { | ||
1446 | 945 | CCRROutputInfo *old = config->priv->outputs[i]; | ||
1447 | 946 | CCRROutputInfo *new = g_object_new (CC_TYPE_RR_OUTPUT_INFO, NULL); | ||
1448 | 947 | *(new->priv) = *(old->priv); | ||
1449 | 948 | if (old->priv->name) | ||
1450 | 949 | new->priv->name = g_strdup (old->priv->name); | ||
1451 | 950 | if (old->priv->display_name) | ||
1452 | 951 | new->priv->display_name = g_strdup (old->priv->display_name); | ||
1453 | 952 | |||
1454 | 953 | if (old->priv->on && !first_on) | ||
1455 | 954 | first_on = old; | ||
1456 | 955 | |||
1457 | 956 | if (config->priv->clone && new->priv->on) | ||
1458 | 957 | { | ||
1459 | 958 | g_assert (first_on); | ||
1460 | 959 | |||
1461 | 960 | new->priv->width = first_on->priv->width; | ||
1462 | 961 | new->priv->height = first_on->priv->height; | ||
1463 | 962 | new->priv->rotation = first_on->priv->rotation; | ||
1464 | 963 | new->priv->x = 0; | ||
1465 | 964 | new->priv->y = 0; | ||
1466 | 965 | } | ||
1467 | 966 | |||
1468 | 967 | g_ptr_array_add (outputs, new); | ||
1469 | 968 | } | ||
1470 | 969 | |||
1471 | 970 | g_ptr_array_add (outputs, NULL); | ||
1472 | 971 | |||
1473 | 972 | return (CCRROutputInfo **)g_ptr_array_free (outputs, FALSE); | ||
1474 | 973 | } | ||
1475 | 974 | |||
1476 | 975 | gboolean | ||
1477 | 976 | cc_rr_config_applicable (CCRRConfig *configuration, | ||
1478 | 977 | CCRRScreen *screen, | ||
1479 | 978 | GError **error) | ||
1480 | 979 | { | ||
1481 | 980 | CCRROutputInfo **outputs; | ||
1482 | 981 | CrtcAssignment *assign; | ||
1483 | 982 | gboolean result; | ||
1484 | 983 | int i; | ||
1485 | 984 | |||
1486 | 985 | g_return_val_if_fail (CC_IS_RR_CONFIG (configuration), FALSE); | ||
1487 | 986 | g_return_val_if_fail (CC_IS_RR_SCREEN (screen), FALSE); | ||
1488 | 987 | g_return_val_if_fail (error == NULL || *error == NULL, FALSE); | ||
1489 | 988 | |||
1490 | 989 | outputs = make_outputs (configuration); | ||
1491 | 990 | assign = crtc_assignment_new (screen, outputs, error); | ||
1492 | 991 | |||
1493 | 992 | if (assign) | ||
1494 | 993 | { | ||
1495 | 994 | result = TRUE; | ||
1496 | 995 | crtc_assignment_free (assign); | ||
1497 | 996 | } | ||
1498 | 997 | else | ||
1499 | 998 | { | ||
1500 | 999 | result = FALSE; | ||
1501 | 1000 | } | ||
1502 | 1001 | |||
1503 | 1002 | for (i = 0; outputs[i] != NULL; i++) { | ||
1504 | 1003 | g_object_unref (outputs[i]); | ||
1505 | 1004 | } | ||
1506 | 1005 | |||
1507 | 1006 | return result; | ||
1508 | 1007 | } | ||
1509 | 1008 | |||
1510 | 1009 | /* Database management */ | ||
1511 | 1010 | |||
1512 | 1011 | static void | ||
1513 | 1012 | ensure_config_directory (void) | ||
1514 | 1013 | { | ||
1515 | 1014 | g_mkdir_with_parents (g_get_user_config_dir (), 0700); | ||
1516 | 1015 | } | ||
1517 | 1016 | |||
1518 | 1017 | char * | ||
1519 | 1018 | cc_rr_config_get_backup_filename (void) | ||
1520 | 1019 | { | ||
1521 | 1020 | ensure_config_directory (); | ||
1522 | 1021 | return g_build_filename (g_get_user_config_dir (), CONFIG_BACKUP_BASENAME, NULL); | ||
1523 | 1022 | } | ||
1524 | 1023 | |||
1525 | 1024 | char * | ||
1526 | 1025 | cc_rr_config_get_intended_filename (void) | ||
1527 | 1026 | { | ||
1528 | 1027 | ensure_config_directory (); | ||
1529 | 1028 | return g_build_filename (g_get_user_config_dir (), CONFIG_INTENDED_BASENAME, NULL); | ||
1530 | 1029 | } | ||
1531 | 1030 | |||
1532 | 1031 | static const char * | ||
1533 | 1032 | get_rotation_name (CCRRRotation r) | ||
1534 | 1033 | { | ||
1535 | 1034 | if (r & CC_RR_ROTATION_0) | ||
1536 | 1035 | return "normal"; | ||
1537 | 1036 | if (r & CC_RR_ROTATION_90) | ||
1538 | 1037 | return "left"; | ||
1539 | 1038 | if (r & CC_RR_ROTATION_180) | ||
1540 | 1039 | return "upside_down"; | ||
1541 | 1040 | if (r & CC_RR_ROTATION_270) | ||
1542 | 1041 | return "right"; | ||
1543 | 1042 | |||
1544 | 1043 | return "normal"; | ||
1545 | 1044 | } | ||
1546 | 1045 | |||
1547 | 1046 | static const char * | ||
1548 | 1047 | yes_no (int x) | ||
1549 | 1048 | { | ||
1550 | 1049 | return x? "yes" : "no"; | ||
1551 | 1050 | } | ||
1552 | 1051 | |||
1553 | 1052 | static const char * | ||
1554 | 1053 | get_reflect_x (CCRRRotation r) | ||
1555 | 1054 | { | ||
1556 | 1055 | return yes_no (r & CC_RR_REFLECT_X); | ||
1557 | 1056 | } | ||
1558 | 1057 | |||
1559 | 1058 | static const char * | ||
1560 | 1059 | get_reflect_y (CCRRRotation r) | ||
1561 | 1060 | { | ||
1562 | 1061 | return yes_no (r & CC_RR_REFLECT_Y); | ||
1563 | 1062 | } | ||
1564 | 1063 | |||
1565 | 1064 | static void | ||
1566 | 1065 | emit_configuration (CCRRConfig *config, | ||
1567 | 1066 | GString *string) | ||
1568 | 1067 | { | ||
1569 | 1068 | int j; | ||
1570 | 1069 | |||
1571 | 1070 | g_string_append_printf (string, " <configuration>\n"); | ||
1572 | 1071 | |||
1573 | 1072 | g_string_append_printf (string, " <clone>%s</clone>\n", yes_no (config->priv->clone)); | ||
1574 | 1073 | |||
1575 | 1074 | for (j = 0; config->priv->outputs[j] != NULL; ++j) | ||
1576 | 1075 | { | ||
1577 | 1076 | CCRROutputInfo *output = config->priv->outputs[j]; | ||
1578 | 1077 | |||
1579 | 1078 | g_string_append_printf ( | ||
1580 | 1079 | string, " <output name=\"%s\">\n", output->priv->name); | ||
1581 | 1080 | |||
1582 | 1081 | if (output->priv->connected && *output->priv->vendor != '\0') | ||
1583 | 1082 | { | ||
1584 | 1083 | g_string_append_printf ( | ||
1585 | 1084 | string, " <vendor>%s</vendor>\n", output->priv->vendor); | ||
1586 | 1085 | g_string_append_printf ( | ||
1587 | 1086 | string, " <product>0x%04x</product>\n", output->priv->product); | ||
1588 | 1087 | g_string_append_printf ( | ||
1589 | 1088 | string, " <serial>0x%08x</serial>\n", output->priv->serial); | ||
1590 | 1089 | } | ||
1591 | 1090 | |||
1592 | 1091 | /* An unconnected output which is on does not make sense */ | ||
1593 | 1092 | if (output->priv->connected && output->priv->on) | ||
1594 | 1093 | { | ||
1595 | 1094 | g_string_append_printf ( | ||
1596 | 1095 | string, " <width>%d</width>\n", output->priv->width); | ||
1597 | 1096 | g_string_append_printf ( | ||
1598 | 1097 | string, " <height>%d</height>\n", output->priv->height); | ||
1599 | 1098 | g_string_append_printf ( | ||
1600 | 1099 | string, " <rate>%d</rate>\n", output->priv->rate); | ||
1601 | 1100 | g_string_append_printf ( | ||
1602 | 1101 | string, " <x>%d</x>\n", output->priv->x); | ||
1603 | 1102 | g_string_append_printf ( | ||
1604 | 1103 | string, " <y>%d</y>\n", output->priv->y); | ||
1605 | 1104 | g_string_append_printf ( | ||
1606 | 1105 | string, " <rotation>%s</rotation>\n", get_rotation_name (output->priv->rotation)); | ||
1607 | 1106 | g_string_append_printf ( | ||
1608 | 1107 | string, " <reflect_x>%s</reflect_x>\n", get_reflect_x (output->priv->rotation)); | ||
1609 | 1108 | g_string_append_printf ( | ||
1610 | 1109 | string, " <reflect_y>%s</reflect_y>\n", get_reflect_y (output->priv->rotation)); | ||
1611 | 1110 | g_string_append_printf ( | ||
1612 | 1111 | string, " <primary>%s</primary>\n", yes_no (output->priv->primary)); | ||
1613 | 1112 | } | ||
1614 | 1113 | |||
1615 | 1114 | g_string_append_printf (string, " </output>\n"); | ||
1616 | 1115 | } | ||
1617 | 1116 | |||
1618 | 1117 | g_string_append_printf (string, " </configuration>\n"); | ||
1619 | 1118 | } | ||
1620 | 1119 | |||
1621 | 1120 | void | ||
1622 | 1121 | cc_rr_config_sanitize (CCRRConfig *config) | ||
1623 | 1122 | { | ||
1624 | 1123 | int i; | ||
1625 | 1124 | int x_offset, y_offset; | ||
1626 | 1125 | gboolean found; | ||
1627 | 1126 | |||
1628 | 1127 | /* Offset everything by the top/left-most coordinate to | ||
1629 | 1128 | * make sure the configuration starts at (0, 0) | ||
1630 | 1129 | */ | ||
1631 | 1130 | x_offset = y_offset = G_MAXINT; | ||
1632 | 1131 | for (i = 0; config->priv->outputs[i]; ++i) | ||
1633 | 1132 | { | ||
1634 | 1133 | CCRROutputInfo *output = config->priv->outputs[i]; | ||
1635 | 1134 | |||
1636 | 1135 | if (output->priv->on) | ||
1637 | 1136 | { | ||
1638 | 1137 | x_offset = MIN (x_offset, output->priv->x); | ||
1639 | 1138 | y_offset = MIN (y_offset, output->priv->y); | ||
1640 | 1139 | } | ||
1641 | 1140 | } | ||
1642 | 1141 | |||
1643 | 1142 | for (i = 0; config->priv->outputs[i]; ++i) | ||
1644 | 1143 | { | ||
1645 | 1144 | CCRROutputInfo *output = config->priv->outputs[i]; | ||
1646 | 1145 | |||
1647 | 1146 | if (output->priv->on) | ||
1648 | 1147 | { | ||
1649 | 1148 | output->priv->x -= x_offset; | ||
1650 | 1149 | output->priv->y -= y_offset; | ||
1651 | 1150 | } | ||
1652 | 1151 | } | ||
1653 | 1152 | |||
1654 | 1153 | /* Only one primary, please */ | ||
1655 | 1154 | found = FALSE; | ||
1656 | 1155 | for (i = 0; config->priv->outputs[i]; ++i) | ||
1657 | 1156 | { | ||
1658 | 1157 | if (config->priv->outputs[i]->priv->primary) | ||
1659 | 1158 | { | ||
1660 | 1159 | if (found) | ||
1661 | 1160 | { | ||
1662 | 1161 | config->priv->outputs[i]->priv->primary = FALSE; | ||
1663 | 1162 | } | ||
1664 | 1163 | else | ||
1665 | 1164 | { | ||
1666 | 1165 | found = TRUE; | ||
1667 | 1166 | } | ||
1668 | 1167 | } | ||
1669 | 1168 | } | ||
1670 | 1169 | } | ||
1671 | 1170 | |||
1672 | 1171 | gboolean | ||
1673 | 1172 | cc_rr_config_ensure_primary (CCRRConfig *configuration) | ||
1674 | 1173 | { | ||
1675 | 1174 | int i; | ||
1676 | 1175 | CCRROutputInfo *laptop; | ||
1677 | 1176 | CCRROutputInfo *top_left; | ||
1678 | 1177 | gboolean found; | ||
1679 | 1178 | CCRRConfigPrivate *priv; | ||
1680 | 1179 | |||
1681 | 1180 | g_return_val_if_fail (CC_IS_RR_CONFIG (configuration), FALSE); | ||
1682 | 1181 | |||
1683 | 1182 | laptop = NULL; | ||
1684 | 1183 | top_left = NULL; | ||
1685 | 1184 | found = FALSE; | ||
1686 | 1185 | priv = configuration->priv; | ||
1687 | 1186 | |||
1688 | 1187 | for (i = 0; priv->outputs[i] != NULL; ++i) { | ||
1689 | 1188 | CCRROutputInfo *info = priv->outputs[i]; | ||
1690 | 1189 | |||
1691 | 1190 | if (!info->priv->on) { | ||
1692 | 1191 | info->priv->primary = FALSE; | ||
1693 | 1192 | continue; | ||
1694 | 1193 | } | ||
1695 | 1194 | |||
1696 | 1195 | /* ensure only one */ | ||
1697 | 1196 | if (info->priv->primary) { | ||
1698 | 1197 | if (found) { | ||
1699 | 1198 | info->priv->primary = FALSE; | ||
1700 | 1199 | } else { | ||
1701 | 1200 | found = TRUE; | ||
1702 | 1201 | } | ||
1703 | 1202 | } | ||
1704 | 1203 | |||
1705 | 1204 | if (top_left == NULL | ||
1706 | 1205 | || (info->priv->x < top_left->priv->x | ||
1707 | 1206 | && info->priv->y < top_left->priv->y)) { | ||
1708 | 1207 | top_left = info; | ||
1709 | 1208 | } | ||
1710 | 1209 | if (laptop == NULL | ||
1711 | 1210 | && _cc_rr_output_name_is_laptop (info->priv->name)) { | ||
1712 | 1211 | /* shame we can't find the connector type | ||
1713 | 1212 | as with cc_rr_output_is_laptop */ | ||
1714 | 1213 | laptop = info; | ||
1715 | 1214 | } | ||
1716 | 1215 | } | ||
1717 | 1216 | |||
1718 | 1217 | if (!found) { | ||
1719 | 1218 | if (laptop != NULL) { | ||
1720 | 1219 | laptop->priv->primary = TRUE; | ||
1721 | 1220 | } else if (top_left != NULL) { | ||
1722 | 1221 | /* Note: top_left can be NULL if all outputs are off */ | ||
1723 | 1222 | top_left->priv->primary = TRUE; | ||
1724 | 1223 | } | ||
1725 | 1224 | } | ||
1726 | 1225 | |||
1727 | 1226 | return !found; | ||
1728 | 1227 | } | ||
1729 | 1228 | |||
1730 | 1229 | gboolean | ||
1731 | 1230 | cc_rr_config_save (CCRRConfig *configuration, GError **error) | ||
1732 | 1231 | { | ||
1733 | 1232 | CCRRConfig **configurations; | ||
1734 | 1233 | GString *output; | ||
1735 | 1234 | int i; | ||
1736 | 1235 | gchar *intended_filename; | ||
1737 | 1236 | gchar *backup_filename; | ||
1738 | 1237 | gboolean result; | ||
1739 | 1238 | |||
1740 | 1239 | g_return_val_if_fail (CC_IS_RR_CONFIG (configuration), FALSE); | ||
1741 | 1240 | g_return_val_if_fail (error == NULL || *error == NULL, FALSE); | ||
1742 | 1241 | |||
1743 | 1242 | output = g_string_new (""); | ||
1744 | 1243 | |||
1745 | 1244 | backup_filename = cc_rr_config_get_backup_filename (); | ||
1746 | 1245 | intended_filename = cc_rr_config_get_intended_filename (); | ||
1747 | 1246 | |||
1748 | 1247 | configurations = configurations_read_from_file (intended_filename, NULL); /* NULL-GError */ | ||
1749 | 1248 | |||
1750 | 1249 | g_string_append_printf (output, "<monitors version=\"1\">\n"); | ||
1751 | 1250 | |||
1752 | 1251 | if (configurations) | ||
1753 | 1252 | { | ||
1754 | 1253 | for (i = 0; configurations[i] != NULL; ++i) | ||
1755 | 1254 | { | ||
1756 | 1255 | if (!cc_rr_config_match (configurations[i], configuration)) | ||
1757 | 1256 | emit_configuration (configurations[i], output); | ||
1758 | 1257 | g_object_unref (configurations[i]); | ||
1759 | 1258 | } | ||
1760 | 1259 | |||
1761 | 1260 | g_free (configurations); | ||
1762 | 1261 | } | ||
1763 | 1262 | |||
1764 | 1263 | emit_configuration (configuration, output); | ||
1765 | 1264 | |||
1766 | 1265 | g_string_append_printf (output, "</monitors>\n"); | ||
1767 | 1266 | |||
1768 | 1267 | /* backup the file first */ | ||
1769 | 1268 | rename (intended_filename, backup_filename); /* no error checking because the intended file may not even exist */ | ||
1770 | 1269 | |||
1771 | 1270 | result = g_file_set_contents (intended_filename, output->str, -1, error); | ||
1772 | 1271 | |||
1773 | 1272 | if (!result) | ||
1774 | 1273 | rename (backup_filename, intended_filename); /* no error checking because the backup may not even exist */ | ||
1775 | 1274 | |||
1776 | 1275 | g_free (backup_filename); | ||
1777 | 1276 | g_free (intended_filename); | ||
1778 | 1277 | |||
1779 | 1278 | return result; | ||
1780 | 1279 | } | ||
1781 | 1280 | |||
1782 | 1281 | gboolean | ||
1783 | 1282 | cc_rr_config_apply_with_time (CCRRConfig *config, | ||
1784 | 1283 | CCRRScreen *screen, | ||
1785 | 1284 | guint32 timestamp, | ||
1786 | 1285 | GError **error) | ||
1787 | 1286 | { | ||
1788 | 1287 | CrtcAssignment *assignment; | ||
1789 | 1288 | CCRROutputInfo **outputs; | ||
1790 | 1289 | gboolean result = FALSE; | ||
1791 | 1290 | int i; | ||
1792 | 1291 | |||
1793 | 1292 | g_return_val_if_fail (CC_IS_RR_CONFIG (config), FALSE); | ||
1794 | 1293 | g_return_val_if_fail (CC_IS_RR_SCREEN (screen), FALSE); | ||
1795 | 1294 | |||
1796 | 1295 | outputs = make_outputs (config); | ||
1797 | 1296 | |||
1798 | 1297 | assignment = crtc_assignment_new (screen, outputs, error); | ||
1799 | 1298 | |||
1800 | 1299 | for (i = 0; outputs[i] != NULL; i++) | ||
1801 | 1300 | g_object_unref (outputs[i]); | ||
1802 | 1301 | g_free (outputs); | ||
1803 | 1302 | |||
1804 | 1303 | if (assignment) | ||
1805 | 1304 | { | ||
1806 | 1305 | if (crtc_assignment_apply (assignment, timestamp, error)) | ||
1807 | 1306 | result = TRUE; | ||
1808 | 1307 | |||
1809 | 1308 | crtc_assignment_free (assignment); | ||
1810 | 1309 | |||
1811 | 1310 | gdk_flush (); | ||
1812 | 1311 | } | ||
1813 | 1312 | |||
1814 | 1313 | return result; | ||
1815 | 1314 | } | ||
1816 | 1315 | |||
1817 | 1316 | /* cc_rr_config_apply_from_filename_with_time: | ||
1818 | 1317 | * @screen: A #CCRRScreen | ||
1819 | 1318 | * @filename: Path of the file to look in for stored RANDR configurations. | ||
1820 | 1319 | * @timestamp: X server timestamp from the event that causes the screen configuration to change (a user's button press, for example) | ||
1821 | 1320 | * @error: Location to store error, or %NULL | ||
1822 | 1321 | * | ||
1823 | 1322 | * Loads the file in @filename and looks for suitable matching RANDR | ||
1824 | 1323 | * configurations in the file; if one is found, that configuration will be | ||
1825 | 1324 | * applied to the current set of RANDR outputs. | ||
1826 | 1325 | * | ||
1827 | 1326 | * Typically, @filename is the result of cc_rr_config_get_intended_filename() or | ||
1828 | 1327 | * cc_rr_config_get_backup_filename(). | ||
1829 | 1328 | * | ||
1830 | 1329 | * Returns: TRUE if the RANDR configuration was loaded and applied from | ||
1831 | 1330 | * the specified file, or FALSE otherwise: | ||
1832 | 1331 | * | ||
1833 | 1332 | * If the file in question is loaded successfully but the configuration cannot | ||
1834 | 1333 | * be applied, the @error will have a domain of #CC_RR_ERROR. Note that an | ||
1835 | 1334 | * error code of #CC_RR_ERROR_NO_MATCHING_CONFIG is not a real error; it | ||
1836 | 1335 | * simply means that there were no stored configurations that match the current | ||
1837 | 1336 | * set of RANDR outputs. | ||
1838 | 1337 | * | ||
1839 | 1338 | * If the file in question cannot be loaded, the @error will have a domain of | ||
1840 | 1339 | * #G_FILE_ERROR. Note that an error code of G_FILE_ERROR_NOENT is not really | ||
1841 | 1340 | * an error, either; it means that there was no stored configuration file and so | ||
1842 | 1341 | * nothing is changed. | ||
1843 | 1342 | */ | ||
1844 | 1343 | gboolean | ||
1845 | 1344 | cc_rr_config_apply_from_filename_with_time (CCRRScreen *screen, const char *filename, guint32 timestamp, GError **error) | ||
1846 | 1345 | { | ||
1847 | 1346 | CCRRConfig *stored; | ||
1848 | 1347 | |||
1849 | 1348 | g_return_val_if_fail (CC_IS_RR_SCREEN (screen), FALSE); | ||
1850 | 1349 | g_return_val_if_fail (filename != NULL, FALSE); | ||
1851 | 1350 | g_return_val_if_fail (error == NULL || *error == NULL, FALSE); | ||
1852 | 1351 | |||
1853 | 1352 | stored = g_object_new (CC_TYPE_RR_CONFIG, "screen", screen, NULL); | ||
1854 | 1353 | |||
1855 | 1354 | if (cc_rr_config_load_filename (stored, filename, error)) | ||
1856 | 1355 | { | ||
1857 | 1356 | gboolean result; | ||
1858 | 1357 | |||
1859 | 1358 | cc_rr_config_ensure_primary (stored); | ||
1860 | 1359 | result = cc_rr_config_apply_with_time (stored, screen, timestamp, error); | ||
1861 | 1360 | |||
1862 | 1361 | g_object_unref (stored); | ||
1863 | 1362 | return result; | ||
1864 | 1363 | } | ||
1865 | 1364 | else | ||
1866 | 1365 | { | ||
1867 | 1366 | g_object_unref (stored); | ||
1868 | 1367 | return FALSE; | ||
1869 | 1368 | } | ||
1870 | 1369 | } | ||
1871 | 1370 | |||
1872 | 1371 | /** | ||
1873 | 1372 | * cc_rr_config_get_outputs: | ||
1874 | 1373 | * | ||
1875 | 1374 | * Returns: (array zero-terminated=1) (element-type GnomeDesktop.RROutputInfo) (transfer none): the output configuration for this #CCRRConfig | ||
1876 | 1375 | */ | ||
1877 | 1376 | CCRROutputInfo ** | ||
1878 | 1377 | cc_rr_config_get_outputs (CCRRConfig *self) | ||
1879 | 1378 | { | ||
1880 | 1379 | g_return_val_if_fail (CC_IS_RR_CONFIG (self), NULL); | ||
1881 | 1380 | |||
1882 | 1381 | return self->priv->outputs; | ||
1883 | 1382 | } | ||
1884 | 1383 | |||
1885 | 1384 | /** | ||
1886 | 1385 | * cc_rr_config_get_clone: | ||
1887 | 1386 | * | ||
1888 | 1387 | * Returns: whether at least two outputs are at (0, 0) offset and they | ||
1889 | 1388 | * have the same width/height. Those outputs are of course connected and on | ||
1890 | 1389 | * (i.e. they have a CRTC assigned). | ||
1891 | 1390 | */ | ||
1892 | 1391 | gboolean | ||
1893 | 1392 | cc_rr_config_get_clone (CCRRConfig *self) | ||
1894 | 1393 | { | ||
1895 | 1394 | g_return_val_if_fail (CC_IS_RR_CONFIG (self), FALSE); | ||
1896 | 1395 | |||
1897 | 1396 | return self->priv->clone; | ||
1898 | 1397 | } | ||
1899 | 1398 | |||
1900 | 1399 | void | ||
1901 | 1400 | cc_rr_config_set_clone (CCRRConfig *self, gboolean clone) | ||
1902 | 1401 | { | ||
1903 | 1402 | g_return_if_fail (CC_IS_RR_CONFIG (self)); | ||
1904 | 1403 | |||
1905 | 1404 | self->priv->clone = clone; | ||
1906 | 1405 | } | ||
1907 | 1406 | |||
1908 | 1407 | /* | ||
1909 | 1408 | * CRTC assignment | ||
1910 | 1409 | */ | ||
1911 | 1410 | typedef struct CrtcInfo CrtcInfo; | ||
1912 | 1411 | |||
1913 | 1412 | struct CrtcInfo | ||
1914 | 1413 | { | ||
1915 | 1414 | CCRRMode *mode; | ||
1916 | 1415 | int x; | ||
1917 | 1416 | int y; | ||
1918 | 1417 | CCRRRotation rotation; | ||
1919 | 1418 | GPtrArray *outputs; | ||
1920 | 1419 | }; | ||
1921 | 1420 | |||
1922 | 1421 | struct CrtcAssignment | ||
1923 | 1422 | { | ||
1924 | 1423 | CCRRScreen *screen; | ||
1925 | 1424 | GHashTable *info; | ||
1926 | 1425 | CCRROutput *primary; | ||
1927 | 1426 | }; | ||
1928 | 1427 | |||
1929 | 1428 | static gboolean | ||
1930 | 1429 | can_clone (CrtcInfo *info, | ||
1931 | 1430 | CCRROutput *output) | ||
1932 | 1431 | { | ||
1933 | 1432 | int i; | ||
1934 | 1433 | |||
1935 | 1434 | for (i = 0; i < info->outputs->len; ++i) | ||
1936 | 1435 | { | ||
1937 | 1436 | CCRROutput *clone = info->outputs->pdata[i]; | ||
1938 | 1437 | |||
1939 | 1438 | if (!cc_rr_output_can_clone (clone, output)) | ||
1940 | 1439 | return FALSE; | ||
1941 | 1440 | } | ||
1942 | 1441 | |||
1943 | 1442 | return TRUE; | ||
1944 | 1443 | } | ||
1945 | 1444 | |||
1946 | 1445 | static gboolean | ||
1947 | 1446 | crtc_assignment_assign (CrtcAssignment *assign, | ||
1948 | 1447 | CCRRCrtc *crtc, | ||
1949 | 1448 | CCRRMode *mode, | ||
1950 | 1449 | int x, | ||
1951 | 1450 | int y, | ||
1952 | 1451 | CCRRRotation rotation, | ||
1953 | 1452 | gboolean primary, | ||
1954 | 1453 | CCRROutput *output, | ||
1955 | 1454 | GError **error) | ||
1956 | 1455 | { | ||
1957 | 1456 | CrtcInfo *info = g_hash_table_lookup (assign->info, crtc); | ||
1958 | 1457 | guint32 crtc_id; | ||
1959 | 1458 | const char *output_name; | ||
1960 | 1459 | |||
1961 | 1460 | crtc_id = cc_rr_crtc_get_id (crtc); | ||
1962 | 1461 | output_name = cc_rr_output_get_name (output); | ||
1963 | 1462 | |||
1964 | 1463 | if (!cc_rr_crtc_can_drive_output (crtc, output)) | ||
1965 | 1464 | { | ||
1966 | 1465 | g_set_error (error, CC_RR_ERROR, CC_RR_ERROR_CRTC_ASSIGNMENT, | ||
1967 | 1466 | _("CRTC %d cannot drive output %s"), crtc_id, output_name); | ||
1968 | 1467 | return FALSE; | ||
1969 | 1468 | } | ||
1970 | 1469 | |||
1971 | 1470 | if (!cc_rr_output_supports_mode (output, mode)) | ||
1972 | 1471 | { | ||
1973 | 1472 | g_set_error (error, CC_RR_ERROR, CC_RR_ERROR_CRTC_ASSIGNMENT, | ||
1974 | 1473 | _("output %s does not support mode %dx%d@%dHz"), | ||
1975 | 1474 | output_name, | ||
1976 | 1475 | cc_rr_mode_get_width (mode), | ||
1977 | 1476 | cc_rr_mode_get_height (mode), | ||
1978 | 1477 | cc_rr_mode_get_freq (mode)); | ||
1979 | 1478 | return FALSE; | ||
1980 | 1479 | } | ||
1981 | 1480 | |||
1982 | 1481 | if (!cc_rr_crtc_supports_rotation (crtc, rotation)) | ||
1983 | 1482 | { | ||
1984 | 1483 | g_set_error (error, CC_RR_ERROR, CC_RR_ERROR_CRTC_ASSIGNMENT, | ||
1985 | 1484 | _("CRTC %d does not support rotation=%s"), | ||
1986 | 1485 | crtc_id, | ||
1987 | 1486 | get_rotation_name (rotation)); | ||
1988 | 1487 | return FALSE; | ||
1989 | 1488 | } | ||
1990 | 1489 | |||
1991 | 1490 | if (info) | ||
1992 | 1491 | { | ||
1993 | 1492 | if (!(info->mode == mode && | ||
1994 | 1493 | info->x == x && | ||
1995 | 1494 | info->y == y && | ||
1996 | 1495 | info->rotation == rotation)) | ||
1997 | 1496 | { | ||
1998 | 1497 | g_set_error (error, CC_RR_ERROR, CC_RR_ERROR_CRTC_ASSIGNMENT, | ||
1999 | 1498 | _("output %s does not have the same parameters as another cloned output:\n" | ||
2000 | 1499 | "existing mode = %d, new mode = %d\n" | ||
2001 | 1500 | "existing coordinates = (%d, %d), new coordinates = (%d, %d)\n" | ||
2002 | 1501 | "existing rotation = %s, new rotation = %s"), | ||
2003 | 1502 | output_name, | ||
2004 | 1503 | cc_rr_mode_get_id (info->mode), cc_rr_mode_get_id (mode), | ||
2005 | 1504 | info->x, info->y, | ||
2006 | 1505 | x, y, | ||
2007 | 1506 | get_rotation_name (info->rotation), get_rotation_name (rotation)); | ||
2008 | 1507 | return FALSE; | ||
2009 | 1508 | } | ||
2010 | 1509 | |||
2011 | 1510 | if (!can_clone (info, output)) | ||
2012 | 1511 | { | ||
2013 | 1512 | g_set_error (error, CC_RR_ERROR, CC_RR_ERROR_CRTC_ASSIGNMENT, | ||
2014 | 1513 | _("cannot clone to output %s"), | ||
2015 | 1514 | output_name); | ||
2016 | 1515 | return FALSE; | ||
2017 | 1516 | } | ||
2018 | 1517 | |||
2019 | 1518 | g_ptr_array_add (info->outputs, output); | ||
2020 | 1519 | |||
2021 | 1520 | if (primary && !assign->primary) | ||
2022 | 1521 | { | ||
2023 | 1522 | assign->primary = output; | ||
2024 | 1523 | } | ||
2025 | 1524 | |||
2026 | 1525 | return TRUE; | ||
2027 | 1526 | } | ||
2028 | 1527 | else | ||
2029 | 1528 | { | ||
2030 | 1529 | CrtcInfo *info = g_new0 (CrtcInfo, 1); | ||
2031 | 1530 | |||
2032 | 1531 | info->mode = mode; | ||
2033 | 1532 | info->x = x; | ||
2034 | 1533 | info->y = y; | ||
2035 | 1534 | info->rotation = rotation; | ||
2036 | 1535 | info->outputs = g_ptr_array_new (); | ||
2037 | 1536 | |||
2038 | 1537 | g_ptr_array_add (info->outputs, output); | ||
2039 | 1538 | |||
2040 | 1539 | g_hash_table_insert (assign->info, crtc, info); | ||
2041 | 1540 | |||
2042 | 1541 | if (primary && !assign->primary) | ||
2043 | 1542 | { | ||
2044 | 1543 | assign->primary = output; | ||
2045 | 1544 | } | ||
2046 | 1545 | |||
2047 | 1546 | return TRUE; | ||
2048 | 1547 | } | ||
2049 | 1548 | } | ||
2050 | 1549 | |||
2051 | 1550 | static void | ||
2052 | 1551 | crtc_assignment_unassign (CrtcAssignment *assign, | ||
2053 | 1552 | CCRRCrtc *crtc, | ||
2054 | 1553 | CCRROutput *output) | ||
2055 | 1554 | { | ||
2056 | 1555 | CrtcInfo *info = g_hash_table_lookup (assign->info, crtc); | ||
2057 | 1556 | |||
2058 | 1557 | if (info) | ||
2059 | 1558 | { | ||
2060 | 1559 | g_ptr_array_remove (info->outputs, output); | ||
2061 | 1560 | |||
2062 | 1561 | if (assign->primary == output) | ||
2063 | 1562 | { | ||
2064 | 1563 | assign->primary = NULL; | ||
2065 | 1564 | } | ||
2066 | 1565 | |||
2067 | 1566 | if (info->outputs->len == 0) | ||
2068 | 1567 | g_hash_table_remove (assign->info, crtc); | ||
2069 | 1568 | } | ||
2070 | 1569 | } | ||
2071 | 1570 | |||
2072 | 1571 | static void | ||
2073 | 1572 | crtc_assignment_free (CrtcAssignment *assign) | ||
2074 | 1573 | { | ||
2075 | 1574 | g_hash_table_destroy (assign->info); | ||
2076 | 1575 | |||
2077 | 1576 | g_free (assign); | ||
2078 | 1577 | } | ||
2079 | 1578 | |||
2080 | 1579 | typedef struct { | ||
2081 | 1580 | guint32 timestamp; | ||
2082 | 1581 | gboolean has_error; | ||
2083 | 1582 | GError **error; | ||
2084 | 1583 | } ConfigureCrtcState; | ||
2085 | 1584 | |||
2086 | 1585 | static void | ||
2087 | 1586 | configure_crtc (gpointer key, | ||
2088 | 1587 | gpointer value, | ||
2089 | 1588 | gpointer data) | ||
2090 | 1589 | { | ||
2091 | 1590 | CCRRCrtc *crtc = key; | ||
2092 | 1591 | CrtcInfo *info = value; | ||
2093 | 1592 | ConfigureCrtcState *state = data; | ||
2094 | 1593 | |||
2095 | 1594 | if (state->has_error) | ||
2096 | 1595 | return; | ||
2097 | 1596 | |||
2098 | 1597 | if (!cc_rr_crtc_set_config_with_time (crtc, | ||
2099 | 1598 | state->timestamp, | ||
2100 | 1599 | info->x, info->y, | ||
2101 | 1600 | info->mode, | ||
2102 | 1601 | info->rotation, | ||
2103 | 1602 | (CCRROutput **)info->outputs->pdata, | ||
2104 | 1603 | info->outputs->len, | ||
2105 | 1604 | state->error)) | ||
2106 | 1605 | state->has_error = TRUE; | ||
2107 | 1606 | } | ||
2108 | 1607 | |||
2109 | 1608 | static gboolean | ||
2110 | 1609 | mode_is_rotated (CrtcInfo *info) | ||
2111 | 1610 | { | ||
2112 | 1611 | if ((info->rotation & CC_RR_ROTATION_270) || | ||
2113 | 1612 | (info->rotation & CC_RR_ROTATION_90)) | ||
2114 | 1613 | { | ||
2115 | 1614 | return TRUE; | ||
2116 | 1615 | } | ||
2117 | 1616 | return FALSE; | ||
2118 | 1617 | } | ||
2119 | 1618 | |||
2120 | 1619 | static gboolean | ||
2121 | 1620 | crtc_is_rotated (CCRRCrtc *crtc) | ||
2122 | 1621 | { | ||
2123 | 1622 | CCRRRotation r = cc_rr_crtc_get_current_rotation (crtc); | ||
2124 | 1623 | |||
2125 | 1624 | if ((r & CC_RR_ROTATION_270) || | ||
2126 | 1625 | (r & CC_RR_ROTATION_90)) | ||
2127 | 1626 | { | ||
2128 | 1627 | return TRUE; | ||
2129 | 1628 | } | ||
2130 | 1629 | |||
2131 | 1630 | return FALSE; | ||
2132 | 1631 | } | ||
2133 | 1632 | |||
2134 | 1633 | static void | ||
2135 | 1634 | accumulate_error (GString *accumulated_error, GError *error) | ||
2136 | 1635 | { | ||
2137 | 1636 | g_string_append_printf (accumulated_error, " %s\n", error->message); | ||
2138 | 1637 | g_error_free (error); | ||
2139 | 1638 | } | ||
2140 | 1639 | |||
2141 | 1640 | /* Check whether the given set of settings can be used | ||
2142 | 1641 | * at the same time -- ie. whether there is an assignment | ||
2143 | 1642 | * of CRTC's to outputs. | ||
2144 | 1643 | * | ||
2145 | 1644 | * Brute force - the number of objects involved is small | ||
2146 | 1645 | * enough that it doesn't matter. | ||
2147 | 1646 | */ | ||
2148 | 1647 | static gboolean | ||
2149 | 1648 | real_assign_crtcs (CCRRScreen *screen, | ||
2150 | 1649 | CCRROutputInfo **outputs, | ||
2151 | 1650 | CrtcAssignment *assignment, | ||
2152 | 1651 | GError **error) | ||
2153 | 1652 | { | ||
2154 | 1653 | CCRRCrtc **crtcs = cc_rr_screen_list_crtcs (screen); | ||
2155 | 1654 | CCRROutputInfo *output; | ||
2156 | 1655 | int i; | ||
2157 | 1656 | gboolean tried_mode; | ||
2158 | 1657 | GError *my_error; | ||
2159 | 1658 | GString *accumulated_error; | ||
2160 | 1659 | gboolean success; | ||
2161 | 1660 | |||
2162 | 1661 | output = *outputs; | ||
2163 | 1662 | if (!output) | ||
2164 | 1663 | return TRUE; | ||
2165 | 1664 | |||
2166 | 1665 | /* It is always allowed for an output to be turned off */ | ||
2167 | 1666 | if (!output->priv->on) | ||
2168 | 1667 | { | ||
2169 | 1668 | return real_assign_crtcs (screen, outputs + 1, assignment, error); | ||
2170 | 1669 | } | ||
2171 | 1670 | |||
2172 | 1671 | success = FALSE; | ||
2173 | 1672 | tried_mode = FALSE; | ||
2174 | 1673 | accumulated_error = g_string_new (NULL); | ||
2175 | 1674 | |||
2176 | 1675 | for (i = 0; crtcs[i] != NULL; ++i) | ||
2177 | 1676 | { | ||
2178 | 1677 | CCRRCrtc *crtc = crtcs[i]; | ||
2179 | 1678 | int crtc_id = cc_rr_crtc_get_id (crtc); | ||
2180 | 1679 | int pass; | ||
2181 | 1680 | |||
2182 | 1681 | g_string_append_printf (accumulated_error, | ||
2183 | 1682 | _("Trying modes for CRTC %d\n"), | ||
2184 | 1683 | crtc_id); | ||
2185 | 1684 | |||
2186 | 1685 | /* Make two passes, one where frequencies must match, then | ||
2187 | 1686 | * one where they don't have to | ||
2188 | 1687 | */ | ||
2189 | 1688 | for (pass = 0; pass < 2; ++pass) | ||
2190 | 1689 | { | ||
2191 | 1690 | CCRROutput *cc_rr_output = cc_rr_screen_get_output_by_name (screen, output->priv->name); | ||
2192 | 1691 | CCRRMode **modes = cc_rr_output_list_modes (cc_rr_output); | ||
2193 | 1692 | int j; | ||
2194 | 1693 | |||
2195 | 1694 | for (j = 0; modes[j] != NULL; ++j) | ||
2196 | 1695 | { | ||
2197 | 1696 | CCRRMode *mode = modes[j]; | ||
2198 | 1697 | int mode_width; | ||
2199 | 1698 | int mode_height; | ||
2200 | 1699 | int mode_freq; | ||
2201 | 1700 | |||
2202 | 1701 | mode_width = cc_rr_mode_get_width (mode); | ||
2203 | 1702 | mode_height = cc_rr_mode_get_height (mode); | ||
2204 | 1703 | mode_freq = cc_rr_mode_get_freq (mode); | ||
2205 | 1704 | |||
2206 | 1705 | g_string_append_printf (accumulated_error, | ||
2207 | 1706 | _("CRTC %d: trying mode %dx%d@%dHz with output at %dx%d@%dHz (pass %d)\n"), | ||
2208 | 1707 | crtc_id, | ||
2209 | 1708 | mode_width, mode_height, mode_freq, | ||
2210 | 1709 | output->priv->width, output->priv->height, output->priv->rate, | ||
2211 | 1710 | pass); | ||
2212 | 1711 | |||
2213 | 1712 | if (mode_width == output->priv->width && | ||
2214 | 1713 | mode_height == output->priv->height && | ||
2215 | 1714 | (pass == 1 || mode_freq == output->priv->rate)) | ||
2216 | 1715 | { | ||
2217 | 1716 | tried_mode = TRUE; | ||
2218 | 1717 | |||
2219 | 1718 | my_error = NULL; | ||
2220 | 1719 | if (crtc_assignment_assign ( | ||
2221 | 1720 | assignment, crtc, modes[j], | ||
2222 | 1721 | output->priv->x, output->priv->y, | ||
2223 | 1722 | output->priv->rotation, | ||
2224 | 1723 | output->priv->primary, | ||
2225 | 1724 | cc_rr_output, | ||
2226 | 1725 | &my_error)) | ||
2227 | 1726 | { | ||
2228 | 1727 | my_error = NULL; | ||
2229 | 1728 | if (real_assign_crtcs (screen, outputs + 1, assignment, &my_error)) { | ||
2230 | 1729 | success = TRUE; | ||
2231 | 1730 | goto out; | ||
2232 | 1731 | } else | ||
2233 | 1732 | accumulate_error (accumulated_error, my_error); | ||
2234 | 1733 | |||
2235 | 1734 | crtc_assignment_unassign (assignment, crtc, cc_rr_output); | ||
2236 | 1735 | } else | ||
2237 | 1736 | accumulate_error (accumulated_error, my_error); | ||
2238 | 1737 | } | ||
2239 | 1738 | } | ||
2240 | 1739 | } | ||
2241 | 1740 | } | ||
2242 | 1741 | |||
2243 | 1742 | out: | ||
2244 | 1743 | |||
2245 | 1744 | if (success) | ||
2246 | 1745 | g_string_free (accumulated_error, TRUE); | ||
2247 | 1746 | else { | ||
2248 | 1747 | char *str; | ||
2249 | 1748 | |||
2250 | 1749 | str = g_string_free (accumulated_error, FALSE); | ||
2251 | 1750 | |||
2252 | 1751 | if (tried_mode) | ||
2253 | 1752 | g_set_error (error, CC_RR_ERROR, CC_RR_ERROR_CRTC_ASSIGNMENT, | ||
2254 | 1753 | _("could not assign CRTCs to outputs:\n%s"), | ||
2255 | 1754 | str); | ||
2256 | 1755 | else | ||
2257 | 1756 | g_set_error (error, CC_RR_ERROR, CC_RR_ERROR_CRTC_ASSIGNMENT, | ||
2258 | 1757 | _("none of the selected modes were compatible with the possible modes:\n%s"), | ||
2259 | 1758 | str); | ||
2260 | 1759 | |||
2261 | 1760 | g_free (str); | ||
2262 | 1761 | } | ||
2263 | 1762 | |||
2264 | 1763 | return success; | ||
2265 | 1764 | } | ||
2266 | 1765 | |||
2267 | 1766 | static void | ||
2268 | 1767 | crtc_info_free (CrtcInfo *info) | ||
2269 | 1768 | { | ||
2270 | 1769 | g_ptr_array_free (info->outputs, TRUE); | ||
2271 | 1770 | g_free (info); | ||
2272 | 1771 | } | ||
2273 | 1772 | |||
2274 | 1773 | static void | ||
2275 | 1774 | get_required_virtual_size (CrtcAssignment *assign, int *width, int *height) | ||
2276 | 1775 | { | ||
2277 | 1776 | GList *active_crtcs = g_hash_table_get_keys (assign->info); | ||
2278 | 1777 | GList *list; | ||
2279 | 1778 | int d; | ||
2280 | 1779 | |||
2281 | 1780 | if (!width) | ||
2282 | 1781 | width = &d; | ||
2283 | 1782 | if (!height) | ||
2284 | 1783 | height = &d; | ||
2285 | 1784 | |||
2286 | 1785 | /* Compute size of the screen */ | ||
2287 | 1786 | *width = *height = 1; | ||
2288 | 1787 | for (list = active_crtcs; list != NULL; list = list->next) | ||
2289 | 1788 | { | ||
2290 | 1789 | CCRRCrtc *crtc = list->data; | ||
2291 | 1790 | CrtcInfo *info = g_hash_table_lookup (assign->info, crtc); | ||
2292 | 1791 | int w, h; | ||
2293 | 1792 | |||
2294 | 1793 | w = cc_rr_mode_get_width (info->mode); | ||
2295 | 1794 | h = cc_rr_mode_get_height (info->mode); | ||
2296 | 1795 | |||
2297 | 1796 | if (mode_is_rotated (info)) | ||
2298 | 1797 | { | ||
2299 | 1798 | int tmp = h; | ||
2300 | 1799 | h = w; | ||
2301 | 1800 | w = tmp; | ||
2302 | 1801 | } | ||
2303 | 1802 | |||
2304 | 1803 | *width = MAX (*width, info->x + w); | ||
2305 | 1804 | *height = MAX (*height, info->y + h); | ||
2306 | 1805 | } | ||
2307 | 1806 | |||
2308 | 1807 | g_list_free (active_crtcs); | ||
2309 | 1808 | } | ||
2310 | 1809 | |||
2311 | 1810 | static gboolean | ||
2312 | 1811 | unity_running (void) | ||
2313 | 1812 | { | ||
2314 | 1813 | const gchar *desktop_environment = g_getenv ("DESKTOP_SESSION"); | ||
2315 | 1814 | |||
2316 | 1815 | return !g_strcmp0 (desktop_environment, "ubuntu"); | ||
2317 | 1816 | } | ||
2318 | 1817 | |||
2319 | 1818 | static gint _max_texture_size_cache = -1; | ||
2320 | 1819 | |||
2321 | 1820 | static gint | ||
2322 | 1821 | get_max_texture_size (CCRRScreen *screen) | ||
2323 | 1822 | { | ||
2324 | 1823 | if (_max_texture_size_cache != -1) | ||
2325 | 1824 | { | ||
2326 | 1825 | return _max_texture_size_cache; | ||
2327 | 1826 | } else { | ||
2328 | 1827 | /* | ||
2329 | 1828 | * Spawn a second process to check the GL texture limits | ||
2330 | 1829 | * We do this across a process boundary to ensure that crashes | ||
2331 | 1830 | * in the GL driver (which are unfortunately common) don't take | ||
2332 | 1831 | * down the app. | ||
2333 | 1832 | */ | ||
2334 | 1833 | int pipe_fd[2]; | ||
2335 | 1834 | pid_t canary_pid; | ||
2336 | 1835 | |||
2337 | 1836 | char * const canary_argv[] = { LIBEXECDIR "/check_gl_texture_size", NULL }; | ||
2338 | 1837 | char *canary_env[2]; | ||
2339 | 1838 | char display_env[80]; | ||
2340 | 1839 | |||
2341 | 1840 | snprintf (display_env, sizeof (display_env), "DISPLAY=%s", DisplayString (screen->priv->xdisplay)); | ||
2342 | 1841 | canary_env[0] = display_env; | ||
2343 | 1842 | canary_env[1] = NULL; | ||
2344 | 1843 | |||
2345 | 1844 | |||
2346 | 1845 | if (pipe (pipe_fd) == -1) | ||
2347 | 1846 | { | ||
2348 | 1847 | _max_texture_size_cache = 0; | ||
2349 | 1848 | return 0; | ||
2350 | 1849 | } | ||
2351 | 1850 | canary_pid = fork (); | ||
2352 | 1851 | if (canary_pid == -1) | ||
2353 | 1852 | { | ||
2354 | 1853 | _max_texture_size_cache = 0; | ||
2355 | 1854 | return 0; | ||
2356 | 1855 | } | ||
2357 | 1856 | |||
2358 | 1857 | if (canary_pid == 0) | ||
2359 | 1858 | { | ||
2360 | 1859 | close (pipe_fd[0]); | ||
2361 | 1860 | dup2 (pipe_fd[1], 1); | ||
2362 | 1861 | close (pipe_fd[1]); | ||
2363 | 1862 | |||
2364 | 1863 | execve (canary_argv[0], canary_argv, canary_env); | ||
2365 | 1864 | } else { | ||
2366 | 1865 | char buffer[10]; | ||
2367 | 1866 | gint max_texture_size; | ||
2368 | 1867 | int child_status; | ||
2369 | 1868 | int num_char; | ||
2370 | 1869 | struct timespec fifty_msec = {0, 50000000}; | ||
2371 | 1870 | int wait_count = 0; | ||
2372 | 1871 | |||
2373 | 1872 | close (pipe_fd[1]); | ||
2374 | 1873 | |||
2375 | 1874 | /* Empirical testing suggests this check takes < 150msec on my | ||
2376 | 1875 | * crappy Atom netbook with slow rotating HDD. A 500msec timeout | ||
2377 | 1876 | * should be generous while not being *too* long if it triggers. | ||
2378 | 1877 | * | ||
2379 | 1878 | * Do a sleep/poll dance because we're a library and there's no | ||
2380 | 1879 | * guarantee that waiting on SIGCHLD won't stomp over a client's | ||
2381 | 1880 | * set up. | ||
2382 | 1881 | */ | ||
2383 | 1882 | while (waitpid (canary_pid, &child_status, WNOHANG) == 0 && wait_count < 10) { | ||
2384 | 1883 | g_debug ("Waiting for GL_MAX_TEXTURE_SIZE helper..."); | ||
2385 | 1884 | nanosleep (&fifty_msec, NULL); | ||
2386 | 1885 | wait_count++; | ||
2387 | 1886 | } | ||
2388 | 1887 | |||
2389 | 1888 | if (WIFEXITED (child_status) && WEXITSTATUS (child_status) == EXIT_SUCCESS) | ||
2390 | 1889 | { | ||
2391 | 1890 | if ((num_char = read (pipe_fd[0], buffer, sizeof(buffer) - 1)) <= 0) | ||
2392 | 1891 | { | ||
2393 | 1892 | g_warning ("Failed to read GL_MAX_TEXTURE_SIZE from helper."); | ||
2394 | 1893 | max_texture_size = 0; | ||
2395 | 1894 | } else { | ||
2396 | 1895 | buffer[num_char] = '\0'; | ||
2397 | 1896 | sscanf (buffer, "%u", &max_texture_size); | ||
2398 | 1897 | /* | ||
2399 | 1898 | * Sanity check the numbers. No hardware I know of has a | ||
2400 | 1899 | * GL_MAX_TEXTURE_SIZE smaller than 1024. | ||
2401 | 1900 | */ | ||
2402 | 1901 | if (max_texture_size < 1024) | ||
2403 | 1902 | max_texture_size = 0; | ||
2404 | 1903 | } | ||
2405 | 1904 | } else { | ||
2406 | 1905 | if (wait_count == 10) { | ||
2407 | 1906 | g_warning ("Timed out waiting for GL_MAX_TEXTURE_SIZE helper"); | ||
2408 | 1907 | |||
2409 | 1908 | /* Ensure we don't leave processes sitting around. Who knows what they're doing? */ | ||
2410 | 1909 | kill (canary_pid, SIGTERM); | ||
2411 | 1910 | waitpid (canary_pid, &child_status, 0); | ||
2412 | 1911 | } else { | ||
2413 | 1912 | g_warning ("GL_MAX_TEXTURE_SIZE helper quit unexpectedly"); | ||
2414 | 1913 | } | ||
2415 | 1914 | max_texture_size = 0; | ||
2416 | 1915 | } | ||
2417 | 1916 | |||
2418 | 1917 | close (pipe_fd[0]); | ||
2419 | 1918 | g_debug ("Found GL_MAX_TEXTURE_SIZE of %u", max_texture_size); | ||
2420 | 1919 | _max_texture_size_cache = max_texture_size; | ||
2421 | 1920 | return _max_texture_size_cache; | ||
2422 | 1921 | } | ||
2423 | 1922 | } | ||
2424 | 1923 | } | ||
2425 | 1924 | |||
2426 | 1925 | static CrtcAssignment * | ||
2427 | 1926 | crtc_assignment_new (CCRRScreen *screen, CCRROutputInfo **outputs, GError **error) | ||
2428 | 1927 | { | ||
2429 | 1928 | CrtcAssignment *assignment = g_new0 (CrtcAssignment, 1); | ||
2430 | 1929 | |||
2431 | 1930 | assignment->info = g_hash_table_new_full ( | ||
2432 | 1931 | g_direct_hash, g_direct_equal, NULL, (GFreeFunc)crtc_info_free); | ||
2433 | 1932 | |||
2434 | 1933 | if (real_assign_crtcs (screen, outputs, assignment, error)) | ||
2435 | 1934 | { | ||
2436 | 1935 | int width, height; | ||
2437 | 1936 | int min_width, max_width, min_height, max_height; | ||
2438 | 1937 | int max_texture_size; | ||
2439 | 1938 | |||
2440 | 1939 | get_required_virtual_size (assignment, &width, &height); | ||
2441 | 1940 | |||
2442 | 1941 | cc_rr_screen_get_ranges ( | ||
2443 | 1942 | screen, &min_width, &max_width, &min_height, &max_height); | ||
2444 | 1943 | |||
2445 | 1944 | if (width < min_width || width > max_width || | ||
2446 | 1945 | height < min_height || height > max_height) | ||
2447 | 1946 | { | ||
2448 | 1947 | g_set_error (error, CC_RR_ERROR, CC_RR_ERROR_BOUNDS_ERROR, | ||
2449 | 1948 | /* Translators: the "requested", "minimum", and | ||
2450 | 1949 | * "maximum" words here are not keywords; please | ||
2451 | 1950 | * translate them as usual. */ | ||
2452 | 1951 | _("required virtual size does not fit available size: " | ||
2453 | 1952 | "requested=(%d, %d), minimum=(%d, %d), maximum=(%d, %d)"), | ||
2454 | 1953 | width, height, | ||
2455 | 1954 | min_width, min_height, | ||
2456 | 1955 | max_width, max_height); | ||
2457 | 1956 | goto fail; | ||
2458 | 1957 | } | ||
2459 | 1958 | |||
2460 | 1959 | /* Hack: | ||
2461 | 1960 | * This should either be solved by | ||
2462 | 1961 | * (a) Allowing the compositor to veto RandR changes | ||
2463 | 1962 | * (b) Fixing the compositor | ||
2464 | 1963 | * | ||
2465 | 1964 | * Nethier of these are feasible at this point, so just fix Unity. | ||
2466 | 1965 | */ | ||
2467 | 1966 | |||
2468 | 1967 | if (unity_running ()) | ||
2469 | 1968 | { | ||
2470 | 1969 | max_texture_size = get_max_texture_size (screen); | ||
2471 | 1970 | if (max_texture_size > 0 && (width > max_texture_size || height > max_texture_size)) | ||
2472 | 1971 | { | ||
2473 | 1972 | g_set_error (error, CC_RR_ERROR, CC_RR_ERROR_BOUNDS_ERROR, | ||
2474 | 1973 | _("Requested size (%d, %d) exceeds 3D hardware limit (%d, %d).\n" | ||
2475 | 1974 | "You must either rearrange the displays so that they fit within a (%d, %d) square."), | ||
2476 | 1975 | width, height, max_texture_size, max_texture_size, | ||
2477 | 1976 | max_texture_size, max_texture_size); | ||
2478 | 1977 | goto fail; | ||
2479 | 1978 | } | ||
2480 | 1979 | } | ||
2481 | 1980 | |||
2482 | 1981 | |||
2483 | 1982 | assignment->screen = screen; | ||
2484 | 1983 | |||
2485 | 1984 | return assignment; | ||
2486 | 1985 | } | ||
2487 | 1986 | |||
2488 | 1987 | fail: | ||
2489 | 1988 | crtc_assignment_free (assignment); | ||
2490 | 1989 | |||
2491 | 1990 | return NULL; | ||
2492 | 1991 | } | ||
2493 | 1992 | |||
2494 | 1993 | static gboolean | ||
2495 | 1994 | crtc_assignment_apply (CrtcAssignment *assign, guint32 timestamp, GError **error) | ||
2496 | 1995 | { | ||
2497 | 1996 | CCRRCrtc **all_crtcs = cc_rr_screen_list_crtcs (assign->screen); | ||
2498 | 1997 | int width, height; | ||
2499 | 1998 | int i; | ||
2500 | 1999 | int min_width, max_width, min_height, max_height; | ||
2501 | 2000 | int width_mm, height_mm; | ||
2502 | 2001 | gboolean success = TRUE; | ||
2503 | 2002 | |||
2504 | 2003 | /* Compute size of the screen */ | ||
2505 | 2004 | get_required_virtual_size (assign, &width, &height); | ||
2506 | 2005 | |||
2507 | 2006 | cc_rr_screen_get_ranges ( | ||
2508 | 2007 | assign->screen, &min_width, &max_width, &min_height, &max_height); | ||
2509 | 2008 | |||
2510 | 2009 | /* We should never get here if the dimensions don't fit in the virtual size, | ||
2511 | 2010 | * but just in case we do, fix it up. | ||
2512 | 2011 | */ | ||
2513 | 2012 | width = MAX (min_width, width); | ||
2514 | 2013 | width = MIN (max_width, width); | ||
2515 | 2014 | height = MAX (min_height, height); | ||
2516 | 2015 | height = MIN (max_height, height); | ||
2517 | 2016 | |||
2518 | 2017 | /* FMQ: do we need to check the sizes instead of clamping them? */ | ||
2519 | 2018 | |||
2520 | 2019 | /* Grab the server while we fiddle with the CRTCs and the screen, so that | ||
2521 | 2020 | * apps that listen for RANDR notifications will only receive the final | ||
2522 | 2021 | * status. | ||
2523 | 2022 | */ | ||
2524 | 2023 | |||
2525 | 2024 | gdk_x11_display_grab (gdk_screen_get_display (assign->screen->priv->gdk_screen)); | ||
2526 | 2025 | |||
2527 | 2026 | /* Turn off all crtcs that are currently displaying outside the new screen, | ||
2528 | 2027 | * or are not used in the new setup | ||
2529 | 2028 | */ | ||
2530 | 2029 | for (i = 0; all_crtcs[i] != NULL; ++i) | ||
2531 | 2030 | { | ||
2532 | 2031 | CCRRCrtc *crtc = all_crtcs[i]; | ||
2533 | 2032 | CCRRMode *mode = cc_rr_crtc_get_current_mode (crtc); | ||
2534 | 2033 | int x, y; | ||
2535 | 2034 | |||
2536 | 2035 | if (mode) | ||
2537 | 2036 | { | ||
2538 | 2037 | int w, h; | ||
2539 | 2038 | cc_rr_crtc_get_position (crtc, &x, &y); | ||
2540 | 2039 | |||
2541 | 2040 | w = cc_rr_mode_get_width (mode); | ||
2542 | 2041 | h = cc_rr_mode_get_height (mode); | ||
2543 | 2042 | |||
2544 | 2043 | if (crtc_is_rotated (crtc)) | ||
2545 | 2044 | { | ||
2546 | 2045 | int tmp = h; | ||
2547 | 2046 | h = w; | ||
2548 | 2047 | w = tmp; | ||
2549 | 2048 | } | ||
2550 | 2049 | |||
2551 | 2050 | if (x + w > width || y + h > height || !g_hash_table_lookup (assign->info, crtc)) | ||
2552 | 2051 | { | ||
2553 | 2052 | if (!cc_rr_crtc_set_config_with_time (crtc, timestamp, 0, 0, NULL, CC_RR_ROTATION_0, NULL, 0, error)) | ||
2554 | 2053 | { | ||
2555 | 2054 | success = FALSE; | ||
2556 | 2055 | break; | ||
2557 | 2056 | } | ||
2558 | 2057 | |||
2559 | 2058 | } | ||
2560 | 2059 | } | ||
2561 | 2060 | } | ||
2562 | 2061 | |||
2563 | 2062 | /* The 'physical size' of an X screen is meaningless if that screen | ||
2564 | 2063 | * can consist of many monitors. So just pick a size that make the | ||
2565 | 2064 | * dpi 96. | ||
2566 | 2065 | * | ||
2567 | 2066 | * Firefox and Evince apparently believe what X tells them. | ||
2568 | 2067 | */ | ||
2569 | 2068 | width_mm = (width / DPI_FALLBACK) * 25.4 + 0.5; | ||
2570 | 2069 | height_mm = (height / DPI_FALLBACK) * 25.4 + 0.5; | ||
2571 | 2070 | |||
2572 | 2071 | if (success) | ||
2573 | 2072 | { | ||
2574 | 2073 | ConfigureCrtcState state; | ||
2575 | 2074 | |||
2576 | 2075 | cc_rr_screen_set_size (assign->screen, width, height, width_mm, height_mm); | ||
2577 | 2076 | |||
2578 | 2077 | state.timestamp = timestamp; | ||
2579 | 2078 | state.has_error = FALSE; | ||
2580 | 2079 | state.error = error; | ||
2581 | 2080 | |||
2582 | 2081 | g_hash_table_foreach (assign->info, configure_crtc, &state); | ||
2583 | 2082 | |||
2584 | 2083 | success = !state.has_error; | ||
2585 | 2084 | } | ||
2586 | 2085 | |||
2587 | 2086 | cc_rr_screen_set_primary_output (assign->screen, assign->primary); | ||
2588 | 2087 | |||
2589 | 2088 | gdk_x11_display_ungrab (gdk_screen_get_display (assign->screen->priv->gdk_screen)); | ||
2590 | 2089 | |||
2591 | 2090 | return success; | ||
2592 | 2091 | } | ||
2593 | 0 | 2092 | ||
2594 | === added file 'panels/common/cc-rr-config.h' | |||
2595 | --- panels/common/cc-rr-config.h 1970-01-01 00:00:00 +0000 | |||
2596 | +++ panels/common/cc-rr-config.h 2014-06-26 03:13:28 +0000 | |||
2597 | @@ -0,0 +1,151 @@ | |||
2598 | 1 | /* gnome-rr-config.h | ||
2599 | 2 | * -*- c-basic-offset: 4 -*- | ||
2600 | 3 | * | ||
2601 | 4 | * Copyright 2007, 2008, Red Hat, Inc. | ||
2602 | 5 | * Copyright 2010 Giovanni Campagna | ||
2603 | 6 | * | ||
2604 | 7 | * This file is part of the Gnome Library. | ||
2605 | 8 | * | ||
2606 | 9 | * The Gnome Library is free software; you can redistribute it and/or | ||
2607 | 10 | * modify it under the terms of the GNU Library General Public License as | ||
2608 | 11 | * published by the Free Software Foundation; either version 2 of the | ||
2609 | 12 | * License, or (at your option) any later version. | ||
2610 | 13 | * | ||
2611 | 14 | * The Gnome Library is distributed in the hope that it will be useful, | ||
2612 | 15 | * but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
2613 | 16 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | ||
2614 | 17 | * Library General Public License for more details. | ||
2615 | 18 | * | ||
2616 | 19 | * You should have received a copy of the GNU Library General Public | ||
2617 | 20 | * License along with the Gnome Library; see the file COPYING.LIB. If not, | ||
2618 | 21 | * write to the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, | ||
2619 | 22 | * Boston, MA 02110-1301, USA. | ||
2620 | 23 | * | ||
2621 | 24 | * Author: Soren Sandmann <sandmann@redhat.com> | ||
2622 | 25 | */ | ||
2623 | 26 | #ifndef CC_RR_CONFIG_H | ||
2624 | 27 | #define CC_RR_CONFIG_H | ||
2625 | 28 | |||
2626 | 29 | #include <glib.h> | ||
2627 | 30 | #include <glib-object.h> | ||
2628 | 31 | #include "cc-rr.h" | ||
2629 | 32 | |||
2630 | 33 | typedef struct _CCRROutputInfo CCRROutputInfo; | ||
2631 | 34 | typedef struct _CCRROutputInfoClass CCRROutputInfoClass; | ||
2632 | 35 | typedef struct _CCRROutputInfoPrivate CCRROutputInfoPrivate; | ||
2633 | 36 | |||
2634 | 37 | struct _CCRROutputInfo | ||
2635 | 38 | { | ||
2636 | 39 | GObject parent; | ||
2637 | 40 | |||
2638 | 41 | /*< private >*/ | ||
2639 | 42 | CCRROutputInfoPrivate *priv; | ||
2640 | 43 | }; | ||
2641 | 44 | |||
2642 | 45 | struct _CCRROutputInfoClass | ||
2643 | 46 | { | ||
2644 | 47 | GObjectClass parent_class; | ||
2645 | 48 | }; | ||
2646 | 49 | |||
2647 | 50 | #define CC_TYPE_RR_OUTPUT_INFO (cc_rr_output_info_get_type()) | ||
2648 | 51 | #define CC_RR_OUTPUT_INFO(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), CC_TYPE_RR_OUTPUT_INFO, CCRROutputInfo)) | ||
2649 | 52 | #define CC_IS_RR_OUTPUT_INFO(obj) (G_TYPE_CHECK_INSTANCE_TYPE ((obj), CC_TYPE_RR_OUTPUT_INFO)) | ||
2650 | 53 | #define CC_RR_OUTPUT_INFO_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST ((klass), CC_TYPE_RR_OUTPUT_INFO, CCRROutputInfoClass)) | ||
2651 | 54 | #define CC_IS_RR_OUTPUT_INFO_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE ((klass), CC_TYPE_RR_OUTPUT_INFO)) | ||
2652 | 55 | #define CC_RR_OUTPUT_INFO_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS ((obj), CC_TYPE_RR_OUTPUT_INFO, CCRROutputInfoClass)) | ||
2653 | 56 | |||
2654 | 57 | GType cc_rr_output_info_get_type (void); | ||
2655 | 58 | |||
2656 | 59 | char *cc_rr_output_info_get_name (CCRROutputInfo *self); | ||
2657 | 60 | |||
2658 | 61 | gboolean cc_rr_output_info_is_active (CCRROutputInfo *self); | ||
2659 | 62 | void cc_rr_output_info_set_active (CCRROutputInfo *self, gboolean active); | ||
2660 | 63 | |||
2661 | 64 | void cc_rr_output_info_get_geometry (CCRROutputInfo *self, int *x, int *y, int *width, int *height); | ||
2662 | 65 | void cc_rr_output_info_set_geometry (CCRROutputInfo *self, int x, int y, int width, int height); | ||
2663 | 66 | |||
2664 | 67 | int cc_rr_output_info_get_refresh_rate (CCRROutputInfo *self); | ||
2665 | 68 | void cc_rr_output_info_set_refresh_rate (CCRROutputInfo *self, int rate); | ||
2666 | 69 | |||
2667 | 70 | CCRRRotation cc_rr_output_info_get_rotation (CCRROutputInfo *self); | ||
2668 | 71 | void cc_rr_output_info_set_rotation (CCRROutputInfo *self, CCRRRotation rotation); | ||
2669 | 72 | |||
2670 | 73 | gboolean cc_rr_output_info_is_connected (CCRROutputInfo *self); | ||
2671 | 74 | void cc_rr_output_info_get_vendor (CCRROutputInfo *self, gchar* vendor); | ||
2672 | 75 | guint cc_rr_output_info_get_product (CCRROutputInfo *self); | ||
2673 | 76 | guint cc_rr_output_info_get_serial (CCRROutputInfo *self); | ||
2674 | 77 | double cc_rr_output_info_get_aspect_ratio (CCRROutputInfo *self); | ||
2675 | 78 | char *cc_rr_output_info_get_display_name (CCRROutputInfo *self); | ||
2676 | 79 | |||
2677 | 80 | gboolean cc_rr_output_info_get_primary (CCRROutputInfo *self); | ||
2678 | 81 | void cc_rr_output_info_set_primary (CCRROutputInfo *self, gboolean primary); | ||
2679 | 82 | |||
2680 | 83 | int cc_rr_output_info_get_preferred_width (CCRROutputInfo *self); | ||
2681 | 84 | int cc_rr_output_info_get_preferred_height (CCRROutputInfo *self); | ||
2682 | 85 | |||
2683 | 86 | typedef struct _CCRRConfig CCRRConfig; | ||
2684 | 87 | typedef struct _CCRRConfigClass CCRRConfigClass; | ||
2685 | 88 | typedef struct _CCRRConfigPrivate CCRRConfigPrivate; | ||
2686 | 89 | |||
2687 | 90 | struct _CCRRConfig | ||
2688 | 91 | { | ||
2689 | 92 | GObject parent; | ||
2690 | 93 | |||
2691 | 94 | /*< private >*/ | ||
2692 | 95 | CCRRConfigPrivate *priv; | ||
2693 | 96 | }; | ||
2694 | 97 | |||
2695 | 98 | struct _CCRRConfigClass | ||
2696 | 99 | { | ||
2697 | 100 | GObjectClass parent_class; | ||
2698 | 101 | }; | ||
2699 | 102 | |||
2700 | 103 | #define CC_TYPE_RR_CONFIG (cc_rr_config_get_type()) | ||
2701 | 104 | #define CC_RR_CONFIG(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), CC_TYPE_RR_CONFIG, CCRRConfig)) | ||
2702 | 105 | #define CC_IS_RR_CONFIG(obj) (G_TYPE_CHECK_INSTANCE_TYPE ((obj), CC_TYPE_RR_CONFIG)) | ||
2703 | 106 | #define CC_RR_CONFIG_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST ((klass), CC_TYPE_RR_CONFIG, CCRRConfigClass)) | ||
2704 | 107 | #define CC_IS_RR_CONFIG_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE ((klass), CC_TYPE_RR_CONFIG)) | ||
2705 | 108 | #define CC_RR_CONFIG_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS ((obj), CC_TYPE_RR_CONFIG, CCRRConfigClass)) | ||
2706 | 109 | |||
2707 | 110 | GType cc_rr_config_get_type (void); | ||
2708 | 111 | |||
2709 | 112 | CCRRConfig *cc_rr_config_new_current (CCRRScreen *screen, | ||
2710 | 113 | GError **error); | ||
2711 | 114 | CCRRConfig *cc_rr_config_new_stored (CCRRScreen *screen, | ||
2712 | 115 | GError **error); | ||
2713 | 116 | gboolean cc_rr_config_load_current (CCRRConfig *self, | ||
2714 | 117 | GError **error); | ||
2715 | 118 | gboolean cc_rr_config_load_filename (CCRRConfig *self, | ||
2716 | 119 | const gchar *filename, | ||
2717 | 120 | GError **error); | ||
2718 | 121 | gboolean cc_rr_config_match (CCRRConfig *config1, | ||
2719 | 122 | CCRRConfig *config2); | ||
2720 | 123 | gboolean cc_rr_config_equal (CCRRConfig *config1, | ||
2721 | 124 | CCRRConfig *config2); | ||
2722 | 125 | gboolean cc_rr_config_save (CCRRConfig *configuration, | ||
2723 | 126 | GError **error); | ||
2724 | 127 | void cc_rr_config_sanitize (CCRRConfig *configuration); | ||
2725 | 128 | gboolean cc_rr_config_ensure_primary (CCRRConfig *configuration); | ||
2726 | 129 | |||
2727 | 130 | gboolean cc_rr_config_apply_with_time (CCRRConfig *configuration, | ||
2728 | 131 | CCRRScreen *screen, | ||
2729 | 132 | guint32 timestamp, | ||
2730 | 133 | GError **error); | ||
2731 | 134 | |||
2732 | 135 | gboolean cc_rr_config_apply_from_filename_with_time (CCRRScreen *screen, | ||
2733 | 136 | const char *filename, | ||
2734 | 137 | guint32 timestamp, | ||
2735 | 138 | GError **error); | ||
2736 | 139 | |||
2737 | 140 | gboolean cc_rr_config_applicable (CCRRConfig *configuration, | ||
2738 | 141 | CCRRScreen *screen, | ||
2739 | 142 | GError **error); | ||
2740 | 143 | |||
2741 | 144 | gboolean cc_rr_config_get_clone (CCRRConfig *configuration); | ||
2742 | 145 | void cc_rr_config_set_clone (CCRRConfig *configuration, gboolean clone); | ||
2743 | 146 | CCRROutputInfo **cc_rr_config_get_outputs (CCRRConfig *configuration); | ||
2744 | 147 | |||
2745 | 148 | char *cc_rr_config_get_backup_filename (void); | ||
2746 | 149 | char *cc_rr_config_get_intended_filename (void); | ||
2747 | 150 | |||
2748 | 151 | #endif | ||
2749 | 0 | 152 | ||
2750 | === added file 'panels/common/cc-rr-output-info.c' | |||
2751 | --- panels/common/cc-rr-output-info.c 1970-01-01 00:00:00 +0000 | |||
2752 | +++ panels/common/cc-rr-output-info.c 2014-06-26 03:13:28 +0000 | |||
2753 | @@ -0,0 +1,242 @@ | |||
2754 | 1 | /* gnome-rr-output-info.c | ||
2755 | 2 | * -*- c-basic-offset: 4 -*- | ||
2756 | 3 | * | ||
2757 | 4 | * Copyright 2010 Giovanni Campagna | ||
2758 | 5 | * | ||
2759 | 6 | * This file is part of the Gnome Desktop Library. | ||
2760 | 7 | * | ||
2761 | 8 | * The Gnome Desktop Library is free software; you can redistribute it and/or | ||
2762 | 9 | * modify it under the terms of the GNU Library General Public License as | ||
2763 | 10 | * published by the Free Software Foundation; either version 2 of the | ||
2764 | 11 | * License, or (at your option) any later version. | ||
2765 | 12 | * | ||
2766 | 13 | * The Gnome Library is distributed in the hope that it will be useful, | ||
2767 | 14 | * but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
2768 | 15 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | ||
2769 | 16 | * Library General Public License for more details. | ||
2770 | 17 | * | ||
2771 | 18 | * You should have received a copy of the GNU Library General Public | ||
2772 | 19 | * License along with the Gnome Desktop Library; see the file COPYING.LIB. If not, | ||
2773 | 20 | * write to the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, | ||
2774 | 21 | * Boston, MA 02110-1301, USA. | ||
2775 | 22 | */ | ||
2776 | 23 | |||
2777 | 24 | #include <config.h> | ||
2778 | 25 | |||
2779 | 26 | #include "cc-rr-config.h" | ||
2780 | 27 | |||
2781 | 28 | #include "edid.h" | ||
2782 | 29 | #include "cc-rr-private.h" | ||
2783 | 30 | |||
2784 | 31 | G_DEFINE_TYPE (CCRROutputInfo, cc_rr_output_info, G_TYPE_OBJECT) | ||
2785 | 32 | |||
2786 | 33 | static void | ||
2787 | 34 | cc_rr_output_info_init (CCRROutputInfo *self) | ||
2788 | 35 | { | ||
2789 | 36 | self->priv = G_TYPE_INSTANCE_GET_PRIVATE (self, CC_TYPE_RR_OUTPUT_INFO, CCRROutputInfoPrivate); | ||
2790 | 37 | |||
2791 | 38 | self->priv->name = NULL; | ||
2792 | 39 | self->priv->on = FALSE; | ||
2793 | 40 | self->priv->display_name = NULL; | ||
2794 | 41 | } | ||
2795 | 42 | |||
2796 | 43 | static void | ||
2797 | 44 | cc_rr_output_info_finalize (GObject *gobject) | ||
2798 | 45 | { | ||
2799 | 46 | CCRROutputInfo *self = CC_RR_OUTPUT_INFO (gobject); | ||
2800 | 47 | |||
2801 | 48 | g_free (self->priv->name); | ||
2802 | 49 | g_free (self->priv->display_name); | ||
2803 | 50 | |||
2804 | 51 | G_OBJECT_CLASS (cc_rr_output_info_parent_class)->finalize (gobject); | ||
2805 | 52 | } | ||
2806 | 53 | |||
2807 | 54 | static void | ||
2808 | 55 | cc_rr_output_info_class_init (CCRROutputInfoClass *klass) | ||
2809 | 56 | { | ||
2810 | 57 | GObjectClass *gobject_class = G_OBJECT_CLASS (klass); | ||
2811 | 58 | |||
2812 | 59 | g_type_class_add_private (klass, sizeof (CCRROutputInfoPrivate)); | ||
2813 | 60 | |||
2814 | 61 | gobject_class->finalize = cc_rr_output_info_finalize; | ||
2815 | 62 | } | ||
2816 | 63 | |||
2817 | 64 | /** | ||
2818 | 65 | * cc_rr_output_info_get_name: | ||
2819 | 66 | * | ||
2820 | 67 | * Returns: (transfer none): the output name | ||
2821 | 68 | */ | ||
2822 | 69 | char *cc_rr_output_info_get_name (CCRROutputInfo *self) | ||
2823 | 70 | { | ||
2824 | 71 | g_return_val_if_fail (CC_IS_RR_OUTPUT_INFO (self), NULL); | ||
2825 | 72 | |||
2826 | 73 | return self->priv->name; | ||
2827 | 74 | } | ||
2828 | 75 | |||
2829 | 76 | /** | ||
2830 | 77 | * cc_rr_output_info_is_active: | ||
2831 | 78 | * | ||
2832 | 79 | * Returns: whether there is a CRTC assigned to this output (i.e. a signal is being sent to it) | ||
2833 | 80 | */ | ||
2834 | 81 | gboolean cc_rr_output_info_is_active (CCRROutputInfo *self) | ||
2835 | 82 | { | ||
2836 | 83 | g_return_val_if_fail (CC_IS_RR_OUTPUT_INFO (self), FALSE); | ||
2837 | 84 | |||
2838 | 85 | return self->priv->on; | ||
2839 | 86 | } | ||
2840 | 87 | |||
2841 | 88 | void cc_rr_output_info_set_active (CCRROutputInfo *self, gboolean active) | ||
2842 | 89 | { | ||
2843 | 90 | g_return_if_fail (CC_IS_RR_OUTPUT_INFO (self)); | ||
2844 | 91 | |||
2845 | 92 | self->priv->on = active; | ||
2846 | 93 | } | ||
2847 | 94 | |||
2848 | 95 | /** | ||
2849 | 96 | * cc_rr_output_info_get_geometry: | ||
2850 | 97 | * @self: a #CCRROutputInfo | ||
2851 | 98 | * @x: (out) (allow-none): | ||
2852 | 99 | * @y: (out) (allow-none): | ||
2853 | 100 | * @width: (out) (allow-none): | ||
2854 | 101 | * @height: (out) (allow-none): | ||
2855 | 102 | */ | ||
2856 | 103 | void cc_rr_output_info_get_geometry (CCRROutputInfo *self, int *x, int *y, int *width, int *height) | ||
2857 | 104 | { | ||
2858 | 105 | g_return_if_fail (CC_IS_RR_OUTPUT_INFO (self)); | ||
2859 | 106 | |||
2860 | 107 | if (x) | ||
2861 | 108 | *x = self->priv->x; | ||
2862 | 109 | if (y) | ||
2863 | 110 | *y = self->priv->y; | ||
2864 | 111 | if (width) | ||
2865 | 112 | *width = self->priv->width; | ||
2866 | 113 | if (height) | ||
2867 | 114 | *height = self->priv->height; | ||
2868 | 115 | } | ||
2869 | 116 | |||
2870 | 117 | void cc_rr_output_info_set_geometry (CCRROutputInfo *self, int x, int y, int width, int height) | ||
2871 | 118 | { | ||
2872 | 119 | g_return_if_fail (CC_IS_RR_OUTPUT_INFO (self)); | ||
2873 | 120 | |||
2874 | 121 | self->priv->x = x; | ||
2875 | 122 | self->priv->y = y; | ||
2876 | 123 | self->priv->width = width; | ||
2877 | 124 | self->priv->height = height; | ||
2878 | 125 | } | ||
2879 | 126 | |||
2880 | 127 | int cc_rr_output_info_get_refresh_rate (CCRROutputInfo *self) | ||
2881 | 128 | { | ||
2882 | 129 | g_return_val_if_fail (CC_IS_RR_OUTPUT_INFO (self), 0); | ||
2883 | 130 | |||
2884 | 131 | return self->priv->rate; | ||
2885 | 132 | } | ||
2886 | 133 | |||
2887 | 134 | void cc_rr_output_info_set_refresh_rate (CCRROutputInfo *self, int rate) | ||
2888 | 135 | { | ||
2889 | 136 | g_return_if_fail (CC_IS_RR_OUTPUT_INFO (self)); | ||
2890 | 137 | |||
2891 | 138 | self->priv->rate = rate; | ||
2892 | 139 | } | ||
2893 | 140 | |||
2894 | 141 | CCRRRotation cc_rr_output_info_get_rotation (CCRROutputInfo *self) | ||
2895 | 142 | { | ||
2896 | 143 | g_return_val_if_fail (CC_IS_RR_OUTPUT_INFO (self), CC_RR_ROTATION_0); | ||
2897 | 144 | |||
2898 | 145 | return self->priv->rotation; | ||
2899 | 146 | } | ||
2900 | 147 | |||
2901 | 148 | void cc_rr_output_info_set_rotation (CCRROutputInfo *self, CCRRRotation rotation) | ||
2902 | 149 | { | ||
2903 | 150 | g_return_if_fail (CC_IS_RR_OUTPUT_INFO (self)); | ||
2904 | 151 | |||
2905 | 152 | self->priv->rotation = rotation; | ||
2906 | 153 | } | ||
2907 | 154 | |||
2908 | 155 | /** | ||
2909 | 156 | * cc_rr_output_info_is_connected: | ||
2910 | 157 | * | ||
2911 | 158 | * Returns: whether the output is physically connected to a monitor | ||
2912 | 159 | */ | ||
2913 | 160 | gboolean cc_rr_output_info_is_connected (CCRROutputInfo *self) | ||
2914 | 161 | { | ||
2915 | 162 | g_return_val_if_fail (CC_IS_RR_OUTPUT_INFO (self), FALSE); | ||
2916 | 163 | |||
2917 | 164 | return self->priv->connected; | ||
2918 | 165 | } | ||
2919 | 166 | |||
2920 | 167 | /** | ||
2921 | 168 | * cc_rr_output_info_get_vendor: | ||
2922 | 169 | * @self: a #CCRROutputInfo | ||
2923 | 170 | * @vendor: (out caller-allocates) (array fixed-size=4): | ||
2924 | 171 | */ | ||
2925 | 172 | void cc_rr_output_info_get_vendor (CCRROutputInfo *self, gchar* vendor) | ||
2926 | 173 | { | ||
2927 | 174 | g_return_if_fail (CC_IS_RR_OUTPUT_INFO (self)); | ||
2928 | 175 | g_return_if_fail (vendor != NULL); | ||
2929 | 176 | |||
2930 | 177 | vendor[0] = self->priv->vendor[0]; | ||
2931 | 178 | vendor[1] = self->priv->vendor[1]; | ||
2932 | 179 | vendor[2] = self->priv->vendor[2]; | ||
2933 | 180 | vendor[3] = self->priv->vendor[3]; | ||
2934 | 181 | } | ||
2935 | 182 | |||
2936 | 183 | guint cc_rr_output_info_get_product (CCRROutputInfo *self) | ||
2937 | 184 | { | ||
2938 | 185 | g_return_val_if_fail (CC_IS_RR_OUTPUT_INFO (self), 0); | ||
2939 | 186 | |||
2940 | 187 | return self->priv->product; | ||
2941 | 188 | } | ||
2942 | 189 | |||
2943 | 190 | guint cc_rr_output_info_get_serial (CCRROutputInfo *self) | ||
2944 | 191 | { | ||
2945 | 192 | g_return_val_if_fail (CC_IS_RR_OUTPUT_INFO (self), 0); | ||
2946 | 193 | |||
2947 | 194 | return self->priv->serial; | ||
2948 | 195 | } | ||
2949 | 196 | |||
2950 | 197 | double cc_rr_output_info_get_aspect_ratio (CCRROutputInfo *self) | ||
2951 | 198 | { | ||
2952 | 199 | g_return_val_if_fail (CC_IS_RR_OUTPUT_INFO (self), 0); | ||
2953 | 200 | |||
2954 | 201 | return self->priv->aspect; | ||
2955 | 202 | } | ||
2956 | 203 | |||
2957 | 204 | /** | ||
2958 | 205 | * cc_rr_output_info_get_display_name: | ||
2959 | 206 | * | ||
2960 | 207 | * Returns: (transfer none): the display name of this output | ||
2961 | 208 | */ | ||
2962 | 209 | char *cc_rr_output_info_get_display_name (CCRROutputInfo *self) | ||
2963 | 210 | { | ||
2964 | 211 | g_return_val_if_fail (CC_IS_RR_OUTPUT_INFO (self), NULL); | ||
2965 | 212 | |||
2966 | 213 | return self->priv->display_name; | ||
2967 | 214 | } | ||
2968 | 215 | |||
2969 | 216 | gboolean cc_rr_output_info_get_primary (CCRROutputInfo *self) | ||
2970 | 217 | { | ||
2971 | 218 | g_return_val_if_fail (CC_IS_RR_OUTPUT_INFO (self), FALSE); | ||
2972 | 219 | |||
2973 | 220 | return self->priv->primary; | ||
2974 | 221 | } | ||
2975 | 222 | |||
2976 | 223 | void cc_rr_output_info_set_primary (CCRROutputInfo *self, gboolean primary) | ||
2977 | 224 | { | ||
2978 | 225 | g_return_if_fail (CC_IS_RR_OUTPUT_INFO (self)); | ||
2979 | 226 | |||
2980 | 227 | self->priv->primary = primary; | ||
2981 | 228 | } | ||
2982 | 229 | |||
2983 | 230 | int cc_rr_output_info_get_preferred_width (CCRROutputInfo *self) | ||
2984 | 231 | { | ||
2985 | 232 | g_return_val_if_fail (CC_IS_RR_OUTPUT_INFO (self), 0); | ||
2986 | 233 | |||
2987 | 234 | return self->priv->pref_width; | ||
2988 | 235 | } | ||
2989 | 236 | |||
2990 | 237 | int cc_rr_output_info_get_preferred_height (CCRROutputInfo *self) | ||
2991 | 238 | { | ||
2992 | 239 | g_return_val_if_fail (CC_IS_RR_OUTPUT_INFO (self), 0); | ||
2993 | 240 | |||
2994 | 241 | return self->priv->pref_height; | ||
2995 | 242 | } | ||
2996 | 0 | 243 | ||
2997 | === added file 'panels/common/cc-rr-private.h' | |||
2998 | --- panels/common/cc-rr-private.h 1970-01-01 00:00:00 +0000 | |||
2999 | +++ panels/common/cc-rr-private.h 2014-06-26 03:13:28 +0000 | |||
3000 | @@ -0,0 +1,79 @@ | |||
3001 | 1 | #ifndef CC_RR_PRIVATE_H | ||
3002 | 2 | #define CC_RR_PRIVATE_H | ||
3003 | 3 | |||
3004 | 4 | #include <X11/Xlib.h> | ||
3005 | 5 | |||
3006 | 6 | #include <X11/extensions/Xrandr.h> | ||
3007 | 7 | |||
3008 | 8 | typedef struct ScreenInfo ScreenInfo; | ||
3009 | 9 | |||
3010 | 10 | struct ScreenInfo | ||
3011 | 11 | { | ||
3012 | 12 | int min_width; | ||
3013 | 13 | int max_width; | ||
3014 | 14 | int min_height; | ||
3015 | 15 | int max_height; | ||
3016 | 16 | |||
3017 | 17 | XRRScreenResources *resources; | ||
3018 | 18 | |||
3019 | 19 | CCRROutput ** outputs; | ||
3020 | 20 | CCRRCrtc ** crtcs; | ||
3021 | 21 | CCRRMode ** modes; | ||
3022 | 22 | |||
3023 | 23 | CCRRScreen * screen; | ||
3024 | 24 | |||
3025 | 25 | CCRRMode ** clone_modes; | ||
3026 | 26 | |||
3027 | 27 | RROutput primary; | ||
3028 | 28 | }; | ||
3029 | 29 | |||
3030 | 30 | struct CCRRScreenPrivate | ||
3031 | 31 | { | ||
3032 | 32 | GdkScreen * gdk_screen; | ||
3033 | 33 | GdkWindow * gdk_root; | ||
3034 | 34 | Display * xdisplay; | ||
3035 | 35 | Screen * xscreen; | ||
3036 | 36 | Window xroot; | ||
3037 | 37 | ScreenInfo * info; | ||
3038 | 38 | |||
3039 | 39 | int randr_event_base; | ||
3040 | 40 | int rr_major_version; | ||
3041 | 41 | int rr_minor_version; | ||
3042 | 42 | |||
3043 | 43 | Atom connector_type_atom; | ||
3044 | 44 | gboolean dpms_capable; | ||
3045 | 45 | }; | ||
3046 | 46 | |||
3047 | 47 | struct _CCRROutputInfoPrivate | ||
3048 | 48 | { | ||
3049 | 49 | char * name; | ||
3050 | 50 | |||
3051 | 51 | gboolean on; | ||
3052 | 52 | int width; | ||
3053 | 53 | int height; | ||
3054 | 54 | int rate; | ||
3055 | 55 | int x; | ||
3056 | 56 | int y; | ||
3057 | 57 | CCRRRotation rotation; | ||
3058 | 58 | |||
3059 | 59 | gboolean connected; | ||
3060 | 60 | gchar vendor[4]; | ||
3061 | 61 | guint product; | ||
3062 | 62 | guint serial; | ||
3063 | 63 | double aspect; | ||
3064 | 64 | int pref_width; | ||
3065 | 65 | int pref_height; | ||
3066 | 66 | char * display_name; | ||
3067 | 67 | gboolean primary; | ||
3068 | 68 | }; | ||
3069 | 69 | |||
3070 | 70 | struct _CCRRConfigPrivate | ||
3071 | 71 | { | ||
3072 | 72 | gboolean clone; | ||
3073 | 73 | CCRRScreen *screen; | ||
3074 | 74 | CCRROutputInfo **outputs; | ||
3075 | 75 | }; | ||
3076 | 76 | |||
3077 | 77 | gboolean _cc_rr_output_name_is_laptop (const char *name); | ||
3078 | 78 | |||
3079 | 79 | #endif | ||
3080 | 0 | 80 | ||
3081 | === added file 'panels/common/cc-rr.c' | |||
3082 | --- panels/common/cc-rr.c 1970-01-01 00:00:00 +0000 | |||
3083 | +++ panels/common/cc-rr.c 2014-06-26 03:13:28 +0000 | |||
3084 | @@ -0,0 +1,2622 @@ | |||
3085 | 1 | /* gnome-rr.c | ||
3086 | 2 | * | ||
3087 | 3 | * Copyright 2007, 2008, Red Hat, Inc. | ||
3088 | 4 | * | ||
3089 | 5 | * This file is part of the Gnome Library. | ||
3090 | 6 | * | ||
3091 | 7 | * The Gnome Library is free software; you can redistribute it and/or | ||
3092 | 8 | * modify it under the terms of the GNU Library General Public License as | ||
3093 | 9 | * published by the Free Software Foundation; either version 2 of the | ||
3094 | 10 | * License, or (at your option) any later version. | ||
3095 | 11 | * | ||
3096 | 12 | * The Gnome Library is distributed in the hope that it will be useful, | ||
3097 | 13 | * but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
3098 | 14 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | ||
3099 | 15 | * Library General Public License for more details. | ||
3100 | 16 | * | ||
3101 | 17 | * You should have received a copy of the GNU Library General Public | ||
3102 | 18 | * License along with the Gnome Library; see the file COPYING.LIB. If not, | ||
3103 | 19 | * write to the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, | ||
3104 | 20 | * Boston, MA 02110-1301, USA. | ||
3105 | 21 | * | ||
3106 | 22 | * Author: Soren Sandmann <sandmann@redhat.com> | ||
3107 | 23 | */ | ||
3108 | 24 | |||
3109 | 25 | #include <config.h> | ||
3110 | 26 | #include <glib/gi18n-lib.h> | ||
3111 | 27 | #include <string.h> | ||
3112 | 28 | #include <X11/Xlib.h> | ||
3113 | 29 | |||
3114 | 30 | #include <X11/extensions/Xrandr.h> | ||
3115 | 31 | |||
3116 | 32 | #include <gtk/gtk.h> | ||
3117 | 33 | #include <gdk/gdkx.h> | ||
3118 | 34 | #include <X11/Xatom.h> | ||
3119 | 35 | #include <X11/extensions/dpms.h> | ||
3120 | 36 | |||
3121 | 37 | #undef GNOME_DISABLE_DEPRECATED | ||
3122 | 38 | #include "cc-rr.h" | ||
3123 | 39 | #include "cc-rr-config.h" | ||
3124 | 40 | |||
3125 | 41 | #include "edid.h" | ||
3126 | 42 | #include "cc-rr-private.h" | ||
3127 | 43 | |||
3128 | 44 | #define DISPLAY(o) ((o)->info->screen->priv->xdisplay) | ||
3129 | 45 | |||
3130 | 46 | #define SERVERS_RANDR_IS_AT_LEAST_1_3(priv) (priv->rr_major_version > 1 || (priv->rr_major_version == 1 && priv->rr_minor_version >= 3)) | ||
3131 | 47 | |||
3132 | 48 | enum { | ||
3133 | 49 | SCREEN_PROP_0, | ||
3134 | 50 | SCREEN_PROP_GDK_SCREEN, | ||
3135 | 51 | SCREEN_PROP_LAST, | ||
3136 | 52 | }; | ||
3137 | 53 | |||
3138 | 54 | enum { | ||
3139 | 55 | SCREEN_CHANGED, | ||
3140 | 56 | SCREEN_OUTPUT_CONNECTED, | ||
3141 | 57 | SCREEN_OUTPUT_DISCONNECTED, | ||
3142 | 58 | SCREEN_SIGNAL_LAST, | ||
3143 | 59 | }; | ||
3144 | 60 | |||
3145 | 61 | gint screen_signals[SCREEN_SIGNAL_LAST]; | ||
3146 | 62 | |||
3147 | 63 | struct CCRROutput | ||
3148 | 64 | { | ||
3149 | 65 | ScreenInfo * info; | ||
3150 | 66 | RROutput id; | ||
3151 | 67 | |||
3152 | 68 | char * name; | ||
3153 | 69 | char * display_name; | ||
3154 | 70 | CCRRCrtc * current_crtc; | ||
3155 | 71 | gboolean connected; | ||
3156 | 72 | gulong width_mm; | ||
3157 | 73 | gulong height_mm; | ||
3158 | 74 | CCRRCrtc ** possible_crtcs; | ||
3159 | 75 | CCRROutput ** clones; | ||
3160 | 76 | CCRRMode ** modes; | ||
3161 | 77 | int n_preferred; | ||
3162 | 78 | guint8 * edid_data; | ||
3163 | 79 | gsize edid_size; | ||
3164 | 80 | char * connector_type; | ||
3165 | 81 | gint backlight_min; | ||
3166 | 82 | gint backlight_max; | ||
3167 | 83 | }; | ||
3168 | 84 | |||
3169 | 85 | struct CCRROutputWrap | ||
3170 | 86 | { | ||
3171 | 87 | RROutput id; | ||
3172 | 88 | }; | ||
3173 | 89 | |||
3174 | 90 | struct CCRRCrtc | ||
3175 | 91 | { | ||
3176 | 92 | ScreenInfo * info; | ||
3177 | 93 | RRCrtc id; | ||
3178 | 94 | |||
3179 | 95 | CCRRMode * current_mode; | ||
3180 | 96 | CCRROutput ** current_outputs; | ||
3181 | 97 | CCRROutput ** possible_outputs; | ||
3182 | 98 | int x; | ||
3183 | 99 | int y; | ||
3184 | 100 | |||
3185 | 101 | CCRRRotation current_rotation; | ||
3186 | 102 | CCRRRotation rotations; | ||
3187 | 103 | int gamma_size; | ||
3188 | 104 | }; | ||
3189 | 105 | |||
3190 | 106 | struct CCRRMode | ||
3191 | 107 | { | ||
3192 | 108 | ScreenInfo * info; | ||
3193 | 109 | RRMode id; | ||
3194 | 110 | char * name; | ||
3195 | 111 | int width; | ||
3196 | 112 | int height; | ||
3197 | 113 | int freq; /* in mHz */ | ||
3198 | 114 | }; | ||
3199 | 115 | |||
3200 | 116 | /* CCRRCrtc */ | ||
3201 | 117 | static CCRRCrtc * crtc_new (ScreenInfo *info, | ||
3202 | 118 | RRCrtc id); | ||
3203 | 119 | static CCRRCrtc * crtc_copy (const CCRRCrtc *from); | ||
3204 | 120 | static void crtc_free (CCRRCrtc *crtc); | ||
3205 | 121 | |||
3206 | 122 | static gboolean crtc_initialize (CCRRCrtc *crtc, | ||
3207 | 123 | XRRScreenResources *res, | ||
3208 | 124 | GError **error); | ||
3209 | 125 | |||
3210 | 126 | /* CCRROutput */ | ||
3211 | 127 | static CCRROutput *output_new (ScreenInfo *info, | ||
3212 | 128 | RROutput id); | ||
3213 | 129 | |||
3214 | 130 | static gboolean output_initialize (CCRROutput *output, | ||
3215 | 131 | XRRScreenResources *res, | ||
3216 | 132 | GError **error); | ||
3217 | 133 | |||
3218 | 134 | static CCRROutput *output_copy (const CCRROutput *from); | ||
3219 | 135 | static void output_free (CCRROutput *output); | ||
3220 | 136 | |||
3221 | 137 | /* CCRRMode */ | ||
3222 | 138 | static CCRRMode * mode_new (ScreenInfo *info, | ||
3223 | 139 | RRMode id); | ||
3224 | 140 | |||
3225 | 141 | static void mode_initialize (CCRRMode *mode, | ||
3226 | 142 | XRRModeInfo *info); | ||
3227 | 143 | |||
3228 | 144 | static CCRRMode * mode_copy (const CCRRMode *from); | ||
3229 | 145 | static void mode_free (CCRRMode *mode); | ||
3230 | 146 | |||
3231 | 147 | static void cc_rr_screen_finalize (GObject*); | ||
3232 | 148 | static void cc_rr_screen_set_property (GObject*, guint, const GValue*, GParamSpec*); | ||
3233 | 149 | static void cc_rr_screen_get_property (GObject*, guint, GValue*, GParamSpec*); | ||
3234 | 150 | static gboolean cc_rr_screen_initable_init (GInitable*, GCancellable*, GError**); | ||
3235 | 151 | static void cc_rr_screen_initable_iface_init (GInitableIface *iface); | ||
3236 | 152 | G_DEFINE_TYPE_WITH_CODE (CCRRScreen, cc_rr_screen, G_TYPE_OBJECT, | ||
3237 | 153 | G_IMPLEMENT_INTERFACE (G_TYPE_INITABLE, cc_rr_screen_initable_iface_init)) | ||
3238 | 154 | |||
3239 | 155 | G_DEFINE_BOXED_TYPE (CCRRCrtc, cc_rr_crtc, crtc_copy, crtc_free) | ||
3240 | 156 | G_DEFINE_BOXED_TYPE (CCRROutput, cc_rr_output, output_copy, output_free) | ||
3241 | 157 | G_DEFINE_BOXED_TYPE (CCRRMode, cc_rr_mode, mode_copy, mode_free) | ||
3242 | 158 | |||
3243 | 159 | /* Errors */ | ||
3244 | 160 | |||
3245 | 161 | /** | ||
3246 | 162 | * cc_rr_error_quark: | ||
3247 | 163 | * | ||
3248 | 164 | * Returns the #GQuark that will be used for #GError values returned by the | ||
3249 | 165 | * CCRR API. | ||
3250 | 166 | * | ||
3251 | 167 | * Return value: a #GQuark used to identify errors coming from the CCRR API. | ||
3252 | 168 | */ | ||
3253 | 169 | GQuark | ||
3254 | 170 | cc_rr_error_quark (void) | ||
3255 | 171 | { | ||
3256 | 172 | return g_quark_from_static_string ("cc-rr-error-quark"); | ||
3257 | 173 | } | ||
3258 | 174 | |||
3259 | 175 | /* Screen */ | ||
3260 | 176 | static CCRROutput * | ||
3261 | 177 | cc_rr_output_by_id (ScreenInfo *info, RROutput id) | ||
3262 | 178 | { | ||
3263 | 179 | CCRROutput **output; | ||
3264 | 180 | |||
3265 | 181 | g_assert (info != NULL); | ||
3266 | 182 | |||
3267 | 183 | for (output = info->outputs; *output; ++output) | ||
3268 | 184 | { | ||
3269 | 185 | if ((*output)->id == id) | ||
3270 | 186 | return *output; | ||
3271 | 187 | } | ||
3272 | 188 | |||
3273 | 189 | return NULL; | ||
3274 | 190 | } | ||
3275 | 191 | |||
3276 | 192 | static CCRRCrtc * | ||
3277 | 193 | crtc_by_id (ScreenInfo *info, RRCrtc id) | ||
3278 | 194 | { | ||
3279 | 195 | CCRRCrtc **crtc; | ||
3280 | 196 | |||
3281 | 197 | if (!info) | ||
3282 | 198 | return NULL; | ||
3283 | 199 | |||
3284 | 200 | for (crtc = info->crtcs; *crtc; ++crtc) | ||
3285 | 201 | { | ||
3286 | 202 | if ((*crtc)->id == id) | ||
3287 | 203 | return *crtc; | ||
3288 | 204 | } | ||
3289 | 205 | |||
3290 | 206 | return NULL; | ||
3291 | 207 | } | ||
3292 | 208 | |||
3293 | 209 | static CCRRMode * | ||
3294 | 210 | mode_by_id (ScreenInfo *info, RRMode id) | ||
3295 | 211 | { | ||
3296 | 212 | CCRRMode **mode; | ||
3297 | 213 | |||
3298 | 214 | g_assert (info != NULL); | ||
3299 | 215 | |||
3300 | 216 | for (mode = info->modes; *mode; ++mode) | ||
3301 | 217 | { | ||
3302 | 218 | if ((*mode)->id == id) | ||
3303 | 219 | return *mode; | ||
3304 | 220 | } | ||
3305 | 221 | |||
3306 | 222 | return NULL; | ||
3307 | 223 | } | ||
3308 | 224 | |||
3309 | 225 | static void | ||
3310 | 226 | screen_info_free (ScreenInfo *info) | ||
3311 | 227 | { | ||
3312 | 228 | CCRROutput **output; | ||
3313 | 229 | CCRRCrtc **crtc; | ||
3314 | 230 | CCRRMode **mode; | ||
3315 | 231 | |||
3316 | 232 | g_assert (info != NULL); | ||
3317 | 233 | |||
3318 | 234 | if (info->resources) | ||
3319 | 235 | { | ||
3320 | 236 | XRRFreeScreenResources (info->resources); | ||
3321 | 237 | |||
3322 | 238 | info->resources = NULL; | ||
3323 | 239 | } | ||
3324 | 240 | |||
3325 | 241 | if (info->outputs) | ||
3326 | 242 | { | ||
3327 | 243 | for (output = info->outputs; *output; ++output) | ||
3328 | 244 | output_free (*output); | ||
3329 | 245 | g_free (info->outputs); | ||
3330 | 246 | } | ||
3331 | 247 | |||
3332 | 248 | if (info->crtcs) | ||
3333 | 249 | { | ||
3334 | 250 | for (crtc = info->crtcs; *crtc; ++crtc) | ||
3335 | 251 | crtc_free (*crtc); | ||
3336 | 252 | g_free (info->crtcs); | ||
3337 | 253 | } | ||
3338 | 254 | |||
3339 | 255 | if (info->modes) | ||
3340 | 256 | { | ||
3341 | 257 | for (mode = info->modes; *mode; ++mode) | ||
3342 | 258 | mode_free (*mode); | ||
3343 | 259 | g_free (info->modes); | ||
3344 | 260 | } | ||
3345 | 261 | |||
3346 | 262 | if (info->clone_modes) | ||
3347 | 263 | { | ||
3348 | 264 | /* The modes themselves were freed above */ | ||
3349 | 265 | g_free (info->clone_modes); | ||
3350 | 266 | } | ||
3351 | 267 | |||
3352 | 268 | g_free (info); | ||
3353 | 269 | } | ||
3354 | 270 | |||
3355 | 271 | static gboolean | ||
3356 | 272 | has_similar_mode (CCRROutput *output, CCRRMode *mode) | ||
3357 | 273 | { | ||
3358 | 274 | int i; | ||
3359 | 275 | CCRRMode **modes = cc_rr_output_list_modes (output); | ||
3360 | 276 | int width = cc_rr_mode_get_width (mode); | ||
3361 | 277 | int height = cc_rr_mode_get_height (mode); | ||
3362 | 278 | |||
3363 | 279 | for (i = 0; modes[i] != NULL; ++i) | ||
3364 | 280 | { | ||
3365 | 281 | CCRRMode *m = modes[i]; | ||
3366 | 282 | |||
3367 | 283 | if (cc_rr_mode_get_width (m) == width && | ||
3368 | 284 | cc_rr_mode_get_height (m) == height) | ||
3369 | 285 | { | ||
3370 | 286 | return TRUE; | ||
3371 | 287 | } | ||
3372 | 288 | } | ||
3373 | 289 | |||
3374 | 290 | return FALSE; | ||
3375 | 291 | } | ||
3376 | 292 | |||
3377 | 293 | static void | ||
3378 | 294 | gather_clone_modes (ScreenInfo *info) | ||
3379 | 295 | { | ||
3380 | 296 | int i; | ||
3381 | 297 | GPtrArray *result = g_ptr_array_new (); | ||
3382 | 298 | |||
3383 | 299 | for (i = 0; info->outputs[i] != NULL; ++i) | ||
3384 | 300 | { | ||
3385 | 301 | int j; | ||
3386 | 302 | CCRROutput *output1, *output2; | ||
3387 | 303 | |||
3388 | 304 | output1 = info->outputs[i]; | ||
3389 | 305 | |||
3390 | 306 | if (!output1->connected) | ||
3391 | 307 | continue; | ||
3392 | 308 | |||
3393 | 309 | for (j = 0; output1->modes[j] != NULL; ++j) | ||
3394 | 310 | { | ||
3395 | 311 | CCRRMode *mode = output1->modes[j]; | ||
3396 | 312 | gboolean valid; | ||
3397 | 313 | int k; | ||
3398 | 314 | |||
3399 | 315 | valid = TRUE; | ||
3400 | 316 | for (k = 0; info->outputs[k] != NULL; ++k) | ||
3401 | 317 | { | ||
3402 | 318 | output2 = info->outputs[k]; | ||
3403 | 319 | |||
3404 | 320 | if (!output2->connected) | ||
3405 | 321 | continue; | ||
3406 | 322 | |||
3407 | 323 | if (!has_similar_mode (output2, mode)) | ||
3408 | 324 | { | ||
3409 | 325 | valid = FALSE; | ||
3410 | 326 | break; | ||
3411 | 327 | } | ||
3412 | 328 | } | ||
3413 | 329 | |||
3414 | 330 | if (valid) | ||
3415 | 331 | g_ptr_array_add (result, mode); | ||
3416 | 332 | } | ||
3417 | 333 | } | ||
3418 | 334 | |||
3419 | 335 | g_ptr_array_add (result, NULL); | ||
3420 | 336 | |||
3421 | 337 | info->clone_modes = (CCRRMode **)g_ptr_array_free (result, FALSE); | ||
3422 | 338 | } | ||
3423 | 339 | |||
3424 | 340 | static gboolean | ||
3425 | 341 | fill_screen_info_from_resources (ScreenInfo *info, | ||
3426 | 342 | XRRScreenResources *resources, | ||
3427 | 343 | GError **error) | ||
3428 | 344 | { | ||
3429 | 345 | int i; | ||
3430 | 346 | GPtrArray *a; | ||
3431 | 347 | CCRRCrtc **crtc; | ||
3432 | 348 | CCRROutput **output; | ||
3433 | 349 | |||
3434 | 350 | info->resources = resources; | ||
3435 | 351 | |||
3436 | 352 | /* We create all the structures before initializing them, so | ||
3437 | 353 | * that they can refer to each other. | ||
3438 | 354 | */ | ||
3439 | 355 | a = g_ptr_array_new (); | ||
3440 | 356 | for (i = 0; i < resources->ncrtc; ++i) | ||
3441 | 357 | { | ||
3442 | 358 | CCRRCrtc *crtc = crtc_new (info, resources->crtcs[i]); | ||
3443 | 359 | |||
3444 | 360 | g_ptr_array_add (a, crtc); | ||
3445 | 361 | } | ||
3446 | 362 | g_ptr_array_add (a, NULL); | ||
3447 | 363 | info->crtcs = (CCRRCrtc **)g_ptr_array_free (a, FALSE); | ||
3448 | 364 | |||
3449 | 365 | a = g_ptr_array_new (); | ||
3450 | 366 | for (i = 0; i < resources->noutput; ++i) | ||
3451 | 367 | { | ||
3452 | 368 | CCRROutput *output = output_new (info, resources->outputs[i]); | ||
3453 | 369 | |||
3454 | 370 | g_ptr_array_add (a, output); | ||
3455 | 371 | } | ||
3456 | 372 | g_ptr_array_add (a, NULL); | ||
3457 | 373 | info->outputs = (CCRROutput **)g_ptr_array_free (a, FALSE); | ||
3458 | 374 | |||
3459 | 375 | a = g_ptr_array_new (); | ||
3460 | 376 | for (i = 0; i < resources->nmode; ++i) | ||
3461 | 377 | { | ||
3462 | 378 | CCRRMode *mode = mode_new (info, resources->modes[i].id); | ||
3463 | 379 | |||
3464 | 380 | g_ptr_array_add (a, mode); | ||
3465 | 381 | } | ||
3466 | 382 | g_ptr_array_add (a, NULL); | ||
3467 | 383 | info->modes = (CCRRMode **)g_ptr_array_free (a, FALSE); | ||
3468 | 384 | |||
3469 | 385 | /* Initialize */ | ||
3470 | 386 | for (crtc = info->crtcs; *crtc; ++crtc) | ||
3471 | 387 | { | ||
3472 | 388 | if (!crtc_initialize (*crtc, resources, error)) | ||
3473 | 389 | return FALSE; | ||
3474 | 390 | } | ||
3475 | 391 | |||
3476 | 392 | for (output = info->outputs; *output; ++output) | ||
3477 | 393 | { | ||
3478 | 394 | if (!output_initialize (*output, resources, error)) | ||
3479 | 395 | return FALSE; | ||
3480 | 396 | } | ||
3481 | 397 | |||
3482 | 398 | for (i = 0; i < resources->nmode; ++i) | ||
3483 | 399 | { | ||
3484 | 400 | CCRRMode *mode = mode_by_id (info, resources->modes[i].id); | ||
3485 | 401 | |||
3486 | 402 | mode_initialize (mode, &(resources->modes[i])); | ||
3487 | 403 | } | ||
3488 | 404 | |||
3489 | 405 | gather_clone_modes (info); | ||
3490 | 406 | |||
3491 | 407 | return TRUE; | ||
3492 | 408 | } | ||
3493 | 409 | |||
3494 | 410 | static gboolean | ||
3495 | 411 | fill_out_screen_info (Display *xdisplay, | ||
3496 | 412 | Window xroot, | ||
3497 | 413 | ScreenInfo *info, | ||
3498 | 414 | gboolean needs_reprobe, | ||
3499 | 415 | GError **error) | ||
3500 | 416 | { | ||
3501 | 417 | XRRScreenResources *resources; | ||
3502 | 418 | CCRRScreenPrivate *priv; | ||
3503 | 419 | |||
3504 | 420 | g_assert (xdisplay != NULL); | ||
3505 | 421 | g_assert (info != NULL); | ||
3506 | 422 | |||
3507 | 423 | priv = info->screen->priv; | ||
3508 | 424 | |||
3509 | 425 | /* First update the screen resources */ | ||
3510 | 426 | |||
3511 | 427 | if (needs_reprobe) | ||
3512 | 428 | resources = XRRGetScreenResources (xdisplay, xroot); | ||
3513 | 429 | else | ||
3514 | 430 | { | ||
3515 | 431 | /* XRRGetScreenResourcesCurrent is less expensive than | ||
3516 | 432 | * XRRGetScreenResources, however it is available only | ||
3517 | 433 | * in RandR 1.3 or higher | ||
3518 | 434 | */ | ||
3519 | 435 | if (SERVERS_RANDR_IS_AT_LEAST_1_3 (priv)) | ||
3520 | 436 | resources = XRRGetScreenResourcesCurrent (xdisplay, xroot); | ||
3521 | 437 | else | ||
3522 | 438 | resources = XRRGetScreenResources (xdisplay, xroot); | ||
3523 | 439 | } | ||
3524 | 440 | |||
3525 | 441 | if (resources) | ||
3526 | 442 | { | ||
3527 | 443 | if (!fill_screen_info_from_resources (info, resources, error)) | ||
3528 | 444 | return FALSE; | ||
3529 | 445 | } | ||
3530 | 446 | else | ||
3531 | 447 | { | ||
3532 | 448 | g_set_error (error, CC_RR_ERROR, CC_RR_ERROR_RANDR_ERROR, | ||
3533 | 449 | /* Translators: a CRTC is a CRT Controller (this is X terminology). */ | ||
3534 | 450 | _("could not get the screen resources (CRTCs, outputs, modes)")); | ||
3535 | 451 | return FALSE; | ||
3536 | 452 | } | ||
3537 | 453 | |||
3538 | 454 | /* Then update the screen size range. We do this after XRRGetScreenResources() so that | ||
3539 | 455 | * the X server will already have an updated view of the outputs. | ||
3540 | 456 | */ | ||
3541 | 457 | |||
3542 | 458 | if (needs_reprobe) { | ||
3543 | 459 | gboolean success; | ||
3544 | 460 | |||
3545 | 461 | gdk_error_trap_push (); | ||
3546 | 462 | success = XRRGetScreenSizeRange (xdisplay, xroot, | ||
3547 | 463 | &(info->min_width), | ||
3548 | 464 | &(info->min_height), | ||
3549 | 465 | &(info->max_width), | ||
3550 | 466 | &(info->max_height)); | ||
3551 | 467 | gdk_flush (); | ||
3552 | 468 | if (gdk_error_trap_pop ()) { | ||
3553 | 469 | g_set_error (error, CC_RR_ERROR, CC_RR_ERROR_UNKNOWN, | ||
3554 | 470 | _("unhandled X error while getting the range of screen sizes")); | ||
3555 | 471 | return FALSE; | ||
3556 | 472 | } | ||
3557 | 473 | |||
3558 | 474 | if (!success) { | ||
3559 | 475 | g_set_error (error, CC_RR_ERROR, CC_RR_ERROR_RANDR_ERROR, | ||
3560 | 476 | _("could not get the range of screen sizes")); | ||
3561 | 477 | return FALSE; | ||
3562 | 478 | } | ||
3563 | 479 | } | ||
3564 | 480 | else | ||
3565 | 481 | { | ||
3566 | 482 | cc_rr_screen_get_ranges (info->screen, | ||
3567 | 483 | &(info->min_width), | ||
3568 | 484 | &(info->max_width), | ||
3569 | 485 | &(info->min_height), | ||
3570 | 486 | &(info->max_height)); | ||
3571 | 487 | } | ||
3572 | 488 | |||
3573 | 489 | info->primary = None; | ||
3574 | 490 | if (SERVERS_RANDR_IS_AT_LEAST_1_3 (priv)) { | ||
3575 | 491 | gdk_error_trap_push (); | ||
3576 | 492 | info->primary = XRRGetOutputPrimary (xdisplay, xroot); | ||
3577 | 493 | gdk_error_trap_pop_ignored (); | ||
3578 | 494 | } | ||
3579 | 495 | |||
3580 | 496 | /* can the screen do DPMS? */ | ||
3581 | 497 | gdk_error_trap_push (); | ||
3582 | 498 | priv->dpms_capable = DPMSCapable (priv->xdisplay); | ||
3583 | 499 | gdk_error_trap_pop_ignored (); | ||
3584 | 500 | |||
3585 | 501 | return TRUE; | ||
3586 | 502 | } | ||
3587 | 503 | |||
3588 | 504 | static ScreenInfo * | ||
3589 | 505 | screen_info_new (CCRRScreen *screen, gboolean needs_reprobe, GError **error) | ||
3590 | 506 | { | ||
3591 | 507 | ScreenInfo *info = g_new0 (ScreenInfo, 1); | ||
3592 | 508 | CCRRScreenPrivate *priv; | ||
3593 | 509 | |||
3594 | 510 | g_assert (screen != NULL); | ||
3595 | 511 | |||
3596 | 512 | priv = screen->priv; | ||
3597 | 513 | |||
3598 | 514 | info->outputs = NULL; | ||
3599 | 515 | info->crtcs = NULL; | ||
3600 | 516 | info->modes = NULL; | ||
3601 | 517 | info->screen = screen; | ||
3602 | 518 | |||
3603 | 519 | if (fill_out_screen_info (priv->xdisplay, priv->xroot, info, needs_reprobe, error)) | ||
3604 | 520 | { | ||
3605 | 521 | return info; | ||
3606 | 522 | } | ||
3607 | 523 | else | ||
3608 | 524 | { | ||
3609 | 525 | screen_info_free (info); | ||
3610 | 526 | return NULL; | ||
3611 | 527 | } | ||
3612 | 528 | } | ||
3613 | 529 | |||
3614 | 530 | static CCRROutput * | ||
3615 | 531 | find_output_by_id (CCRROutput **haystack, guint32 id) | ||
3616 | 532 | { | ||
3617 | 533 | guint i; | ||
3618 | 534 | |||
3619 | 535 | for (i = 0; haystack[i] != NULL; i++) | ||
3620 | 536 | { | ||
3621 | 537 | if (cc_rr_output_get_id (haystack[i]) == id) | ||
3622 | 538 | return haystack[i]; | ||
3623 | 539 | } | ||
3624 | 540 | return NULL; | ||
3625 | 541 | } | ||
3626 | 542 | |||
3627 | 543 | static void | ||
3628 | 544 | diff_outputs_and_emit_signals (ScreenInfo *old, ScreenInfo *new) | ||
3629 | 545 | { | ||
3630 | 546 | guint i; | ||
3631 | 547 | guint32 id_old, id_new; | ||
3632 | 548 | CCRROutput *output_old; | ||
3633 | 549 | CCRROutput *output_new; | ||
3634 | 550 | |||
3635 | 551 | /* have any outputs been removed or disconnected */ | ||
3636 | 552 | for (i = 0; old->outputs[i] != NULL; i++) | ||
3637 | 553 | { | ||
3638 | 554 | id_old = cc_rr_output_get_id (old->outputs[i]); | ||
3639 | 555 | output_new = find_output_by_id (new->outputs, id_old); | ||
3640 | 556 | if (output_new == NULL) | ||
3641 | 557 | { | ||
3642 | 558 | /* output removed (and disconnected) */ | ||
3643 | 559 | if (cc_rr_output_is_connected (old->outputs[i])) | ||
3644 | 560 | { | ||
3645 | 561 | g_signal_emit (G_OBJECT (new->screen), | ||
3646 | 562 | screen_signals[SCREEN_OUTPUT_DISCONNECTED], 0, | ||
3647 | 563 | old->outputs[i]); | ||
3648 | 564 | } | ||
3649 | 565 | continue; | ||
3650 | 566 | } | ||
3651 | 567 | if (cc_rr_output_is_connected (old->outputs[i]) && | ||
3652 | 568 | !cc_rr_output_is_connected (output_new)) | ||
3653 | 569 | { | ||
3654 | 570 | /* output disconnected */ | ||
3655 | 571 | g_signal_emit (G_OBJECT (new->screen), | ||
3656 | 572 | screen_signals[SCREEN_OUTPUT_DISCONNECTED], 0, | ||
3657 | 573 | old->outputs[i]); | ||
3658 | 574 | } | ||
3659 | 575 | } | ||
3660 | 576 | |||
3661 | 577 | /* have any outputs been created or connected */ | ||
3662 | 578 | for (i = 0; new->outputs[i] != NULL; i++) | ||
3663 | 579 | { | ||
3664 | 580 | id_new = cc_rr_output_get_id (new->outputs[i]); | ||
3665 | 581 | output_old = find_output_by_id (old->outputs, id_new); | ||
3666 | 582 | if (output_old == NULL) | ||
3667 | 583 | { | ||
3668 | 584 | /* output created */ | ||
3669 | 585 | if (cc_rr_output_is_connected (new->outputs[i])) | ||
3670 | 586 | { | ||
3671 | 587 | g_signal_emit (G_OBJECT (new->screen), | ||
3672 | 588 | screen_signals[SCREEN_OUTPUT_CONNECTED], 0, | ||
3673 | 589 | new->outputs[i]); | ||
3674 | 590 | } | ||
3675 | 591 | continue; | ||
3676 | 592 | } | ||
3677 | 593 | if (!cc_rr_output_is_connected (output_old) && | ||
3678 | 594 | cc_rr_output_is_connected (new->outputs[i])) | ||
3679 | 595 | { | ||
3680 | 596 | /* output connected */ | ||
3681 | 597 | g_signal_emit (G_OBJECT (new->screen), | ||
3682 | 598 | screen_signals[SCREEN_OUTPUT_CONNECTED], 0, | ||
3683 | 599 | new->outputs[i]); | ||
3684 | 600 | } | ||
3685 | 601 | } | ||
3686 | 602 | } | ||
3687 | 603 | |||
3688 | 604 | static gboolean | ||
3689 | 605 | screen_update (CCRRScreen *screen, gboolean force_callback, gboolean needs_reprobe, GError **error) | ||
3690 | 606 | { | ||
3691 | 607 | ScreenInfo *info; | ||
3692 | 608 | gboolean changed = FALSE; | ||
3693 | 609 | |||
3694 | 610 | g_assert (screen != NULL); | ||
3695 | 611 | |||
3696 | 612 | info = screen_info_new (screen, needs_reprobe, error); | ||
3697 | 613 | if (!info) | ||
3698 | 614 | return FALSE; | ||
3699 | 615 | |||
3700 | 616 | if (info->resources->configTimestamp != screen->priv->info->resources->configTimestamp) | ||
3701 | 617 | changed = TRUE; | ||
3702 | 618 | |||
3703 | 619 | /* work out if any outputs have changed connected state */ | ||
3704 | 620 | diff_outputs_and_emit_signals (screen->priv->info, info); | ||
3705 | 621 | |||
3706 | 622 | screen_info_free (screen->priv->info); | ||
3707 | 623 | |||
3708 | 624 | screen->priv->info = info; | ||
3709 | 625 | |||
3710 | 626 | if (changed || force_callback) | ||
3711 | 627 | g_signal_emit (G_OBJECT (screen), screen_signals[SCREEN_CHANGED], 0); | ||
3712 | 628 | |||
3713 | 629 | return changed; | ||
3714 | 630 | } | ||
3715 | 631 | |||
3716 | 632 | static GdkFilterReturn | ||
3717 | 633 | screen_on_event (GdkXEvent *xevent, | ||
3718 | 634 | GdkEvent *event, | ||
3719 | 635 | gpointer data) | ||
3720 | 636 | { | ||
3721 | 637 | CCRRScreen *screen = data; | ||
3722 | 638 | CCRRScreenPrivate *priv = screen->priv; | ||
3723 | 639 | XEvent *e = xevent; | ||
3724 | 640 | int event_num; | ||
3725 | 641 | |||
3726 | 642 | if (!e) | ||
3727 | 643 | return GDK_FILTER_CONTINUE; | ||
3728 | 644 | |||
3729 | 645 | event_num = e->type - priv->randr_event_base; | ||
3730 | 646 | |||
3731 | 647 | if (event_num == RRScreenChangeNotify) { | ||
3732 | 648 | /* We don't reprobe the hardware; we just fetch the X server's latest | ||
3733 | 649 | * state. The server already knows the new state of the outputs; that's | ||
3734 | 650 | * why it sent us an event! | ||
3735 | 651 | */ | ||
3736 | 652 | screen_update (screen, TRUE, FALSE, NULL); /* NULL-GError */ | ||
3737 | 653 | #if 0 | ||
3738 | 654 | /* Enable this code to get a dialog showing the RANDR timestamps, for debugging purposes */ | ||
3739 | 655 | { | ||
3740 | 656 | GtkWidget *dialog; | ||
3741 | 657 | XRRScreenChangeNotifyEvent *rr_event; | ||
3742 | 658 | static int dialog_num; | ||
3743 | 659 | |||
3744 | 660 | rr_event = (XRRScreenChangeNotifyEvent *) e; | ||
3745 | 661 | |||
3746 | 662 | dialog = gtk_message_dialog_new (NULL, | ||
3747 | 663 | 0, | ||
3748 | 664 | GTK_MESSAGE_INFO, | ||
3749 | 665 | GTK_BUTTONS_CLOSE, | ||
3750 | 666 | "RRScreenChangeNotify timestamps (%d):\n" | ||
3751 | 667 | "event change: %u\n" | ||
3752 | 668 | "event config: %u\n" | ||
3753 | 669 | "event serial: %lu\n" | ||
3754 | 670 | "----------------------" | ||
3755 | 671 | "screen change: %u\n" | ||
3756 | 672 | "screen config: %u\n", | ||
3757 | 673 | dialog_num++, | ||
3758 | 674 | (guint32) rr_event->timestamp, | ||
3759 | 675 | (guint32) rr_event->config_timestamp, | ||
3760 | 676 | rr_event->serial, | ||
3761 | 677 | (guint32) priv->info->resources->timestamp, | ||
3762 | 678 | (guint32) priv->info->resources->configTimestamp); | ||
3763 | 679 | g_signal_connect (dialog, "response", | ||
3764 | 680 | G_CALLBACK (gtk_widget_destroy), NULL); | ||
3765 | 681 | gtk_widget_show (dialog); | ||
3766 | 682 | } | ||
3767 | 683 | #endif | ||
3768 | 684 | } | ||
3769 | 685 | #if 0 | ||
3770 | 686 | /* WHY THIS CODE IS DISABLED: | ||
3771 | 687 | * | ||
3772 | 688 | * Note that in cc_rr_screen_new(), we only select for | ||
3773 | 689 | * RRScreenChangeNotifyMask. We used to select for other values in | ||
3774 | 690 | * RR*NotifyMask, but we weren't really doing anything useful with those | ||
3775 | 691 | * events. We only care about "the screens changed in some way or another" | ||
3776 | 692 | * for now. | ||
3777 | 693 | * | ||
3778 | 694 | * If we ever run into a situtation that could benefit from processing more | ||
3779 | 695 | * detailed events, we can enable this code again. | ||
3780 | 696 | * | ||
3781 | 697 | * Note that the X server sends RRScreenChangeNotify in conjunction with the | ||
3782 | 698 | * more detailed events from RANDR 1.2 - see xserver/randr/randr.c:TellChanged(). | ||
3783 | 699 | */ | ||
3784 | 700 | else if (event_num == RRNotify) | ||
3785 | 701 | { | ||
3786 | 702 | /* Other RandR events */ | ||
3787 | 703 | |||
3788 | 704 | XRRNotifyEvent *event = (XRRNotifyEvent *)e; | ||
3789 | 705 | |||
3790 | 706 | /* Here we can distinguish between RRNotify events supported | ||
3791 | 707 | * since RandR 1.2 such as RRNotify_OutputProperty. For now, we | ||
3792 | 708 | * don't have anything special to do for particular subevent types, so | ||
3793 | 709 | * we leave this as an empty switch(). | ||
3794 | 710 | */ | ||
3795 | 711 | switch (event->subtype) | ||
3796 | 712 | { | ||
3797 | 713 | default: | ||
3798 | 714 | break; | ||
3799 | 715 | } | ||
3800 | 716 | |||
3801 | 717 | /* No need to reprobe hardware here */ | ||
3802 | 718 | screen_update (screen, TRUE, FALSE, NULL); /* NULL-GError */ | ||
3803 | 719 | } | ||
3804 | 720 | #endif | ||
3805 | 721 | |||
3806 | 722 | /* Pass the event on to GTK+ */ | ||
3807 | 723 | return GDK_FILTER_CONTINUE; | ||
3808 | 724 | } | ||
3809 | 725 | |||
3810 | 726 | static gboolean | ||
3811 | 727 | cc_rr_screen_initable_init (GInitable *initable, GCancellable *canc, GError **error) | ||
3812 | 728 | { | ||
3813 | 729 | CCRRScreen *self = CC_RR_SCREEN (initable); | ||
3814 | 730 | CCRRScreenPrivate *priv = self->priv; | ||
3815 | 731 | Display *dpy = GDK_SCREEN_XDISPLAY (self->priv->gdk_screen); | ||
3816 | 732 | int event_base; | ||
3817 | 733 | int ignore; | ||
3818 | 734 | |||
3819 | 735 | priv->connector_type_atom = XInternAtom (dpy, "ConnectorType", FALSE); | ||
3820 | 736 | |||
3821 | 737 | if (XRRQueryExtension (dpy, &event_base, &ignore)) | ||
3822 | 738 | { | ||
3823 | 739 | priv->randr_event_base = event_base; | ||
3824 | 740 | |||
3825 | 741 | XRRQueryVersion (dpy, &priv->rr_major_version, &priv->rr_minor_version); | ||
3826 | 742 | if (priv->rr_major_version < 1 || (priv->rr_major_version == 1 && priv->rr_minor_version < 2)) { | ||
3827 | 743 | g_set_error (error, CC_RR_ERROR, CC_RR_ERROR_NO_RANDR_EXTENSION, | ||
3828 | 744 | "RANDR extension is too old (must be at least 1.2)"); | ||
3829 | 745 | return FALSE; | ||
3830 | 746 | } | ||
3831 | 747 | |||
3832 | 748 | priv->info = screen_info_new (self, TRUE, error); | ||
3833 | 749 | |||
3834 | 750 | if (!priv->info) { | ||
3835 | 751 | return FALSE; | ||
3836 | 752 | } | ||
3837 | 753 | |||
3838 | 754 | XRRSelectInput (priv->xdisplay, | ||
3839 | 755 | priv->xroot, | ||
3840 | 756 | RRScreenChangeNotifyMask); | ||
3841 | 757 | gdk_x11_register_standard_event_type (gdk_screen_get_display (priv->gdk_screen), | ||
3842 | 758 | event_base, | ||
3843 | 759 | RRNotify + 1); | ||
3844 | 760 | gdk_window_add_filter (priv->gdk_root, screen_on_event, self); | ||
3845 | 761 | |||
3846 | 762 | return TRUE; | ||
3847 | 763 | } | ||
3848 | 764 | else | ||
3849 | 765 | { | ||
3850 | 766 | g_set_error (error, CC_RR_ERROR, CC_RR_ERROR_NO_RANDR_EXTENSION, | ||
3851 | 767 | _("RANDR extension is not present")); | ||
3852 | 768 | |||
3853 | 769 | return FALSE; | ||
3854 | 770 | } | ||
3855 | 771 | } | ||
3856 | 772 | |||
3857 | 773 | void | ||
3858 | 774 | cc_rr_screen_initable_iface_init (GInitableIface *iface) | ||
3859 | 775 | { | ||
3860 | 776 | iface->init = cc_rr_screen_initable_init; | ||
3861 | 777 | } | ||
3862 | 778 | |||
3863 | 779 | void | ||
3864 | 780 | cc_rr_screen_finalize (GObject *gobject) | ||
3865 | 781 | { | ||
3866 | 782 | CCRRScreen *screen = CC_RR_SCREEN (gobject); | ||
3867 | 783 | |||
3868 | 784 | gdk_window_remove_filter (screen->priv->gdk_root, screen_on_event, screen); | ||
3869 | 785 | |||
3870 | 786 | if (screen->priv->info) | ||
3871 | 787 | screen_info_free (screen->priv->info); | ||
3872 | 788 | |||
3873 | 789 | G_OBJECT_CLASS (cc_rr_screen_parent_class)->finalize (gobject); | ||
3874 | 790 | } | ||
3875 | 791 | |||
3876 | 792 | void | ||
3877 | 793 | cc_rr_screen_set_property (GObject *gobject, guint property_id, const GValue *value, GParamSpec *property) | ||
3878 | 794 | { | ||
3879 | 795 | CCRRScreen *self = CC_RR_SCREEN (gobject); | ||
3880 | 796 | CCRRScreenPrivate *priv = self->priv; | ||
3881 | 797 | |||
3882 | 798 | switch (property_id) | ||
3883 | 799 | { | ||
3884 | 800 | case SCREEN_PROP_GDK_SCREEN: | ||
3885 | 801 | priv->gdk_screen = g_value_get_object (value); | ||
3886 | 802 | priv->gdk_root = gdk_screen_get_root_window (priv->gdk_screen); | ||
3887 | 803 | priv->xroot = gdk_x11_window_get_xid (priv->gdk_root); | ||
3888 | 804 | priv->xdisplay = GDK_SCREEN_XDISPLAY (priv->gdk_screen); | ||
3889 | 805 | priv->xscreen = gdk_x11_screen_get_xscreen (priv->gdk_screen); | ||
3890 | 806 | return; | ||
3891 | 807 | default: | ||
3892 | 808 | G_OBJECT_WARN_INVALID_PROPERTY_ID (gobject, property_id, property); | ||
3893 | 809 | return; | ||
3894 | 810 | } | ||
3895 | 811 | } | ||
3896 | 812 | |||
3897 | 813 | void | ||
3898 | 814 | cc_rr_screen_get_property (GObject *gobject, guint property_id, GValue *value, GParamSpec *property) | ||
3899 | 815 | { | ||
3900 | 816 | CCRRScreen *self = CC_RR_SCREEN (gobject); | ||
3901 | 817 | CCRRScreenPrivate *priv = self->priv; | ||
3902 | 818 | |||
3903 | 819 | switch (property_id) | ||
3904 | 820 | { | ||
3905 | 821 | case SCREEN_PROP_GDK_SCREEN: | ||
3906 | 822 | g_value_set_object (value, priv->gdk_screen); | ||
3907 | 823 | return; | ||
3908 | 824 | default: | ||
3909 | 825 | G_OBJECT_WARN_INVALID_PROPERTY_ID (gobject, property_id, property); | ||
3910 | 826 | return; | ||
3911 | 827 | } | ||
3912 | 828 | } | ||
3913 | 829 | |||
3914 | 830 | void | ||
3915 | 831 | cc_rr_screen_class_init (CCRRScreenClass *klass) | ||
3916 | 832 | { | ||
3917 | 833 | GObjectClass *gobject_class = G_OBJECT_CLASS (klass); | ||
3918 | 834 | g_type_class_add_private (klass, sizeof (CCRRScreenPrivate)); | ||
3919 | 835 | |||
3920 | 836 | bindtextdomain (GETTEXT_PACKAGE, GNOMELOCALEDIR); | ||
3921 | 837 | bind_textdomain_codeset (GETTEXT_PACKAGE, "UTF-8"); | ||
3922 | 838 | |||
3923 | 839 | gobject_class->set_property = cc_rr_screen_set_property; | ||
3924 | 840 | gobject_class->get_property = cc_rr_screen_get_property; | ||
3925 | 841 | gobject_class->finalize = cc_rr_screen_finalize; | ||
3926 | 842 | |||
3927 | 843 | g_object_class_install_property( | ||
3928 | 844 | gobject_class, | ||
3929 | 845 | SCREEN_PROP_GDK_SCREEN, | ||
3930 | 846 | g_param_spec_object ( | ||
3931 | 847 | "gdk-screen", | ||
3932 | 848 | "GDK Screen", | ||
3933 | 849 | "The GDK Screen represented by this CCRRScreen", | ||
3934 | 850 | GDK_TYPE_SCREEN, | ||
3935 | 851 | G_PARAM_READWRITE | | ||
3936 | 852 | G_PARAM_CONSTRUCT_ONLY | | ||
3937 | 853 | G_PARAM_STATIC_STRINGS) | ||
3938 | 854 | ); | ||
3939 | 855 | |||
3940 | 856 | screen_signals[SCREEN_CHANGED] = g_signal_new("changed", | ||
3941 | 857 | G_TYPE_FROM_CLASS (gobject_class), | ||
3942 | 858 | G_SIGNAL_RUN_FIRST | G_SIGNAL_NO_RECURSE | G_SIGNAL_NO_HOOKS, | ||
3943 | 859 | G_STRUCT_OFFSET (CCRRScreenClass, changed), | ||
3944 | 860 | NULL, | ||
3945 | 861 | NULL, | ||
3946 | 862 | g_cclosure_marshal_VOID__VOID, | ||
3947 | 863 | G_TYPE_NONE, | ||
3948 | 864 | 0); | ||
3949 | 865 | |||
3950 | 866 | /** | ||
3951 | 867 | * CCRRScreen::output-connected: | ||
3952 | 868 | * @screen: the #CCRRScreen that emitted the signal | ||
3953 | 869 | * @output: the #CCRROutput that was connected | ||
3954 | 870 | * | ||
3955 | 871 | * This signal is emitted when a display device is connected to a | ||
3956 | 872 | * port, or a port is hotplugged with an active output. The latter | ||
3957 | 873 | * can happen if a laptop is docked, and the dock provides a new | ||
3958 | 874 | * active output. | ||
3959 | 875 | * | ||
3960 | 876 | * The @output value is not a #GObject. The returned @output value can | ||
3961 | 877 | * only assume to be valid during the emission of the signal (i.e. within | ||
3962 | 878 | * your signal handler only), as it may change later when the @screen | ||
3963 | 879 | * is modified due to an event from the X server, or due to another | ||
3964 | 880 | * place in the application modifying the @screen and the @output. | ||
3965 | 881 | * Therefore, deal with changes to the @output right in your signal | ||
3966 | 882 | * handler, instead of keeping the @output reference for an async or | ||
3967 | 883 | * idle function. | ||
3968 | 884 | **/ | ||
3969 | 885 | screen_signals[SCREEN_OUTPUT_CONNECTED] = g_signal_new("output-connected", | ||
3970 | 886 | G_TYPE_FROM_CLASS (gobject_class), | ||
3971 | 887 | G_SIGNAL_RUN_FIRST | G_SIGNAL_NO_RECURSE | G_SIGNAL_NO_HOOKS, | ||
3972 | 888 | G_STRUCT_OFFSET (CCRRScreenClass, output_connected), | ||
3973 | 889 | NULL, | ||
3974 | 890 | NULL, | ||
3975 | 891 | g_cclosure_marshal_VOID__POINTER, | ||
3976 | 892 | G_TYPE_NONE, | ||
3977 | 893 | 1, G_TYPE_POINTER); | ||
3978 | 894 | |||
3979 | 895 | /** | ||
3980 | 896 | * CCRRScreen::output-disconnected: | ||
3981 | 897 | * @screen: the #CCRRScreen that emitted the signal | ||
3982 | 898 | * @output: the #CCRROutput that was disconnected | ||
3983 | 899 | * | ||
3984 | 900 | * This signal is emitted when a display device is disconnected from | ||
3985 | 901 | * a port, or a port output is hot-unplugged. The latter can happen | ||
3986 | 902 | * if a laptop is undocked, and the dock provided the output. | ||
3987 | 903 | * | ||
3988 | 904 | * The @output value is not a #GObject. The returned @output value can | ||
3989 | 905 | * only assume to be valid during the emission of the signal (i.e. within | ||
3990 | 906 | * your signal handler only), as it may change later when the @screen | ||
3991 | 907 | * is modified due to an event from the X server, or due to another | ||
3992 | 908 | * place in the application modifying the @screen and the @output. | ||
3993 | 909 | * Therefore, deal with changes to the @output right in your signal | ||
3994 | 910 | * handler, instead of keeping the @output reference for an async or | ||
3995 | 911 | * idle function. | ||
3996 | 912 | **/ | ||
3997 | 913 | screen_signals[SCREEN_OUTPUT_DISCONNECTED] = g_signal_new("output-disconnected", | ||
3998 | 914 | G_TYPE_FROM_CLASS (gobject_class), | ||
3999 | 915 | G_SIGNAL_RUN_FIRST | G_SIGNAL_NO_RECURSE | G_SIGNAL_NO_HOOKS, | ||
4000 | 916 | G_STRUCT_OFFSET (CCRRScreenClass, output_disconnected), | ||
4001 | 917 | NULL, | ||
4002 | 918 | NULL, | ||
4003 | 919 | g_cclosure_marshal_VOID__POINTER, | ||
4004 | 920 | G_TYPE_NONE, | ||
4005 | 921 | 1, G_TYPE_POINTER); | ||
4006 | 922 | } | ||
4007 | 923 | |||
4008 | 924 | void | ||
4009 | 925 | cc_rr_screen_init (CCRRScreen *self) | ||
4010 | 926 | { | ||
4011 | 927 | CCRRScreenPrivate *priv = G_TYPE_INSTANCE_GET_PRIVATE (self, CC_TYPE_RR_SCREEN, CCRRScreenPrivate); | ||
4012 | 928 | self->priv = priv; | ||
4013 | 929 | |||
4014 | 930 | priv->gdk_screen = NULL; | ||
4015 | 931 | priv->gdk_root = NULL; | ||
4016 | 932 | priv->xdisplay = NULL; | ||
4017 | 933 | priv->xroot = None; | ||
4018 | 934 | priv->xscreen = NULL; | ||
4019 | 935 | priv->info = NULL; | ||
4020 | 936 | priv->rr_major_version = 0; | ||
4021 | 937 | priv->rr_minor_version = 0; | ||
4022 | 938 | } | ||
4023 | 939 | |||
4024 | 940 | /* Weak reference callback set in cc_rr_screen_new(); we remove the GObject data from the GdkScreen. */ | ||
4025 | 941 | static void | ||
4026 | 942 | rr_screen_weak_notify_cb (gpointer data, GObject *where_the_object_was) | ||
4027 | 943 | { | ||
4028 | 944 | GdkScreen *screen = GDK_SCREEN (data); | ||
4029 | 945 | |||
4030 | 946 | g_object_set_data (G_OBJECT (screen), "CCRRScreen", NULL); | ||
4031 | 947 | } | ||
4032 | 948 | |||
4033 | 949 | /** | ||
4034 | 950 | * cc_rr_screen_new: | ||
4035 | 951 | * @screen: the #GdkScreen on which to operate | ||
4036 | 952 | * @error: will be set if XRandR is not supported | ||
4037 | 953 | * | ||
4038 | 954 | * Creates a unique #CCRRScreen instance for the specified @screen. | ||
4039 | 955 | * | ||
4040 | 956 | * Returns: a unique #CCRRScreen instance, specific to the @screen, or NULL | ||
4041 | 957 | * if this could not be created, for instance if the driver does not support | ||
4042 | 958 | * Xrandr 1.2. Each #GdkScreen thus has a single instance of #CCRRScreen. | ||
4043 | 959 | */ | ||
4044 | 960 | CCRRScreen * | ||
4045 | 961 | cc_rr_screen_new (GdkScreen *screen, | ||
4046 | 962 | GError **error) | ||
4047 | 963 | { | ||
4048 | 964 | CCRRScreen *rr_screen; | ||
4049 | 965 | |||
4050 | 966 | g_return_val_if_fail (GDK_IS_SCREEN (screen), NULL); | ||
4051 | 967 | g_return_val_if_fail (error == NULL || *error == NULL, NULL); | ||
4052 | 968 | |||
4053 | 969 | rr_screen = g_object_get_data (G_OBJECT (screen), "CCRRScreen"); | ||
4054 | 970 | if (rr_screen) | ||
4055 | 971 | g_object_ref (rr_screen); | ||
4056 | 972 | else { | ||
4057 | 973 | rr_screen = g_initable_new (CC_TYPE_RR_SCREEN, NULL, error, "gdk-screen", screen, NULL); | ||
4058 | 974 | if (rr_screen) { | ||
4059 | 975 | g_object_set_data (G_OBJECT (screen), "CCRRScreen", rr_screen); | ||
4060 | 976 | g_object_weak_ref (G_OBJECT (rr_screen), rr_screen_weak_notify_cb, screen); | ||
4061 | 977 | } | ||
4062 | 978 | } | ||
4063 | 979 | |||
4064 | 980 | return rr_screen; | ||
4065 | 981 | } | ||
4066 | 982 | |||
4067 | 983 | void | ||
4068 | 984 | cc_rr_screen_set_size (CCRRScreen *screen, | ||
4069 | 985 | int width, | ||
4070 | 986 | int height, | ||
4071 | 987 | int mm_width, | ||
4072 | 988 | int mm_height) | ||
4073 | 989 | { | ||
4074 | 990 | g_return_if_fail (CC_IS_RR_SCREEN (screen)); | ||
4075 | 991 | |||
4076 | 992 | gdk_error_trap_push (); | ||
4077 | 993 | XRRSetScreenSize (screen->priv->xdisplay, screen->priv->xroot, | ||
4078 | 994 | width, height, mm_width, mm_height); | ||
4079 | 995 | gdk_error_trap_pop_ignored (); | ||
4080 | 996 | } | ||
4081 | 997 | |||
4082 | 998 | /** | ||
4083 | 999 | * cc_rr_screen_get_ranges: | ||
4084 | 1000 | * @screen: a #CCRRScreen | ||
4085 | 1001 | * @min_width: (out): the minimum width | ||
4086 | 1002 | * @max_width: (out): the maximum width | ||
4087 | 1003 | * @min_height: (out): the minimum height | ||
4088 | 1004 | * @max_height: (out): the maximum height | ||
4089 | 1005 | * | ||
4090 | 1006 | * Get the ranges of the screen | ||
4091 | 1007 | */ | ||
4092 | 1008 | void | ||
4093 | 1009 | cc_rr_screen_get_ranges (CCRRScreen *screen, | ||
4094 | 1010 | int *min_width, | ||
4095 | 1011 | int *max_width, | ||
4096 | 1012 | int *min_height, | ||
4097 | 1013 | int *max_height) | ||
4098 | 1014 | { | ||
4099 | 1015 | CCRRScreenPrivate *priv; | ||
4100 | 1016 | |||
4101 | 1017 | g_return_if_fail (CC_IS_RR_SCREEN (screen)); | ||
4102 | 1018 | |||
4103 | 1019 | priv = screen->priv; | ||
4104 | 1020 | |||
4105 | 1021 | if (min_width) | ||
4106 | 1022 | *min_width = priv->info->min_width; | ||
4107 | 1023 | |||
4108 | 1024 | if (max_width) | ||
4109 | 1025 | *max_width = priv->info->max_width; | ||
4110 | 1026 | |||
4111 | 1027 | if (min_height) | ||
4112 | 1028 | *min_height = priv->info->min_height; | ||
4113 | 1029 | |||
4114 | 1030 | if (max_height) | ||
4115 | 1031 | *max_height = priv->info->max_height; | ||
4116 | 1032 | } | ||
4117 | 1033 | |||
4118 | 1034 | /** | ||
4119 | 1035 | * cc_rr_screen_get_timestamps: | ||
4120 | 1036 | * @screen: a #CCRRScreen | ||
4121 | 1037 | * @change_timestamp_ret: (out): Location in which to store the timestamp at which the RANDR configuration was last changed | ||
4122 | 1038 | * @config_timestamp_ret: (out): Location in which to store the timestamp at which the RANDR configuration was last obtained | ||
4123 | 1039 | * | ||
4124 | 1040 | * Queries the two timestamps that the X RANDR extension maintains. The X | ||
4125 | 1041 | * server will prevent change requests for stale configurations, those whose | ||
4126 | 1042 | * timestamp is not equal to that of the latest request for configuration. The | ||
4127 | 1043 | * X server will also prevent change requests that have an older timestamp to | ||
4128 | 1044 | * the latest change request. | ||
4129 | 1045 | */ | ||
4130 | 1046 | void | ||
4131 | 1047 | cc_rr_screen_get_timestamps (CCRRScreen *screen, | ||
4132 | 1048 | guint32 *change_timestamp_ret, | ||
4133 | 1049 | guint32 *config_timestamp_ret) | ||
4134 | 1050 | { | ||
4135 | 1051 | CCRRScreenPrivate *priv; | ||
4136 | 1052 | |||
4137 | 1053 | g_return_if_fail (CC_IS_RR_SCREEN (screen)); | ||
4138 | 1054 | |||
4139 | 1055 | priv = screen->priv; | ||
4140 | 1056 | |||
4141 | 1057 | if (change_timestamp_ret) | ||
4142 | 1058 | *change_timestamp_ret = priv->info->resources->timestamp; | ||
4143 | 1059 | |||
4144 | 1060 | if (config_timestamp_ret) | ||
4145 | 1061 | *config_timestamp_ret = priv->info->resources->configTimestamp; | ||
4146 | 1062 | } | ||
4147 | 1063 | |||
4148 | 1064 | static gboolean | ||
4149 | 1065 | force_timestamp_update (CCRRScreen *screen) | ||
4150 | 1066 | { | ||
4151 | 1067 | CCRRScreenPrivate *priv = screen->priv; | ||
4152 | 1068 | CCRRCrtc *crtc; | ||
4153 | 1069 | XRRCrtcInfo *current_info; | ||
4154 | 1070 | Status status; | ||
4155 | 1071 | gboolean timestamp_updated; | ||
4156 | 1072 | |||
4157 | 1073 | timestamp_updated = FALSE; | ||
4158 | 1074 | |||
4159 | 1075 | crtc = priv->info->crtcs[0]; | ||
4160 | 1076 | |||
4161 | 1077 | if (crtc == NULL) | ||
4162 | 1078 | goto out; | ||
4163 | 1079 | |||
4164 | 1080 | current_info = XRRGetCrtcInfo (priv->xdisplay, | ||
4165 | 1081 | priv->info->resources, | ||
4166 | 1082 | crtc->id); | ||
4167 | 1083 | |||
4168 | 1084 | if (current_info == NULL) | ||
4169 | 1085 | goto out; | ||
4170 | 1086 | |||
4171 | 1087 | gdk_error_trap_push (); | ||
4172 | 1088 | status = XRRSetCrtcConfig (priv->xdisplay, | ||
4173 | 1089 | priv->info->resources, | ||
4174 | 1090 | crtc->id, | ||
4175 | 1091 | current_info->timestamp, | ||
4176 | 1092 | current_info->x, | ||
4177 | 1093 | current_info->y, | ||
4178 | 1094 | current_info->mode, | ||
4179 | 1095 | current_info->rotation, | ||
4180 | 1096 | current_info->outputs, | ||
4181 | 1097 | current_info->noutput); | ||
4182 | 1098 | |||
4183 | 1099 | XRRFreeCrtcInfo (current_info); | ||
4184 | 1100 | |||
4185 | 1101 | gdk_flush (); | ||
4186 | 1102 | if (gdk_error_trap_pop ()) | ||
4187 | 1103 | goto out; | ||
4188 | 1104 | |||
4189 | 1105 | if (status == RRSetConfigSuccess) | ||
4190 | 1106 | timestamp_updated = TRUE; | ||
4191 | 1107 | out: | ||
4192 | 1108 | return timestamp_updated; | ||
4193 | 1109 | } | ||
4194 | 1110 | |||
4195 | 1111 | /** | ||
4196 | 1112 | * cc_rr_screen_refresh: | ||
4197 | 1113 | * @screen: a #CCRRScreen | ||
4198 | 1114 | * @error: location to store error, or %NULL | ||
4199 | 1115 | * | ||
4200 | 1116 | * Refreshes the screen configuration, and calls the screen's callback if it | ||
4201 | 1117 | * exists and if the screen's configuration changed. | ||
4202 | 1118 | * | ||
4203 | 1119 | * Return value: TRUE if the screen's configuration changed; otherwise, the | ||
4204 | 1120 | * function returns FALSE and a NULL error if the configuration didn't change, | ||
4205 | 1121 | * or FALSE and a non-NULL error if there was an error while refreshing the | ||
4206 | 1122 | * configuration. | ||
4207 | 1123 | */ | ||
4208 | 1124 | gboolean | ||
4209 | 1125 | cc_rr_screen_refresh (CCRRScreen *screen, | ||
4210 | 1126 | GError **error) | ||
4211 | 1127 | { | ||
4212 | 1128 | gboolean refreshed; | ||
4213 | 1129 | |||
4214 | 1130 | g_return_val_if_fail (error == NULL || *error == NULL, FALSE); | ||
4215 | 1131 | |||
4216 | 1132 | gdk_x11_display_grab (gdk_screen_get_display (screen->priv->gdk_screen)); | ||
4217 | 1133 | |||
4218 | 1134 | refreshed = screen_update (screen, FALSE, TRUE, error); | ||
4219 | 1135 | force_timestamp_update (screen); /* this is to keep other clients from thinking that the X server re-detected things by itself - bgo#621046 */ | ||
4220 | 1136 | |||
4221 | 1137 | gdk_x11_display_ungrab (gdk_screen_get_display (screen->priv->gdk_screen)); | ||
4222 | 1138 | |||
4223 | 1139 | return refreshed; | ||
4224 | 1140 | } | ||
4225 | 1141 | |||
4226 | 1142 | /** | ||
4227 | 1143 | * cc_rr_screen_get_dpms_mode: | ||
4228 | 1144 | * @mode: (out): The current #CCRRDpmsMode of this screen | ||
4229 | 1145 | **/ | ||
4230 | 1146 | gboolean | ||
4231 | 1147 | cc_rr_screen_get_dpms_mode (CCRRScreen *screen, | ||
4232 | 1148 | CCRRDpmsMode *mode, | ||
4233 | 1149 | GError **error) | ||
4234 | 1150 | { | ||
4235 | 1151 | BOOL enabled = FALSE; | ||
4236 | 1152 | CARD16 state; | ||
4237 | 1153 | gboolean ret = FALSE; | ||
4238 | 1154 | |||
4239 | 1155 | g_return_val_if_fail (error == NULL || *error == NULL, FALSE); | ||
4240 | 1156 | g_return_val_if_fail (mode != NULL, FALSE); | ||
4241 | 1157 | |||
4242 | 1158 | if (!screen->priv->dpms_capable) { | ||
4243 | 1159 | g_set_error_literal (error, | ||
4244 | 1160 | CC_RR_ERROR, | ||
4245 | 1161 | CC_RR_ERROR_NO_DPMS_EXTENSION, | ||
4246 | 1162 | "Display is not DPMS capable"); | ||
4247 | 1163 | goto out; | ||
4248 | 1164 | } | ||
4249 | 1165 | |||
4250 | 1166 | if (!DPMSInfo (screen->priv->xdisplay, | ||
4251 | 1167 | &state, | ||
4252 | 1168 | &enabled)) { | ||
4253 | 1169 | g_set_error_literal (error, | ||
4254 | 1170 | CC_RR_ERROR, | ||
4255 | 1171 | CC_RR_ERROR_UNKNOWN, | ||
4256 | 1172 | "Unable to get DPMS state"); | ||
4257 | 1173 | goto out; | ||
4258 | 1174 | } | ||
4259 | 1175 | |||
4260 | 1176 | /* DPMS not enabled is a valid mode */ | ||
4261 | 1177 | if (!enabled) { | ||
4262 | 1178 | *mode = CC_RR_DPMS_DISABLED; | ||
4263 | 1179 | ret = TRUE; | ||
4264 | 1180 | goto out; | ||
4265 | 1181 | } | ||
4266 | 1182 | |||
4267 | 1183 | switch (state) { | ||
4268 | 1184 | case DPMSModeOn: | ||
4269 | 1185 | *mode = CC_RR_DPMS_ON; | ||
4270 | 1186 | break; | ||
4271 | 1187 | case DPMSModeStandby: | ||
4272 | 1188 | *mode = CC_RR_DPMS_STANDBY; | ||
4273 | 1189 | break; | ||
4274 | 1190 | case DPMSModeSuspend: | ||
4275 | 1191 | *mode = CC_RR_DPMS_SUSPEND; | ||
4276 | 1192 | break; | ||
4277 | 1193 | case DPMSModeOff: | ||
4278 | 1194 | *mode = CC_RR_DPMS_OFF; | ||
4279 | 1195 | break; | ||
4280 | 1196 | default: | ||
4281 | 1197 | g_assert_not_reached (); | ||
4282 | 1198 | break; | ||
4283 | 1199 | } | ||
4284 | 1200 | ret = TRUE; | ||
4285 | 1201 | out: | ||
4286 | 1202 | return ret; | ||
4287 | 1203 | } | ||
4288 | 1204 | |||
4289 | 1205 | /** | ||
4290 | 1206 | * cc_rr_screen_clear_dpms_timeouts: | ||
4291 | 1207 | **/ | ||
4292 | 1208 | static gboolean | ||
4293 | 1209 | cc_rr_screen_clear_dpms_timeouts (CCRRScreen *screen, | ||
4294 | 1210 | GError **error) | ||
4295 | 1211 | { | ||
4296 | 1212 | gdk_error_trap_push (); | ||
4297 | 1213 | /* DPMSSetTimeouts() return value is often a lie, so ignore it */ | ||
4298 | 1214 | DPMSSetTimeouts (screen->priv->xdisplay, 0, 0, 0); | ||
4299 | 1215 | if (gdk_error_trap_pop ()) { | ||
4300 | 1216 | g_set_error_literal (error, | ||
4301 | 1217 | CC_RR_ERROR, | ||
4302 | 1218 | CC_RR_ERROR_UNKNOWN, | ||
4303 | 1219 | "Could not set DPMS timeouts"); | ||
4304 | 1220 | return FALSE; | ||
4305 | 1221 | } | ||
4306 | 1222 | return TRUE; | ||
4307 | 1223 | } | ||
4308 | 1224 | |||
4309 | 1225 | /** | ||
4310 | 1226 | * cc_rr_screen_set_dpms_mode: | ||
4311 | 1227 | * | ||
4312 | 1228 | * This method also disables the DPMS timeouts. | ||
4313 | 1229 | **/ | ||
4314 | 1230 | gboolean | ||
4315 | 1231 | cc_rr_screen_set_dpms_mode (CCRRScreen *screen, | ||
4316 | 1232 | CCRRDpmsMode mode, | ||
4317 | 1233 | GError **error) | ||
4318 | 1234 | { | ||
4319 | 1235 | CARD16 state = 0; | ||
4320 | 1236 | gboolean ret; | ||
4321 | 1237 | CCRRDpmsMode current_mode; | ||
4322 | 1238 | |||
4323 | 1239 | g_return_val_if_fail (error == NULL || *error == NULL, FALSE); | ||
4324 | 1240 | |||
4325 | 1241 | /* set, if the new mode is different */ | ||
4326 | 1242 | ret = cc_rr_screen_get_dpms_mode (screen, ¤t_mode, error); | ||
4327 | 1243 | if (!ret) | ||
4328 | 1244 | goto out; | ||
4329 | 1245 | if (current_mode == mode) { | ||
4330 | 1246 | ret = cc_rr_screen_clear_dpms_timeouts (screen, error); | ||
4331 | 1247 | goto out; | ||
4332 | 1248 | } | ||
4333 | 1249 | |||
4334 | 1250 | switch (mode) { | ||
4335 | 1251 | case CC_RR_DPMS_ON: | ||
4336 | 1252 | state = DPMSModeOn; | ||
4337 | 1253 | break; | ||
4338 | 1254 | case CC_RR_DPMS_STANDBY: | ||
4339 | 1255 | state = DPMSModeStandby; | ||
4340 | 1256 | break; | ||
4341 | 1257 | case CC_RR_DPMS_SUSPEND: | ||
4342 | 1258 | state = DPMSModeSuspend; | ||
4343 | 1259 | break; | ||
4344 | 1260 | case CC_RR_DPMS_OFF: | ||
4345 | 1261 | state = DPMSModeOff; | ||
4346 | 1262 | break; | ||
4347 | 1263 | default: | ||
4348 | 1264 | g_assert_not_reached (); | ||
4349 | 1265 | break; | ||
4350 | 1266 | } | ||
4351 | 1267 | |||
4352 | 1268 | gdk_error_trap_push (); | ||
4353 | 1269 | /* DPMSForceLevel() return value is often a lie, so ignore it */ | ||
4354 | 1270 | DPMSForceLevel (screen->priv->xdisplay, state); | ||
4355 | 1271 | XSync (screen->priv->xdisplay, False); | ||
4356 | 1272 | if (gdk_error_trap_pop ()) { | ||
4357 | 1273 | ret = FALSE; | ||
4358 | 1274 | g_set_error_literal (error, | ||
4359 | 1275 | CC_RR_ERROR, | ||
4360 | 1276 | CC_RR_ERROR_UNKNOWN, | ||
4361 | 1277 | "Could not change DPMS mode"); | ||
4362 | 1278 | goto out; | ||
4363 | 1279 | } | ||
4364 | 1280 | |||
4365 | 1281 | ret = cc_rr_screen_clear_dpms_timeouts (screen, error); | ||
4366 | 1282 | if (!ret) | ||
4367 | 1283 | goto out; | ||
4368 | 1284 | out: | ||
4369 | 1285 | return ret; | ||
4370 | 1286 | } | ||
4371 | 1287 | |||
4372 | 1288 | /** | ||
4373 | 1289 | * cc_rr_screen_list_modes: | ||
4374 | 1290 | * | ||
4375 | 1291 | * List available XRandR modes | ||
4376 | 1292 | * | ||
4377 | 1293 | * Returns: (array zero-terminated=1) (transfer none): | ||
4378 | 1294 | */ | ||
4379 | 1295 | CCRRMode ** | ||
4380 | 1296 | cc_rr_screen_list_modes (CCRRScreen *screen) | ||
4381 | 1297 | { | ||
4382 | 1298 | g_return_val_if_fail (CC_IS_RR_SCREEN (screen), NULL); | ||
4383 | 1299 | g_return_val_if_fail (screen->priv->info != NULL, NULL); | ||
4384 | 1300 | |||
4385 | 1301 | return screen->priv->info->modes; | ||
4386 | 1302 | } | ||
4387 | 1303 | |||
4388 | 1304 | /** | ||
4389 | 1305 | * cc_rr_screen_list_clone_modes: | ||
4390 | 1306 | * | ||
4391 | 1307 | * List available XRandR clone modes | ||
4392 | 1308 | * | ||
4393 | 1309 | * Returns: (array zero-terminated=1) (transfer none): | ||
4394 | 1310 | */ | ||
4395 | 1311 | CCRRMode ** | ||
4396 | 1312 | cc_rr_screen_list_clone_modes (CCRRScreen *screen) | ||
4397 | 1313 | { | ||
4398 | 1314 | g_return_val_if_fail (CC_IS_RR_SCREEN (screen), NULL); | ||
4399 | 1315 | g_return_val_if_fail (screen->priv->info != NULL, NULL); | ||
4400 | 1316 | |||
4401 | 1317 | return screen->priv->info->clone_modes; | ||
4402 | 1318 | } | ||
4403 | 1319 | |||
4404 | 1320 | /** | ||
4405 | 1321 | * cc_rr_screen_list_crtcs: | ||
4406 | 1322 | * | ||
4407 | 1323 | * List all CRTCs | ||
4408 | 1324 | * | ||
4409 | 1325 | * Returns: (array zero-terminated=1) (transfer none): | ||
4410 | 1326 | */ | ||
4411 | 1327 | CCRRCrtc ** | ||
4412 | 1328 | cc_rr_screen_list_crtcs (CCRRScreen *screen) | ||
4413 | 1329 | { | ||
4414 | 1330 | g_return_val_if_fail (CC_IS_RR_SCREEN (screen), NULL); | ||
4415 | 1331 | g_return_val_if_fail (screen->priv->info != NULL, NULL); | ||
4416 | 1332 | |||
4417 | 1333 | return screen->priv->info->crtcs; | ||
4418 | 1334 | } | ||
4419 | 1335 | |||
4420 | 1336 | /** | ||
4421 | 1337 | * cc_rr_screen_list_outputs: | ||
4422 | 1338 | * | ||
4423 | 1339 | * List all outputs | ||
4424 | 1340 | * | ||
4425 | 1341 | * Returns: (array zero-terminated=1) (transfer none): | ||
4426 | 1342 | */ | ||
4427 | 1343 | CCRROutput ** | ||
4428 | 1344 | cc_rr_screen_list_outputs (CCRRScreen *screen) | ||
4429 | 1345 | { | ||
4430 | 1346 | g_return_val_if_fail (CC_IS_RR_SCREEN (screen), NULL); | ||
4431 | 1347 | g_return_val_if_fail (screen->priv->info != NULL, NULL); | ||
4432 | 1348 | |||
4433 | 1349 | return screen->priv->info->outputs; | ||
4434 | 1350 | } | ||
4435 | 1351 | |||
4436 | 1352 | /** | ||
4437 | 1353 | * cc_rr_screen_get_crtc_by_id: | ||
4438 | 1354 | * | ||
4439 | 1355 | * Returns: (transfer none): the CRTC identified by @id | ||
4440 | 1356 | */ | ||
4441 | 1357 | CCRRCrtc * | ||
4442 | 1358 | cc_rr_screen_get_crtc_by_id (CCRRScreen *screen, | ||
4443 | 1359 | guint32 id) | ||
4444 | 1360 | { | ||
4445 | 1361 | CCRRCrtc **crtcs; | ||
4446 | 1362 | int i; | ||
4447 | 1363 | |||
4448 | 1364 | g_return_val_if_fail (CC_IS_RR_SCREEN (screen), NULL); | ||
4449 | 1365 | g_return_val_if_fail (screen->priv->info != NULL, NULL); | ||
4450 | 1366 | |||
4451 | 1367 | crtcs = screen->priv->info->crtcs; | ||
4452 | 1368 | |||
4453 | 1369 | for (i = 0; crtcs[i] != NULL; ++i) | ||
4454 | 1370 | { | ||
4455 | 1371 | if (crtcs[i]->id == id) | ||
4456 | 1372 | return crtcs[i]; | ||
4457 | 1373 | } | ||
4458 | 1374 | |||
4459 | 1375 | return NULL; | ||
4460 | 1376 | } | ||
4461 | 1377 | |||
4462 | 1378 | /** | ||
4463 | 1379 | * cc_rr_screen_get_output_by_id: | ||
4464 | 1380 | * | ||
4465 | 1381 | * Returns: (transfer none): the output identified by @id | ||
4466 | 1382 | */ | ||
4467 | 1383 | CCRROutput * | ||
4468 | 1384 | cc_rr_screen_get_output_by_id (CCRRScreen *screen, | ||
4469 | 1385 | guint32 id) | ||
4470 | 1386 | { | ||
4471 | 1387 | CCRROutput **outputs; | ||
4472 | 1388 | int i; | ||
4473 | 1389 | |||
4474 | 1390 | g_return_val_if_fail (CC_IS_RR_SCREEN (screen), NULL); | ||
4475 | 1391 | g_return_val_if_fail (screen->priv->info != NULL, NULL); | ||
4476 | 1392 | |||
4477 | 1393 | outputs = screen->priv->info->outputs; | ||
4478 | 1394 | |||
4479 | 1395 | for (i = 0; outputs[i] != NULL; ++i) | ||
4480 | 1396 | { | ||
4481 | 1397 | if (outputs[i]->id == id) | ||
4482 | 1398 | return outputs[i]; | ||
4483 | 1399 | } | ||
4484 | 1400 | |||
4485 | 1401 | return NULL; | ||
4486 | 1402 | } | ||
4487 | 1403 | |||
4488 | 1404 | /* CCRROutput */ | ||
4489 | 1405 | static CCRROutput * | ||
4490 | 1406 | output_new (ScreenInfo *info, RROutput id) | ||
4491 | 1407 | { | ||
4492 | 1408 | CCRROutput *output = g_slice_new0 (CCRROutput); | ||
4493 | 1409 | |||
4494 | 1410 | output->id = id; | ||
4495 | 1411 | output->info = info; | ||
4496 | 1412 | |||
4497 | 1413 | return output; | ||
4498 | 1414 | } | ||
4499 | 1415 | |||
4500 | 1416 | static guint8 * | ||
4501 | 1417 | get_property (Display *dpy, | ||
4502 | 1418 | RROutput output, | ||
4503 | 1419 | Atom atom, | ||
4504 | 1420 | gsize *len) | ||
4505 | 1421 | { | ||
4506 | 1422 | unsigned char *prop; | ||
4507 | 1423 | int actual_format; | ||
4508 | 1424 | unsigned long nitems, bytes_after; | ||
4509 | 1425 | Atom actual_type; | ||
4510 | 1426 | guint8 *result; | ||
4511 | 1427 | |||
4512 | 1428 | XRRGetOutputProperty (dpy, output, atom, | ||
4513 | 1429 | 0, 100, False, False, | ||
4514 | 1430 | AnyPropertyType, | ||
4515 | 1431 | &actual_type, &actual_format, | ||
4516 | 1432 | &nitems, &bytes_after, &prop); | ||
4517 | 1433 | |||
4518 | 1434 | if (actual_type == XA_INTEGER && actual_format == 8) | ||
4519 | 1435 | { | ||
4520 | 1436 | result = g_memdup (prop, nitems); | ||
4521 | 1437 | if (len) | ||
4522 | 1438 | *len = nitems; | ||
4523 | 1439 | } | ||
4524 | 1440 | else | ||
4525 | 1441 | { | ||
4526 | 1442 | result = NULL; | ||
4527 | 1443 | } | ||
4528 | 1444 | |||
4529 | 1445 | XFree (prop); | ||
4530 | 1446 | |||
4531 | 1447 | return result; | ||
4532 | 1448 | } | ||
4533 | 1449 | |||
4534 | 1450 | static guint8 * | ||
4535 | 1451 | read_edid_data (CCRROutput *output, gsize *len) | ||
4536 | 1452 | { | ||
4537 | 1453 | Atom edid_atom; | ||
4538 | 1454 | guint8 *result; | ||
4539 | 1455 | |||
4540 | 1456 | edid_atom = XInternAtom (DISPLAY (output), "EDID", FALSE); | ||
4541 | 1457 | result = get_property (DISPLAY (output), | ||
4542 | 1458 | output->id, edid_atom, len); | ||
4543 | 1459 | |||
4544 | 1460 | if (!result) | ||
4545 | 1461 | { | ||
4546 | 1462 | edid_atom = XInternAtom (DISPLAY (output), "EDID_DATA", FALSE); | ||
4547 | 1463 | result = get_property (DISPLAY (output), | ||
4548 | 1464 | output->id, edid_atom, len); | ||
4549 | 1465 | } | ||
4550 | 1466 | |||
4551 | 1467 | if (!result) | ||
4552 | 1468 | { | ||
4553 | 1469 | edid_atom = XInternAtom (DISPLAY (output), "XFree86_DDC_EDID1_RAWDATA", FALSE); | ||
4554 | 1470 | result = get_property (DISPLAY (output), | ||
4555 | 1471 | output->id, edid_atom, len); | ||
4556 | 1472 | } | ||
4557 | 1473 | |||
4558 | 1474 | if (result) | ||
4559 | 1475 | { | ||
4560 | 1476 | if (*len % 128 == 0) | ||
4561 | 1477 | return result; | ||
4562 | 1478 | else | ||
4563 | 1479 | g_free (result); | ||
4564 | 1480 | } | ||
4565 | 1481 | |||
4566 | 1482 | return NULL; | ||
4567 | 1483 | } | ||
4568 | 1484 | |||
4569 | 1485 | static char * | ||
4570 | 1486 | get_connector_type_string (CCRROutput *output) | ||
4571 | 1487 | { | ||
4572 | 1488 | char *result; | ||
4573 | 1489 | unsigned char *prop; | ||
4574 | 1490 | int actual_format; | ||
4575 | 1491 | unsigned long nitems, bytes_after; | ||
4576 | 1492 | Atom actual_type; | ||
4577 | 1493 | Atom connector_type; | ||
4578 | 1494 | char *connector_type_str; | ||
4579 | 1495 | |||
4580 | 1496 | result = NULL; | ||
4581 | 1497 | |||
4582 | 1498 | if (XRRGetOutputProperty (DISPLAY (output), output->id, output->info->screen->priv->connector_type_atom, | ||
4583 | 1499 | 0, 100, False, False, | ||
4584 | 1500 | AnyPropertyType, | ||
4585 | 1501 | &actual_type, &actual_format, | ||
4586 | 1502 | &nitems, &bytes_after, &prop) != Success) | ||
4587 | 1503 | return NULL; | ||
4588 | 1504 | |||
4589 | 1505 | if (!(actual_type == XA_ATOM && actual_format == 32 && nitems == 1)) | ||
4590 | 1506 | goto out; | ||
4591 | 1507 | |||
4592 | 1508 | connector_type = *((Atom *) prop); | ||
4593 | 1509 | |||
4594 | 1510 | connector_type_str = XGetAtomName (DISPLAY (output), connector_type); | ||
4595 | 1511 | if (connector_type_str) { | ||
4596 | 1512 | result = g_strdup (connector_type_str); /* so the caller can g_free() it */ | ||
4597 | 1513 | XFree (connector_type_str); | ||
4598 | 1514 | } | ||
4599 | 1515 | |||
4600 | 1516 | out: | ||
4601 | 1517 | |||
4602 | 1518 | XFree (prop); | ||
4603 | 1519 | |||
4604 | 1520 | return result; | ||
4605 | 1521 | } | ||
4606 | 1522 | |||
4607 | 1523 | static void | ||
4608 | 1524 | update_brightness_limits (CCRROutput *output) | ||
4609 | 1525 | { | ||
4610 | 1526 | gint rc; | ||
4611 | 1527 | Atom atom; | ||
4612 | 1528 | XRRPropertyInfo *info; | ||
4613 | 1529 | |||
4614 | 1530 | gdk_error_trap_push (); | ||
4615 | 1531 | atom = XInternAtom (DISPLAY (output), "Backlight", FALSE); | ||
4616 | 1532 | info = XRRQueryOutputProperty (DISPLAY (output), output->id, atom); | ||
4617 | 1533 | rc = gdk_error_trap_pop (); | ||
4618 | 1534 | if (rc != Success) | ||
4619 | 1535 | { | ||
4620 | 1536 | if (rc != BadName) | ||
4621 | 1537 | g_warning ("could not get output property for %s, rc: %i", | ||
4622 | 1538 | output->name, rc); | ||
4623 | 1539 | goto out; | ||
4624 | 1540 | } | ||
4625 | 1541 | if (info == NULL) | ||
4626 | 1542 | { | ||
4627 | 1543 | g_warning ("could not get output property for %s", | ||
4628 | 1544 | output->name); | ||
4629 | 1545 | goto out; | ||
4630 | 1546 | } | ||
4631 | 1547 | if (!info->range || info->num_values != 2) | ||
4632 | 1548 | { | ||
4633 | 1549 | g_debug ("backlight %s was not range", output->name); | ||
4634 | 1550 | goto out; | ||
4635 | 1551 | } | ||
4636 | 1552 | output->backlight_min = info->values[0]; | ||
4637 | 1553 | output->backlight_max = info->values[1]; | ||
4638 | 1554 | out: | ||
4639 | 1555 | if (info != NULL) | ||
4640 | 1556 | { | ||
4641 | 1557 | XFree (info); | ||
4642 | 1558 | } | ||
4643 | 1559 | } | ||
4644 | 1560 | |||
4645 | 1561 | static gboolean | ||
4646 | 1562 | output_initialize (CCRROutput *output, XRRScreenResources *res, GError **error) | ||
4647 | 1563 | { | ||
4648 | 1564 | XRROutputInfo *info = XRRGetOutputInfo ( | ||
4649 | 1565 | DISPLAY (output), res, output->id); | ||
4650 | 1566 | GPtrArray *a; | ||
4651 | 1567 | int i; | ||
4652 | 1568 | |||
4653 | 1569 | #if 0 | ||
4654 | 1570 | g_print ("Output %lx Timestamp: %u\n", output->id, (guint32)info->timestamp); | ||
4655 | 1571 | #endif | ||
4656 | 1572 | |||
4657 | 1573 | if (!info || !output->info) | ||
4658 | 1574 | { | ||
4659 | 1575 | /* FIXME: see the comment in crtc_initialize() */ | ||
4660 | 1576 | /* Translators: here, an "output" is a video output */ | ||
4661 | 1577 | g_set_error (error, CC_RR_ERROR, CC_RR_ERROR_RANDR_ERROR, | ||
4662 | 1578 | _("could not get information about output %d"), | ||
4663 | 1579 | (int) output->id); | ||
4664 | 1580 | return FALSE; | ||
4665 | 1581 | } | ||
4666 | 1582 | |||
4667 | 1583 | output->name = g_strdup (info->name); /* FIXME: what is nameLen used for? */ | ||
4668 | 1584 | output->display_name = NULL; /* set first time the getter is used */ | ||
4669 | 1585 | output->current_crtc = crtc_by_id (output->info, info->crtc); | ||
4670 | 1586 | output->width_mm = info->mm_width; | ||
4671 | 1587 | output->height_mm = info->mm_height; | ||
4672 | 1588 | output->connected = (info->connection == RR_Connected); | ||
4673 | 1589 | output->connector_type = get_connector_type_string (output); | ||
4674 | 1590 | |||
4675 | 1591 | /* Possible crtcs */ | ||
4676 | 1592 | a = g_ptr_array_new (); | ||
4677 | 1593 | |||
4678 | 1594 | for (i = 0; i < info->ncrtc; ++i) | ||
4679 | 1595 | { | ||
4680 | 1596 | CCRRCrtc *crtc = crtc_by_id (output->info, info->crtcs[i]); | ||
4681 | 1597 | |||
4682 | 1598 | if (crtc) | ||
4683 | 1599 | g_ptr_array_add (a, crtc); | ||
4684 | 1600 | } | ||
4685 | 1601 | g_ptr_array_add (a, NULL); | ||
4686 | 1602 | output->possible_crtcs = (CCRRCrtc **)g_ptr_array_free (a, FALSE); | ||
4687 | 1603 | |||
4688 | 1604 | /* Clones */ | ||
4689 | 1605 | a = g_ptr_array_new (); | ||
4690 | 1606 | for (i = 0; i < info->nclone; ++i) | ||
4691 | 1607 | { | ||
4692 | 1608 | CCRROutput *cc_rr_output = cc_rr_output_by_id (output->info, info->clones[i]); | ||
4693 | 1609 | |||
4694 | 1610 | if (cc_rr_output) | ||
4695 | 1611 | g_ptr_array_add (a, cc_rr_output); | ||
4696 | 1612 | } | ||
4697 | 1613 | g_ptr_array_add (a, NULL); | ||
4698 | 1614 | output->clones = (CCRROutput **)g_ptr_array_free (a, FALSE); | ||
4699 | 1615 | |||
4700 | 1616 | /* Modes */ | ||
4701 | 1617 | a = g_ptr_array_new (); | ||
4702 | 1618 | for (i = 0; i < info->nmode; ++i) | ||
4703 | 1619 | { | ||
4704 | 1620 | CCRRMode *mode = mode_by_id (output->info, info->modes[i]); | ||
4705 | 1621 | |||
4706 | 1622 | if (mode) | ||
4707 | 1623 | g_ptr_array_add (a, mode); | ||
4708 | 1624 | } | ||
4709 | 1625 | g_ptr_array_add (a, NULL); | ||
4710 | 1626 | output->modes = (CCRRMode **)g_ptr_array_free (a, FALSE); | ||
4711 | 1627 | |||
4712 | 1628 | output->n_preferred = info->npreferred; | ||
4713 | 1629 | |||
4714 | 1630 | /* Edid data */ | ||
4715 | 1631 | output->edid_data = read_edid_data (output, &output->edid_size); | ||
4716 | 1632 | |||
4717 | 1633 | /* brightness data */ | ||
4718 | 1634 | if (output->connected) | ||
4719 | 1635 | update_brightness_limits (output); | ||
4720 | 1636 | |||
4721 | 1637 | XRRFreeOutputInfo (info); | ||
4722 | 1638 | |||
4723 | 1639 | return TRUE; | ||
4724 | 1640 | } | ||
4725 | 1641 | |||
4726 | 1642 | static CCRROutput* | ||
4727 | 1643 | output_copy (const CCRROutput *from) | ||
4728 | 1644 | { | ||
4729 | 1645 | GPtrArray *array; | ||
4730 | 1646 | CCRRCrtc **p_crtc; | ||
4731 | 1647 | CCRROutput **p_output; | ||
4732 | 1648 | CCRRMode **p_mode; | ||
4733 | 1649 | CCRROutput *output = g_slice_new0 (CCRROutput); | ||
4734 | 1650 | |||
4735 | 1651 | output->id = from->id; | ||
4736 | 1652 | output->info = from->info; | ||
4737 | 1653 | output->name = g_strdup (from->name); | ||
4738 | 1654 | output->current_crtc = from->current_crtc; | ||
4739 | 1655 | output->width_mm = from->width_mm; | ||
4740 | 1656 | output->height_mm = from->height_mm; | ||
4741 | 1657 | output->connected = from->connected; | ||
4742 | 1658 | output->n_preferred = from->n_preferred; | ||
4743 | 1659 | output->connector_type = g_strdup (from->connector_type); | ||
4744 | 1660 | output->backlight_min = -1; | ||
4745 | 1661 | output->backlight_max = -1; | ||
4746 | 1662 | |||
4747 | 1663 | array = g_ptr_array_new (); | ||
4748 | 1664 | for (p_crtc = from->possible_crtcs; *p_crtc != NULL; p_crtc++) | ||
4749 | 1665 | { | ||
4750 | 1666 | g_ptr_array_add (array, *p_crtc); | ||
4751 | 1667 | } | ||
4752 | 1668 | output->possible_crtcs = (CCRRCrtc**) g_ptr_array_free (array, FALSE); | ||
4753 | 1669 | |||
4754 | 1670 | array = g_ptr_array_new (); | ||
4755 | 1671 | for (p_output = from->clones; *p_output != NULL; p_output++) | ||
4756 | 1672 | { | ||
4757 | 1673 | g_ptr_array_add (array, *p_output); | ||
4758 | 1674 | } | ||
4759 | 1675 | output->clones = (CCRROutput**) g_ptr_array_free (array, FALSE); | ||
4760 | 1676 | |||
4761 | 1677 | array = g_ptr_array_new (); | ||
4762 | 1678 | for (p_mode = from->modes; *p_mode != NULL; p_mode++) | ||
4763 | 1679 | { | ||
4764 | 1680 | g_ptr_array_add (array, *p_mode); | ||
4765 | 1681 | } | ||
4766 | 1682 | output->modes = (CCRRMode**) g_ptr_array_free (array, FALSE); | ||
4767 | 1683 | |||
4768 | 1684 | output->edid_size = from->edid_size; | ||
4769 | 1685 | output->edid_data = g_memdup (from->edid_data, from->edid_size); | ||
4770 | 1686 | |||
4771 | 1687 | return output; | ||
4772 | 1688 | } | ||
4773 | 1689 | |||
4774 | 1690 | static void | ||
4775 | 1691 | output_free (CCRROutput *output) | ||
4776 | 1692 | { | ||
4777 | 1693 | g_free (output->clones); | ||
4778 | 1694 | g_free (output->modes); | ||
4779 | 1695 | g_free (output->possible_crtcs); | ||
4780 | 1696 | g_free (output->edid_data); | ||
4781 | 1697 | g_free (output->name); | ||
4782 | 1698 | g_free (output->display_name); | ||
4783 | 1699 | g_free (output->connector_type); | ||
4784 | 1700 | g_slice_free (CCRROutput, output); | ||
4785 | 1701 | } | ||
4786 | 1702 | |||
4787 | 1703 | guint32 | ||
4788 | 1704 | cc_rr_output_get_id (CCRROutput *output) | ||
4789 | 1705 | { | ||
4790 | 1706 | g_assert(output != NULL); | ||
4791 | 1707 | |||
4792 | 1708 | return output->id; | ||
4793 | 1709 | } | ||
4794 | 1710 | |||
4795 | 1711 | const guint8 * | ||
4796 | 1712 | cc_rr_output_get_edid_data (CCRROutput *output, gsize *size) | ||
4797 | 1713 | { | ||
4798 | 1714 | g_return_val_if_fail (output != NULL, NULL); | ||
4799 | 1715 | if (size) | ||
4800 | 1716 | *size = output->edid_size; | ||
4801 | 1717 | return output->edid_data; | ||
4802 | 1718 | } | ||
4803 | 1719 | |||
4804 | 1720 | /** | ||
4805 | 1721 | * cc_rr_output_get_ids_from_edid: | ||
4806 | 1722 | * @output: a #CCRROutput | ||
4807 | 1723 | * @vendor: (out) (allow-none): | ||
4808 | 1724 | * @product: (out) (allow-none): | ||
4809 | 1725 | * @serial: (out) (allow-none): | ||
4810 | 1726 | */ | ||
4811 | 1727 | gboolean | ||
4812 | 1728 | cc_rr_output_get_ids_from_edid (CCRROutput *output, | ||
4813 | 1729 | char **vendor, | ||
4814 | 1730 | int *product, | ||
4815 | 1731 | int *serial) | ||
4816 | 1732 | { | ||
4817 | 1733 | MonitorInfo *info; | ||
4818 | 1734 | |||
4819 | 1735 | g_return_val_if_fail (output != NULL, FALSE); | ||
4820 | 1736 | |||
4821 | 1737 | if (!output->edid_data) | ||
4822 | 1738 | return FALSE; | ||
4823 | 1739 | info = decode_edid (output->edid_data); | ||
4824 | 1740 | if (!info) | ||
4825 | 1741 | return FALSE; | ||
4826 | 1742 | if (vendor) | ||
4827 | 1743 | *vendor = g_memdup (info->manufacturer_code, 4); | ||
4828 | 1744 | if (product) | ||
4829 | 1745 | *product = info->product_code; | ||
4830 | 1746 | if (serial) | ||
4831 | 1747 | *serial = info->serial_number; | ||
4832 | 1748 | |||
4833 | 1749 | g_free (info); | ||
4834 | 1750 | |||
4835 | 1751 | return TRUE; | ||
4836 | 1752 | |||
4837 | 1753 | } | ||
4838 | 1754 | |||
4839 | 1755 | static void | ||
4840 | 1756 | ensure_display_name (CCRROutput *output) | ||
4841 | 1757 | { | ||
4842 | 1758 | if (output->display_name != NULL) | ||
4843 | 1759 | return; | ||
4844 | 1760 | |||
4845 | 1761 | if (cc_rr_output_is_laptop (output)) | ||
4846 | 1762 | output->display_name = g_strdup (_("Built-in Display")); | ||
4847 | 1763 | |||
4848 | 1764 | if (output->display_name == NULL | ||
4849 | 1765 | && output->edid_data != NULL) { | ||
4850 | 1766 | MonitorInfo *info; | ||
4851 | 1767 | |||
4852 | 1768 | info = decode_edid (output->edid_data); | ||
4853 | 1769 | if (info != NULL) | ||
4854 | 1770 | output->display_name = make_display_name (info); | ||
4855 | 1771 | |||
4856 | 1772 | g_free (info); | ||
4857 | 1773 | } | ||
4858 | 1774 | |||
4859 | 1775 | if (output->display_name == NULL) { | ||
4860 | 1776 | char *inches; | ||
4861 | 1777 | inches = make_display_size_string (output->width_mm, output->height_mm); | ||
4862 | 1778 | if (inches != NULL) { | ||
4863 | 1779 | /* Translators: %s is the size of the monitor in inches */ | ||
4864 | 1780 | output->display_name = g_strdup_printf (_("%s Display"), inches); | ||
4865 | 1781 | } | ||
4866 | 1782 | g_free (inches); | ||
4867 | 1783 | } | ||
4868 | 1784 | |||
4869 | 1785 | /* last chance on the stairway */ | ||
4870 | 1786 | if (output->display_name == NULL) { | ||
4871 | 1787 | output->display_name = g_strdup (_("Unknown Display")); | ||
4872 | 1788 | } | ||
4873 | 1789 | } | ||
4874 | 1790 | |||
4875 | 1791 | const char * | ||
4876 | 1792 | cc_rr_output_get_display_name (CCRROutput *output) | ||
4877 | 1793 | { | ||
4878 | 1794 | g_return_val_if_fail (output != NULL, NULL); | ||
4879 | 1795 | |||
4880 | 1796 | ensure_display_name (output); | ||
4881 | 1797 | |||
4882 | 1798 | return output->display_name; | ||
4883 | 1799 | } | ||
4884 | 1800 | |||
4885 | 1801 | /** | ||
4886 | 1802 | * cc_rr_output_get_backlight_min: | ||
4887 | 1803 | * | ||
4888 | 1804 | * Returns: The mimimum backlight value, or -1 if not supported | ||
4889 | 1805 | */ | ||
4890 | 1806 | gint | ||
4891 | 1807 | cc_rr_output_get_backlight_min (CCRROutput *output) | ||
4892 | 1808 | { | ||
4893 | 1809 | g_return_val_if_fail (output != NULL, -1); | ||
4894 | 1810 | return output->backlight_min; | ||
4895 | 1811 | } | ||
4896 | 1812 | |||
4897 | 1813 | /** | ||
4898 | 1814 | * cc_rr_output_get_backlight_max: | ||
4899 | 1815 | * | ||
4900 | 1816 | * Returns: The maximum backlight value, or -1 if not supported | ||
4901 | 1817 | */ | ||
4902 | 1818 | gint | ||
4903 | 1819 | cc_rr_output_get_backlight_max (CCRROutput *output) | ||
4904 | 1820 | { | ||
4905 | 1821 | g_return_val_if_fail (output != NULL, -1); | ||
4906 | 1822 | return output->backlight_max; | ||
4907 | 1823 | } | ||
4908 | 1824 | |||
4909 | 1825 | /** | ||
4910 | 1826 | * cc_rr_output_get_backlight: | ||
4911 | 1827 | * | ||
4912 | 1828 | * Returns: The currently set backlight brightness | ||
4913 | 1829 | */ | ||
4914 | 1830 | gint | ||
4915 | 1831 | cc_rr_output_get_backlight (CCRROutput *output, GError **error) | ||
4916 | 1832 | { | ||
4917 | 1833 | guint now = -1; | ||
4918 | 1834 | unsigned long nitems; | ||
4919 | 1835 | unsigned long bytes_after; | ||
4920 | 1836 | guint *prop; | ||
4921 | 1837 | Atom atom; | ||
4922 | 1838 | Atom actual_type; | ||
4923 | 1839 | int actual_format; | ||
4924 | 1840 | gint retval; | ||
4925 | 1841 | |||
4926 | 1842 | g_return_val_if_fail (output != NULL, -1); | ||
4927 | 1843 | |||
4928 | 1844 | gdk_error_trap_push (); | ||
4929 | 1845 | atom = XInternAtom (DISPLAY (output), "Backlight", FALSE); | ||
4930 | 1846 | retval = XRRGetOutputProperty (DISPLAY (output), output->id, atom, | ||
4931 | 1847 | 0, 4, False, False, None, | ||
4932 | 1848 | &actual_type, &actual_format, | ||
4933 | 1849 | &nitems, &bytes_after, ((unsigned char **)&prop)); | ||
4934 | 1850 | gdk_flush (); | ||
4935 | 1851 | if (gdk_error_trap_pop ()) | ||
4936 | 1852 | { | ||
4937 | 1853 | g_set_error_literal (error, | ||
4938 | 1854 | CC_RR_ERROR, | ||
4939 | 1855 | CC_RR_ERROR_UNKNOWN, | ||
4940 | 1856 | "unhandled X error while getting the range of backlight values"); | ||
4941 | 1857 | goto out; | ||
4942 | 1858 | } | ||
4943 | 1859 | |||
4944 | 1860 | if (retval != Success) { | ||
4945 | 1861 | g_set_error_literal (error, | ||
4946 | 1862 | CC_RR_ERROR, | ||
4947 | 1863 | CC_RR_ERROR_RANDR_ERROR, | ||
4948 | 1864 | "could not get the range of backlight values"); | ||
4949 | 1865 | goto out; | ||
4950 | 1866 | } | ||
4951 | 1867 | if (actual_type == XA_INTEGER && | ||
4952 | 1868 | nitems == 1 && | ||
4953 | 1869 | actual_format == 32) | ||
4954 | 1870 | { | ||
4955 | 1871 | memcpy (&now, prop, sizeof (guint)); | ||
4956 | 1872 | } | ||
4957 | 1873 | else | ||
4958 | 1874 | { | ||
4959 | 1875 | g_set_error (error, | ||
4960 | 1876 | CC_RR_ERROR, | ||
4961 | 1877 | CC_RR_ERROR_RANDR_ERROR, | ||
4962 | 1878 | "failed to get correct property type, got %lu,%i", | ||
4963 | 1879 | nitems, actual_format); | ||
4964 | 1880 | } | ||
4965 | 1881 | out: | ||
4966 | 1882 | XFree (prop); | ||
4967 | 1883 | return now; | ||
4968 | 1884 | } | ||
4969 | 1885 | |||
4970 | 1886 | /** | ||
4971 | 1887 | * cc_rr_output_set_backlight: | ||
4972 | 1888 | * @value: the absolute value which is min >= this <= max | ||
4973 | 1889 | * | ||
4974 | 1890 | * Returns: %TRUE for success | ||
4975 | 1891 | */ | ||
4976 | 1892 | gboolean | ||
4977 | 1893 | cc_rr_output_set_backlight (CCRROutput *output, gint value, GError **error) | ||
4978 | 1894 | { | ||
4979 | 1895 | gboolean ret = FALSE; | ||
4980 | 1896 | Atom atom; | ||
4981 | 1897 | |||
4982 | 1898 | g_return_val_if_fail (output != NULL, FALSE); | ||
4983 | 1899 | |||
4984 | 1900 | /* check this is sane */ | ||
4985 | 1901 | if (value < output->backlight_min || | ||
4986 | 1902 | value > output->backlight_max) | ||
4987 | 1903 | { | ||
4988 | 1904 | g_set_error (error, | ||
4989 | 1905 | CC_RR_ERROR, | ||
4990 | 1906 | CC_RR_ERROR_BOUNDS_ERROR, | ||
4991 | 1907 | "out of brightness range: %i, has to be %i -> %i", | ||
4992 | 1908 | value, | ||
4993 | 1909 | output->backlight_max, output->backlight_min); | ||
4994 | 1910 | goto out; | ||
4995 | 1911 | } | ||
4996 | 1912 | |||
4997 | 1913 | /* don't abort on error */ | ||
4998 | 1914 | gdk_error_trap_push (); | ||
4999 | 1915 | atom = XInternAtom (DISPLAY (output), "Backlight", FALSE); | ||
5000 | 1916 | XRRChangeOutputProperty (DISPLAY (output), output->id, atom, |
PASSED: Continuous integration, rev:12784 jenkins. qa.ubuntu. com/job/ unity-control- center- ci/101/ jenkins. qa.ubuntu. com/job/ unity-control- center- utopic- amd64-ci/ 3 jenkins. qa.ubuntu. com/job/ unity-control- center- utopic- armhf-ci/ 3 jenkins. qa.ubuntu. com/job/ unity-control- center- utopic- i386-ci/ 3
http://
Executed test runs:
SUCCESS: http://
SUCCESS: http://
SUCCESS: http://
Click here to trigger a rebuild: s-jenkins. ubuntu- ci:8080/ job/unity- control- center- ci/101/ rebuild
http://