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 c0480f502d
)
(this fix is actually a side effect from fixing something else in
master)
This commit is contained in:
@ -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))
|
||||
{
|
||||
|
@ -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:
|
||||
|
@ -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,
|
||||
|
@ -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)
|
||||
{
|
||||
|
@ -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;
|
||||
|
Reference in New Issue
Block a user