[libhandy/wip/haecker-felix/flap-widget] Fix



commit f06c4e79345ea0125ff86ef9b9c3f373f0b59f9d
Author: Alexander Mikhaylenko <alexm gnome org>
Date:   Mon Nov 23 18:00:17 2020 +0500

    Fix

 src/hdy-flap.c | 93 +++++++++++++++++++++++++++++++++++++---------------------
 1 file changed, 59 insertions(+), 34 deletions(-)
---
diff --git a/src/hdy-flap.c b/src/hdy-flap.c
index c2cfc193..20b7bf19 100644
--- a/src/hdy-flap.c
+++ b/src/hdy-flap.c
@@ -51,7 +51,6 @@ typedef struct {
   GtkWidget *widget;
   GdkWindow *window;
   GtkAllocation allocation;
-  gboolean visible;
 } ChildInfo;
 
 struct _HdyFlap
@@ -149,13 +148,44 @@ set_orientation (HdyFlap        *self,
   g_object_notify (G_OBJECT (self), "orientation");
 }
 
+static void
+update_child_visibility (HdyFlap *self)
+{
+  gboolean visible = self->reveal_progress > 0;
+
+  if (self->flap.widget)
+    gtk_widget_set_child_visible (self->flap.widget, visible);
+
+  if (self->separator.widget)
+    gtk_widget_set_child_visible (self->separator.widget, visible);
+
+  if (!gtk_widget_get_realized (GTK_WIDGET (self)))
+    return;
+
+  if (self->flap.widget) {
+    if (visible)
+      gdk_window_show (self->flap.window);
+    else
+      gdk_window_hide (self->flap.window);
+  }
+
+  if (self->separator.widget) {
+    if (visible)
+      gdk_window_show (self->separator.window);
+    else
+      gdk_window_hide (self->separator.window);
+  }
+
+  gtk_widget_queue_resize (GTK_WIDGET (self));
+}
+
 static void
 set_reveal_progress (HdyFlap *self,
                      gdouble  progress)
 {
   self->reveal_progress = progress;
 
-  gtk_widget_queue_resize (GTK_WIDGET (self));
+  update_child_visibility (self);
 }
 
 static void
@@ -213,6 +243,8 @@ reveal_animation_done_cb (HdyFlap *self)
 
     animate_fold (self);
   }
+
+  gtk_widget_queue_allocate (GTK_WIDGET (self));
 }
 
 static void
@@ -256,9 +288,6 @@ set_reveal_flap (HdyFlap  *self,
       hdy_swipeable_emit_child_switched (HDY_SWIPEABLE (self), reveal_flap ? 1 : 0, duration);
   }
 
-  if (self->click_to_close)
-    gtk_event_controller_reset (GTK_EVENT_CONTROLLER (self->click_gesture));
-
   g_object_notify_by_pspec (G_OBJECT (self), props[PROP_REVEAL_FLAP]);
 }
 
@@ -287,9 +316,6 @@ set_folded (HdyFlap  *self,
   if (!self->locked)
     set_reveal_flap (self, !self->folded, self->fold_duration, TRUE);
 
-  if (self->click_to_close)
-    gtk_event_controller_reset (GTK_EVENT_CONTROLLER (self->click_gesture));
-
   g_object_notify_by_pspec (G_OBJECT (self), props[PROP_FOLDED]);
 }
 
@@ -489,8 +515,6 @@ add_child (HdyFlap   *self,
   }
 
   gtk_widget_set_parent (info->widget, GTK_WIDGET (self));
-
-  info->visible = FALSE;
 }
 
 static void
@@ -501,8 +525,6 @@ remove_child (HdyFlap   *self,
     unregister_window (self, info);
 
   gtk_widget_unparent (info->widget);
-
-  info->visible = FALSE;
 }
 
 static inline void
@@ -765,34 +787,29 @@ compute_allocation (HdyFlap       *self,
 static inline void
 allocate_child (HdyFlap   *self,
                 ChildInfo *info,
-                gboolean   visible)
+                gboolean   expand_window)
 {
   GtkAllocation child_alloc;
 
   if (!info->widget)
     return;
 
-  if (visible != info->visible) {
-    gtk_widget_set_child_visible (info->widget, visible);
-    info->visible = visible;
-  }
-
   if (gtk_widget_get_realized (GTK_WIDGET (self))) {
-    if (visible) {
-      gdk_window_show (info->window);
+    if (expand_window)
       gdk_window_move_resize (info->window,
-                              info->allocation.x, info->allocation.y,
-                              info->allocation.width, info->allocation.height);
-    } else {
-      gdk_window_hide (info->window);
-    }
+                              0, 0,
+                              gtk_widget_get_allocated_width (GTK_WIDGET (self)),
+                              gtk_widget_get_allocated_height (GTK_WIDGET (self)));
+    else
+      gdk_window_move_resize (info->window,
+                              info->allocation.x,
+                              info->allocation.y,
+                              info->allocation.width,
+                              info->allocation.height);
   }
 
-  if (!visible)
-    return;
-
-  child_alloc.x = 0;
-  child_alloc.y = 0;
+  child_alloc.x = expand_window ? info->allocation.x : 0;
+  child_alloc.y = expand_window ? info->allocation.y : 0;
   child_alloc.width = info->allocation.width;
   child_alloc.height = info->allocation.height;
 
@@ -830,9 +847,12 @@ hdy_flap_size_allocate (GtkWidget     *widget,
                       &self->content.allocation,
                       &self->separator.allocation);
 
-  allocate_child (self, &self->content, TRUE);
-  allocate_child (self, &self->separator, self->reveal_progress > 0);
-  allocate_child (self, &self->flap, self->reveal_progress > 0);
+  allocate_child (self, &self->content, FALSE);
+  allocate_child (self, &self->separator, FALSE);
+  allocate_child (self, &self->flap,
+                  self->click_to_close &&
+                  self->reveal_progress > 0 &&
+                  self->fold_progress > 0);
 
   gtk_widget_set_clip (widget, alloc);
 }
@@ -1699,6 +1719,8 @@ hdy_flap_set_flap (HdyFlap   *self,
   if (self->tracker)
     hdy_swipe_tracker_set_enabled (self->tracker, self->flap.widget != NULL);
 
+  update_child_visibility (self);
+
   g_object_notify_by_pspec (G_OBJECT (self), props[PROP_FLAP]);
 }
 
@@ -1743,6 +1765,8 @@ hdy_flap_set_separator (HdyFlap   *self,
   if (self->separator.widget)
     add_child (self, &self->separator);
 
+  update_child_visibility (self);
+
   g_object_notify_by_pspec (G_OBJECT (self), props[PROP_SEPARATOR]);
 }
 
@@ -2074,9 +2098,10 @@ hdy_flap_set_click_to_close (HdyFlap  *self,
   if (click_to_close)
     phase = GTK_PHASE_CAPTURE;
 
-  gtk_event_controller_reset (GTK_EVENT_CONTROLLER (self->click_gesture));
   gtk_event_controller_set_propagation_phase (GTK_EVENT_CONTROLLER (self->click_gesture),
                                               phase);
 
+  gtk_widget_queue_allocate (GTK_WIDGET (self));
+
   g_object_notify_by_pspec (G_OBJECT (self), props[PROP_CLICK_TO_CLOSE]);
 }


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