app: continue running GIMP when run non-interactively without --quit.

Right now, running GIMP non-interactively (i.e. either as gimp-console
or with --no-interface) without --quit, the process was still exiting
immediately, yet not properly cleaning after itself. This is a
regression, since there used to be use cases with people wanting
long-running GIMP (for instance with a long-running plug-in waiting for
input through whatever inter-process communication method).

With this commit:

* GIMP now continues running when run non-interactively without --quit;
* It will catch SIGINT (typically Ctrl-C) and will quit cleanly when the
  signal happens.
* At the end of the normal process (processing command line options,
  such as opening images or running batch commands) and before going
  on-hold, it will display some info text saying that the process can be
  exited with SIGINT and informing that --quit exists if you were in
  fact intending to quit immediately after the normal process actions.
* This also fixes the "gimp_finalize: list of contexts not empty upon
  exit" WARNING we had when it was exiting without --quit (because of no
  proper cleanup).

Note that I add some CLI text which ideally should be localized. But
since we are in string freeze, I am letting them untranslated with a
TODO (also assuming CLI-using people have more chances being used to
English, which may be or not a wrong assumption; but anyway most people
don't read the terminal output, and people running GIMP
non-interactively are even less).
Since this was not just an enhancement but also really a regression fix,
I prefer to do this now despite the string freeze and lack of
localization.
This commit is contained in:
Jehan 2024-09-18 22:16:09 +02:00
parent 2d063d8876
commit 8f3931a45e
1 changed files with 32 additions and 0 deletions

View File

@ -93,6 +93,8 @@ static gboolean app_exit_after_callback (Gimp *gimp,
gboolean kill_it, gboolean kill_it,
GApplication *app); GApplication *app);
static void app_quit_on_ctrl_c (gint sig_num);
#if 0 #if 0
/* left here as documentation how to do compat enums */ /* left here as documentation how to do compat enums */
GType gimp_convert_dither_type_compat_get_type (void); /* compat cruft */ GType gimp_convert_dither_type_compat_get_type (void); /* compat cruft */
@ -522,6 +524,25 @@ app_activate_callback (GimpCoreApp *app,
*/ */
gimp_exit (gimp, TRUE); gimp_exit (gimp, TRUE);
} }
else
#ifndef GIMP_CONSOLE_COMPILATION
if (gimp->no_interface)
#endif
{
/* In console version or GUI version with no interface, we keep
* running when --quit was not set. For instance, there could be
* an always-ON plug-in (GIMP_PDB_PROC_TYPE_EXTENSION) which is
* set up to receive commands for GIMP.
*/
gimp_signal_private (SIGINT, app_quit_on_ctrl_c, 0);
g_printf ("\n== %s ==\n%s\n\n%s\n",
/* TODO: localize when string freeze is over. */
"INFO",
"GIMP is now running as a background process. "
"You can quit anytime with Ctrl-C (SIGINT).",
"If you wanted to quit immediately instead, call GIMP with --quit.");
g_application_hold (G_APPLICATION (app));
}
} }
static void static void
@ -571,3 +592,14 @@ app_exit_after_callback (Gimp *gimp,
return FALSE; return FALSE;
} }
static void
app_quit_on_ctrl_c (gint sig_num)
{
GApplication *app = g_application_get_default ();
Gimp *gimp;
g_application_release (app);
gimp = gimp_core_app_get_gimp (GIMP_CORE_APP (app));
gimp_exit (gimp, TRUE);
}