app: improve opening images through the DBus service.

- Set the software as `initialized` later, and in particular after all
  recovered images (from crash) then all command line images were
  opened. The reason is that the DBus calls have necessarily been made
  after GIMP was started (typically could be images double-clicked
  through GUI). We don't want them to appear before the images given in
  command line (or worse, some before and some after).
- Process DBus service's data queue as a FIFO. The image requested first
  will be loaded first.
- When a DBus call happens while GIMP is not initialized or restored,
  switch to a timeout handler. The problem with idle handlers is that
  they would be attempted too often (probably even more during startup
  when no user event happens). This is good for actions we want to
  happen reasonably quickly (like would be normally DBus calls), but not
  when we are unsure of program availability schedule (i.e. at startup).
  Here not only the handler would run a lot uselessly but it would
  likely even slow the startup down by doing so. So while GIMP is not
  initialized, switch to half-a-second timeout handler, then only switch
  back to idle handler when we are properly initialized and GIMP is
  ready to answer calls in a timely manner.

(cherry picked from commit b2649daf11)
This commit is contained in:
Jehan 2020-11-10 22:19:11 +01:00
parent f2f0b6aae8
commit 2fd4fc7c7a
3 changed files with 64 additions and 10 deletions

View File

@ -346,9 +346,6 @@ app_run (const gchar *full_prog_name,
G_CALLBACK (app_exit_after_callback),
&run_loop);
/* The software is now fully loaded and ready to be used. */
gimp->initialized = TRUE;
#ifndef GIMP_CONSOLE_COMPILATION
if (run_loop && ! no_interface)
{
@ -425,6 +422,12 @@ app_run (const gchar *full_prog_name,
}
}
}
/* The software is now fully loaded and ready to be used and get
* external input.
*/
gimp->initialized = TRUE;
if (font_error)
{
gimp_message_literal (gimp, NULL,

View File

@ -147,6 +147,7 @@ gimp_dbus_service_dispose (GObject *object)
{
g_source_remove (g_source_get_id (service->source));
service->source = NULL;
service->timeout_source = FALSE;
}
while (! g_queue_is_empty (service->queue))
@ -269,6 +270,7 @@ gimp_dbus_service_queue_open (GimpDBusService *service,
if (! service->source)
{
service->source = g_idle_source_new ();
service->timeout_source = FALSE;
g_source_set_priority (service->source, G_PRIORITY_LOW);
g_source_set_callback (service->source,
@ -302,6 +304,7 @@ gimp_dbus_service_queue_batch (GimpDBusService *service,
if (! service->source)
{
service->source = g_idle_source_new ();
service->timeout_source = FALSE;
g_source_set_priority (service->source, G_PRIORITY_LOW);
g_source_set_callback (service->source,
@ -329,9 +332,35 @@ gimp_dbus_service_process_idle (GimpDBusService *service)
IdleData *data;
if (! service->gimp->initialized || ! service->gimp->restored)
return TRUE;
{
if (! service->timeout_source)
{
/* We are probably starting the program. No need to spam GIMP with
* an idle handler (which might make GIMP slower to start even
* with low priority).
* Instead let's add a timeout of half a second.
*/
service->source = g_timeout_source_new (500);
service->timeout_source = TRUE;
data = g_queue_pop_tail (service->queue);
g_source_set_priority (service->source, G_PRIORITY_LOW);
g_source_set_callback (service->source,
(GSourceFunc) gimp_dbus_service_process_idle,
service,
NULL);
g_source_attach (service->source, NULL);
g_source_unref (service->source);
return G_SOURCE_REMOVE;
}
else
{
return G_SOURCE_CONTINUE;
}
}
/* Process data as a FIFO. */
data = g_queue_pop_head (service->queue);
if (data)
{
@ -349,12 +378,33 @@ gimp_dbus_service_process_idle (GimpDBusService *service)
gimp_dbus_service_idle_data_free (data);
return TRUE;
if (service->timeout_source)
{
/* Now GIMP is fully functional and can respond quickly to
* DBus calls. Switch to a usual idle source.
*/
service->source = g_idle_source_new ();
service->timeout_source = FALSE;
g_source_set_priority (service->source, G_PRIORITY_LOW);
g_source_set_callback (service->source,
(GSourceFunc) gimp_dbus_service_process_idle,
service,
NULL);
g_source_attach (service->source, NULL);
g_source_unref (service->source);
return G_SOURCE_REMOVE;
}
else
{
return G_SOURCE_CONTINUE;
}
}
service->source = NULL;
return FALSE;
return G_SOURCE_REMOVE;
}
static IdleData *

View File

@ -49,9 +49,10 @@ struct _GimpDBusService
{
GimpDBusServiceUISkeleton parent_instance;
Gimp *gimp;
GQueue *queue;
GSource *source;
Gimp *gimp;
GQueue *queue;
GSource *source;
gboolean timeout_source;
};
struct _GimpDBusServiceClass