[Spice-devel] [spice-gtk v2 3/4] gtk-deprecated: silence warn on gtk_widget_set_double_buffered()

Victor Toso victortoso at redhat.com
Wed Jul 25 10:56:14 UTC 2018


Hi,

On Wed, Jul 25, 2018 at 05:20:45AM -0400, Frediano Ziglio wrote:
> > 
> > From: Victor Toso <me at victortoso.com>
> > 
> > To quote documentation:
> >  | gtk_widget_set_double_buffered has been deprecated since version
> >  | 3.14 and should not be used in newly-written code.
> >  | This function does not work under non-X11 backends or with
> >  | non-native windows. It should not be used in newly written code.
> > 
> > So be sure to only call this function on X11 backend and silence
> > warnings with G_GNUC_BEGIN/END_IGNORE_DEPRECATIONS
> > 
> > Warnings fixed:
> >  | spice-widget.c: In function ‘spice_display_init’:
> >  | spice-widget.c:643:5: warning: ‘gtk_widget_set_double_buffered’ is
> >  | deprecated
> >  |
> >  |     gtk_widget_set_double_buffered(area, true);
> >  |     ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
> >  |
> >  | spice-widget.c:661:5: warning: ‘gtk_widget_set_double_buffered’ is
> >  | deprecated
> >  |
> >  |     gtk_widget_set_double_buffered(area, true);
> >  |     ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
> >  |
> >  | spice-widget.c: In function ‘set_egl_enabled’:
> >  | spice-widget.c:1290:9: warning: ‘gtk_widget_set_double_buffered’ is
> >  | deprecated
> >  |     gtk_widget_set_double_buffered(GTK_WIDGET(area), !enabled);
> >  |     ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
> > 
> > Signed-off-by: Victor Toso <victortoso at redhat.com>
> > ---
> >  src/spice-widget.c | 18 +++++++++++++++---
> >  1 file changed, 15 insertions(+), 3 deletions(-)
> > 
> > diff --git a/src/spice-widget.c b/src/spice-widget.c
> > index ce123bd..bf10a0b 100644
> > --- a/src/spice-widget.c
> > +++ b/src/spice-widget.c
> > @@ -104,6 +104,18 @@ static guint signals[SPICE_DISPLAY_LAST_SIGNAL];
> >  static HWND win32_window = NULL;
> >  #endif
> >  
> > +#ifdef GDK_WINDOWING_X11
> > +#define SET_DOUBLE_BUFFERED_ON_X11(widget, enabled) G_STMT_START { \
> > +    if (GDK_IS_X11_DISPLAY(gdk_display_get_default())) {           \
> > +        G_GNUC_BEGIN_IGNORE_DEPRECATIONS                           \
> > +        gtk_widget_set_double_buffered(widget, enabled);           \
> > +        G_GNUC_END_IGNORE_DEPRECATIONS                             \
> > +    }                                                              \
> > +} G_STMT_END
> > +#else
> > +#define SET_DOUBLE_BUFFERED_ON_X11(widget, enabled) G_STMT_START { }
> > G_STMT_END
> > +#endif
> > +
> >  static void update_keyboard_grab(SpiceDisplay *display);
> >  static void try_keyboard_grab(SpiceDisplay *display);
> >  static void try_keyboard_ungrab(SpiceDisplay *display);
> > @@ -640,7 +652,7 @@ static void spice_display_init(SpiceDisplay *display)
> >                       "signal::realize", drawing_area_realize, display,
> >                       NULL);
> >      gtk_stack_add_named(d->stack, area, "draw-area");
> > -    gtk_widget_set_double_buffered(area, true);
> > +    SET_DOUBLE_BUFFERED_ON_X11(area, true);
> >      gtk_stack_set_visible_child(d->stack, area);
> >  
> >  #if HAVE_EGL
> > @@ -658,7 +670,7 @@ G_GNUC_END_IGNORE_DEPRECATIONS
> >  #endif
> >      area = gtk_drawing_area_new();
> >      gtk_stack_add_named(d->stack, area, "gst-area");
> > -    gtk_widget_set_double_buffered(area, true);
> > +    SET_DOUBLE_BUFFERED_ON_X11(area, true);
> >  
> >      gtk_widget_show_all(widget);
> >  
> > @@ -1281,7 +1293,7 @@ static void set_egl_enabled(SpiceDisplay *display, bool
> > enabled)
> >           * only way I found to prevent glitches when the window is
> >           * resized. */
> >          GtkWidget *area = gtk_stack_get_child_by_name(d->stack,
> >          "draw-area");
> > -        gtk_widget_set_double_buffered(GTK_WIDGET(area), !enabled);
> > +        SET_DOUBLE_BUFFERED_ON_X11(GTK_WIDGET(area), !enabled);
> >      } else
> >  #endif
> >      {
> 
> I would go for a simpler
> 
> diff --git a/src/spice-widget.c b/src/spice-widget.c
> index 00b9562..80be8d4 100644
> --- a/src/spice-widget.c
> +++ b/src/spice-widget.c
> @@ -637,7 +637,6 @@ static void spice_display_init(SpiceDisplay *display)
>                       "signal::realize", drawing_area_realize, display,
>                       NULL);
>      gtk_stack_add_named(d->stack, area, "draw-area");
> -    gtk_widget_set_double_buffered(area, true);
>      gtk_stack_set_visible_child(d->stack, area);
> 
>  #if HAVE_EGL
> @@ -652,7 +651,6 @@ static void spice_display_init(SpiceDisplay *display)
>  #endif
>      area = gtk_drawing_area_new();
>      gtk_stack_add_named(d->stack, area, "gst-area");
> -    gtk_widget_set_double_buffered(area, true);

I just tested this, just to be sure, my removing
gtk_widget_set_double_buffered() and printing the outcome of
gtk_widget_get_double_buffered() and they are enabled by default
indeed.

I checked in glib and seems that the function did not change
after deprecation so it should be good. (note that this does not
exist in git master anymore and the function was removed and the
removal reverted at some point as it broke Apps :D)

I'll update the commit log with some info and send this patch
again.

Cheers,

> 
>      gtk_widget_show_all(widget);
> 
> @@ -1275,7 +1273,9 @@ static void set_egl_enabled(SpiceDisplay *display, bool enabled)
>           * only way I found to prevent glitches when the window is
>           * resized. */
>          GtkWidget *area = gtk_stack_get_child_by_name(d->stack, "draw-area");
> +        G_GNUC_BEGIN_IGNORE_DEPRECATIONS
>          gtk_widget_set_double_buffered(GTK_WIDGET(area), !enabled);
> +        G_GNUC_END_IGNORE_DEPRECATIONS
>      } else
>  #endif
>      {
> 
> 
> As default is TRUE there's no effect setting TRUE again after widgets creation.
> 
> Frediano
-------------- next part --------------
A non-text attachment was scrubbed...
Name: signature.asc
Type: application/pgp-signature
Size: 833 bytes
Desc: not available
URL: <https://lists.freedesktop.org/archives/spice-devel/attachments/20180725/57e71488/attachment.sig>


More information about the Spice-devel mailing list