[virt-tools-list] [PATCH virt-viewer 1/2] display: Use common code to get preferred size

Pavel Grunt pgrunt at redhat.com
Mon Feb 15 07:36:51 UTC 2016


Hi,

On Fri, 2016-02-05 at 14:14 -0200, Eduardo Lima (Etrunko) wrote:
> On 02/05/2016 01:27 PM, Pavel Grunt wrote:
> > ---
> >  src/virt-viewer-display.c | 52 ++++++++++++++++++++++++++++-------
> > ------------
> >  1 file changed, 31 insertions(+), 21 deletions(-)
> > 
> > diff --git a/src/virt-viewer-display.c b/src/virt-viewer-display.c
> > index 654cada..a289b6f 100644
> > --- a/src/virt-viewer-display.c
> > +++ b/src/virt-viewer-display.c
> > @@ -448,24 +448,39 @@
> > virt_viewer_display_make_resizable(VirtViewerDisplay *self)
> >  
> >  #else
> >  
> > +static void
> > virt_viewer_display_get_preferred_dimension_from_desktop(VirtViewer
> > Display *display,
> > +                                                                  
> >    const int minimal_size,
> > +                                                                  
> >    const int desktop_dim,
> > +                                                                  
> >    int *minimal_dim,
> > +                                                                  
> >    int *preferred_dim)
> > +{
> > +    int border_width =
> > gtk_container_get_border_width(GTK_CONTAINER(display));
> > +
> > +    if (virt_viewer_display_get_zoom(display)) {
> > +        guint zoom_level =
> > virt_viewer_display_get_zoom_level(display);
> 
> The functions you removed access these fields directly? Any reason
> for
> not doing it?

I don't want to have a 'priv' variable - I would only read it for these
two values, so I change the code to use getters.

Pavel

> 
> Acked-by: Eduardo Lima (Etrunko) <etrunko at redhat.com>
> 
> > +        *preferred_dim = round(desktop_dim * zoom_level / (double)
> > NORMAL_ZOOM_LEVEL);
> > +        *minimal_dim = round(minimal_size * zoom_level / (double)
> > NORMAL_ZOOM_LEVEL);
> > +    } else {
> > +        *preferred_dim = desktop_dim;
> > +        *minimal_dim = minimal_size;
> > +    }
> > +    *preferred_dim += 2 * border_width;
> > +    *minimal_dim += 2 * border_width;
> > +}
> > +
> > +
> >  static void virt_viewer_display_get_preferred_width(GtkWidget
> > *widget,
> >                                                      int *minwidth,
> >                                                      int *defwidth)
> >  {
> >      VirtViewerDisplay *display = VIRT_VIEWER_DISPLAY(widget);
> >      VirtViewerDisplayPrivate *priv = display->priv;
> > -    int border_width =
> > gtk_container_get_border_width(GTK_CONTAINER(widget));
> > -
> >  
> > -    if (priv->zoom) {
> > -        *defwidth = round(priv->desktopWidth * priv->zoom_level /
> > (double) NORMAL_ZOOM_LEVEL);
> > -        *minwidth = round(MIN_DISPLAY_WIDTH * priv->zoom_level /
> > (double) NORMAL_ZOOM_LEVEL);
> > -    } else {
> > -        *defwidth = priv->desktopWidth;
> > -        *minwidth = MIN_DISPLAY_WIDTH;
> > -    }
> > -    *defwidth += 2 * border_width;
> > -    *minwidth += 2 * border_width;
> > +    virt_viewer_display_get_preferred_dimension_from_desktop(displ
> > ay,
> > +                                                             MIN_D
> > ISPLAY_WIDTH,
> > +                                                             priv-
> > >desktopWidth,
> > +                                                             minwi
> > dth,
> > +                                                             defwi
> > dth);
> >  }
> >  
> >  
> > @@ -475,17 +490,12 @@ static void
> > virt_viewer_display_get_preferred_height(GtkWidget *widget,
> >  {
> >      VirtViewerDisplay *display = VIRT_VIEWER_DISPLAY(widget);
> >      VirtViewerDisplayPrivate *priv = display->priv;
> > -    int border_height =
> > gtk_container_get_border_width(GTK_CONTAINER(widget));
> >  
> > -    if (priv->zoom) {
> > -        *defheight = round(priv->desktopHeight * priv->zoom_level
> > / (double) NORMAL_ZOOM_LEVEL);
> > -        *minheight = round(MIN_DISPLAY_HEIGHT * priv->zoom_level /
> > (double) NORMAL_ZOOM_LEVEL);
> > -    } else {
> > -        *defheight = priv->desktopHeight;
> > -        *minheight = MIN_DISPLAY_HEIGHT;
> > -    }
> > -    *defheight += 2 * border_height;
> > -    *minheight += 2 * border_height;
> > +    virt_viewer_display_get_preferred_dimension_from_desktop(displ
> > ay,
> > +                                                             MIN_D
> > ISPLAY_HEIGHT,
> > +                                                             priv-
> > >desktopHeight,
> > +                                                             minhe
> > ight,
> > +                                                             defhe
> > ight);
> >  }
> >  #endif
> >  
> > 
> 
> 




More information about the virt-tools-list mailing list