~rodrigo-moya/ubuntu/oneiric/gnome-desktop3/fix_863038

« back to all changes in this revision

Viewing changes to debian/patches/100_load_desired_settings.patch

  • Committer: Bazaar Package Importer
  • Author(s): Sebastien Bacher
  • Date: 2011-02-03 16:30:39 UTC
  • mfrom: (1.2.4 upstream)
  • Revision ID: james.westby@ubuntu.com-20110203163039-z3bqr26w4t70v7r1
Tags: 2.91.6.1-0ubuntu1
New upstream version

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
Description: Enable gnome-settings-daemon to load the desired settings saved by the xrandr capplet when the virtual resolution has to be saved and the settings cannot be applied immediately.
2
 
Bug: https://bugs.edge.launchpad.net/ubuntu/+bug/384439
3
 
Author: ?
4
 
 
5
 
diff -Nur -x '*.orig' -x '*~' gnome-desktop-2.29.92/libgnome-desktop/gnome-rr-config.c gnome-desktop-2.29.92.new/libgnome-desktop/gnome-rr-config.c
6
 
--- gnome-desktop-2.29.92/libgnome-desktop/gnome-rr-config.c    2010-03-08 14:52:09.000000000 +0000
7
 
+++ gnome-desktop-2.29.92.new/libgnome-desktop/gnome-rr-config.c        2010-03-27 23:53:20.462671123 +0000
8
 
@@ -41,6 +41,7 @@
9
 
 
10
 
 #define CONFIG_INTENDED_BASENAME "monitors.xml"
11
 
 #define CONFIG_BACKUP_BASENAME "monitors.xml.backup"
12
 
+#define CONFIG_DESIRED_BASENAME "monitors.xml.desired"
13
 
 
14
 
 /* In version 0 of the config file format, we had several <configuration>
15
 
  * toplevel elements and no explicit version number.  So, the filed looked
16
 
@@ -85,6 +86,10 @@
17
 
 static void             output_free           (GnomeOutputInfo  *output);
18
 
 static GnomeOutputInfo *output_copy           (GnomeOutputInfo  *output);
19
 
 
20
 
+static gboolean        gnome_rr_config_save_to_file (GnomeRRConfig *configuration,
21
 
+                       GError **err, gchar *filename);
22
 
+static void            remove_desired_settings      (void);
23
 
+
24
 
 typedef struct Parser Parser;
25
 
 
26
 
 /* Parser for monitor configurations */
27
 
@@ -410,6 +415,16 @@
28
 
        NULL, /* error */
29
 
     };
30
 
 
31
 
+       /* return NULL if the file doesn't exist */
32
 
+       if (!g_file_test (filename, G_FILE_TEST_EXISTS))
33
 
+    {
34
 
+       result = NULL;
35
 
+       g_set_error (error, G_FILE_ERROR, G_FILE_ERROR_NOENT,
36
 
+                    "No such file: %s", filename);     
37
 
+       return result;
38
 
+    }
39
 
+
40
 
+
41
 
     parser->config_file_version = 0;
42
 
     parser->configurations = g_ptr_array_new ();
43
 
     parser->outputs = g_ptr_array_new ();
44
 
@@ -918,6 +933,65 @@
45
 
     return g_build_filename (g_get_user_config_dir (), CONFIG_INTENDED_BASENAME, NULL);
46
 
 }
47
 
 
48
 
+static gchar *
49
 
+get_desired_config_filename (void)
50
 
+{
51
 
+    return g_build_filename (g_get_user_config_dir (), CONFIG_DESIRED_BASENAME, NULL);
52
 
+}
53
 
+
54
 
+static GnomeRRConfig **
55
 
+desired_configurations_read (GError **error)
56
 
