Create a sparse array for monitor-geometry-changed

It's possible to have only display N enabled without having all of the displays
before it. I experienced this a couple times with a windows guest where display
1 would show up before display 0 and we'd hit a warning that nth is not less
than nmonitors. So find the highest display ID and then create an array of that
size, leaving missing displays initialized to 0
This commit is contained in:
Jonathon Jongsma 2013-11-13 16:39:43 -06:00
parent 81f70304ed
commit 03bf8d3051

View File

@ -393,13 +393,22 @@ virt_viewer_session_on_monitor_geometry_changed(VirtViewerSession* self,
{
VirtViewerSessionClass *klass;
gboolean all_fullscreen = TRUE;
guint nmonitors = g_list_length(self->priv->displays);
guint nmonitors = 0;
GdkRectangle *monitors = NULL;
klass = VIRT_VIEWER_SESSION_GET_CLASS(self);
if (!klass->apply_monitor_geometry)
return;
/* find highest monitor ID so we can create the sparse array */
for (GList *l = self->priv->displays; l; l = l->next) {
VirtViewerDisplay *d = VIRT_VIEWER_DISPLAY(l->data);
guint nth = 0;
g_object_get(d, "nth-display", &nth, NULL);
nmonitors = MAX(nth + 1, nmonitors);
}
monitors = g_new0(GdkRectangle, nmonitors);
for (GList *l = self->priv->displays; l; l = l->next) {
VirtViewerDisplay *d = VIRT_VIEWER_DISPLAY(l->data);