diff --git a/docs/reference/gio/gio-sections.txt b/docs/reference/gio/gio-sections.txt index c9ed66bc8..b72b37d05 100644 --- a/docs/reference/gio/gio-sections.txt +++ b/docs/reference/gio/gio-sections.txt @@ -2897,6 +2897,7 @@ g_application_register g_application_hold g_application_release +g_application_quit g_application_activate g_application_open diff --git a/gio/gapplication.c b/gio/gapplication.c index 380634dc3..fe01d2a43 100644 --- a/gio/gapplication.c +++ b/gio/gapplication.c @@ -211,6 +211,7 @@ struct _GApplicationPrivate guint is_remote : 1; guint did_startup : 1; guint did_shutdown : 1; + guint must_quit_now : 1; GRemoteActionGroup *remote_actions; GApplicationImpl *impl; @@ -1425,6 +1426,7 @@ g_application_run (GApplication *application, g_return_val_if_fail (G_IS_APPLICATION (application), 1); g_return_val_if_fail (argc == 0 || argv != NULL, 1); + g_return_val_if_fail (!application->priv->must_quit_now, 1); arguments = g_new (gchar *, argc + 1); for (i = 0; i < argc; i++) @@ -1488,6 +1490,9 @@ g_application_run (GApplication *application, while (application->priv->use_count || application->priv->inactivity_timeout_id) { + if (application->priv->must_quit_now) + break; + g_main_context_iteration (NULL, TRUE); status = 0; } @@ -1694,5 +1699,29 @@ g_application_set_default (GApplication *application) default_app = application; } +/** + * g_application_quit: + * @application: a #GApplication + * + * Immediately quits the application. + * + * Upon return to the mainloop, g_application_run() will return, + * calling only the 'shutdown' function before doing so. + * + * The hold count is ignored. + * + * The result of calling g_application_run() again after it returns is + * unspecified. + * + * Since: 2.32 + **/ +void +g_application_quit (GApplication *application) +{ + g_return_if_fail (G_IS_APPLICATION (application)); + + application->priv->must_quit_now = TRUE; +} + /* Epilogue {{{1 */ /* vim:set foldmethod=marker: */ diff --git a/gio/gapplication.h b/gio/gapplication.h index 20f90afd3..c6c63a5c6 100644 --- a/gio/gapplication.h +++ b/gio/gapplication.h @@ -138,6 +138,8 @@ int g_application_run (GApplic int argc, char **argv); +void g_application_quit (GApplication *application); + GApplication * g_application_get_default (void); void g_application_set_default (GApplication *application); diff --git a/gio/gio.symbols b/gio/gio.symbols index 9b609c17f..23938feca 100644 --- a/gio/gio.symbols +++ b/gio/gio.symbols @@ -31,6 +31,7 @@ g_application_set_application_id g_application_set_default g_application_set_flags g_application_set_inactivity_timeout +g_application_quit g_application_command_line_get_arguments g_application_command_line_get_cwd g_application_command_line_get_environ