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
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
10
#define CONFIG_INTENDED_BASENAME "monitors.xml"
11
#define CONFIG_BACKUP_BASENAME "monitors.xml.backup"
12
+#define CONFIG_DESIRED_BASENAME "monitors.xml.desired"
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
17
static void output_free (GnomeOutputInfo *output);
18
static GnomeOutputInfo *output_copy (GnomeOutputInfo *output);
20
+static gboolean gnome_rr_config_save_to_file (GnomeRRConfig *configuration,
21
+ GError **err, gchar *filename);
22
+static void remove_desired_settings (void);
24
typedef struct Parser Parser;
26
/* Parser for monitor configurations */
31
+ /* return NULL if the file doesn't exist */
32
+ if (!g_file_test (filename, G_FILE_TEST_EXISTS))
35
+ g_set_error (error, G_FILE_ERROR, G_FILE_ERROR_NOENT,
36
+ "No such file: %s", filename);
41
parser->config_file_version = 0;
42
parser->configurations = g_ptr_array_new ();
43
parser->outputs = g_ptr_array_new ();
45
return g_build_filename (g_get_user_config_dir (), CONFIG_INTENDED_BASENAME, NULL);
49
+get_desired_config_filename (void)
51
+ return g_build_filename (g_get_user_config_dir (), CONFIG_DESIRED_BASENAME, NULL);
54
+static GnomeRRConfig **
55
+desired_configurations_read (GError **error)
58
+ GnomeRRConfig **configs;
61
+ /* Try the desired configuration file... */
63
+ filename = get_desired_config_filename ();
66
+ g_debug("desired is = %s\n", filename);
71
+ g_debug("reading configuration...\n");
73
+ configs = configurations_read_from_file (filename, &err);
82
+ if (g_error_matches (err, G_FILE_ERROR, G_FILE_ERROR_NOENT))
86
+ g_debug("error MATCHES\n");
90
+ /* Okay, so try the old configuration file */
91
+ filename = gnome_rr_config_get_intended_filename ();
92
+ configs = configurations_read_from_file (filename, error);
98
+ g_debug("error does NOT MATCH\n");
100
+ g_propagate_error (error, err);
108
get_rotation_name (GnomeRRRotation r)
110
@@ -1059,13 +1133,13 @@
115
-gnome_rr_config_save (GnomeRRConfig *configuration, GError **error)
117
+gnome_rr_config_save_to_file (GnomeRRConfig *configuration, GError **error, gchar *intended_filename)
119
GnomeRRConfig **configurations;
122
- gchar *intended_filename;
124
gchar *backup_filename;
127
@@ -1075,7 +1149,7 @@
128
output = g_string_new ("");
130
backup_filename = gnome_rr_config_get_backup_filename ();
131
- intended_filename = gnome_rr_config_get_intended_filename ();
134
configurations = configurations_read_from_file (intended_filename, NULL); /* NULL-GError */
136
@@ -1110,6 +1184,37 @@
141
+gnome_rr_config_save (GnomeRRConfig *configuration, GError **err)
143
+ gchar *intended_filename;
144
+ intended_filename = gnome_rr_config_get_intended_filename ();
146
+ return(gnome_rr_config_save_to_file(configuration, err, intended_filename));
150
+ubuntu_gnome_rr_config_save_desired (GnomeRRConfig *configuration, GError **err)
153
+ filename = get_desired_config_filename ();
155
+ return(gnome_rr_config_save_to_file(configuration, err, filename));
159
+remove_desired_settings(void)
162
+ filename = get_desired_config_filename ();
163
+ if (g_file_test (filename, G_FILE_TEST_EXISTS))
164
+ g_unlink (filename);
171
static GnomeRRConfig *
172
gnome_rr_config_copy (GnomeRRConfig *config)
174
@@ -1129,6 +1234,49 @@
177
static GnomeRRConfig *
178
+gnome_rr_desired_config_new_stored (GnomeRRScreen *screen, GError **error)
180
+ GnomeRRConfig *current;
181
+ GnomeRRConfig **configs;
182
+ GnomeRRConfig *result;
184
+ g_return_val_if_fail (screen != NULL, NULL);
185
+ g_return_val_if_fail (error == NULL || *error == NULL, NULL);
187
+ current = gnome_rr_config_new_current (screen);
189
+ configs = desired_configurations_read (error);
196
+ for (i = 0; configs[i] != NULL; ++i)
198
+ if (gnome_rr_config_match (configs[i], current))
200
+ result = gnome_rr_config_copy (configs[i]);
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"));
211
+ configurations_free (configs);
214
+ gnome_rr_config_free (current);
220
+static GnomeRRConfig *
221
config_new_stored (GnomeRRScreen *screen, const char *filename, GError **error)
223
GnomeRRConfig *current;
224
@@ -1193,6 +1341,65 @@
230
+ubuntu_compute_virtual_size_for_configuration (GnomeRRConfig *config, int *ret_width, int *ret_height)
235
+ width = height = 0;
237
+ for (i = 0; config->outputs[i] != NULL; i++)
239
+ GnomeOutputInfo *output;
241
+ output = config->outputs[i];
245
+ width = MAX (width, output->x + output->width);
246
+ height = MAX (height, output->y + output->height);
250
+ *ret_width = width;
251
+ *ret_height = height;
255
+check_framebuffer_size (GnomeRRConfig *config, GnomeRRScreen *screen)
257
+ int req_width, req_height;
258
+ int min_width, max_width;
259
+ int min_height, max_height;
261
+ /* Put the desired configuration
262
+ * instead of app->current_configuration
264
+ ubuntu_compute_virtual_size_for_configuration (config, &req_width, &req_height);
267
+ * instead of app->screen
269
+ gnome_rr_screen_get_ranges (screen, &min_width, &max_width, &min_height, &max_height);
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);
276
+ g_debug ("Requesting size of %dx%d\n", req_width, req_height);
279
+ if (!(min_width <= req_width && req_width <= max_width
280
+ && min_height <= req_height && req_height <= max_height))
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)
293
GnomeRRConfig *stored;
294
+ gboolean is_desired = FALSE;
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 */
302
- stored = config_new_stored (screen, filename, error);
308
- result = gnome_rr_config_apply_with_time (stored, screen, timestamp, error);
309
+ /* Look for the desired settings and try to load that
311
+ * Then remove such settings.
312
+ * else read the usual configuration
314
+ gchar *desired_filename;
315
+ desired_filename = get_desired_config_filename ();
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);
321
+ /* If the desired file can't be applied */
323
+ stored = gnome_rr_config_new_stored (screen, error);
326
+ /* the desired file is valid and
331
+ /* If the desired file does not exist */
333
+ stored = config_new_stored (screen, filename, error);
336
- gnome_rr_config_free (stored);
339
+ /* remove desired */
340
+ remove_desired_settings();
343
+ gboolean result = FALSE;
345
+ /* Check framebuffer size. Do not apply
346
+ * the settings if the fb is not big
349
+ if (check_framebuffer_size (stored, screen)) {
351
+ result = gnome_rr_config_apply_with_time (stored, screen, timestamp, error);
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
359
+ g_clear_error (error);
360
+ gnome_rr_config_sanitize (stored);
361
+ result = gnome_rr_config_save (stored, error);
365
+ g_set_error (error, GNOME_RR_ERROR, GNOME_RR_ERROR_UNKNOWN,
366
+ "X server does not support size requested");
369
+ gnome_rr_config_free (stored);
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
387
char *gnome_rr_config_get_backup_filename (void);
388
char *gnome_rr_config_get_intended_filename (void);
390
+gboolean ubuntu_gnome_rr_config_save_desired (GnomeRRConfig *configuration,
392
+void ubuntu_compute_virtual_size_for_configuration (GnomeRRConfig *config,
393
+ int *ret_width, int *ret_height);
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.