[virt-tools-list] [virt-viewer v2 3/4] timed-revealer: Inherit from GtkEventBox

Christophe Fergeau cfergeau at redhat.com
Tue Jun 28 15:30:26 UTC 2016


Acked-by: Christophe Fergeau <cfergeau at redhat.com>

On Tue, Jun 28, 2016 at 05:23:01PM +0200, Fabiano Fidêncio wrote:
> As suggested by Christophe, inheriting from GtkEventBox instead of
> having one instance of it as a member can help us to get rid of
> virt_viewer_timed_revealer_get_overlay_widget().
> ---
>  src/virt-viewer-timed-revealer.c | 35 ++++++++++++-----------------------
>  src/virt-viewer-timed-revealer.h |  7 ++-----
>  src/virt-viewer-window.c         |  5 ++---
>  3 files changed, 16 insertions(+), 31 deletions(-)
> 
> diff --git a/src/virt-viewer-timed-revealer.c b/src/virt-viewer-timed-revealer.c
> index 61b2d20..7892436 100644
> --- a/src/virt-viewer-timed-revealer.c
> +++ b/src/virt-viewer-timed-revealer.c
> @@ -25,7 +25,7 @@
>  
>  #include "virt-viewer-timed-revealer.h"
>  
> -G_DEFINE_TYPE (VirtViewerTimedRevealer, virt_viewer_timed_revealer, G_TYPE_OBJECT)
> +G_DEFINE_TYPE (VirtViewerTimedRevealer, virt_viewer_timed_revealer, GTK_TYPE_EVENT_BOX)
>  
>  #define VIRT_VIEWER_TIMED_REVEALER_GET_PRIVATE(obj) \
>      (G_TYPE_INSTANCE_GET_PRIVATE ((obj), VIRT_VIEWER_TYPE_TIMED_REVEALER, VirtViewerTimedRevealerPrivate))
> @@ -36,7 +36,6 @@ struct _VirtViewerTimedRevealerPrivate
>      guint timeout_id;
>  
>      GtkWidget *revealer;
> -    GtkWidget *evBox;
>  };
>  
>  static void
> @@ -76,9 +75,9 @@ virt_viewer_timed_revealer_schedule_unreveal_timeout(VirtViewerTimedRevealer *se
>  }
>  
>  static gboolean
> -virt_viewer_timed_revealer_enter_leave_notify(GtkWidget *evBox,
> +virt_viewer_timed_revealer_enter_leave_notify(VirtViewerTimedRevealer *self,
>                                                GdkEventCrossing *event,
> -                                              VirtViewerTimedRevealer *self)
> +                                              gpointer user_data G_GNUC_UNUSED)
>  {
>      VirtViewerTimedRevealerPrivate *priv = self->priv;
>      GdkDevice *device;
> @@ -92,7 +91,7 @@ virt_viewer_timed_revealer_enter_leave_notify(GtkWidget *evBox,
>      device = gdk_event_get_device((GdkEvent *)event);
>  
>      gdk_window_get_device_position(event->window, device, &x, &y, 0);
> -    gtk_widget_get_allocation(evBox, &allocation);
> +    gtk_widget_get_allocation(GTK_WIDGET(self), &allocation);
>  
>      entered = !!(x >= 0 && y >= 0 && x < allocation.width && y < allocation.height);
>  
> @@ -125,7 +124,6 @@ virt_viewer_timed_revealer_dispose(GObject *object)
>      VirtViewerTimedRevealer *self = VIRT_VIEWER_TIMED_REVEALER(object);
>      VirtViewerTimedRevealerPrivate *priv = self->priv;
>  
> -    priv->evBox = NULL;
>      priv->revealer = NULL;
>  
>      if (priv->timeout_id) {
> @@ -170,20 +168,19 @@ virt_viewer_timed_revealer_new(GtkWidget *toolbar)
>       * the hidden toolbar.
>       */
>  
> -    priv->evBox = gtk_event_box_new();
> -    gtk_container_add(GTK_CONTAINER(priv->evBox), priv->revealer);
> -    gtk_widget_set_halign(priv->evBox, GTK_ALIGN_CENTER);
> -    gtk_widget_set_valign(priv->evBox, GTK_ALIGN_START);
> -    gtk_widget_show_all(priv->evBox);
> +    gtk_container_add(GTK_CONTAINER(self), priv->revealer);
> +    gtk_widget_set_halign(GTK_WIDGET(self), GTK_ALIGN_CENTER);
> +    gtk_widget_set_valign(GTK_WIDGET(self), GTK_ALIGN_START);
> +    gtk_widget_show_all(GTK_WIDGET(self));
>  
> -    g_signal_connect(priv->evBox,
> +    g_signal_connect(self,
>                       "enter-notify-event",
>                       G_CALLBACK(virt_viewer_timed_revealer_enter_leave_notify),
> -                     self);
> -    g_signal_connect(priv->evBox,
> +                     NULL);
> +    g_signal_connect(self,
>                       "leave-notify-event",
>                       G_CALLBACK(virt_viewer_timed_revealer_enter_leave_notify),
> -                     self);
> +                     NULL);
>  
>      return self;
>  }
> @@ -203,11 +200,3 @@ virt_viewer_timed_revealer_force_reveal(VirtViewerTimedRevealer *self,
>      gtk_revealer_set_reveal_child(GTK_REVEALER(priv->revealer), fullscreen);
>      virt_viewer_timed_revealer_schedule_unreveal_timeout(self, 2000);
>  }
> -
> -GtkWidget *
> -virt_viewer_timed_revealer_get_overlay_widget(VirtViewerTimedRevealer *self)
> -{
> -    g_return_val_if_fail(VIRT_VIEWER_IS_TIMED_REVEALER(self), NULL);
> -
> -    return self->priv->evBox;
> -}
> diff --git a/src/virt-viewer-timed-revealer.h b/src/virt-viewer-timed-revealer.h
> index 6720a63..2305952 100644
> --- a/src/virt-viewer-timed-revealer.h
> +++ b/src/virt-viewer-timed-revealer.h
> @@ -49,12 +49,12 @@ G_BEGIN_DECLS
>  typedef struct _VirtViewerTimedRevealerPrivate VirtViewerTimedRevealerPrivate;
>  
>  typedef struct {
> -    GObject parent;
> +    GtkEventBox parent;
>      VirtViewerTimedRevealerPrivate *priv;
>  } VirtViewerTimedRevealer;
>  
>  typedef struct {
> -    GObjectClass parent_class;
> +    GtkEventBoxClass parent_class;
>  } VirtViewerTimedRevealerClass;
>  
>  GType virt_viewer_timed_revealer_get_type (void);
> @@ -66,9 +66,6 @@ void
>  virt_viewer_timed_revealer_force_reveal(VirtViewerTimedRevealer *self,
>                                          gboolean fullscreen);
>  
> -GtkWidget *
> -virt_viewer_timed_revealer_get_overlay_widget(VirtViewerTimedRevealer *self);
> -
>  G_END_DECLS
>  
>  #endif /* _VIRT_VIEWER_TIMED_REVEALER_H */
> diff --git a/src/virt-viewer-window.c b/src/virt-viewer-window.c
> index 1ebb423..bf48516 100644
> --- a/src/virt-viewer-window.c
> +++ b/src/virt-viewer-window.c
> @@ -188,7 +188,7 @@ virt_viewer_window_dispose (GObject *object)
>          priv->builder = NULL;
>      }
>  
> -    g_clear_object(&priv->revealer);
> +    priv->revealer = NULL;
>  
>      for (it = priv->accel_list ; it != NULL ; it = it->next) {
>          g_object_unref(G_OBJECT(it->data));
> @@ -1115,8 +1115,7 @@ virt_viewer_window_toolbar_setup(VirtViewerWindow *self)
>  
>      priv->revealer = virt_viewer_timed_revealer_new(priv->toolbar);
>      overlay = GTK_WIDGET(gtk_builder_get_object(priv->builder, "viewer-overlay"));
> -    gtk_overlay_add_overlay(GTK_OVERLAY(overlay),
> -                            virt_viewer_timed_revealer_get_overlay_widget(priv->revealer));
> +    gtk_overlay_add_overlay(GTK_OVERLAY(overlay), GTK_WIDGET(priv->revealer));
>  }
>  
>  VirtViewerNotebook*
> -- 
> 2.7.4
> 
> _______________________________________________
> virt-tools-list mailing list
> virt-tools-list at redhat.com
> https://www.redhat.com/mailman/listinfo/virt-tools-list
-------------- next part --------------
A non-text attachment was scrubbed...
Name: signature.asc
Type: application/pgp-signature
Size: 819 bytes
Desc: not available
URL: <http://listman.redhat.com/archives/virt-tools-list/attachments/20160628/9326dc20/attachment.sig>


More information about the virt-tools-list mailing list