[virt-tools-list] [PATCH virt-viewer 18/19] Simplify display flag handling

Christophe Fergeau cfergeau at redhat.com
Tue Jul 17 13:41:46 UTC 2012


Looks good, I'd have put this much earlier in the series, but no
big deal.
ACK, a few comments below.

On Mon, Jul 16, 2012 at 06:57:53PM +0200, Marc-André Lureau wrote:
> ---
>  src/virt-viewer-display-spice.c |    9 +--------
>  src/virt-viewer-display.c       |   20 ++++++++++----------
>  src/virt-viewer-display.h       |    2 +-
>  src/virt-viewer-session-vnc.c   |    8 ++++----
>  4 files changed, 16 insertions(+), 23 deletions(-)
> 
> diff --git a/src/virt-viewer-display-spice.c b/src/virt-viewer-display-spice.c
> index a91d73e..bbc1773 100644
> --- a/src/virt-viewer-display-spice.c
> +++ b/src/virt-viewer-display-spice.c
> @@ -140,19 +140,12 @@ display_ready(GObject *display,
>                GParamSpec *pspec G_GNUC_UNUSED,
>                VirtViewerDisplay *self)
>  {
> -    guint hint;
>      gboolean ready;
>  
>      g_object_get(display, "ready", &ready, NULL);
>      DEBUG_LOG("display %p ready:%d", self, ready);
>  
> -    hint = virt_viewer_display_get_show_hint(self);
> -    if (ready)
> -        hint |= VIRT_VIEWER_DISPLAY_SHOW_HINT_READY;
> -    else
> -        hint &= ~VIRT_VIEWER_DISPLAY_SHOW_HINT_READY;
> -
> -    virt_viewer_display_set_show_hint(self, hint);
> +    virt_viewer_display_set_show_hint(self, VIRT_VIEWER_DISPLAY_SHOW_HINT_READY, ready);
>  }
>  
>  static void
> diff --git a/src/virt-viewer-display.c b/src/virt-viewer-display.c
> index 4612970..b8e6d67 100644
> --- a/src/virt-viewer-display.c
> +++ b/src/virt-viewer-display.c
> @@ -551,12 +551,20 @@ guint virt_viewer_display_get_show_hint(VirtViewerDisplay *self)
>      return self->priv->show_hint;
>  }
>  
> -void virt_viewer_display_set_show_hint(VirtViewerDisplay *self, guint hint)
> +void virt_viewer_display_set_show_hint(VirtViewerDisplay *self, guint mask, gboolean enabled)

maybe s/enabled/enable since the flag is not enabled yet.

>  {
>      VirtViewerDisplayPrivate *priv;
> +    guint hint;
>      g_return_if_fail(VIRT_VIEWER_IS_DISPLAY(self));
>  
>      priv = self->priv;
> +    hint = priv->show_hint;
> +
> +    if (enabled)
> +        hint |= mask;
> +    else
> +        hint &= ~mask;
> +
>      if (priv->show_hint == hint)
>          return;
>  
> @@ -566,17 +574,9 @@ void virt_viewer_display_set_show_hint(VirtViewerDisplay *self, guint hint)
>  
>  void virt_viewer_display_set_enabled(VirtViewerDisplay *self, gboolean enabled)
>  {
> -    guint hint;
> -
>      g_return_if_fail(VIRT_VIEWER_IS_DISPLAY(self));
>  
> -    hint = virt_viewer_display_get_show_hint(self);
> -    if (enabled)
> -        hint &= ~VIRT_VIEWER_DISPLAY_SHOW_HINT_DISABLED;
> -    else
> -        hint |= VIRT_VIEWER_DISPLAY_SHOW_HINT_DISABLED;
> -
> -    virt_viewer_display_set_show_hint(self, hint);
> +    virt_viewer_display_set_show_hint(self, VIRT_VIEWER_DISPLAY_SHOW_HINT_DISABLED, !enabled);
>  }
>  
>  VirtViewerSession* virt_viewer_display_get_session(VirtViewerDisplay *self)
> diff --git a/src/virt-viewer-display.h b/src/virt-viewer-display.h
> index 4247570..d838c07 100644
> --- a/src/virt-viewer-display.h
> +++ b/src/virt-viewer-display.h
> @@ -110,7 +110,7 @@ gboolean virt_viewer_display_get_zoom(VirtViewerDisplay *display);
>  void virt_viewer_display_send_keys(VirtViewerDisplay *display,
>                                     const guint *keyvals, int nkeyvals);
>  GdkPixbuf* virt_viewer_display_get_pixbuf(VirtViewerDisplay *display);
> -void virt_viewer_display_set_show_hint(VirtViewerDisplay *display, guint hint);
> +void virt_viewer_display_set_show_hint(VirtViewerDisplay *display, guint mask, gboolean enabled);
>  guint virt_viewer_display_get_show_hint(VirtViewerDisplay *display);
>  VirtViewerSession* virt_viewer_display_get_session(VirtViewerDisplay *display);
>  void virt_viewer_display_set_auto_resize(VirtViewerDisplay *display, gboolean auto_resize);
> diff --git a/src/virt-viewer-session-vnc.c b/src/virt-viewer-session-vnc.c
> index 238c865..52baf5c 100644
> --- a/src/virt-viewer-session-vnc.c
> +++ b/src/virt-viewer-session-vnc.c
> @@ -95,7 +95,7 @@ virt_viewer_session_vnc_connected(VncDisplay *vnc G_GNUC_UNUSED,
>      GtkWidget *display = virt_viewer_display_vnc_new(session->priv->vnc);
>      g_signal_emit_by_name(session, "session-connected");
>      virt_viewer_display_set_show_hint(VIRT_VIEWER_DISPLAY(display),
> -                                      VIRT_VIEWER_DISPLAY_SHOW_HINT_READY);
> +                                      VIRT_VIEWER_DISPLAY_SHOW_HINT_READY, TRUE);
>      virt_viewer_session_add_display(VIRT_VIEWER_SESSION(session),
>                                      VIRT_VIEWER_DISPLAY(display));
>  }
> @@ -104,11 +104,11 @@ static void
>  virt_viewer_session_vnc_disconnected(VncDisplay *vnc G_GNUC_UNUSED,
>                                       VirtViewerSessionVnc *session)
>  {
> +    GtkWidget *display = virt_viewer_display_vnc_new(session->priv->vnc);
>      DEBUG_LOG("Disconnected");
>      g_signal_emit_by_name(session, "session-disconnected");
> -    /* TODO perhaps? */
> -    /* virt_viewer_display_set_show_hint(VIRT_VIEWER_DISPLAY(session->priv->vnc), */
> -    /*                                   VIRT_VIEWER_DISPLAY_SHOW_HINT_HIDE); */
> +    virt_viewer_display_set_show_hint(VIRT_VIEWER_DISPLAY(display),
> +                                      VIRT_VIEWER_DISPLAY_SHOW_HINT_READY, FALSE);

This is a slight change in behaviour, maybe this patch should change the
call but keep it commented out, and then another patch would uncomment it?

Christophe
-------------- next part --------------
A non-text attachment was scrubbed...
Name: not available
Type: application/pgp-signature
Size: 198 bytes
Desc: not available
URL: <http://listman.redhat.com/archives/virt-tools-list/attachments/20120717/e3c61adb/attachment.sig>


More information about the virt-tools-list mailing list