Blame SOURCES/0003-Create-a-sparse-array-for-monitor-geometry-changed.patch

4a6991
From 734d7ff11e6b3a15832bab06a0d7f0cb0f5339a8 Mon Sep 17 00:00:00 2001
4a6991
From: Jonathon Jongsma <jjongsma@redhat.com>
4a6991
Date: Wed, 13 Nov 2013 16:39:43 -0600
4a6991
Subject: [PATCH] Create a sparse array for monitor-geometry-changed
4a6991
4a6991
It's possible to have only display N enabled without having all of the displays
4a6991
before it. I experienced this a couple times with a windows guest where display
4a6991
1 would show up before display 0 and we'd hit a warning that nth is not less
4a6991
than nmonitors. So find the highest display ID and then create an array of that
4a6991
size, leaving missing displays initialized to 0
4a6991
---
4a6991
 src/virt-viewer-session.c | 11 ++++++++++-
4a6991
 1 file changed, 10 insertions(+), 1 deletion(-)
4a6991
4a6991
diff --git a/src/virt-viewer-session.c b/src/virt-viewer-session.c
4a6991
index 24f0c72..20d5fb1 100644
4a6991
--- a/src/virt-viewer-session.c
4a6991
+++ b/src/virt-viewer-session.c
4a6991
@@ -393,13 +393,22 @@ virt_viewer_session_on_monitor_geometry_changed(VirtViewerSession* self,
4a6991
 {
4a6991
     VirtViewerSessionClass *klass;
4a6991
     gboolean all_fullscreen = TRUE;
4a6991
-    guint nmonitors = g_list_length(self->priv->displays);
4a6991
+    guint nmonitors = 0;
4a6991
     GdkRectangle *monitors = NULL;
4a6991
 
4a6991
     klass = VIRT_VIEWER_SESSION_GET_CLASS(self);
4a6991
     if (!klass->apply_monitor_geometry)
4a6991
         return;
4a6991
 
4a6991
+    /* find highest monitor ID so we can create the sparse array */
4a6991
+    for (GList *l = self->priv->displays; l; l = l->next) {
4a6991
+        VirtViewerDisplay *d = VIRT_VIEWER_DISPLAY(l->data);
4a6991
+        guint nth = 0;
4a6991
+        g_object_get(d, "nth-display", &nth, NULL);
4a6991
+
4a6991
+        nmonitors = MAX(nth + 1, nmonitors);
4a6991
+    }
4a6991
+
4a6991
     monitors = g_new0(GdkRectangle, nmonitors);
4a6991
     for (GList *l = self->priv->displays; l; l = l->next) {
4a6991
         VirtViewerDisplay *d = VIRT_VIEWER_DISPLAY(l->data);