[libhandy] view-switcher-bar: Make it final
- From: Alexander Mikhaylenko <alexm src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [libhandy] view-switcher-bar: Make it final
- Date: Wed, 15 Jul 2020 11:28:07 +0000 (UTC)
commit cd31709345057be610d8b877fcb09f48d6b53c1d
Author: Adrien Plazas <kekun plazas laposte net>
Date: Tue Jul 14 21:37:17 2020 +0200
view-switcher-bar: Make it final
Fixes https://gitlab.gnome.org/GNOME/libhandy/-/issues/193
src/hdy-view-switcher-bar.c | 87 ++++++++++++++-------------------------------
src/hdy-view-switcher-bar.h | 6 +---
2 files changed, 28 insertions(+), 65 deletions(-)
---
diff --git a/src/hdy-view-switcher-bar.c b/src/hdy-view-switcher-bar.c
index f2445347..32a3cf72 100644
--- a/src/hdy-view-switcher-bar.c
+++ b/src/hdy-view-switcher-bar.c
@@ -75,7 +75,10 @@ enum {
LAST_PROP,
};
-typedef struct {
+struct _HdyViewSwitcherBar
+{
+ GtkBin parent_instance;
+
GtkActionBar *action_bar;
GtkRevealer *revealer;
HdyViewSwitcher *view_switcher;
@@ -83,12 +86,11 @@ typedef struct {
HdyViewSwitcherPolicy policy;
GtkIconSize icon_size;
gboolean reveal;
-} HdyViewSwitcherBarPrivate;
+};
static GParamSpec *props[LAST_PROP];
-G_DEFINE_TYPE_WITH_CODE (HdyViewSwitcherBar, hdy_view_switcher_bar, GTK_TYPE_BIN,
- G_ADD_PRIVATE (HdyViewSwitcherBar))
+G_DEFINE_TYPE (HdyViewSwitcherBar, hdy_view_switcher_bar, GTK_TYPE_BIN)
static void
count_children_cb (GtkWidget *widget,
@@ -99,14 +101,13 @@ count_children_cb (GtkWidget *widget,
static void
update_bar_revealed (HdyViewSwitcherBar *self) {
- HdyViewSwitcherBarPrivate *priv = hdy_view_switcher_bar_get_instance_private (self);
- GtkStack *stack = hdy_view_switcher_get_stack (priv->view_switcher);
+ GtkStack *stack = hdy_view_switcher_get_stack (self->view_switcher);
gint count = 0;
- if (priv->reveal && stack)
+ if (self->reveal && stack)
gtk_container_foreach (GTK_CONTAINER (stack), (GtkCallback) count_children_cb, &count);
- gtk_revealer_set_reveal_child (priv->revealer, count > 1);
+ gtk_revealer_set_reveal_child (self->revealer, count > 1);
}
static void
@@ -236,28 +237,24 @@ hdy_view_switcher_bar_class_init (HdyViewSwitcherBarClass *klass)
gtk_widget_class_set_template_from_resource (widget_class,
"/sm/puri/handy/ui/hdy-view-switcher-bar.ui");
- gtk_widget_class_bind_template_child_private (widget_class, HdyViewSwitcherBar, action_bar);
- gtk_widget_class_bind_template_child_private (widget_class, HdyViewSwitcherBar, view_switcher);
+ gtk_widget_class_bind_template_child (widget_class, HdyViewSwitcherBar, action_bar);
+ gtk_widget_class_bind_template_child (widget_class, HdyViewSwitcherBar, view_switcher);
}
static void
hdy_view_switcher_bar_init (HdyViewSwitcherBar *self)
{
- HdyViewSwitcherBarPrivate *priv;
-
- priv = hdy_view_switcher_bar_get_instance_private (self);
-
/* This must be initialized before the template so the embedded view switcher
* can pick up the correct default value.
*/
- priv->policy = HDY_VIEW_SWITCHER_POLICY_NARROW;
- priv->icon_size = GTK_ICON_SIZE_BUTTON;
+ self->policy = HDY_VIEW_SWITCHER_POLICY_NARROW;
+ self->icon_size = GTK_ICON_SIZE_BUTTON;
gtk_widget_init_template (GTK_WIDGET (self));
- priv->revealer = GTK_REVEALER (gtk_bin_get_child (GTK_BIN (priv->action_bar)));
+ self->revealer = GTK_REVEALER (gtk_bin_get_child (GTK_BIN (self->action_bar)));
update_bar_revealed (self);
- gtk_revealer_set_transition_type (priv->revealer, GTK_REVEALER_TRANSITION_TYPE_SLIDE_UP);
+ gtk_revealer_set_transition_type (self->revealer, GTK_REVEALER_TRANSITION_TYPE_SLIDE_UP);
}
/**
@@ -288,13 +285,9 @@ hdy_view_switcher_bar_new (void)
HdyViewSwitcherPolicy
hdy_view_switcher_bar_get_policy (HdyViewSwitcherBar *self)
{
- HdyViewSwitcherBarPrivate *priv;
-
g_return_val_if_fail (HDY_IS_VIEW_SWITCHER_BAR (self), HDY_VIEW_SWITCHER_POLICY_NARROW);
- priv = hdy_view_switcher_bar_get_instance_private (self);
-
- return priv->policy;
+ return self->policy;
}
/**
@@ -310,16 +303,12 @@ void
hdy_view_switcher_bar_set_policy (HdyViewSwitcherBar *self,
HdyViewSwitcherPolicy policy)
{
- HdyViewSwitcherBarPrivate *priv;
-
g_return_if_fail (HDY_IS_VIEW_SWITCHER_BAR (self));
- priv = hdy_view_switcher_bar_get_instance_private (self);
-
- if (priv->policy == policy)
+ if (self->policy == policy)
return;
- priv->policy = policy;
+ self->policy = policy;
g_object_notify_by_pspec (G_OBJECT (self), props[PROP_POLICY]);
@@ -339,13 +328,9 @@ hdy_view_switcher_bar_set_policy (HdyViewSwitcherBar *self,
GtkIconSize
hdy_view_switcher_bar_get_icon_size (HdyViewSwitcherBar *self)
{
- HdyViewSwitcherBarPrivate *priv;
-
g_return_val_if_fail (HDY_IS_VIEW_SWITCHER_BAR (self), GTK_ICON_SIZE_BUTTON);
- priv = hdy_view_switcher_bar_get_instance_private (self);
-
- return priv->icon_size;
+ return self->icon_size;
}
/**
@@ -361,16 +346,12 @@ void
hdy_view_switcher_bar_set_icon_size (HdyViewSwitcherBar *self,
GtkIconSize icon_size)
{
- HdyViewSwitcherBarPrivate *priv;
-
g_return_if_fail (HDY_IS_VIEW_SWITCHER_BAR (self));
- priv = hdy_view_switcher_bar_get_instance_private (self);
-
- if (priv->icon_size == icon_size)
+ if (self->icon_size == icon_size)
return;
- priv->icon_size = icon_size;
+ self->icon_size = icon_size;
g_object_notify_by_pspec (G_OBJECT (self), props[PROP_ICON_SIZE]);
}
@@ -388,13 +369,9 @@ hdy_view_switcher_bar_set_icon_size (HdyViewSwitcherBar *self,
GtkStack *
hdy_view_switcher_bar_get_stack (HdyViewSwitcherBar *self)
{
- HdyViewSwitcherBarPrivate *priv;
-
g_return_val_if_fail (HDY_IS_VIEW_SWITCHER_BAR (self), NULL);
- priv = hdy_view_switcher_bar_get_instance_private (self);
-
- return hdy_view_switcher_get_stack (priv->view_switcher);
+ return hdy_view_switcher_get_stack (self->view_switcher);
}
/**
@@ -410,14 +387,12 @@ void
hdy_view_switcher_bar_set_stack (HdyViewSwitcherBar *self,
GtkStack *stack)
{
- HdyViewSwitcherBarPrivate *priv;
GtkStack *previous_stack;
g_return_if_fail (HDY_IS_VIEW_SWITCHER_BAR (self));
g_return_if_fail (stack == NULL || GTK_IS_STACK (stack));
- priv = hdy_view_switcher_bar_get_instance_private (self);
- previous_stack = hdy_view_switcher_get_stack (priv->view_switcher);
+ previous_stack = hdy_view_switcher_get_stack (self->view_switcher);
if (previous_stack == stack)
return;
@@ -425,7 +400,7 @@ hdy_view_switcher_bar_set_stack (HdyViewSwitcherBar *self,
if (previous_stack)
g_signal_handlers_disconnect_by_func (previous_stack, G_CALLBACK (update_bar_revealed), self);
- hdy_view_switcher_set_stack (priv->view_switcher, stack);
+ hdy_view_switcher_set_stack (self->view_switcher, stack);
if (stack) {
g_signal_connect_swapped (stack, "add", G_CALLBACK (update_bar_revealed), self);
@@ -450,13 +425,9 @@ hdy_view_switcher_bar_set_stack (HdyViewSwitcherBar *self,
gboolean
hdy_view_switcher_bar_get_reveal (HdyViewSwitcherBar *self)
{
- HdyViewSwitcherBarPrivate *priv;
-
g_return_val_if_fail (HDY_IS_VIEW_SWITCHER_BAR (self), FALSE);
- priv = hdy_view_switcher_bar_get_instance_private (self);
-
- return priv->reveal;
+ return self->reveal;
}
/**
@@ -472,18 +443,14 @@ void
hdy_view_switcher_bar_set_reveal (HdyViewSwitcherBar *self,
gboolean reveal)
{
- HdyViewSwitcherBarPrivate *priv;
-
g_return_if_fail (HDY_IS_VIEW_SWITCHER_BAR (self));
- priv = hdy_view_switcher_bar_get_instance_private (self);
-
reveal = !!reveal;
- if (priv->reveal == reveal)
+ if (self->reveal == reveal)
return;
- priv->reveal = reveal;
+ self->reveal = reveal;
update_bar_revealed (self);
g_object_notify_by_pspec (G_OBJECT (self), props[PROP_REVEAL]);
diff --git a/src/hdy-view-switcher-bar.h b/src/hdy-view-switcher-bar.h
index 289fd688..88e26fa0 100644
--- a/src/hdy-view-switcher-bar.h
+++ b/src/hdy-view-switcher-bar.h
@@ -19,11 +19,7 @@ G_BEGIN_DECLS
#define HDY_TYPE_VIEW_SWITCHER_BAR (hdy_view_switcher_bar_get_type())
-struct _HdyViewSwitcherBarClass {
- GtkBinClass parent_class;
-};
-
-G_DECLARE_DERIVABLE_TYPE (HdyViewSwitcherBar, hdy_view_switcher_bar, HDY, VIEW_SWITCHER_BAR, GtkBin)
+G_DECLARE_FINAL_TYPE (HdyViewSwitcherBar, hdy_view_switcher_bar, HDY, VIEW_SWITCHER_BAR, GtkBin)
GtkWidget *hdy_view_switcher_bar_new (void);
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]