[gimp/gimp-2-10] app: fix jumping around of newly created images



commit 21f87d7d82b94165901310fa3580cd839295d89f
Author: Michael Natterer <mitch gimp org>
Date:   Thu Jun 28 00:52:08 2018 +0200

    app: fix jumping around of newly created images
    
    Put the center_image_on_size_allocate() code into the canvas'
    size-allocate callbacck.
    
    As a side effect we now have a flag in GimpDisplayShell which
    indicates that there will be a size allocate before the next frame, so
    simply skip drawing the canvas completely. This fixes new images
    jumping around when they are first shown.
    
    (cherry picked from commit c0480f502d85de44e94424f4f2ec2c811d431aa7)
    
    (this fix is actually a side effect from fixing something else in
    master)

 app/display/gimpdisplayshell-callbacks.c | 14 ++++++++-
 app/display/gimpdisplayshell-scroll.c    | 54 --------------------------------
 app/display/gimpdisplayshell-scroll.h    |  4 ---
 app/display/gimpdisplayshell.c           | 10 ++----
 app/display/gimpdisplayshell.h           |  1 +
 5 files changed, 16 insertions(+), 67 deletions(-)
---
diff --git a/app/display/gimpdisplayshell-callbacks.c b/app/display/gimpdisplayshell-callbacks.c
index 47ed7268be..9e332a7a2b 100644
--- a/app/display/gimpdisplayshell-callbacks.c
+++ b/app/display/gimpdisplayshell-callbacks.c
@@ -235,9 +235,15 @@ gimp_display_shell_canvas_size_allocate (GtkWidget        *widget,
       gimp_display_shell_scroll_clamp_and_update (shell);
       gimp_display_shell_scaled (shell);
 
-      /* Reset */
       shell->size_allocate_from_configure_event = FALSE;
     }
+
+  if (shell->size_allocate_center_image)
+    {
+      gimp_display_shell_scroll_center_image (shell, TRUE, TRUE);
+
+      shell->size_allocate_center_image = FALSE;
+    }
 }
 
 gboolean
