diff --git a/gdk/gdk-private.h b/gdk/gdk-private.h index 5d35eb54d8..9ec724bced 100644 --- a/gdk/gdk-private.h +++ b/gdk/gdk-private.h @@ -62,5 +62,6 @@ GDK_AVAILABLE_IN_ALL GdkPrivateVTable * gdk__private__ (void); gboolean gdk_running_in_sandbox (void); +gboolean gdk_should_use_portal (void); #endif /* __GDK__PRIVATE_H__ */ diff --git a/gdk/gdk.c b/gdk/gdk.c index f4e4413300..26950a87e3 100644 --- a/gdk/gdk.c +++ b/gdk/gdk.c @@ -474,6 +474,26 @@ gdk_running_in_sandbox (void) return g_file_test ("/.flatpak-info", G_FILE_TEST_EXISTS); } +gboolean +gdk_should_use_portal (void) +{ + static const char *use_portal = NULL; + + if (G_UNLIKELY (use_portal == NULL)) + { + if (gdk_running_in_sandbox ()) + use_portal = "1"; + else + { + use_portal = g_getenv ("GTK_USE_PORTAL"); + if (!use_portal) + use_portal = ""; + } + } + + return use_portal[0] == '1'; +} + /** * gdk_display_open_default_libgtk_only: *