+{
57
 
+    char *filename;
58
 
+    GnomeRRConfig **configs;
59
 
+    GError *err;
60
 
+
61
 
+    /* Try the desired configuration file... */
62
 
+
63
 
+    filename = get_desired_config_filename ();
64
 
+    
65
 
+#if 0
66
 
+    g_debug("desired is = %s\n", filename);
67
 
+#endif
68
 
+    err = NULL;
69
 
+
70
 
+#if 0
71
 
+    g_debug("reading configuration...\n");
72
 
+#endif
73
 
+    configs = configurations_read_from_file (filename, &err);
74
 
+
75
 
+    g_free (filename);
76
 
+    
77
 
+#if 0
78
 
+    g_debug("done\n");
79
 
+#endif
80
 
+    if (err)
81
 
+    {
82
 
+        if (g_error_matches (err, G_FILE_ERROR, G_FILE_ERROR_NOENT))
83
 
+        {
84
 
+            
85
 
+#if 0
86
 
+            g_debug("error MATCHES\n");
87
 
+#endif
88
 
+            g_error_free (err);
89
 
+            
90
 
+            /* Okay, so try the old configuration file */
91
 
+            filename = gnome_rr_config_get_intended_filename ();
92
 
+            configs = configurations_read_from_file (filename, error);
93
 
+            g_free (filename);
94
 
+        }
95
 
+        else
96
 
+        {
97
 
+#if 0
98
 
+            g_debug("error does NOT MATCH\n");
99
 
+#endif
100
 
+            g_propagate_error (error, err);
101
 
+        }
102
 
+    }
103
 
+    
104
 
+    return configs;
105
 
+}
106
 
+
107
 
 static const char *
108
 
 get_rotation_name (GnomeRRRotation r)
109
 
 {
110
 
@@ -1059,13 +1133,13 @@
111
 
 }
112
 
 
113
 
 
114
 
-gboolean
115
 
-gnome_rr_config_save (GnomeRRConfig *configuration, GError **error)
116
 
+static gboolean
117
 
+gnome_rr_config_save_to_file (GnomeRRConfig *configuration, GError **error, gchar *intended_filename)
118
 
 {
119
 
     GnomeRRConfig **configurations;
120
 
     GString *output;
121
 
     int i;
122
 
-    gchar *intended_filename;
123
 
+
124
 
     gchar *backup_filename;
125
 
     gboolean result;
126
 
 
127
 
@@ -1075,7 +1149,7 @@
128
 
     output = g_string_new ("");
129
 
 
130
 
     backup_filename = gnome_rr_config_get_backup_filename ();
131
 
-    intended_filename = gnome_rr_config_get_intended_filename ();
132
 
+
133
 
 
134
 
     configurations = configurations_read_from_file (intended_filename, NULL); /* NULL-GError */
135
 
     
136
 
@@ -1110,6 +1184,37 @@
137
 
     return result;
138
 
 }
139
 
 
140
 
+gboolean
141
 
+gnome_rr_config_save (GnomeRRConfig *configuration, GError **err)
142
 
+{
143
 
+    gchar *intended_filename;
144
 
+    intended_filename = gnome_rr_config_get_intended_filename ();
145
 
+    
146
 
+    return(gnome_rr_config_save_to_file(configuration, err, intended_filename));
147
 
+}
148
 
+
149
 
+gboolean
150
 
+ubuntu_gnome_rr_config_save_desired (GnomeRRConfig *configuration, GError **err)
151
 
+{
152
 
+    gchar *filename;
153
 
+    filename = get_desired_config_filename ();
154
 
+    
155
 
+    return(gnome_rr_config_save_to_file(configuration, err, filename));
156
 
+}
157
 
+
158
 
+static void
159
 
+remove_desired_settings(void)
160
 
+{
161
 
+    gchar *filename;
162
 
+    filename = get_desired_config_filename ();
163
 
+    if (g_file_test (filename, G_FILE_TEST_EXISTS))
164
 
+        g_unlink (filename);
165
 
+
166
 
+    g_free (filename);
167
 
+
168
 
+}
169
 
+
170
 
+
171
 
 static GnomeRRConfig *
172
 
 gnome_rr_config_copy (GnomeRRConfig *config)
173
 
 {
174
 
@@ -1129,6 +1234,49 @@
175
 
 }
176
 
 
177
 
 static GnomeRRConfig *
178
 
+gnome_rr_desired_config_new_stored (GnomeRRScreen *screen, GError **error)
179
 
