[gtk+/wip/csoriano/pathbar-bin-view-window] f



commit de2240a9a26950946f91e39c4fd47f609b4763a8
Author: Carlos Soriano <csoriano gnome org>
Date:   Thu Jun 9 14:33:59 2016 +0200

    f

 gtk/gtkhidingbox.c |  213 ++++++++++++++++++++++++---------------------------
 1 files changed, 100 insertions(+), 113 deletions(-)
---
diff --git a/gtk/gtkhidingbox.c b/gtk/gtkhidingbox.c
index 50c0f13..61c5854 100644
--- a/gtk/gtkhidingbox.c
+++ b/gtk/gtkhidingbox.c
@@ -38,6 +38,7 @@
 
 #define REVEALER_ANIMATION_TIME 250 //ms
 #define INVERT_ANIMATION_SPEED 1.2 //px/ms
+#define INVERT_ANIMATION_MAX_TIME 750 //px/ms
 
 struct _GtkHidingBoxPrivate
 {
@@ -177,6 +178,7 @@ unrevealed_really_remove_child (GObject    *widget,
   GtkHidingBox *self = GTK_HIDING_BOX (user_data);
 
   g_print ("unrevelaed really remove child %p %s\n", widget, G_OBJECT_TYPE_NAME (widget));
+  g_signal_handlers_disconnect_by_func (widget, unrevealed_really_remove_child, self);
   really_remove_child (self, gtk_bin_get_child (GTK_BIN (widget)));
 }
 
@@ -326,7 +328,7 @@ add_opacity_class (GtkWidget   *widget,
 }
 
 static void
-remove_all_opacity_classes (GtkWidget *widget)
+remove_opacity_classes (GtkWidget *widget)
 {
   GtkStyleContext *style_context;
 
@@ -340,30 +342,32 @@ remove_all_opacity_classes (GtkWidget *widget)
 }
 
 static void
-opacity_on (GObject    *widget,
-            GParamSpec *pspec,
-            gpointer    user_data)
+revealer_on_show_completed (GObject    *widget,
+                            GParamSpec *pspec,
+                            gpointer    user_data)
 {
   GtkHidingBoxPrivate *priv = gtk_hiding_box_get_instance_private (GTK_HIDING_BOX (user_data));
 
   g_print ("opacity on!!!!!\n");
-  g_signal_handlers_disconnect_by_func (widget, opacity_on, user_data);
+  remove_opacity_classes (GTK_WIDGET (widget));
+  g_signal_handlers_disconnect_by_func (widget, revealer_on_show_completed, user_data);
   priv->widgets_to_show = g_list_remove (priv->widgets_to_show,
                                          gtk_bin_get_child (GTK_BIN (widget)));
-  remove_all_opacity_classes (GTK_WIDGET (widget));
 }
 
 static void
-opacity_off (GObject    *widget,
+revealer_on_hide_completed (GObject    *widget,
              GParamSpec *pspec,
              gpointer    user_data)
 {
   GtkHidingBoxPrivate *priv = gtk_hiding_box_get_instance_private (GTK_HIDING_BOX (user_data));
 
   g_print ("opacity off!!!!!\n");
-  g_signal_handlers_disconnect_by_func (widget, opacity_off, user_data);
-  priv->widgets_to_hide = g_list_remove (priv->widgets_to_hide, gtk_bin_get_child (GTK_BIN (widget)));
-  remove_all_opacity_classes (GTK_WIDGET (widget));
+  remove_opacity_classes (GTK_WIDGET (widget));
+  g_signal_handlers_disconnect_by_func (widget, revealer_on_hide_completed,
+                                        user_data);
+  priv->widgets_to_hide = g_list_remove (priv->widgets_to_hide,
+                                         gtk_bin_get_child (GTK_BIN (widget)));
 }
 
 static void
@@ -371,55 +375,28 @@ idle_update_revealers (GtkHidingBox *self)
 {
   GtkHidingBoxPrivate *priv = gtk_hiding_box_get_instance_private (self);
   GList *l;
-  GList *widgets_to_hide_copy;
 
-  g_print ("UPDATE REVEALERS\n");
-  widgets_to_hide_copy = g_list_copy (priv->widgets_to_hide);
-  for (l = widgets_to_hide_copy; l != NULL; l = l->next)
+  /* The invert animation is handled in a tick callback, do nothing here */
+  if (priv->invert_animation)
+    return;
+
+  for (l = priv->widgets_to_hide; l != NULL; l = l->next)
     {
       GtkWidget *revealer;
 
       revealer = gtk_widget_get_parent (l->data);
-      g_print ("widget to hide %s\n", gtk_button_get_label (GTK_BUTTON (l->data)));
       if (gtk_revealer_get_child_revealed (GTK_REVEALER (revealer)) &&
           gtk_revealer_get_reveal_child (GTK_REVEALER (revealer)))
         {
-          remove_all_opacity_classes (revealer);
-          if (priv->invert_animation && priv->invert_animation_progress >= 1)
-            {
-              gdouble velocity = INVERT_ANIMATION_SPEED; // px / ms
-              gint revealer_animation_time;
-
-              add_opacity_class (revealer, "pathbar-invert-animation-opacity-off");
-  g_signal_handlers_disconnect_by_func (revealer, opacity_off, self);
-              g_signal_connect (revealer, "notify::child-revealed", (GCallback) opacity_off, self);
-              gtk_revealer_set_transition_duration (GTK_REVEALER (revealer),
-                                                    priv->inverted ? 0 :
-                                                                     REVEALER_ANIMATION_TIME);
-
-              gtk_revealer_set_reveal_child (GTK_REVEALER (revealer), FALSE);
-              g_print ("~~~~~~~~ finishing\n");
-            }
-          else if (!priv->invert_animation)
-            {
-              add_opacity_class (revealer, "pathbar-opacity-off");
-  g_signal_handlers_disconnect_by_func (revealer, opacity_off, self);
-              g_signal_connect (revealer, "notify::child-revealed", (GCallback) opacity_off, self);
-              gtk_revealer_set_reveal_child (GTK_REVEALER (revealer), FALSE);
-              g_print ("~~~~~~~~ NOT finishing\n");
-            }
-#if 0
-          if (!priv->invert_animation)
-            {
-              add_opacity_class (revealer, "pathbar-opacity-off");
-              g_signal_connect (revealer, "notify::child-revealed", (GCallback) opacity_off, box);
-              gtk_revealer_set_transition_duration (GTK_REVEALER (revealer), REVEALER_ANIMATION_TIME);
-              gtk_revealer_set_reveal_child (GTK_REVEALER (revealer), FALSE);
-            }
-#endif
+          g_signal_handlers_disconnect_by_func (revealer, revealer_on_hide_completed, self);
+          g_signal_connect (revealer, "notify::child-revealed", (GCallback) revealer_on_hide_completed, 
self);
+
+          remove_opacity_classes (revealer);
+          add_opacity_class (revealer, "pathbar-opacity-off");
+
+          gtk_revealer_set_reveal_child (GTK_REVEALER (revealer), FALSE);
         }
     }
-  g_list_free (widgets_to_hide_copy);
 
   for (l = priv->widgets_to_remove; l != NULL; l = l->next)
     {
@@ -428,20 +405,24 @@ idle_update_revealers (GtkHidingBox *self)
       revealer = gtk_widget_get_parent (l->data);
       if (gtk_revealer_get_child_revealed (GTK_REVEALER (revealer)))
         {
-          remove_all_opacity_classes (revealer);
-          add_opacity_class (revealer, "pathbar-opacity-off");
+          g_signal_handlers_disconnect_by_func (revealer, revealer_on_hide_completed, self);
           g_signal_connect (revealer, "notify::child-revealed",
                             (GCallback) unrevealed_really_remove_child, self);
-          gtk_revealer_set_transition_duration (GTK_REVEALER (revealer), REVEALER_ANIMATION_TIME);
+
+          remove_opacity_classes (revealer);
+          add_opacity_class (revealer, "pathbar-opacity-off");
+
           gtk_revealer_set_reveal_child (GTK_REVEALER (revealer), FALSE);
         }
       else
         {
-          g_print ("widget to remove NOT revealed %p\n", l->data);
           really_remove_child (self, l->data);
         }
     }
 
+  /* We want to defer to show revealers until the animation of those that needs
+   * to be hidden or removed are done
+   */
   if (priv->widgets_to_remove || priv->widgets_to_hide)
     return;
 
@@ -452,14 +433,13 @@ idle_update_revealers (GtkHidingBox *self)
       revealer = gtk_widget_get_parent (l->data);
       if (!gtk_revealer_get_reveal_child (GTK_REVEALER (revealer)))
         {
-          remove_all_opacity_classes (revealer);
+          g_signal_handlers_disconnect_by_func (revealer, revealer_on_show_completed, self);
+          g_signal_connect (revealer, "notify::child-revealed", (GCallback) revealer_on_show_completed, 
self);
+
+          remove_opacity_classes (revealer);
           add_opacity_class (revealer, "pathbar-opacity-on");
-          if (priv->invert_animation)
-            gtk_revealer_set_transition_duration (GTK_REVEALER (revealer), REVEALER_ANIMATION_TIME);
-          else
-            gtk_revealer_set_transition_duration (GTK_REVEALER (revealer), REVEALER_ANIMATION_TIME);
+
           gtk_revealer_set_reveal_child (GTK_REVEALER (revealer), TRUE);
-          g_signal_connect (revealer, "notify::child-revealed", (GCallback) opacity_on, self);
         }
     }
 
@@ -470,26 +450,26 @@ get_max_scroll (GtkHidingBox *self)
 {
   GtkHidingBoxPrivate *priv = gtk_hiding_box_get_instance_private (self);
   GtkAllocation *used_children_allocation;
-  gint child_width;
+  gint children_width;
   gdouble max_scroll;
 
   used_children_allocation = get_children_allocation (self, TRUE);
-  child_width = gtk_widget_get_allocated_width (priv->box);
-  g_print ("get max scroll %d %d\n", used_children_allocation->width, child_width);
+  children_width = gtk_widget_get_allocated_width (priv->box);
+
   if (priv->invert_animation)
     {
       if (priv->inverted)
         {
-          max_scroll = MAX (0, child_width - used_children_allocation->width);
+          max_scroll = MAX (0, children_width - used_children_allocation->width);
         }
       else
         {
-          max_scroll = child_width - used_children_allocation->width;
+          max_scroll = children_width - used_children_allocation->width;
         }
     }
   else
     {
-      max_scroll = MAX (0, child_width - used_children_allocation->width);
+      max_scroll = MAX (0, children_width - used_children_allocation->width);
     }
 
   return max_scroll;
@@ -507,39 +487,26 @@ update_scrolling (GtkHidingBox *self)
   gtk_widget_get_allocation (GTK_WIDGET (self), &allocation);
   gtk_widget_get_allocation (priv->box, &child_allocation);
   max_scroll = get_max_scroll (self);
+
   if (gtk_widget_get_realized (GTK_WIDGET (self)))
     {
       if (priv->invert_animation)
         {
+          /* We only move the window to the left of the allocation, so negative values */
           if (priv->inverted)
-            {
-              scroll_value = priv->invert_animation_progress * max_scroll;
-            }
+            scroll_value = - priv->invert_animation_progress * max_scroll;
           else
-            {
-              scroll_value = (1 - priv->invert_animation_progress) * max_scroll;
-            }
+            scroll_value = - (1 - priv->invert_animation_progress) * max_scroll;
         }
       else
         {
-          if (priv->inverted)
-            {
-              scroll_value = 0;
-            }
-          else
-            {
-              scroll_value = 0;
-            }
+          scroll_value = 0;
         }
 
       gdk_window_move_resize (priv->bin_window,
-                              -scroll_value, 0,
+                              scroll_value, 0,
                               child_allocation.width, child_allocation.height);
-
-        g_print ("update scrolling %d %d\n", max_scroll, scroll_value);
     }
-
-  gtk_widget_queue_resize (self);
 }
 
 static void
@@ -574,10 +541,7 @@ gtk_hiding_box_size_allocate (GtkWidget     *widget,
       gdk_window_move_resize (priv->view_window,
                               allocation->x, allocation->y,
                               allocation->width, allocation->height);
-        g_print ("view window %d %d", allocation->width, allocation->height);
       gdk_window_show (priv->view_window);
-
-      g_print ("visibles? %d %d\n", gdk_window_is_visible (priv->bin_window), gdk_window_is_visible 
(priv->view_window));
     }
 }
 
@@ -586,28 +550,46 @@ finish_invert_animation (GtkHidingBox *self)
 {
   GtkHidingBoxPrivate *priv = gtk_hiding_box_get_instance_private (self);
   GtkAllocation allocation;
-  GList *child;
+  GList *widgets_to_hide_copy;
+  GList *l;
 
-  g_print ("\n\n\n\n\n\n\n\n##################ss#######finish invert animation\n\n\n\n\n\n\n");
-  gtk_widget_get_allocation (self, &allocation);
+  /* Hide the revealers that need to be hidden now. */
   update_children_visibility (self, &allocation);
-  idle_update_revealers (self);
+  widgets_to_hide_copy = g_list_copy (priv->widgets_to_hide);
+  for (l = widgets_to_hide_copy; l != NULL; l = l->next)
+    {
+      GtkWidget *revealer;
+      double animation_time;
+
+      revealer = gtk_widget_get_parent (l->data);
+      remove_opacity_classes (revealer);
+
+      add_opacity_class (revealer, "pathbar-invert-animation-opacity-off");
+      g_signal_handlers_disconnect_by_func (revealer, revealer_on_hide_completed, self);
+      g_signal_connect (revealer, "notify::child-revealed", (GCallback) revealer_on_hide_completed, self);
+
+      /* If the animation we just did was to the inverted state, we
+       * have the revealers that need to be hidden out of the view, so
+       * there's no point on animating them.
+       * Not only that, we want to update the scroll in a way that takes
+       * into account the state when the animation is finished, if not
+       * we are going to show the animation of the revealers next time
+       * the scroll is updated
+       */
+      animation_time =  priv->inverted ? 0 : REVEALER_ANIMATION_TIME;
+      gtk_revealer_set_transition_duration (GTK_REVEALER (revealer),
+                                            animation_time);
+      gtk_revealer_set_reveal_child (GTK_REVEALER (revealer), FALSE);
+      gtk_revealer_set_transition_duration (GTK_REVEALER (revealer),
+                                            REVEALER_ANIMATION_TIME);
+    }
+
   priv->invert_animation = FALSE;
   priv->invert_animation_progress = 0;
   priv->invert_animation_initial_time = 0;
   gtk_widget_remove_tick_callback (priv->box,
                                    priv->invert_animation_tick_id);
   priv->invert_animation_tick_id = 0;
-
-  gtk_widget_queue_resize (self);
-  for (child = priv->children; child != NULL; child = child->next)
-    {
-      GtkWidget *revealer;
-
-      revealer = gtk_widget_get_parent (GTK_WIDGET (child->data));
-      gtk_widget_queue_resize (revealer);
-    }
-  gtk_widget_queue_resize (priv->box);
 }
 
 
@@ -620,25 +602,35 @@ invert_animation_on_tick (GtkWidget     *widget,
   GtkHidingBoxPrivate *priv = gtk_hiding_box_get_instance_private (self);
   guint64 elapsed;
   gint max_scroll;
+  double animation_speed;
   GtkAllocation *used_children_allocation;
   GtkAllocation child_allocation;
   GtkAllocation allocation;
 
+  /* Initialize the frame clock the first time this is called */
   if (priv->invert_animation_initial_time == 0)
     priv->invert_animation_initial_time = gdk_frame_clock_get_frame_time (frame_clock);
 
   gtk_widget_get_allocation (GTK_WIDGET (self), &allocation);
   gtk_widget_get_allocation (priv->box, &child_allocation);
   used_children_allocation = get_children_allocation (self, TRUE);
+
   max_scroll = get_max_scroll (self);
   if (!max_scroll)
     return TRUE;
 
+  /* If there are several items the animation can take some time, so let's limit
+   * it to some extend
+   */
+  if (max_scroll / INVERT_ANIMATION_SPEED > INVERT_ANIMATION_MAX_TIME)
+    animation_speed = max_scroll / INVERT_ANIMATION_MAX_TIME;
+  else
+    animation_speed = INVERT_ANIMATION_SPEED;
+
   elapsed = gdk_frame_clock_get_frame_time (frame_clock) - priv->invert_animation_initial_time;
-  priv->invert_animation_progress = MIN (1, elapsed * INVERT_ANIMATION_SPEED / (1000. * max_scroll));
+  priv->invert_animation_progress = MIN (1, elapsed * animation_speed / (1000. * max_scroll));
   g_print ("################animation progres %d %d %d %f %f\n", gtk_widget_get_allocated_width (GTK_WIDGET 
(self)), used_children_allocation->width, max_scroll, elapsed / 1000., priv->invert_animation_progress);
   update_scrolling (self);
-  gtk_widget_queue_draw (GTK_WIDGET (self));
 
   if (priv->invert_animation_progress >= 1)
     {
@@ -656,18 +648,20 @@ start_invert_animation (GtkHidingBox *self)
   GtkHidingBoxPrivate *priv = gtk_hiding_box_get_instance_private (self);
   GList *child;
 
+  if (priv->invert_animation)
+    finish_invert_animation (self);
+
   priv->invert_animation = TRUE;
   priv->invert_animation_progress = 0;
   priv->invert_animation_initial_children_width = gtk_widget_get_allocated_width (GTK_WIDGET (self));
 
-  g_print ("start animation!!!\n");
   for (child = priv->children; child != NULL; child = child->next)
     {
       GtkWidget *revealer;
 
       revealer = gtk_widget_get_parent (GTK_WIDGET (child->data));
 
-      remove_all_opacity_classes (revealer);
+      remove_opacity_classes (revealer);
       if (gtk_revealer_get_child_revealed (GTK_REVEALER (gtk_widget_get_parent (child->data))))
         {
           add_opacity_class (revealer, "pathbar-initial-opacity");
@@ -676,6 +670,7 @@ start_invert_animation (GtkHidingBox *self)
 
       gtk_revealer_set_transition_duration (GTK_REVEALER (revealer), 0);
       gtk_revealer_set_reveal_child (GTK_REVEALER (revealer), TRUE);
+      gtk_revealer_set_transition_duration (GTK_REVEALER (revealer), REVEALER_ANIMATION_TIME);
     }
 
   priv->invert_animation_tick_id = gtk_widget_add_tick_callback (priv->box,
@@ -765,13 +760,6 @@ gtk_hiding_box_get_request_mode (GtkWidget *self)
 }
 
 static void
-on_what (gpointer  data,
-         GObject  *where_the_object_was)
-{
-  G_BREAKPOINT ();
-}
-
-static void
 gtk_hiding_box_container_add (GtkContainer *container,
                               GtkWidget    *child)
 {
@@ -881,7 +869,6 @@ gtk_hiding_box_init (GtkHidingBox *self)
   GTK_CONTAINER_CLASS (gtk_hiding_box_parent_class)->add (GTK_CONTAINER (self), priv->box);
 
   gtk_widget_show (priv->box);
-  g_object_weak_ref (G_OBJECT (priv->box), on_what, NULL);
 
   priv->invert_animation = FALSE;
   priv->inverted = FALSE;


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]