@@ -249,6 +255,12 @@ gimp_display_shell_canvas_expose (GtkWidget        *widget,
   if (! shell->display || ! gimp_display_get_shell (shell->display))
     return TRUE;
 
+  /*  we will scroll around in the next tick anyway, so we just can as
+   *  well skip the drawing of this frame and wait for the next
+   */
+  if (shell->size_allocate_center_image)
+    return TRUE;
+
   /*  ignore events on overlays  */
   if (eevent->window == gtk_widget_get_window (widget))
     {
diff --git a/app/display/gimpdisplayshell-scroll.c b/app/display/gimpdisplayshell-scroll.c
index 1b5c06fdab..67fb755ea2 100644
--- a/app/display/gimpdisplayshell-scroll.c
+++ b/app/display/gimpdisplayshell-scroll.c
@@ -389,60 +389,6 @@ gimp_display_shell_scroll_center_image (GimpDisplayShell *shell,
   gimp_display_shell_scroll (shell, offset_x, offset_y);
 }
 
-typedef struct
-{
-  GimpDisplayShell *shell;
-  gboolean          vertically;
-  gboolean          horizontally;
-} CenterImageData;
-
-static void
-gimp_display_shell_scroll_center_image_callback (GtkWidget       *canvas,
-                                                 GtkAllocation   *allocation,
-                                                 CenterImageData *data)
-{
-  g_signal_handlers_disconnect_by_func (canvas,
-                                        gimp_display_shell_scroll_center_image_callback,
-                                        data);
-
-  gimp_display_shell_scroll_center_image (data->shell,
-                                          data->horizontally,
-                                          data->vertically);
-
-  g_slice_free (CenterImageData, data);
-}
-
-/**
- * gimp_display_shell_scroll_center_image_on_size_allocate:
- * @shell:
- *
- * Centers the image in the display as soon as the canvas has got its
- * new size.
- *
- * Only call this if you are sure the canvas size will change.
- * (Otherwise the signal connection and centering will lurk until the
- * canvas size is changed e.g. by toggling the rulers.)
- **/
-void
-gimp_display_shell_scroll_center_image_on_size_allocate (GimpDisplayShell *shell,
-                                                         gboolean          horizontally,
-                                                         gboolean          vertically)
-{
-  CenterImageData *data;
-
-  g_return_if_fail (GIMP_IS_DISPLAY_SHELL (shell));
-
-  data = g_slice_new (CenterImageData);
-
-  data->shell        = shell;
-  data->horizontally = horizontally;
-  data->vertically   = vertically;
-
-  g_signal_connect (shell->canvas, "size-allocate",
-                    G_CALLBACK (gimp_display_shell_scroll_center_image_callback),
-                    data);
-}
-
 /**
  * gimp_display_shell_scroll_get_scaled_viewport:
  * @shell:
diff --git a/app/display/gimpdisplayshell-scroll.h b/app/display/gimpdisplayshell-scroll.h
index 9d5dc093a6..8bdb7d5c4d 100644
--- a/app/display/gimpdisplayshell-scroll.h
+++ b/app/display/gimpdisplayshell-scroll.h
@@ -40,10 +40,6 @@ void   gimp_display_shell_scroll_center_image_xy     (GimpDisplayShell *shell,
 void   gimp_display_shell_scroll_center_image        (GimpDisplayShell *shell,
                                                       gboolean          horizontally,
                                                       gboolean          vertically);
-void   gimp_display_shell_scroll_center_image_on_size_allocate
-                                                     (GimpDisplayShell *shell,
-                                                      gboolean          horizontally,
-                                                      gboolean          vertically);
 
 void   gimp_display_shell_scroll_get_scaled_viewport (GimpDisplayShell *shell,
                                                       gint             *x,
diff --git a/app/display/gimpdisplayshell.c b/app/display/gimpdisplayshell.c
index 0e39aafa25..4c06fc36a7 100644
--- a/app/display/gimpdisplayshell.c
+++ b/app/display/gimpdisplayshell.c
@@ -779,8 +779,7 @@ gimp_display_shell_constructed (GObject *object)
        * not even finished creating the display shell, we can safely
        * assume we will get a size-allocate later.
        */
-      gimp_display_shell_scroll_center_image_on_size_allocate (shell,
-                                                               TRUE, TRUE);
+      shell->size_allocate_center_image = TRUE;
     }
   else
     {
@@ -1505,11 +1504,6 @@ gimp_display_shell_fill (GimpDisplayShell *shell,
   gimp_display_shell_set_initial_scale (shell, scale, NULL, NULL);
   gimp_display_shell_scale_update (shell);
 
-  /* center the image so subsequent stuff only moves it a little in
-   * the center
-   */
-  gimp_display_shell_scroll_center_image (shell, TRUE, TRUE);
-
   gimp_display_shell_sync_config (shell, config);
 
   gimp_image_window_suspend_keep_pos (window);
@@ -1526,7 +1520,7 @@ gimp_display_shell_fill (GimpDisplayShell *shell,
   /* A size-allocate will always occur because the scrollbars will
    * become visible forcing the canvas to become smaller
    */
-  gimp_display_shell_scroll_center_image_on_size_allocate (shell, TRUE, TRUE);
+  shell->size_allocate_center_image = TRUE;
 
   if (shell->blink_timeout_id)
     {
diff --git a/app/display/gimpdisplayshell.h b/app/display/gimpdisplayshell.h
index e1018338c3..dfd9e94821 100644
--- a/app/display/gimpdisplayshell.h
+++ b/app/display/gimpdisplayshell.h
@@ -179,6 +179,7 @@ struct _GimpDisplayShell
   gboolean           zoom_on_resize;
 
   gboolean           size_allocate_from_configure_event;
+  gboolean           size_allocate_center_image;
 
   /*  the state of gimp_display_shell_tool_events()  */
   gboolean           pointer_grabbed;


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