app: add back a timeout-based idle function to queue a canvas redraw.

I'm still very unclear why exactly but it would seem that just queuing
the redraw with an idle function is not enough. At least on Windows,
Jacob was having cases where opening an image would get stuck unless the
mouse was moved (causing draw events most likely).

So let's use a timeout function instead. Probably no need to queue the
idle followed by the timeout function as we had before commit
4fee04b839. Instead just directly queue a draw if relevant, then run the
timeout at regular interval (marching ants speed).

(cherry picked from commit 668c9de5a5)
This commit is contained in:
Jehan
2021-05-11 19:11:30 +02:00
parent 9314ba7051
commit 71b23da329

View File

@ -76,7 +76,7 @@ static void selection_zoom_segs (Selection *selection,
static void selection_generate_segs (Selection *selection);
static void selection_free_segs (Selection *selection);
static gboolean selection_start_timeout (Selection *selection);
static gboolean selection_timeout (Selection *selection);
static gboolean selection_window_state_event (GtkWidget *shell,
GdkEventWindowState *event,
@ -229,10 +229,22 @@ selection_start (Selection *selection)
selection_stop (selection);
/* If this selection is paused, do not start it */
if (selection->paused == 0 && selection->timeout == 0)
if (selection->paused == 0 &&
gimp_display_get_image (selection->shell->display) &&
selection->show_selection)
{
selection->timeout = g_idle_add ((GSourceFunc) selection_start_timeout,
selection);
/* Draw the ants once */
selection_timeout (selection);
if (selection->segs_in && selection->shell_visible)
{
GimpDisplayConfig *config = selection->shell->display->config;
selection->timeout = g_timeout_add_full (G_PRIORITY_DEFAULT_IDLE,
config->marching_ants_speed,
(GSourceFunc) selection_timeout,
selection, NULL);
}
}
}
@ -439,11 +451,7 @@ selection_free_segs (Selection *selection)
}
static gboolean
selection_start_timeout (Selection *selection)
{
/* Draw the ants */
if (gimp_display_get_image (selection->shell->display) &&
selection->show_selection)
selection_timeout (Selection *selection)
{
GimpDisplayConfig *config = selection->shell->display->config;
gint64 time = g_get_monotonic_time ();
@ -465,16 +473,9 @@ selection_start_timeout (Selection *selection)
gtk_widget_queue_draw_region (GTK_WIDGET (selection->shell), region);
cairo_region_destroy (region);
}
else
{
return G_SOURCE_CONTINUE;
}
}
selection->timeout = 0;
return G_SOURCE_REMOVE;
}
static void
selection_set_shell_visible (Selection *selection,