+{
180
 
+    GnomeRRConfig *current;
181
 
+    GnomeRRConfig **configs;
182
 
+    GnomeRRConfig *result;
183
 
+
184
 
+    g_return_val_if_fail (screen != NULL, NULL);
185
 
+    g_return_val_if_fail (error == NULL || *error == NULL, NULL);
186
 
+    
187
 
+    current = gnome_rr_config_new_current (screen);
188
 
+    
189
 
+    configs = desired_configurations_read (error);
190
 
+
191
 
+    result = NULL;
192
 
+    if (configs)
193
 
+    {
194
 
+       int i;
195
 
+       
196
 
+       for (i = 0; configs[i] != NULL; ++i)
197
 
+       {
198
 
+           if (gnome_rr_config_match (configs[i], current))
199
 
+           {
200
 
+               result = gnome_rr_config_copy (configs[i]);
201
 
+               break;
202
 
+           }
203
 
+       }
204
 
+
205
 
+       /*
206
 
+       if (result == NULL)
207
 
+           g_set_error (error, GNOME_RR_ERROR, GNOME_RR_ERROR_NO_MATCHING_CONFIG,
208
 
+                        _("none of the saved display configurations matched the active configuration"));
209
 
+       */
210
 
+
211
 
+       configurations_free (configs);
212
 
+    }
213
 
+
214
 
+    gnome_rr_config_free (current);
215
 
+    
216
 
+    return result;
217
 
+}
218
 
+
219
 
+
220
 
+static GnomeRRConfig *
221
 
 config_new_stored (GnomeRRScreen *screen, const char *filename, GError **error)
222
 
 {
223
 
     GnomeRRConfig *current;
224
 
@@ -1193,6 +1341,65 @@
225
 
 }
226
 
 #endif
227
 
 
228
 
+
229
 
+void
230
 
+ubuntu_compute_virtual_size_for_configuration (GnomeRRConfig *config, int *ret_width, int *ret_height)
231
 
+{
232
 
+    int i;
233
 
+    int width, height;
234
 
+
235
 
+    width = height = 0;
236
 
+
237
 
+    for (i = 0; config->outputs[i] != NULL; i++)
238
 
+    {
239
 
+       GnomeOutputInfo *output;
240
 
+
241
 
+       output = config->outputs[i];
242
 
+
243
 
+       if (output->on)
244
 
+       {
245
 
+           width = MAX (width, output->x + output->width);
246
 
+           height = MAX (height, output->y + output->height);
247
 
+       }
248
 
+    }
249
 
+
250
 
+    *ret_width = width;
251
 
+    *ret_height = height;
252
 
+}
253
 
+
254
 
+static gboolean
255
 
+check_framebuffer_size (GnomeRRConfig *config, GnomeRRScreen *screen)
256
 
+{
257
 
+    int req_width, req_height;
258
 
+    int min_width, max_width;
259
 
+    int min_height, max_height;
260
 
+    
261
 
+    /* Put the desired configuration 
262
 
+     * instead of app->current_configuration
263
 
+     */
264
 
+    ubuntu_compute_virtual_size_for_configuration (config, &req_width, &req_height);
265
 
+    
266
 
+    /* Put screen 
267
 
+     * instead of app->screen
268
 
+     */
269
 
+    gnome_rr_screen_get_ranges (screen, &min_width, &max_width, &min_height, &max_height);
270
 
+
271
 
+#if 0
272
 
+    g_debug ("X Server supports:\n");
273
 
+    g_debug ("min_width = %d, max_width = %d\n", min_width, max_width);
274
 
+    g_debug ("min_height = %d, max_height = %d\n", min_height, max_height);
275
 
+
276
 
+    g_debug ("Requesting size of %dx%d\n", req_width, req_height);
277
 
+#endif
278
 
+
279
 
+    if (!(min_width <= req_width && req_width <= max_width
280
 
+         && min_height <= req_height && req_height <= max_height))
281
 
+        return FALSE;
282
 
+    else
283
 
+        return TRUE;
284
 
+}
285
 
+
286
 
+
287
 
 gboolean
