File gnome-settings-daemon-bnc517240-weird-cycling.diff of Package gnome-settings-daemon
From c33fdbc156530c9c5f9d9225b651d97f9729634c Mon Sep 17 00:00:00 2001
From: Jens Granseuer <jensgr@gmx.net>
Date: Sat, 28 Mar 2009 09:30:21 +0000
Subject: [PATCH 1/4] if the sanitized array ends up having no members at all return a NULL
2009-03-28 Jens Granseuer <jensgr@gmx.net>
* plugins/xrandr/gsd-xrandr-manager.c: (sanitize),
(generate_fn_f7_configs): if the sanitized array ends up having no
members at all return a NULL configuration since the following code
assumes it has at least one valid setup if it's not NULL. Fixes a
crash when closing the lid on some laptops (bug #576875)
svn path=/trunk/; revision=806
---
plugins/xrandr/gsd-xrandr-manager.c | 22 ++++++++++++++--------
1 files changed, 14 insertions(+), 8 deletions(-)
diff --git a/plugins/xrandr/gsd-xrandr-manager.c b/plugins/xrandr/gsd-xrandr-manager.c
index f99e9ac..e1cf8d1 100644
--- a/plugins/xrandr/gsd-xrandr-manager.c
+++ b/plugins/xrandr/gsd-xrandr-manager.c
@@ -787,7 +787,7 @@ sanitize (GsdXrandrManager *manager, GPtrArray *array)
int i;
GPtrArray *new;
- g_print ("before sanitizing\n");
+ g_debug ("before sanitizing");
for (i = 0; i < array->len; ++i) {
if (array->pdata[i]) {
@@ -799,7 +799,7 @@ sanitize (GsdXrandrManager *manager, GPtrArray *array)
/* Remove configurations that are duplicates of
* configurations earlier in the cycle
*/
- for (i = 0; i < array->len; ++i) {
+ for (i = 1; i < array->len; ++i) {
int j;
for (j = 0; j < i; ++j) {
@@ -807,7 +807,7 @@ sanitize (GsdXrandrManager *manager, GPtrArray *array)
GnomeRRConfig *other = array->pdata[i];
if (this && other && gnome_rr_config_equal (this, other)) {
- g_print ("removing duplicate configuration\n");
+ g_debug ("removing duplicate configuration");
gnome_rr_config_free (this);
array->pdata[j] = NULL;
break;
@@ -866,7 +866,12 @@ sanitize (GsdXrandrManager *manager, GPtrArray *array)
}
}
- g_ptr_array_add (new, NULL);
+ if (new->len > 0) {
+ g_ptr_array_add (new, NULL);
+ } else {
+ g_ptr_array_free (new, TRUE);
+ new = NULL;
+ }
g_ptr_array_free (array, TRUE);
@@ -879,7 +884,7 @@ generate_fn_f7_configs (GsdXrandrManager *mgr)
GPtrArray *array = g_ptr_array_new ();
GnomeRRScreen *screen = mgr->priv->rw_screen;
- g_print ("Generating configurations\n");
+ g_debug ("Generating configurations");
/* Free any existing list of configurations */
if (mgr->priv->fn_f7_configs) {
@@ -899,12 +904,13 @@ generate_fn_f7_configs (GsdXrandrManager *mgr)
g_ptr_array_add (array, make_laptop_setup (screen));
g_ptr_array_add (array, make_other_setup (screen));
g_ptr_array_add (array, gnome_rr_config_new_stored (screen, NULL)); /* NULL-GError - if this can't read the stored config, no big deal */
- g_ptr_array_add (array, NULL);
array = sanitize (mgr, array);
- mgr->priv->fn_f7_configs = (GnomeRRConfig **)g_ptr_array_free (array, FALSE);
- mgr->priv->current_fn_f7_config = 0;
+ if (array) {
+ mgr->priv->fn_f7_configs = (GnomeRRConfig **)g_ptr_array_free (array, FALSE);
+ mgr->priv->current_fn_f7_config = 0;
+ }
}
static void
--
1.6.0.2
From 4cf46dc18aa551de6edc65f21b485521dfd06bac Mon Sep 17 00:00:00 2001
From: Federico Mena Quintero <federico@novell.com>
Date: Fri, 26 Jun 2009 14:38:02 -0500
Subject: [PATCH 2/4] RANDR - Fix order of arguments to strstr()
Signed-off-by: Federico Mena Quintero <federico@novell.com>
---
plugins/xrandr/gsd-xrandr-manager.c | 6 +++---
1 files changed, 3 insertions(+), 3 deletions(-)
diff --git a/plugins/xrandr/gsd-xrandr-manager.c b/plugins/xrandr/gsd-xrandr-manager.c
index e1cf8d1..f00212f 100644
--- a/plugins/xrandr/gsd-xrandr-manager.c
+++ b/plugins/xrandr/gsd-xrandr-manager.c
@@ -535,9 +535,9 @@ is_laptop (GnomeOutputInfo *output)
const char *output_name = output->name;
if (output->connected && output_name &&
- (strstr ("lvds", output_name) ||
- strstr ("LVDS", output_name) ||
- strstr ("Lvds", output_name)))
+ (strstr (output_name, "lvds") ||
+ strstr (output_name, "LVDS") ||
+ strstr (output_name, "Lvds")))
{
return TRUE;
}
--
1.6.0.2
From f735a73b931732c647995629a084aca03d3b5f11 Mon Sep 17 00:00:00 2001
From: Federico Mena Quintero <federico@novell.com>
Date: Thu, 16 Jul 2009 16:25:56 -0500
Subject: [PATCH 3/4] RANDR - Really lay out displays from left to right when using the XF86Display hotkey
We were not setting the horizontal position of an output if it was already on
when the configuration was being generated.
Signed-off-by: Federico Mena Quintero <federico@novell.com>
---
plugins/xrandr/gsd-xrandr-manager.c | 82 +++++++++++++++++++++++++++++------
1 files changed, 69 insertions(+), 13 deletions(-)
diff --git a/plugins/xrandr/gsd-xrandr-manager.c b/plugins/xrandr/gsd-xrandr-manager.c
index f00212f..6de736a 100644
--- a/plugins/xrandr/gsd-xrandr-manager.c
+++ b/plugins/xrandr/gsd-xrandr-manager.c
@@ -660,14 +660,61 @@ make_clone_setup (GnomeRRScreen *screen)
return result;
}
+static GnomeRRMode *
+find_best_mode (GnomeRROutput *output)
+{
+ GnomeRRMode *preferred;
+ GnomeRRMode **modes;
+ int best_size;
+ int best_width, best_height, best_rate;
+ int i;
+ GnomeRRMode *best_mode;
+
+ preferred = gnome_rr_output_get_preferred_mode (output);
+ if (preferred)
+ return preferred;
+
+ modes = gnome_rr_output_list_modes (output);
+ if (!modes)
+ return NULL;
+
+ best_size = best_width = best_height = best_rate = 0;
+ best_mode = NULL;
+
+ for (i = 0; modes[i] != NULL; i++) {
+ int w, h, r;
+ int size;
+
+ w = gnome_rr_mode_get_width (modes[i]);
+ h = gnome_rr_mode_get_height (modes[i]);
+ r = gnome_rr_mode_get_freq (modes[i]);
+
+ size = w * h;
+
+ if (size > best_size) {
+ best_size = size;
+ best_width = w;
+ best_height = h;
+ best_rate = r;
+ best_mode = modes[i];
+ } else if (size == best_size) {
+ if (r > best_rate) {
+ best_rate = r;
+ best_mode = modes[i];
+ }
+ }
+ }
+
+ return best_mode;
+}
+
static gboolean
turn_on (GnomeRRScreen *screen,
GnomeOutputInfo *info,
int x, int y)
{
- GnomeRROutput *output =
- gnome_rr_screen_get_output_by_name (screen, info->name);
- GnomeRRMode *mode = gnome_rr_output_get_preferred_mode (output);
+ GnomeRROutput *output = gnome_rr_screen_get_output_by_name (screen, info->name);
+ GnomeRRMode *mode = find_best_mode (output);
if (mode) {
info->on = TRUE;
@@ -717,6 +764,21 @@ make_laptop_setup (GnomeRRScreen *screen)
}
+static int
+turn_on_and_get_rightmost_offset (GnomeRRScreen *screen, GnomeOutputInfo *info, int x)
+{
+ if (info->on) {
+ info->x = x;
+ info->y = 0;
+ x += info->width;
+ } else {
+ if (turn_on (screen, info, x, 0))
+ x += info->width;
+ }
+
+ return x;
+}
+
static GnomeRRConfig *
make_xinerama_setup (GnomeRRScreen *screen)
{
@@ -731,21 +793,15 @@ make_xinerama_setup (GnomeRRScreen *screen)
for (i = 0; result->outputs[i] != NULL; ++i) {
GnomeOutputInfo *info = result->outputs[i];
- if (is_laptop (info)) {
- if (info->on || turn_on (screen, info, x, 0)) {
- x += info->width;
- }
- }
+ if (is_laptop (info))
+ x = turn_on_and_get_rightmost_offset (screen, info, x);
}
for (i = 0; result->outputs[i] != NULL; ++i) {
GnomeOutputInfo *info = result->outputs[i];
- if (info->connected && !is_laptop (info)) {
- if (info->on || turn_on (screen, info, x, 0)) {
- x += info->width;
- }
- }
+ if (info->connected && !is_laptop (info))
+ x = turn_on_and_get_rightmost_offset (screen, info, x);
}
print_configuration (result, "xinerama setup");
--
1.6.0.2
From 552ccacbef521f630d7c06331971ab29a8e9d374 Mon Sep 17 00:00:00 2001
From: Federico Mena Quintero <federico@novell.com>
Date: Fri, 17 Jul 2009 11:24:37 -0500
Subject: [PATCH 4/4] RANDR - For the XF86Display hotkey, preserve the cycle order when sanitizing the configurations
The cycle is this:
- current configuration
- clone setup
- xinerama setup (extended desktop)
- laptop-only setup
- external monitors only
- any saved configuration that matches the current monitors
However, the sanitize() stage was removing duplicated configurations by giving preference
to the modes closer to the end of the cycle, so the cycle became rather unpredictable.
Now we remove duplicated configurations by giving preference to the modes closer to the
start of the cycle.
Signed-off-by: Federico Mena Quintero <federico@novell.com>
---
plugins/xrandr/gsd-xrandr-manager.c | 4 ++--
1 files changed, 2 insertions(+), 2 deletions(-)
diff --git a/plugins/xrandr/gsd-xrandr-manager.c b/plugins/xrandr/gsd-xrandr-manager.c
index 6de736a..9ed1b34 100644
--- a/plugins/xrandr/gsd-xrandr-manager.c
+++ b/plugins/xrandr/gsd-xrandr-manager.c
@@ -855,10 +855,10 @@ sanitize (GsdXrandrManager *manager, GPtrArray *array)
/* Remove configurations that are duplicates of
* configurations earlier in the cycle
*/
- for (i = 1; i < array->len; ++i) {
+ for (i = 0; i < array->len; i++) {
int j;
- for (j = 0; j < i; ++j) {
+ for (j = i + 1; j < array->len; j++) {
GnomeRRConfig *this = array->pdata[j];
GnomeRRConfig *other = array->pdata[i];
--
1.6.0.2