[virt-tools-list] [PATCH 2/2] Create a sparse array for monitor-geometry-changed

Marc-André Lureau marcandre.lureau at gmail.com
Wed Nov 20 17:24:25 UTC 2013


On Thu, Nov 14, 2013 at 6:53 PM, Jonathon Jongsma <jjongsma at redhat.com> wrote:
> 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 this warning. So find the highest
> display ID and then create an array of that size, leaving missing displays
> initialized to 0

what warning? :) please add it to commit msg please.

> ---
>  src/virt-viewer-session.c | 12 +++++++++++-
>  1 file changed, 11 insertions(+), 1 deletion(-)
>
> diff --git a/src/virt-viewer-session.c b/src/virt-viewer-session.c
> index 24f0c72..b2ce1d6 100644
> --- a/src/virt-viewer-session.c
> +++ b/src/virt-viewer-session.c
> @@ -393,13 +393,23 @@ 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);
> +
> +        if ((nth + 1) > nmonitors)
> +            nmonitors = nth + 1;

this is where I like a MAX macro makes reading easier.

> +    }
> +
>      monitors = g_new0(GdkRectangle, nmonitors);
>      for (GList *l = self->priv->displays; l; l = l->next) {
>          VirtViewerDisplay *d = VIRT_VIEWER_DISPLAY(l->data);
> --
> 1.8.3.1
>
> _______________________________________________
> virt-tools-list mailing list
> virt-tools-list at redhat.com
> https://www.redhat.com/mailman/listinfo/virt-tools-list



-- 
Marc-André Lureau




More information about the virt-tools-list mailing list