288
 
 gnome_rr_config_apply_with_time (GnomeRRConfig *config,
289
 
                                 GnomeRRScreen *screen,
290
 
@@ -1326,6 +1533,7 @@
291
 
 gnome_rr_config_apply_from_filename_with_time (GnomeRRScreen *screen, const char *filename, guint32 timestamp, GError **error)
292
 
 {
293
 
     GnomeRRConfig *stored;
294
 
+    gboolean is_desired = FALSE;
295
 
     GError *my_error;
296
 
 
297
 
     g_return_val_if_fail (screen != NULL, FALSE);
298
 
@@ -1342,22 +1550,71 @@
299
 
            /* This means the screen didn't change, so just proceed */
300
 
     }
301
 
 
302
 
-    stored = config_new_stored (screen, filename, error);
303
 
-
304
 
-    if (stored)
305
 
-    {
306
 
-       gboolean result;
307
 
-
308
 
-       result = gnome_rr_config_apply_with_time (stored, screen, timestamp, error);
309
 
+    /* Look for the desired settings and try to load that
310
 
+     * instead.
311
 
+     * Then remove such settings.
312
 
+     * else read the usual configuration
313
 
+     */
314
 
+    gchar *desired_filename;
315
 
+    desired_filename = get_desired_config_filename ();
316
 
+    
317
 
+    /* If the desired file exists */
318
 
+    if ((g_file_test(desired_filename, G_FILE_TEST_EXISTS))) {
319
 
+        stored = gnome_rr_desired_config_new_stored (screen, NULL);
320
 
+        
321
 
+        /* If the desired file can't be applied */
322
 
+        if (!stored) {
323
 
+            stored = gnome_rr_config_new_stored (screen, error);
324
 
+        }
325
 
+        else {
326
 
+            /* the desired file is valid and 
327
 
+               can be applied */
328
 
+            is_desired = TRUE;
329
 
+        }
330
 
+    }
331
 
+    /* If the desired file does not exist */
332
 
+    else {
333
 
+        stored = config_new_stored (screen, filename, error);
334
 
+    }
335
 
 
336
 
-       gnome_rr_config_free (stored);
337
 
-       
338
 
-       return result;
339
 
+    /* remove desired */
340
 
+       remove_desired_settings();
341
 
+       
342
 
+    if (stored) {
343
 
+       gboolean result = FALSE;
344
 
+        
345
 
+        /* Check framebuffer size. Do not apply
346
 
+            * the settings if the fb is not big
347
 
+            * enough
348
 
+            */
349
 
+        if (check_framebuffer_size (stored, screen)) {
350
 
+        
351
 
+               result = gnome_rr_config_apply_with_time (stored, screen, timestamp, error);
352
 
+
353
 
+               /* if we are using the desired settings and
354
 
+                  the settings were applied successfully */
355
 
+               if (is_desired && result) {
356
 
+                /* Try to save the desired settings to the default
357
 
+                 * settings file
358
 
+                 */
359
 
+                g_clear_error (error);
360
 
+                gnome_rr_config_sanitize (stored);
361
 
+                result = gnome_rr_config_save (stored, error);
362
 
+               }
363
 
+       
364
 
+       } else {
365
 
+               g_set_error (error, GNOME_RR_ERROR, GNOME_RR_ERROR_UNKNOWN,
366
 
+                               "X server does not support size requested");
367
 
+       }
368
 
+       
369
 
+       gnome_rr_config_free (stored);
370
 
+       
371
 
+       return result;
372
 
     }
373
 
-    else
374
 
-    {
375
 
-       return FALSE;
376
 
+    else {
377
 
+           return FALSE;
378
 
     }
379
 
+
380
 
 }
381
 
 
382
 
 /*
383
 
diff -Nur -x '*.orig' -x '*~' gnome-desktop-2.29.92/libgnome-desktop/libgnomeui/gnome-rr-config.h gnome-desktop-2.29.92.new/libgnome-desktop/libgnomeui/gnome-rr-config.h
384
 
--- gnome-desktop-2.29.92/libgnome-desktop/libgnomeui/gnome-rr-config.h 2009-08-19 19:13:53.000000000 +0100
385
 
+++ gnome-desktop-2.29.92.new/libgnome-desktop/libgnomeui/gnome-rr-config.h     2010-03-27 23:40:40.500187203 +0000
386
 
@@ -123,6 +123,11 @@
387
 
 char *gnome_rr_config_get_backup_filename (void);
388
 
 char *gnome_rr_config_get_intended_filename (void);
389
 
 
390
 
+gboolean        ubuntu_gnome_rr_config_save_desired (GnomeRRConfig *configuration,
391
 
+                        GError **err);
392
 
+void            ubuntu_compute_virtual_size_for_configuration (GnomeRRConfig *config,
393
 
+                          int *ret_width, int *ret_height);
394
 
+          
395
 
 /* A utility function that isn't really in the spirit of this file, but I don't
396
 
  * don't know a better place for it.
397
 
  */