[libhandy] squeezer: Make it final
- From: Alexander Mikhaylenko <alexm src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [libhandy] squeezer: Make it final
- Date: Wed, 15 Jul 2020 11:28:32 +0000 (UTC)
commit fddd2deaa624bca15093e600f418c1ac06f07d41
Author: Adrien Plazas <kekun plazas laposte net>
Date: Tue Jul 14 21:56:18 2020 +0200
squeezer: Make it final
Fixes https://gitlab.gnome.org/GNOME/libhandy/-/issues/193
src/hdy-squeezer.c | 394 +++++++++++++++++++++++------------------------------
src/hdy-squeezer.h | 11 +-
2 files changed, 170 insertions(+), 235 deletions(-)
---
diff --git a/src/hdy-squeezer.c b/src/hdy-squeezer.c
index 5c40cacb..86050318 100644
--- a/src/hdy-squeezer.c
+++ b/src/hdy-squeezer.c
@@ -78,7 +78,10 @@ typedef struct {
GtkWidget *last_focus;
} HdySqueezerChildInfo;
-typedef struct {
+struct _HdySqueezer
+{
+ GtkContainer parent_instance;
+
GList *children;
GdkWindow* bin_window;
@@ -106,33 +109,28 @@ typedef struct {
gboolean interpolate_size;
GtkOrientation orientation;
-} HdySqueezerPrivate;
+};
static GParamSpec *props[LAST_PROP];
static GParamSpec *child_props[LAST_CHILD_PROP];
G_DEFINE_TYPE_WITH_CODE (HdySqueezer, hdy_squeezer, GTK_TYPE_CONTAINER,
- G_ADD_PRIVATE (HdySqueezer)
G_IMPLEMENT_INTERFACE (GTK_TYPE_ORIENTABLE, NULL))
static GtkOrientation
get_orientation (HdySqueezer *self)
{
- HdySqueezerPrivate *priv = hdy_squeezer_get_instance_private (self);
-
- return priv->orientation;
+ return self->orientation;
}
static void
set_orientation (HdySqueezer *self,
GtkOrientation orientation)
{
- HdySqueezerPrivate *priv = hdy_squeezer_get_instance_private (self);
-
- if (priv->orientation == orientation)
+ if (self->orientation == orientation)
return;
- priv->orientation = orientation;
+ self->orientation = orientation;
gtk_widget_queue_resize (GTK_WIDGET (self));
g_object_notify (G_OBJECT (self), "orientation");
}
@@ -141,11 +139,10 @@ static HdySqueezerChildInfo *
find_child_info_for_widget (HdySqueezer *self,
GtkWidget *child)
{
- HdySqueezerPrivate *priv = hdy_squeezer_get_instance_private (self);
HdySqueezerChildInfo *info;
GList *l;
- for (l = priv->children; l != NULL; l = l->next) {
+ for (l = self->children; l != NULL; l = l->next) {
info = l->data;
if (info->widget == child)
return info;
@@ -157,22 +154,20 @@ find_child_info_for_widget (HdySqueezer *self,
static void
hdy_squeezer_progress_updated (HdySqueezer *self)
{
- HdySqueezerPrivate *priv = hdy_squeezer_get_instance_private (self);
-
gtk_widget_queue_draw (GTK_WIDGET (self));
- if (!priv->homogeneous)
+ if (!self->homogeneous)
gtk_widget_queue_resize (GTK_WIDGET (self));
- if (gtk_progress_tracker_get_state (&priv->tracker) == GTK_PROGRESS_STATE_AFTER) {
- if (priv->last_visible_surface != NULL) {
- cairo_surface_destroy (priv->last_visible_surface);
- priv->last_visible_surface = NULL;
+ if (gtk_progress_tracker_get_state (&self->tracker) == GTK_PROGRESS_STATE_AFTER) {
+ if (self->last_visible_surface != NULL) {
+ cairo_surface_destroy (self->last_visible_surface);
+ self->last_visible_surface = NULL;
}
- if (priv->last_visible_child != NULL) {
- gtk_widget_set_child_visible (priv->last_visible_child->widget, FALSE);
- priv->last_visible_child = NULL;
+ if (self->last_visible_child != NULL) {
+ gtk_widget_set_child_visible (self->last_visible_child->widget, FALSE);
+ self->last_visible_child = NULL;
}
}
}
@@ -183,23 +178,22 @@ hdy_squeezer_transition_cb (GtkWidget *widget,
gpointer user_data)
{
HdySqueezer *self = HDY_SQUEEZER (widget);
- HdySqueezerPrivate *priv = hdy_squeezer_get_instance_private (self);
- if (priv->first_frame_skipped) {
- gtk_progress_tracker_advance_frame (&priv->tracker,
+ if (self->first_frame_skipped) {
+ gtk_progress_tracker_advance_frame (&self->tracker,
gdk_frame_clock_get_frame_time (frame_clock));
} else {
- priv->first_frame_skipped = TRUE;
+ self->first_frame_skipped = TRUE;
}
/* Finish the animation early if the widget isn't mapped anymore. */
if (!gtk_widget_get_mapped (widget))
- gtk_progress_tracker_finish (&priv->tracker);
+ gtk_progress_tracker_finish (&self->tracker);
hdy_squeezer_progress_updated (HDY_SQUEEZER (widget));
- if (gtk_progress_tracker_get_state (&priv->tracker) == GTK_PROGRESS_STATE_AFTER) {
- priv->tick_id = 0;
+ if (gtk_progress_tracker_get_state (&self->tracker) == GTK_PROGRESS_STATE_AFTER) {
+ self->tick_id = 0;
g_object_notify_by_pspec (G_OBJECT (self), props[PROP_TRANSITION_RUNNING]);
return FALSE;
@@ -211,10 +205,8 @@ hdy_squeezer_transition_cb (GtkWidget *widget,
static void
hdy_squeezer_schedule_ticks (HdySqueezer *self)
{
- HdySqueezerPrivate *priv = hdy_squeezer_get_instance_private (self);
-
- if (priv->tick_id == 0) {
- priv->tick_id =
+ if (self->tick_id == 0) {
+ self->tick_id =
gtk_widget_add_tick_callback (GTK_WIDGET (self), hdy_squeezer_transition_cb, self, NULL);
g_object_notify_by_pspec (G_OBJECT (self), props[PROP_TRANSITION_RUNNING]);
}
@@ -223,11 +215,9 @@ hdy_squeezer_schedule_ticks (HdySqueezer *self)
static void
hdy_squeezer_unschedule_ticks (HdySqueezer *self)
{
- HdySqueezerPrivate *priv = hdy_squeezer_get_instance_private (self);
-
- if (priv->tick_id != 0) {
- gtk_widget_remove_tick_callback (GTK_WIDGET (self), priv->tick_id);
- priv->tick_id = 0;
+ if (self->tick_id != 0) {
+ gtk_widget_remove_tick_callback (GTK_WIDGET (self), self->tick_id);
+ self->tick_id = 0;
g_object_notify_by_pspec (G_OBJECT (self), props[PROP_TRANSITION_RUNNING]);
}
}
@@ -237,25 +227,24 @@ hdy_squeezer_start_transition (HdySqueezer *self,
HdySqueezerTransitionType transition_type,
guint transition_duration)
{
- HdySqueezerPrivate *priv = hdy_squeezer_get_instance_private (self);
GtkWidget *widget = GTK_WIDGET (self);
if (gtk_widget_get_mapped (widget) &&
hdy_get_enable_animations (widget) &&
transition_type != HDY_SQUEEZER_TRANSITION_TYPE_NONE &&
transition_duration != 0 &&
- priv->last_visible_child != NULL) {
- priv->active_transition_type = transition_type;
- priv->first_frame_skipped = FALSE;
+ self->last_visible_child != NULL) {
+ self->active_transition_type = transition_type;
+ self->first_frame_skipped = FALSE;
hdy_squeezer_schedule_ticks (self);
- gtk_progress_tracker_start (&priv->tracker,
- priv->transition_duration * 1000,
+ gtk_progress_tracker_start (&self->tracker,
+ self->transition_duration * 1000,
0,
1.0);
} else {
hdy_squeezer_unschedule_ticks (self);
- priv->active_transition_type = HDY_SQUEEZER_TRANSITION_TYPE_NONE;
- gtk_progress_tracker_finish (&priv->tracker);
+ self->active_transition_type = HDY_SQUEEZER_TRANSITION_TYPE_NONE;
+ gtk_progress_tracker_finish (&self->tracker);
}
hdy_squeezer_progress_updated (HDY_SQUEEZER (widget));
@@ -267,7 +256,6 @@ set_visible_child (HdySqueezer *self,
HdySqueezerTransitionType transition_type,
guint transition_duration)
{
- HdySqueezerPrivate *priv = hdy_squeezer_get_instance_private (self);
HdySqueezerChildInfo *info;
GtkWidget *widget = GTK_WIDGET (self);
GList *l;
@@ -283,7 +271,7 @@ set_visible_child (HdySqueezer *self,
/* If none, pick the first visible. */
if (child_info == NULL) {
- for (l = priv->children; l != NULL; l = l->next) {
+ for (l = self->children; l != NULL; l = l->next) {
info = l->data;
if (gtk_widget_get_visible (info->widget)) {
child_info = info;
@@ -292,49 +280,49 @@ set_visible_child (HdySqueezer *self,
}
}
- if (child_info == priv->visible_child)
+ if (child_info == self->visible_child)
return;
toplevel = gtk_widget_get_toplevel (widget);
if (GTK_IS_WINDOW (toplevel)) {
focus = gtk_window_get_focus (GTK_WINDOW (toplevel));
if (focus &&
- priv->visible_child &&
- priv->visible_child->widget &&
- gtk_widget_is_ancestor (focus, priv->visible_child->widget)) {
+ self->visible_child &&
+ self->visible_child->widget &&
+ gtk_widget_is_ancestor (focus, self->visible_child->widget)) {
contains_focus = TRUE;
- if (priv->visible_child->last_focus)
- g_object_remove_weak_pointer (G_OBJECT (priv->visible_child->last_focus),
- (gpointer *)&priv->visible_child->last_focus);
- priv->visible_child->last_focus = focus;
- g_object_add_weak_pointer (G_OBJECT (priv->visible_child->last_focus),
- (gpointer *)&priv->visible_child->last_focus);
+ if (self->visible_child->last_focus)
+ g_object_remove_weak_pointer (G_OBJECT (self->visible_child->last_focus),
+ (gpointer *)&self->visible_child->last_focus);
+ self->visible_child->last_focus = focus;
+ g_object_add_weak_pointer (G_OBJECT (self->visible_child->last_focus),
+ (gpointer *)&self->visible_child->last_focus);
}
}
- if (priv->last_visible_child != NULL)
- gtk_widget_set_child_visible (priv->last_visible_child->widget, FALSE);
- priv->last_visible_child = NULL;
+ if (self->last_visible_child != NULL)
+ gtk_widget_set_child_visible (self->last_visible_child->widget, FALSE);
+ self->last_visible_child = NULL;
- if (priv->last_visible_surface != NULL)
- cairo_surface_destroy (priv->last_visible_surface);
- priv->last_visible_surface = NULL;
+ if (self->last_visible_surface != NULL)
+ cairo_surface_destroy (self->last_visible_surface);
+ self->last_visible_surface = NULL;
- if (priv->visible_child && priv->visible_child->widget) {
+ if (self->visible_child && self->visible_child->widget) {
if (gtk_widget_is_visible (widget)) {
GtkAllocation allocation;
- priv->last_visible_child = priv->visible_child;
- gtk_widget_get_allocated_size (priv->last_visible_child->widget, &allocation, NULL);
- priv->last_visible_widget_width = allocation.width;
- priv->last_visible_widget_height = allocation.height;
+ self->last_visible_child = self->visible_child;
+ gtk_widget_get_allocated_size (self->last_visible_child->widget, &allocation, NULL);
+ self->last_visible_widget_width = allocation.width;
+ self->last_visible_widget_height = allocation.height;
} else {
- gtk_widget_set_child_visible (priv->visible_child->widget, FALSE);
+ gtk_widget_set_child_visible (self->visible_child->widget, FALSE);
}
}
- priv->visible_child = child_info;
+ self->visible_child = child_info;
if (child_info) {
gtk_widget_set_child_visible (child_info->widget, TRUE);
@@ -347,7 +335,7 @@ set_visible_child (HdySqueezer *self,
}
}
- if (priv->homogeneous)
+ if (self->homogeneous)
gtk_widget_queue_allocate (widget);
else
gtk_widget_queue_resize (widget);
@@ -363,22 +351,21 @@ stack_child_visibility_notify_cb (GObject *obj,
gpointer user_data)
{
HdySqueezer *self = HDY_SQUEEZER (user_data);
- HdySqueezerPrivate *priv = hdy_squeezer_get_instance_private (self);
GtkWidget *child = GTK_WIDGET (obj);
HdySqueezerChildInfo *child_info;
child_info = find_child_info_for_widget (self, child);
- if (priv->visible_child == NULL &&
+ if (self->visible_child == NULL &&
gtk_widget_get_visible (child))
- set_visible_child (self, child_info, priv->transition_type, priv->transition_duration);
- else if (priv->visible_child == child_info &&
+ set_visible_child (self, child_info, self->transition_type, self->transition_duration);
+ else if (self->visible_child == child_info &&
!gtk_widget_get_visible (child))
- set_visible_child (self, NULL, priv->transition_type, priv->transition_duration);
+ set_visible_child (self, NULL, self->transition_type, self->transition_duration);
- if (child_info == priv->last_visible_child) {
- gtk_widget_set_child_visible (priv->last_visible_child->widget, FALSE);
- priv->last_visible_child = NULL;
+ if (child_info == self->last_visible_child) {
+ gtk_widget_set_child_visible (self->last_visible_child->widget, FALSE);
+ self->last_visible_child = NULL;
}
}
@@ -387,7 +374,6 @@ hdy_squeezer_add (GtkContainer *container,
GtkWidget *child)
{
HdySqueezer *self = HDY_SQUEEZER (container);
- HdySqueezerPrivate *priv = hdy_squeezer_get_instance_private (self);
HdySqueezerChildInfo *child_info;
g_return_if_fail (child != NULL);
@@ -397,26 +383,26 @@ hdy_squeezer_add (GtkContainer *container,
child_info->enabled = TRUE;
child_info->last_focus = NULL;
- priv->children = g_list_append (priv->children, child_info);
+ self->children = g_list_append (self->children, child_info);
gtk_widget_set_child_visible (child, FALSE);
- gtk_widget_set_parent_window (child, priv->bin_window);
+ gtk_widget_set_parent_window (child, self->bin_window);
gtk_widget_set_parent (child, GTK_WIDGET (self));
- if (priv->bin_window != NULL) {
- gdk_window_set_events (priv->bin_window,
- gdk_window_get_events (priv->bin_window) |
+ if (self->bin_window != NULL) {
+ gdk_window_set_events (self->bin_window,
+ gdk_window_get_events (self->bin_window) |
gtk_widget_get_events (child));
}
g_signal_connect (child, "notify::visible",
G_CALLBACK (stack_child_visibility_notify_cb), self);
- if (priv->visible_child == NULL &&
+ if (self->visible_child == NULL &&
gtk_widget_get_visible (child))
- set_visible_child (self, child_info, priv->transition_type, priv->transition_duration);
+ set_visible_child (self, child_info, self->transition_type, self->transition_duration);
- if (priv->visible_child == child_info)
+ if (self->visible_child == child_info)
gtk_widget_queue_resize (GTK_WIDGET (self));
}
@@ -425,7 +411,6 @@ hdy_squeezer_remove (GtkContainer *container,
GtkWidget *child)
{
HdySqueezer *self = HDY_SQUEEZER (container);
- HdySqueezerPrivate *priv = hdy_squeezer_get_instance_private (self);
HdySqueezerChildInfo *child_info;
gboolean was_visible;
@@ -433,7 +418,7 @@ hdy_squeezer_remove (GtkContainer *container,
if (child_info == NULL)
return;
- priv->children = g_list_remove (priv->children, child_info);
+ self->children = g_list_remove (self->children, child_info);
g_signal_handlers_disconnect_by_func (child,
stack_child_visibility_notify_cb,
@@ -443,11 +428,11 @@ hdy_squeezer_remove (GtkContainer *container,
child_info->widget = NULL;
- if (priv->visible_child == child_info)
- set_visible_child (self, NULL, priv->transition_type, priv->transition_duration);
+ if (self->visible_child == child_info)
+ set_visible_child (self, NULL, self->transition_type, self->transition_duration);
- if (priv->last_visible_child == child_info)
- priv->last_visible_child = NULL;
+ if (self->last_visible_child == child_info)
+ self->last_visible_child = NULL;
gtk_widget_unparent (child);
@@ -457,7 +442,7 @@ hdy_squeezer_remove (GtkContainer *container,
g_slice_free (HdySqueezerChildInfo, child_info);
- if (priv->homogeneous && was_visible)
+ if (self->homogeneous && was_visible)
gtk_widget_queue_resize (GTK_WIDGET (self));
}
@@ -531,7 +516,6 @@ static void
hdy_squeezer_realize (GtkWidget *widget)
{
HdySqueezer *self = HDY_SQUEEZER (widget);
- HdySqueezerPrivate *priv = hdy_squeezer_get_instance_private (self);
GtkAllocation allocation;
GdkWindowAttr attributes = { 0 };
GdkWindowAttributesType attributes_mask;
@@ -554,46 +538,45 @@ hdy_squeezer_realize (GtkWidget *widget)
gtk_widget_get_events (widget);
attributes_mask = (GDK_WA_X | GDK_WA_Y) | GDK_WA_VISUAL;
- priv->view_window =
+ self->view_window =
gdk_window_new (gtk_widget_get_window (GTK_WIDGET (self)),
&attributes, attributes_mask);
- gtk_widget_register_window (widget, priv->view_window);
+ gtk_widget_register_window (widget, self->view_window);
attributes.x = 0;
attributes.y = 0;
attributes.width = allocation.width;
attributes.height = allocation.height;
- for (l = priv->children; l != NULL; l = l->next) {
+ for (l = self->children; l != NULL; l = l->next) {
info = l->data;
attributes.event_mask |= gtk_widget_get_events (info->widget);
}
- priv->bin_window =
- gdk_window_new (priv->view_window, &attributes, attributes_mask);
- gtk_widget_register_window (widget, priv->bin_window);
+ self->bin_window =
+ gdk_window_new (self->view_window, &attributes, attributes_mask);
+ gtk_widget_register_window (widget, self->bin_window);
- for (l = priv->children; l != NULL; l = l->next) {
+ for (l = self->children; l != NULL; l = l->next) {
info = l->data;
- gtk_widget_set_parent_window (info->widget, priv->bin_window);
+ gtk_widget_set_parent_window (info->widget, self->bin_window);
}
- gdk_window_show (priv->bin_window);
+ gdk_window_show (self->bin_window);
}
static void
hdy_squeezer_unrealize (GtkWidget *widget)
{
HdySqueezer *self = HDY_SQUEEZER (widget);
- HdySqueezerPrivate *priv = hdy_squeezer_get_instance_private (self);
- gtk_widget_unregister_window (widget, priv->bin_window);
- gdk_window_destroy (priv->bin_window);
- priv->bin_window = NULL;
- gtk_widget_unregister_window (widget, priv->view_window);
- gdk_window_destroy (priv->view_window);
- priv->view_window = NULL;
+ gtk_widget_unregister_window (widget, self->bin_window);
+ gdk_window_destroy (self->bin_window);
+ self->bin_window = NULL;
+ gtk_widget_unregister_window (widget, self->view_window);
+ gdk_window_destroy (self->view_window);
+ self->view_window = NULL;
GTK_WIDGET_CLASS (hdy_squeezer_parent_class)->unrealize (widget);
}
@@ -602,20 +585,18 @@ static void
hdy_squeezer_map (GtkWidget *widget)
{
HdySqueezer *self = HDY_SQUEEZER (widget);
- HdySqueezerPrivate *priv = hdy_squeezer_get_instance_private (self);
GTK_WIDGET_CLASS (hdy_squeezer_parent_class)->map (widget);
- gdk_window_show (priv->view_window);
+ gdk_window_show (self->view_window);
}
static void
hdy_squeezer_unmap (GtkWidget *widget)
{
HdySqueezer *self = HDY_SQUEEZER (widget);
- HdySqueezerPrivate *priv = hdy_squeezer_get_instance_private (self);
- gdk_window_hide (priv->view_window);
+ gdk_window_hide (self->view_window);
GTK_WIDGET_CLASS (hdy_squeezer_parent_class)->unmap (widget);
}
@@ -627,11 +608,10 @@ hdy_squeezer_forall (GtkContainer *container,
gpointer callback_data)
{
HdySqueezer *self = HDY_SQUEEZER (container);
- HdySqueezerPrivate *priv = hdy_squeezer_get_instance_private (self);
HdySqueezerChildInfo *child_info;
GList *l;
- l = priv->children;
+ l = self->children;
while (l) {
child_info = l->data;
l = l->next;
@@ -646,7 +626,6 @@ hdy_squeezer_compute_expand (GtkWidget *widget,
gboolean *vexpand_p)
{
HdySqueezer *self = HDY_SQUEEZER (widget);
- HdySqueezerPrivate *priv = hdy_squeezer_get_instance_private (self);
gboolean hexpand, vexpand;
HdySqueezerChildInfo *child_info;
GtkWidget *child;
@@ -654,7 +633,7 @@ hdy_squeezer_compute_expand (GtkWidget *widget,
hexpand = FALSE;
vexpand = FALSE;
- for (l = priv->children; l != NULL; l = l->next) {
+ for (l = self->children; l != NULL; l = l->next) {
child_info = l->data;
child = child_info->widget;
@@ -679,12 +658,11 @@ hdy_squeezer_draw_crossfade (GtkWidget *widget,
cairo_t *cr)
{
HdySqueezer *self = HDY_SQUEEZER (widget);
- HdySqueezerPrivate *priv = hdy_squeezer_get_instance_private (self);
- gdouble progress = gtk_progress_tracker_get_progress (&priv->tracker, FALSE);
+ gdouble progress = gtk_progress_tracker_get_progress (&self->tracker, FALSE);
cairo_push_group (cr);
gtk_container_propagate_draw (GTK_CONTAINER (self),
- priv->visible_child->widget,
+ self->visible_child->widget,
cr);
cairo_save (cr);
@@ -693,10 +671,10 @@ hdy_squeezer_draw_crossfade (GtkWidget *widget,
cairo_set_operator (cr, CAIRO_OPERATOR_DEST_IN);
cairo_paint (cr);
- if (priv->last_visible_surface != NULL) {
- cairo_set_source_surface (cr, priv->last_visible_surface,
- priv->last_visible_surface_allocation.x,
- priv->last_visible_surface_allocation.y);
+ if (self->last_visible_surface != NULL) {
+ cairo_set_source_surface (cr, self->last_visible_surface,
+ self->last_visible_surface_allocation.x,
+ self->last_visible_surface_allocation.y);
cairo_set_operator (cr, CAIRO_OPERATOR_ADD);
cairo_paint_with_alpha (cr, MAX (1.0 - progress, 0));
}
@@ -713,9 +691,8 @@ hdy_squeezer_draw (GtkWidget *widget,
cairo_t *cr)
{
HdySqueezer *self = HDY_SQUEEZER (widget);
- HdySqueezerPrivate *priv = hdy_squeezer_get_instance_private (self);
- if (gtk_cairo_should_draw_window (cr, priv->view_window)) {
+ if (gtk_cairo_should_draw_window (cr, self->view_window)) {
GtkStyleContext *context;
context = gtk_widget_get_style_context (widget);
@@ -726,24 +703,24 @@ hdy_squeezer_draw (GtkWidget *widget,
gtk_widget_get_allocated_height (widget));
}
- if (priv->visible_child) {
- if (gtk_progress_tracker_get_state (&priv->tracker) != GTK_PROGRESS_STATE_AFTER) {
- if (priv->last_visible_surface == NULL &&
- priv->last_visible_child != NULL) {
+ if (self->visible_child) {
+ if (gtk_progress_tracker_get_state (&self->tracker) != GTK_PROGRESS_STATE_AFTER) {
+ if (self->last_visible_surface == NULL &&
+ self->last_visible_child != NULL) {
g_autoptr (cairo_t) pattern_cr = NULL;
- gtk_widget_get_allocation (priv->last_visible_child->widget,
- &priv->last_visible_surface_allocation);
- priv->last_visible_surface =
+ gtk_widget_get_allocation (self->last_visible_child->widget,
+ &self->last_visible_surface_allocation);
+ self->last_visible_surface =
gdk_window_create_similar_surface (gtk_widget_get_window (widget),
CAIRO_CONTENT_COLOR_ALPHA,
- priv->last_visible_surface_allocation.width,
- priv->last_visible_surface_allocation.height);
- pattern_cr = cairo_create (priv->last_visible_surface);
+ self->last_visible_surface_allocation.width,
+ self->last_visible_surface_allocation.height);
+ pattern_cr = cairo_create (self->last_visible_surface);
/* We don't use propagate_draw here, because we don't want to apply the
* bin_window offset.
*/
- gtk_widget_draw (priv->last_visible_child->widget, pattern_cr);
+ gtk_widget_draw (self->last_visible_child->widget, pattern_cr);
}
cairo_rectangle (cr,
@@ -752,9 +729,9 @@ hdy_squeezer_draw (GtkWidget *widget,
gtk_widget_get_allocated_height (widget));
cairo_clip (cr);
- switch (priv->active_transition_type) {
+ switch (self->active_transition_type) {
case HDY_SQUEEZER_TRANSITION_TYPE_CROSSFADE:
- if (gtk_cairo_should_draw_window (cr, priv->bin_window))
+ if (gtk_cairo_should_draw_window (cr, self->bin_window))
hdy_squeezer_draw_crossfade (widget, cr);
break;
case HDY_SQUEEZER_TRANSITION_TYPE_NONE:
@@ -762,9 +739,9 @@ hdy_squeezer_draw (GtkWidget *widget,
g_assert_not_reached ();
}
- } else if (gtk_cairo_should_draw_window (cr, priv->bin_window))
+ } else if (gtk_cairo_should_draw_window (cr, self->bin_window))
gtk_container_propagate_draw (GTK_CONTAINER (self),
- priv->visible_child->widget,
+ self->visible_child->widget,
cr);
}
@@ -776,7 +753,6 @@ hdy_squeezer_size_allocate (GtkWidget *widget,
GtkAllocation *allocation)
{
HdySqueezer *self = HDY_SQUEEZER (widget);
- HdySqueezerPrivate *priv = hdy_squeezer_get_instance_private (self);
HdySqueezerChildInfo *child_info = NULL;
GtkWidget *child = NULL;
gint child_min;
@@ -785,7 +761,7 @@ hdy_squeezer_size_allocate (GtkWidget *widget,
gtk_widget_set_allocation (widget, allocation);
- for (l = priv->children; l != NULL; l = l->next) {
+ for (l = self->children; l != NULL; l = l->next) {
child_info = l->data;
child = child_info->widget;
@@ -795,7 +771,7 @@ hdy_squeezer_size_allocate (GtkWidget *widget,
if (!child_info->enabled)
continue;
- if (priv->orientation == GTK_ORIENTATION_VERTICAL) {
+ if (self->orientation == GTK_ORIENTATION_VERTICAL) {
if (gtk_widget_get_request_mode (child) != GTK_SIZE_REQUEST_HEIGHT_FOR_WIDTH)
gtk_widget_get_preferred_height (child, &child_min, NULL);
else
@@ -815,45 +791,45 @@ hdy_squeezer_size_allocate (GtkWidget *widget,
}
set_visible_child (self, child_info,
- priv->transition_type,
- priv->transition_duration);
+ self->transition_type,
+ self->transition_duration);
child_allocation.x = 0;
child_allocation.y = 0;
if (gtk_widget_get_realized (widget)) {
- gdk_window_move_resize (priv->view_window,
+ gdk_window_move_resize (self->view_window,
allocation->x, allocation->y,
allocation->width, allocation->height);
- gdk_window_move_resize (priv->bin_window,
+ gdk_window_move_resize (self->bin_window,
0, 0,
allocation->width, allocation->height);
}
- if (priv->last_visible_child != NULL) {
+ if (self->last_visible_child != NULL) {
int min, nat;
- gtk_widget_get_preferred_width (priv->last_visible_child->widget, &min, &nat);
+ gtk_widget_get_preferred_width (self->last_visible_child->widget, &min, &nat);
child_allocation.width = MAX (min, allocation->width);
- gtk_widget_get_preferred_height_for_width (priv->last_visible_child->widget,
+ gtk_widget_get_preferred_height_for_width (self->last_visible_child->widget,
child_allocation.width,
&min, &nat);
child_allocation.height = MAX (min, allocation->height);
- gtk_widget_size_allocate (priv->last_visible_child->widget, &child_allocation);
+ gtk_widget_size_allocate (self->last_visible_child->widget, &child_allocation);
}
child_allocation.width = allocation->width;
child_allocation.height = allocation->height;
- if (priv->visible_child) {
+ if (self->visible_child) {
int min, nat;
GtkAlign valign;
- gtk_widget_get_preferred_height_for_width (priv->visible_child->widget,
+ gtk_widget_get_preferred_height_for_width (self->visible_child->widget,
allocation->width,
&min, &nat);
- if (priv->interpolate_size) {
- valign = gtk_widget_get_valign (priv->visible_child->widget);
+ if (self->interpolate_size) {
+ valign = gtk_widget_get_valign (self->visible_child->widget);
child_allocation.height = MAX (nat, allocation->height);
if (valign == GTK_ALIGN_END &&
child_allocation.height > allocation->height)
@@ -863,7 +839,7 @@ hdy_squeezer_size_allocate (GtkWidget *widget,
child_allocation.y -= (nat - allocation->height) / 2;
}
- gtk_widget_size_allocate (priv->visible_child->widget, &child_allocation);
+ gtk_widget_size_allocate (self->visible_child->widget, &child_allocation);
}
}
@@ -880,7 +856,6 @@ hdy_squeezer_measure (GtkWidget *widget,
int *natural_baseline)
{
HdySqueezer *self = HDY_SQUEEZER (widget);
- HdySqueezerPrivate *priv = hdy_squeezer_get_instance_private (self);
HdySqueezerChildInfo *child_info;
GtkWidget *child;
gint child_min, child_nat;
@@ -889,12 +864,12 @@ hdy_squeezer_measure (GtkWidget *widget,
*minimum = 0;
*natural = 0;
- for (l = priv->children; l != NULL; l = l->next) {
+ for (l = self->children; l != NULL; l = l->next) {
child_info = l->data;
child = child_info->widget;
- if (priv->orientation != orientation && !priv->homogeneous &&
- priv->visible_child != child_info)
+ if (self->orientation != orientation && !self->homogeneous &&
+ self->visible_child != child_info)
continue;
if (!gtk_widget_get_visible (child))
@@ -918,23 +893,23 @@ hdy_squeezer_measure (GtkWidget *widget,
gtk_widget_get_preferred_width_for_height (child, for_size, &child_min, &child_nat);
}
- if (priv->orientation == orientation)
+ if (self->orientation == orientation)
*minimum = *minimum == 0 ? child_min : MIN (*minimum, child_min);
else
*minimum = MAX (*minimum, child_min);
*natural = MAX (*natural, child_nat);
}
- if (priv->orientation != orientation && !priv->homogeneous &&
- priv->interpolate_size &&
- priv->last_visible_child != NULL) {
- gdouble t = gtk_progress_tracker_get_ease_out_cubic (&priv->tracker, FALSE);
+ if (self->orientation != orientation && !self->homogeneous &&
+ self->interpolate_size &&
+ self->last_visible_child != NULL) {
+ gdouble t = gtk_progress_tracker_get_ease_out_cubic (&self->tracker, FALSE);
if (orientation == GTK_ORIENTATION_VERTICAL) {
- *minimum = hdy_lerp (*minimum, priv->last_visible_widget_height, t);
- *natural = hdy_lerp (*natural, priv->last_visible_widget_height, t);
+ *minimum = hdy_lerp (*minimum, self->last_visible_widget_height, t);
+ *natural = hdy_lerp (*natural, self->last_visible_widget_height, t);
} else {
- *minimum = hdy_lerp (*minimum, priv->last_visible_widget_width, t);
- *natural = hdy_lerp (*natural, priv->last_visible_widget_width, t);
+ *minimum = hdy_lerp (*minimum, self->last_visible_widget_width, t);
+ *natural = hdy_lerp (*natural, self->last_visible_widget_width, t);
}
}
}
@@ -1032,9 +1007,8 @@ static void
hdy_squeezer_dispose (GObject *object)
{
HdySqueezer *self = HDY_SQUEEZER (object);
- HdySqueezerPrivate *priv = hdy_squeezer_get_instance_private (self);
- priv->visible_child = NULL;
+ self->visible_child = NULL;
G_OBJECT_CLASS (hdy_squeezer_parent_class)->dispose (object);
}
@@ -1043,12 +1017,11 @@ static void
hdy_squeezer_finalize (GObject *object)
{
HdySqueezer *self = HDY_SQUEEZER (object);
- HdySqueezerPrivate *priv = hdy_squeezer_get_instance_private (self);
hdy_squeezer_unschedule_ticks (self);
- if (priv->last_visible_surface != NULL)
- cairo_surface_destroy (priv->last_visible_surface);
+ if (self->last_visible_surface != NULL)
+ cairo_surface_destroy (self->last_visible_surface);
G_OBJECT_CLASS (hdy_squeezer_parent_class)->finalize (object);
}
@@ -1148,13 +1121,12 @@ hdy_squeezer_class_init (HdySqueezerClass *klass)
static void
hdy_squeezer_init (HdySqueezer *self)
{
- HdySqueezerPrivate *priv = hdy_squeezer_get_instance_private (self);
gtk_widget_set_has_window (GTK_WIDGET (self), FALSE);
- priv->homogeneous = TRUE;
- priv->transition_duration = 200;
- priv->transition_type = HDY_SQUEEZER_TRANSITION_TYPE_NONE;
+ self->homogeneous = TRUE;
+ self->transition_duration = 200;
+ self->transition_type = HDY_SQUEEZER_TRANSITION_TYPE_NONE;
}
/**
@@ -1185,13 +1157,9 @@ hdy_squeezer_new (void)
gboolean
hdy_squeezer_get_homogeneous (HdySqueezer *self)
{
- HdySqueezerPrivate *priv;
-
g_return_val_if_fail (HDY_IS_SQUEEZER (self), FALSE);
- priv = hdy_squeezer_get_instance_private (self);
-
- return priv->homogeneous;
+ return self->homogeneous;
}
/**
@@ -1211,18 +1179,14 @@ void
hdy_squeezer_set_homogeneous (HdySqueezer *self,
gboolean homogeneous)
{
- HdySqueezerPrivate *priv;
-
g_return_if_fail (HDY_IS_SQUEEZER (self));
- priv = hdy_squeezer_get_instance_private (self);
-
homogeneous = !!homogeneous;
- if (priv->homogeneous == homogeneous)
+ if (self->homogeneous == homogeneous)
return;
- priv->homogeneous = homogeneous;
+ self->homogeneous = homogeneous;
if (gtk_widget_get_visible (GTK_WIDGET(self)))
gtk_widget_queue_resize (GTK_WIDGET (self));
@@ -1242,11 +1206,9 @@ hdy_squeezer_set_homogeneous (HdySqueezer *self,
guint
hdy_squeezer_get_transition_duration (HdySqueezer *self)
{
- HdySqueezerPrivate *priv = hdy_squeezer_get_instance_private (self);
-
g_return_val_if_fail (HDY_IS_SQUEEZER (self), 0);
- return priv->transition_duration;
+ return self->transition_duration;
}
/**
@@ -1260,14 +1222,12 @@ void
hdy_squeezer_set_transition_duration (HdySqueezer *self,
guint duration)
{
- HdySqueezerPrivate *priv = hdy_squeezer_get_instance_private (self);
-
g_return_if_fail (HDY_IS_SQUEEZER (self));
- if (priv->transition_duration == duration)
+ if (self->transition_duration == duration)
return;
- priv->transition_duration = duration;
+ self->transition_duration = duration;
g_object_notify_by_pspec (G_OBJECT (self), props[PROP_TRANSITION_DURATION]);
}
@@ -1283,11 +1243,9 @@ hdy_squeezer_set_transition_duration (HdySqueezer *self,
HdySqueezerTransitionType
hdy_squeezer_get_transition_type (HdySqueezer *self)
{
- HdySqueezerPrivate *priv = hdy_squeezer_get_instance_private (self);
-
g_return_val_if_fail (HDY_IS_SQUEEZER (self), HDY_SQUEEZER_TRANSITION_TYPE_NONE);
- return priv->transition_type;
+ return self->transition_type;
}
/**
@@ -1306,14 +1264,12 @@ void
hdy_squeezer_set_transition_type (HdySqueezer *self,
HdySqueezerTransitionType transition)
{
- HdySqueezerPrivate *priv = hdy_squeezer_get_instance_private (self);
-
g_return_if_fail (HDY_IS_SQUEEZER (self));
- if (priv->transition_type == transition)
+ if (self->transition_type == transition)
return;
- priv->transition_type = transition;
+ self->transition_type = transition;
g_object_notify_by_pspec (G_OBJECT (self), props[PROP_TRANSITION_TYPE]);
}
@@ -1328,11 +1284,9 @@ hdy_squeezer_set_transition_type (HdySqueezer *self,
gboolean
hdy_squeezer_get_transition_running (HdySqueezer *self)
{
- HdySqueezerPrivate *priv = hdy_squeezer_get_instance_private (self);
-
g_return_val_if_fail (HDY_IS_SQUEEZER (self), FALSE);
- return (priv->tick_id != 0);
+ return (self->tick_id != 0);
}
/**
@@ -1350,13 +1304,9 @@ hdy_squeezer_get_transition_running (HdySqueezer *self)
gboolean
hdy_squeezer_get_interpolate_size (HdySqueezer *self)
{
- HdySqueezerPrivate *priv;
-
g_return_val_if_fail (HDY_IS_SQUEEZER (self), FALSE);
- priv = hdy_squeezer_get_instance_private (self);
-
- return priv->interpolate_size;
+ return self->interpolate_size;
}
/**
@@ -1376,18 +1326,14 @@ void
hdy_squeezer_set_interpolate_size (HdySqueezer *self,
gboolean interpolate_size)
{
- HdySqueezerPrivate *priv;
-
g_return_if_fail (HDY_IS_SQUEEZER (self));
- priv = hdy_squeezer_get_instance_private (self);
-
interpolate_size = !!interpolate_size;
- if (priv->interpolate_size == interpolate_size)
+ if (self->interpolate_size == interpolate_size)
return;
- priv->interpolate_size = interpolate_size;
+ self->interpolate_size = interpolate_size;
g_object_notify_by_pspec (G_OBJECT (self), props[PROP_INTERPOLATE_SIZE]);
}
@@ -1403,11 +1349,9 @@ hdy_squeezer_set_interpolate_size (HdySqueezer *self,
GtkWidget *
hdy_squeezer_get_visible_child (HdySqueezer *self)
{
- HdySqueezerPrivate *priv = hdy_squeezer_get_instance_private (self);
-
g_return_val_if_fail (HDY_IS_SQUEEZER (self), NULL);
- return priv->visible_child ? priv->visible_child->widget : NULL;
+ return self->visible_child ? self->visible_child->widget : NULL;
}
/**
diff --git a/src/hdy-squeezer.h b/src/hdy-squeezer.h
index 804eb2fa..e0f21006 100644
--- a/src/hdy-squeezer.h
+++ b/src/hdy-squeezer.h
@@ -17,22 +17,13 @@ G_BEGIN_DECLS
#define HDY_TYPE_SQUEEZER (hdy_squeezer_get_type ())
-G_DECLARE_DERIVABLE_TYPE (HdySqueezer, hdy_squeezer, HDY, SQUEEZER, GtkContainer)
+G_DECLARE_FINAL_TYPE (HdySqueezer, hdy_squeezer, HDY, SQUEEZER, GtkContainer)
typedef enum {
HDY_SQUEEZER_TRANSITION_TYPE_NONE,
HDY_SQUEEZER_TRANSITION_TYPE_CROSSFADE,
} HdySqueezerTransitionType;
-/**
- * HdySqueezerClass
- * @parent_class: The parent class
- */
-struct _HdySqueezerClass
-{
- GtkContainerClass parent_class;
-};
-
GtkWidget *hdy_squeezer_new (void);
gboolean hdy_squeezer_get_homogeneous (HdySqueezer *self);
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]