[Spice-devel] [PATCH spice-gtk] main: use stable comparison function for monitors

Marc-André Lureau marcandre.lureau at gmail.com
Wed Feb 20 02:35:36 PST 2013


If monitors are equal, compare them by their addresses, to get the
effect of a stable sort.
---
 gtk/channel-main.c | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)

diff --git a/gtk/channel-main.c b/gtk/channel-main.c
index fe57684..f86e81d 100644
--- a/gtk/channel-main.c
+++ b/gtk/channel-main.c
@@ -973,8 +973,9 @@ static int monitors_cmp(const void *p1, const void *p2, gpointer user_data)
     const VDAgentMonConfig *m2 = p2;
     double d1 = sqrt(m1->x * m1->x + m1->y * m1->y);
     double d2 = sqrt(m2->x * m2->x + m2->y * m2->y);
+    int diff = d1 - d2;
 
-    return d1 - d2;
+    return diff == 0 ? (char*)p1 - (char*)p2 : diff;
 }
 
 static void monitors_align(VDAgentMonConfig *monitors, int nmonitors)
-- 
1.8.1.1.439.g50a6b54



More information about the Spice-devel mailing list