[sysprof] libsysprof-ui: simplify zoom at load



commit 2cb11dce463cdac1bbc88e49326b9d6aa23b232d
Author: Christian Hergert <chergert redhat com>
Date:   Wed May 15 14:38:30 2019 -0700

    libsysprof-ui: simplify zoom at load

 src/libsysprof-ui/sysprof-capture-view.c    | 33 ++++++++++++++++++++++-------
 src/libsysprof-ui/sysprof-capture-view.h    |  2 ++
 src/libsysprof-ui/sysprof-visualizer-view.c | 13 ------------
 3 files changed, 27 insertions(+), 21 deletions(-)
---
diff --git a/src/libsysprof-ui/sysprof-capture-view.c b/src/libsysprof-ui/sysprof-capture-view.c
index d1e84ec..1fedccd 100644
--- a/src/libsysprof-ui/sysprof-capture-view.c
+++ b/src/libsysprof-ui/sysprof-capture-view.c
@@ -462,6 +462,13 @@ sysprof_capture_view_real_load_async (SysprofCaptureView   *self,
                         load_async_free);
   sysprof_capture_view_monitor_task (self, task);
 
+  /* Zoom after loading state */
+  g_signal_connect_object (task,
+                           "notify::completed",
+                           G_CALLBACK (sysprof_capture_view_fit_to_width),
+                           self,
+                           G_CONNECT_SWAPPED);
+
   /* Cancel any previously in-flight operations and save a cancellable so
    * that any supplimental calls will result in the previous being cancelled.
    */
@@ -512,18 +519,11 @@ fit_zoom_cb (GSimpleAction *action,
              gpointer       user_data)
 {
   SysprofCaptureView *self = user_data;
-  SysprofCaptureViewPrivate *priv = sysprof_capture_view_get_instance_private (self);
-  GtkAllocation alloc;
-  gdouble zoom;
-  gint64 duration;
 
   g_assert (G_IS_SIMPLE_ACTION (action));
   g_assert (SYSPROF_IS_CAPTURE_VIEW (self));
 
-  duration = priv->features.end_time - priv->features.begin_time;
-  gtk_widget_get_allocation (GTK_WIDGET (self), &alloc);
-  zoom = sysprof_zoom_manager_fit_zoom_for_duration (priv->zoom_manager, duration, alloc.width);
-  sysprof_zoom_manager_set_zoom (priv->zoom_manager, zoom);
+  sysprof_capture_view_fit_to_width (self);
 }
 
 static void
@@ -697,6 +697,7 @@ sysprof_capture_view_reset (SysprofCaptureView *self)
   g_return_if_fail (SYSPROF_IS_CAPTURE_VIEW (self));
 
   /* TODO: reset */
+  g_warning ("Clear all loaded state");
 }
 
 /**
@@ -716,3 +717,19 @@ sysprof_capture_view_get_zoom_manager (SysprofCaptureView *self)
 
   return priv->zoom_manager;
 }
+
+void
+sysprof_capture_view_fit_to_width (SysprofCaptureView *self)
+{
+  SysprofCaptureViewPrivate *priv = sysprof_capture_view_get_instance_private (self);
+  GtkAllocation alloc;
+  gdouble zoom;
+  gint64 duration;
+
+  g_return_if_fail (SYSPROF_IS_CAPTURE_VIEW (self));
+
+  duration = priv->features.end_time - priv->features.begin_time;
+  gtk_widget_get_allocation (GTK_WIDGET (self), &alloc);
+  zoom = sysprof_zoom_manager_fit_zoom_for_duration (priv->zoom_manager, duration, alloc.width);
+  sysprof_zoom_manager_set_zoom (priv->zoom_manager, zoom);
+}
diff --git a/src/libsysprof-ui/sysprof-capture-view.h b/src/libsysprof-ui/sysprof-capture-view.h
index 82358a4..3dad57d 100644
--- a/src/libsysprof-ui/sysprof-capture-view.h
+++ b/src/libsysprof-ui/sysprof-capture-view.h
@@ -67,5 +67,7 @@ gboolean              sysprof_capture_view_load_finish      (SysprofCaptureView
                                                              GError               **error);
 SYSPROF_AVAILABLE_IN_ALL
 gboolean              sysprof_capture_view_get_busy         (SysprofCaptureView    *self);
+SYSPROF_AVAILABLE_IN_ALL
+void                  sysprof_capture_view_fit_to_width     (SysprofCaptureView    *self);
 
 G_END_DECLS
diff --git a/src/libsysprof-ui/sysprof-visualizer-view.c b/src/libsysprof-ui/sysprof-visualizer-view.c
index 82d78c4..fba677e 100644
--- a/src/libsysprof-ui/sysprof-visualizer-view.c
+++ b/src/libsysprof-ui/sysprof-visualizer-view.c
@@ -619,7 +619,6 @@ sysprof_visualizer_view_set_reader (SysprofVisualizerView *self,
 
       if (reader != NULL)
         {
-          GtkAllocation alloc;
           gint64 begin_time;
           gint64 end_time;
 
@@ -632,18 +631,6 @@ sysprof_visualizer_view_set_reader (SysprofVisualizerView *self,
           sysprof_visualizer_ticks_set_time_range (priv->ticks, begin_time, end_time);
 
           sysprof_selection_unselect_all (priv->selection);
-
-          gtk_widget_get_allocation (GTK_WIDGET (self), &alloc);
-
-          if (alloc.width)
-            {
-              gdouble zoom;
-
-              zoom = sysprof_zoom_manager_fit_zoom_for_duration (priv->zoom_manager,
-                                                                 end_time - begin_time,
-                                                                 alloc.width);
-              sysprof_zoom_manager_set_zoom (priv->zoom_manager, zoom);
-            }
         }
 
       sysprof_visualizer_list_set_reader (priv->list, reader);


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