[gtk/wip/settings-portal: 2/3] Move the should_use_portal helper to gdk
- From: Matthias Clasen <matthiasc src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gtk/wip/settings-portal: 2/3] Move the should_use_portal helper to gdk
- Date: Thu, 1 Nov 2018 23:50:43 +0000 (UTC)
commit 6f58c31e915d812fa7e873116c57f52125bee03e
Author: Matthias Clasen <mclasen redhat com>
Date: Thu Nov 1 13:46:04 2018 -0400
Move the should_use_portal helper to gdk
We want to use it there too, in the future.
Update all callers.
gdk/gdk-private.h | 1 +
gdk/gdk.c | 20 ++++++++++++++++++++
gtk/gtkapplication-dbus.c | 2 +-
gtk/gtkcolorpickerportal.c | 2 +-
gtk/gtkfilechoosernativeportal.c | 2 +-
gtk/gtkprintoperation-unix.c | 6 +++---
gtk/gtkprivate.c | 24 ------------------------
gtk/gtkprivate.h | 1 -
8 files changed, 27 insertions(+), 31 deletions(-)
---
diff --git a/gdk/gdk-private.h b/gdk/gdk-private.h
index f6c712c3e7..0c83002bfc 100644
--- a/gdk/gdk-private.h
+++ b/gdk/gdk-private.h
@@ -32,6 +32,7 @@ void gdk_display_set_cursor_theme (GdkDisplay *display,
const char *theme,
int size);
gboolean gdk_running_in_sandbox (void);
+gboolean gdk_should_use_portal (void);
const gchar * gdk_get_startup_notification_id (void);
diff --git a/gdk/gdk.c b/gdk/gdk.c
index 6a8bb6dc82..f6dc7aa91c 100644
--- a/gdk/gdk.c
+++ b/gdk/gdk.c
@@ -279,6 +279,26 @@ gdk_running_in_sandbox (void)
return ret;
}
+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';
+}
+
/**
* SECTION:threads
* @Short_description: Functions for using GDK in multi-threaded programs
diff --git a/gtk/gtkapplication-dbus.c b/gtk/gtkapplication-dbus.c
index f089e06483..e83265091c 100644
--- a/gtk/gtkapplication-dbus.c
+++ b/gtk/gtkapplication-dbus.c
@@ -259,7 +259,7 @@ gtk_application_impl_dbus_startup (GtkApplicationImpl *impl,
dbus->object_path = g_application_get_dbus_object_path (G_APPLICATION (impl->application));
dbus->unique_name = g_dbus_connection_get_unique_name (dbus->session);
- if (gtk_should_use_portal ())
+ if (gdk_should_use_portal ())
goto out;
g_debug ("Connecting to session manager");
diff --git a/gtk/gtkcolorpickerportal.c b/gtk/gtkcolorpickerportal.c
index 3198545a0b..993427bb6e 100644
--- a/gtk/gtkcolorpickerportal.c
+++ b/gtk/gtkcolorpickerportal.c
@@ -53,7 +53,7 @@ gtk_color_picker_portal_initable_init (GInitable *initable,
GVariant *ret;
guint version;
- if (!gtk_should_use_portal ())
+ if (!gdk_should_use_portal ())
return FALSE;
picker->portal_proxy = g_dbus_proxy_new_for_bus_sync (G_BUS_TYPE_SESSION,
diff --git a/gtk/gtkfilechoosernativeportal.c b/gtk/gtkfilechoosernativeportal.c
index 4073bb0814..912013140e 100644
--- a/gtk/gtkfilechoosernativeportal.c
+++ b/gtk/gtkfilechoosernativeportal.c
@@ -406,7 +406,7 @@ gtk_file_chooser_native_portal_show (GtkFileChooserNative *self)
GtkFileChooserAction action;
const char *method_name;
- if (!gtk_should_use_portal ())
+ if (!gdk_should_use_portal ())
return FALSE;
connection = g_bus_get_sync (G_BUS_TYPE_SESSION, NULL, NULL);
diff --git a/gtk/gtkprintoperation-unix.c b/gtk/gtkprintoperation-unix.c
index 7c044120b9..85cc171805 100644
--- a/gtk/gtkprintoperation-unix.c
+++ b/gtk/gtkprintoperation-unix.c
@@ -1217,7 +1217,7 @@ _gtk_print_operation_platform_backend_run_dialog (GtkPrintOperation *op,
GtkWindow *parent,
gboolean *do_print)
{
- if (gtk_should_use_portal ())
+ if (gdk_should_use_portal ())
return gtk_print_operation_portal_run_dialog (op, show_dialog, parent, do_print);
else
return gtk_print_operation_unix_run_dialog (op, show_dialog, parent, do_print);
@@ -1228,7 +1228,7 @@ _gtk_print_operation_platform_backend_run_dialog_async (GtkPrintOperation
GtkWindow *parent,
GtkPrintOperationPrintFunc print_cb)
{
- if (gtk_should_use_portal ())
+ if (gdk_should_use_portal ())
gtk_print_operation_portal_run_dialog_async (op, show_dialog, parent, print_cb);
else
gtk_print_operation_unix_run_dialog_async (op, show_dialog, parent, print_cb);
@@ -1240,7 +1240,7 @@ _gtk_print_operation_platform_backend_launch_preview (GtkPrintOperation *op,
GtkWindow *parent,
const gchar *filename)
{
- if (gtk_should_use_portal ())
+ if (gdk_should_use_portal ())
gtk_print_operation_portal_launch_preview (op, surface, parent, filename);
else
gtk_print_operation_unix_launch_preview (op, surface, parent, filename);
diff --git a/gtk/gtkprivate.c b/gtk/gtkprivate.c
index 0d3dfd78a0..8de1e81a5e 100644
--- a/gtk/gtkprivate.c
+++ b/gtk/gtkprivate.c
@@ -268,30 +268,6 @@ _gtk_ensure_resources (void)
g_once (®ister_resources_once, register_resources, NULL);
}
-gboolean
-gtk_should_use_portal (void)
-{
- static const char *use_portal = NULL;
-
- if (G_UNLIKELY (use_portal == NULL))
- {
- char *path;
-
- path = g_build_filename (g_get_user_runtime_dir (), "flatpak-info", NULL);
- if (g_file_test (path, G_FILE_TEST_EXISTS))
- use_portal = "1";
- else
- {
- use_portal = g_getenv ("GTK_USE_PORTAL");
- if (!use_portal)
- use_portal = "";
- }
- g_free (path);
- }
-
- return use_portal[0] == '1';
-}
-
static char *
get_portal_path (GDBusConnection *connection,
const char *kind,
diff --git a/gtk/gtkprivate.h b/gtk/gtkprivate.h
index 58b2453930..6a13633f47 100644
--- a/gtk/gtkprivate.h
+++ b/gtk/gtkprivate.h
@@ -109,7 +109,6 @@ GtkWidget * _gtk_toplevel_pick (GtkWindow *toplevel,
gdouble _gtk_get_slowdown (void);
void _gtk_set_slowdown (gdouble slowdown_factor);
-gboolean gtk_should_use_portal (void);
char *gtk_get_portal_request_path (GDBusConnection *connection,
char **token);
char *gtk_get_portal_session_path (GDBusConnection *connection,
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]