mirror of
https://gitlab.gnome.org/GNOME/glib.git
synced 2025-08-01 06:33:41 +02:00
application: introduce methods to mark the application as busy
This feature is intended for clients that want to signal a desktop shell their busy state, for instance because a long-running operation is pending. The API works in a similar way to g_application_hold and g_application_release: applications can call g_application_mark_busy() to increase a counter that will keep the application marked as busy until the counter reaches zero again. The busy state is exported read-only on the org.gtk.Application interface for clients to use. https://bugzilla.gnome.org/show_bug.cgi?id=672018
This commit is contained in:
@@ -239,6 +239,7 @@ struct _GApplicationPrivate
|
||||
guint inactivity_timeout_id;
|
||||
guint inactivity_timeout;
|
||||
guint use_count;
|
||||
guint busy_count;
|
||||
|
||||
guint is_registered : 1;
|
||||
guint is_remote : 1;
|
||||
@@ -1850,5 +1851,62 @@ g_application_quit (GApplication *application)
|
||||
application->priv->must_quit_now = TRUE;
|
||||
}
|
||||
|
||||
/**
|
||||
* g_application_mark_busy:
|
||||
* @application: a #GApplication
|
||||
*
|
||||
* Increases the busy count of @application.
|
||||
*
|
||||
* Use this function to indicate that the application is busy, for instance
|
||||
* while a long running operation is pending.
|
||||
*
|
||||
* The busy state will be exposed to other processes, so a session shell will
|
||||
* use that information to indicate the state to the user (e.g. with a
|
||||
* spinner).
|
||||
*
|
||||
* To cancel the busy indication, use g_application_unmark_busy().
|
||||
*
|
||||
* Since: 2.38
|
||||
**/
|
||||
void
|
||||
g_application_mark_busy (GApplication *application)
|
||||
{
|
||||
gboolean was_busy;
|
||||
|
||||
g_return_if_fail (G_IS_APPLICATION (application));
|
||||
|
||||
was_busy = (application->priv->busy_count > 0);
|
||||
application->priv->busy_count++;
|
||||
|
||||
if (!was_busy)
|
||||
g_application_impl_set_busy_state (application->priv->impl, TRUE);
|
||||
}
|
||||
|
||||
/**
|
||||
* g_application_unmark_busy:
|
||||
* @application: a #GApplication
|
||||
*
|
||||
* Decreases the busy count of @application.
|
||||
*
|
||||
* When the busy count reaches zero, the new state will be propagated
|
||||
* to other processes.
|
||||
*
|
||||
* This function must only be called to cancel the effect of a previous
|
||||
* call to g_application_mark_busy().
|
||||
*
|
||||
* Since: 2.38
|
||||
**/
|
||||
void
|
||||
g_application_unmark_busy (GApplication *application)
|
||||
{
|
||||
g_return_if_fail (G_IS_APPLICATION (application));
|
||||
g_return_if_fail (application->priv->busy_count > 0);
|
||||
|
||||
application->priv->busy_count--;
|
||||
|
||||
if (application->priv->busy_count == 0)
|
||||
g_application_impl_set_busy_state (application->priv->impl, FALSE);
|
||||
}
|
||||
|
||||
/* Epilogue {{{1 */
|
||||
/* vim:set foldmethod=marker: */
|
||||
|
Reference in New Issue
Block a user