[gnome-builder] libide/gui: add inhibit hooks for IdeWorkspace
- From: Christian Hergert <chergert src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gnome-builder] libide/gui: add inhibit hooks for IdeWorkspace
- Date: Wed, 14 Sep 2022 01:56:13 +0000 (UTC)
commit 2659df253569b595c8d584315d1f8489dd041778
Author: Christian Hergert <chergert redhat com>
Date: Tue Sep 13 18:56:07 2022 -0700
libide/gui: add inhibit hooks for IdeWorkspace
That way we can use this from plugin code and keep IdeEditorPage less
tied to policy.
src/libide/gui/ide-workspace.c | 43 ++++++++++++++++++++++++++++++++++++++++++
src/libide/gui/ide-workspace.h | 4 ++++
2 files changed, 47 insertions(+)
---
diff --git a/src/libide/gui/ide-workspace.c b/src/libide/gui/ide-workspace.c
index 20d7b18e4..de8ac1c49 100644
--- a/src/libide/gui/ide-workspace.c
+++ b/src/libide/gui/ide-workspace.c
@@ -22,11 +22,14 @@
#include "config.h"
+#include <glib/gi18n.h>
+
#include <libpanel.h>
#include <libide-search.h>
#include <libide-plugins.h>
+#include "ide-application.h"
#include "ide-gui-global.h"
#include "ide-page-private.h"
#include "ide-search-popover-private.h"
@@ -90,6 +93,10 @@ typedef struct
/* Weak pointer to the current page. */
gpointer current_page_ptr;
+
+ /* Inhibit desktop session logout */
+ guint inhibit_logout_count;
+ guint inhibit_logout_cookie;
} IdeWorkspacePrivate;
typedef struct
@@ -1620,3 +1627,39 @@ _ide_workspace_agree_to_close_finish (IdeWorkspace *self,
IDE_RETURN (ret);
}
+
+void
+ide_workspace_inhibit_logout (IdeWorkspace *self)
+{
+ IdeWorkspacePrivate *priv = ide_workspace_get_instance_private (self);
+
+ g_return_if_fail (IDE_IS_WORKSPACE (self));
+
+ priv->inhibit_logout_count++;
+
+ if (priv->inhibit_logout_count == 1)
+ {
+ priv->inhibit_logout_cookie =
+ gtk_application_inhibit (GTK_APPLICATION (IDE_APPLICATION_DEFAULT),
+ GTK_WINDOW (self),
+ GTK_APPLICATION_INHIBIT_LOGOUT,
+ _("There are unsaved documents"));
+ }
+}
+
+void
+ide_workspace_uninhibit_logout (IdeWorkspace *self)
+{
+ IdeWorkspacePrivate *priv = ide_workspace_get_instance_private (self);
+
+ g_return_if_fail (IDE_IS_WORKSPACE (self));
+
+ if (priv->inhibit_logout_count == 1)
+ {
+ gtk_application_uninhibit (GTK_APPLICATION (IDE_APPLICATION_DEFAULT),
+ priv->inhibit_logout_cookie);
+ priv->inhibit_logout_cookie = 0;
+ }
+
+ priv->inhibit_logout_count--;
+}
diff --git a/src/libide/gui/ide-workspace.h b/src/libide/gui/ide-workspace.h
index 2efec44ee..1f8c6a78d 100644
--- a/src/libide/gui/ide-workspace.h
+++ b/src/libide/gui/ide-workspace.h
@@ -146,5 +146,9 @@ void ide_workspace_add_overlay (IdeWorkspace
IDE_AVAILABLE_IN_ALL
void ide_workspace_remove_overlay (IdeWorkspace *self,
GtkWidget *widget);
+IDE_AVAILABLE_IN_ALL
+void ide_workspace_inhibit_logout (IdeWorkspace *self);
+IDE_AVAILABLE_IN_ALL
+void ide_workspace_uninhibit_logout (IdeWorkspace *self);
G_END_DECLS
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]