[gnome-settings-daemon/gnome-3-8] xrandr: Simplify layout of adjacent screens
- From: Bastien Nocera <hadess src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gnome-settings-daemon/gnome-3-8] xrandr: Simplify layout of adjacent screens
- Date: Thu, 18 Jul 2013 14:12:08 +0000 (UTC)
commit 65bca47fc83599eeecafe99355a463c898141189
Author: Bastien Nocera <hadess hadess net>
Date: Wed Jul 17 09:49:33 2013 +0200
xrandr: Simplify layout of adjacent screens
Rather than going through the loop a number of times,
add the outputs to a GPtrArray directly, and sort it.
https://bugzilla.gnome.org/show_bug.cgi?id=704286
plugins/xrandr/gsd-xrandr-manager.c | 39 +++++++++++++---------------------
1 files changed, 15 insertions(+), 24 deletions(-)
---
diff --git a/plugins/xrandr/gsd-xrandr-manager.c b/plugins/xrandr/gsd-xrandr-manager.c
index ed9fc25..9ae965c 100644
--- a/plugins/xrandr/gsd-xrandr-manager.c
+++ b/plugins/xrandr/gsd-xrandr-manager.c
@@ -1048,16 +1048,16 @@ turn_on_and_get_rightmost_offset (GnomeRRScreen *screen, GnomeRROutputInfo *info
return x;
}
-/* Used from qsort(); compares outputs based on their X position */
+/* Used from g_ptr_array_sort(); compares outputs based on their X position */
static int
-compare_output_positions (const void *a, const void *b)
+compare_output_positions (gconstpointer a, gconstpointer b)
{
- GnomeRROutputInfo *oa = (GnomeRROutputInfo *) a;
- GnomeRROutputInfo *ob = (GnomeRROutputInfo *) b;
+ GnomeRROutputInfo **oa = (GnomeRROutputInfo **) a;
+ GnomeRROutputInfo **ob = (GnomeRROutputInfo **) b;
int xa, xb;
- gnome_rr_output_info_get_geometry (oa, &xa, NULL, NULL, NULL);
- gnome_rr_output_info_get_geometry (ob, &xb, NULL, NULL, NULL);
+ gnome_rr_output_info_get_geometry (*oa, &xa, NULL, NULL, NULL);
+ gnome_rr_output_info_get_geometry (*ob, &xb, NULL, NULL, NULL);
return xb - xa;
}
@@ -1071,39 +1071,30 @@ static gboolean
trim_rightmost_outputs_that_dont_fit_in_framebuffer (GnomeRRScreen *rr_screen, GnomeRRConfig *config)
{
GnomeRROutputInfo **outputs;
- GnomeRROutputInfo **sorted_outputs;
- int num_on_outputs;
- int i, j;
+ int i;
gboolean applicable;
+ GPtrArray *sorted_outputs;
outputs = gnome_rr_config_get_outputs (config);
+ g_return_val_if_fail (outputs != NULL, FALSE);
/* How many are on? */
- num_on_outputs = 0;
+ sorted_outputs = g_ptr_array_new ();
for (i = 0; outputs[i] != NULL; i++) {
if (gnome_rr_output_info_is_active (outputs[i]))
- num_on_outputs++;
+ g_ptr_array_add (sorted_outputs, outputs[i]);
}
/* Lay them out from left to right */
- sorted_outputs = g_new (GnomeRROutputInfo *, num_on_outputs);
- j = 0;
- for (i = 0; outputs[i] != NULL; i++) {
- if (gnome_rr_output_info_is_active (outputs[i])) {
- sorted_outputs[j] = outputs[i];
- j++;
- }
- }
-
- qsort (sorted_outputs, num_on_outputs, sizeof (sorted_outputs[0]), compare_output_positions);
+ g_ptr_array_sort (sorted_outputs, compare_output_positions);
/* Trim! */
applicable = FALSE;
- for (i = num_on_outputs - 1; i >= 0; i--) {
+ for (i = sorted_outputs->len - 1; i >= 0; i--) {
GError *error = NULL;
gboolean is_bounds_error;
@@ -1117,13 +1108,13 @@ trim_rightmost_outputs_that_dont_fit_in_framebuffer (GnomeRRScreen *rr_screen, G
if (!is_bounds_error)
break;
- gnome_rr_output_info_set_active (sorted_outputs[i], FALSE);
+ gnome_rr_output_info_set_active (sorted_outputs->pdata[i], FALSE);
}
if (config_is_all_off (config))
applicable = FALSE;
- g_free (sorted_outputs);
+ g_ptr_array_free (sorted_outputs, FALSE);
return applicable;
}
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]