[nautilus] previewer: use NautilusPreviewer2 interface
- From: António Fernandes <antoniof src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [nautilus] previewer: use NautilusPreviewer2 interface
- Date: Tue, 27 Aug 2019 10:19:12 +0000 (UTC)
commit 74a528130204f97f8306e0046eda747458e2a73d
Author: Cosimo Cecchi <cosimoc gnome org>
Date: Tue Jul 2 21:49:15 2019 -0700
previewer: use NautilusPreviewer2 interface
Use the NautilusPreviewer2 interface, so the preview window can
get correctly parented under Wayland.
Fixes https://gitlab.gnome.org/GNOME/sushi/issues/1
Closes https://gitlab.gnome.org/GNOME/nautilus/merge_requests/469
src/nautilus-files-view.c | 31 +++++++++++++++---------------
src/nautilus-previewer.c | 49 +++++++++++++++--------------------------------
src/nautilus-previewer.h | 1 +
3 files changed, 32 insertions(+), 49 deletions(-)
---
diff --git a/src/nautilus-files-view.c b/src/nautilus-files-view.c
index 666fcf365..916de2581 100644
--- a/src/nautilus-files-view.c
+++ b/src/nautilus-files-view.c
@@ -1230,30 +1230,31 @@ get_view_directory (NautilusFilesView *view)
return path;
}
+static void
+on_window_handle_export (NautilusWindow *window,
+ const char *handle,
+ guint xid,
+ gpointer user_data)
+{
+ g_autofree gchar *uri = user_data;
+ nautilus_previewer_call_show_file (uri, handle, xid, TRUE);
+}
+
void
nautilus_files_view_preview_files (NautilusFilesView *view,
GList *files,
GArray *locations)
{
- gchar *uri;
- guint xid = 0;
- GtkWidget *toplevel;
- GdkWindow *window;
+ g_autofree gchar *uri = NULL;
uri = nautilus_file_get_uri (files->data);
- toplevel = gtk_widget_get_toplevel (GTK_WIDGET (view));
-
-#ifdef GDK_WINDOWING_X11
- window = gtk_widget_get_window (toplevel);
- if (GDK_IS_X11_WINDOW (window))
+ if (!nautilus_window_export_handle (nautilus_files_view_get_window (view),
+ on_window_handle_export,
+ g_strdup (uri)))
{
- xid = gdk_x11_window_get_xid (gtk_widget_get_window (toplevel));
+ /* Let's use a fallback, so at least a preview will be displayed */
+ nautilus_previewer_call_show_file (uri, "x11:0", 0, TRUE);
}
-#endif
-
- nautilus_previewer_call_show_file (uri, xid, TRUE);
-
- g_free (uri);
}
void
diff --git a/src/nautilus-previewer.c b/src/nautilus-previewer.c
index 17e666d89..aef60e615 100644
--- a/src/nautilus-previewer.c
+++ b/src/nautilus-previewer.c
@@ -30,67 +30,48 @@
#include <gio/gio.h>
#define PREVIEWER_DBUS_NAME "org.gnome.NautilusPreviewer"
-#define PREVIEWER_DBUS_IFACE "org.gnome.NautilusPreviewer"
+#define PREVIEWER2_DBUS_IFACE "org.gnome.NautilusPreviewer2"
#define PREVIEWER_DBUS_PATH "/org/gnome/NautilusPreviewer"
static void
-previewer_show_file_ready_cb (GObject *source,
- GAsyncResult *res,
- gpointer user_data)
+previewer2_method_ready_cb (GObject *source,
+ GAsyncResult *res,
+ gpointer user_data)
{
- GError *error = NULL;
+ GDBusConnection *connection = G_DBUS_CONNECTION (source);
+ g_autoptr(GError) error = NULL;
- g_dbus_connection_call_finish (G_DBUS_CONNECTION (source),
- res, &error);
+ g_dbus_connection_call_finish (connection, res, &error);
if (error != NULL)
{
- DEBUG ("Unable to call ShowFile on NautilusPreviewer: %s",
- error->message);
- g_error_free (error);
- }
-}
-
-static void
-previewer_close_ready_cb (GObject *source,
- GAsyncResult *res,
- gpointer user_data)
-{
- GError *error = NULL;
-
- g_dbus_connection_call_finish (G_DBUS_CONNECTION (source),
- res, &error);
-
- if (error != NULL)
- {
- DEBUG ("Unable to call Close on NautilusPreviewer: %s",
- error->message);
- g_error_free (error);
+ DEBUG ("Unable to call method on NautilusPreviewer: %s", error->message);
}
}
void
nautilus_previewer_call_show_file (const gchar *uri,
+ const gchar *window_handle,
guint xid,
gboolean close_if_already_visible)
{
GDBusConnection *connection = g_application_get_dbus_connection (g_application_get_default ());
GVariant *variant;
- variant = g_variant_new ("(sib)",
- uri, xid, close_if_already_visible);
+ variant = g_variant_new ("(ssb)",
+ uri, window_handle, close_if_already_visible);
g_dbus_connection_call (connection,
PREVIEWER_DBUS_NAME,
PREVIEWER_DBUS_PATH,
- PREVIEWER_DBUS_IFACE,
+ PREVIEWER2_DBUS_IFACE,
"ShowFile",
variant,
NULL,
G_DBUS_CALL_FLAGS_NONE,
-1,
NULL,
- previewer_show_file_ready_cb,
+ previewer2_method_ready_cb,
NULL);
}
@@ -103,13 +84,13 @@ nautilus_previewer_call_close (void)
g_dbus_connection_call (connection,
PREVIEWER_DBUS_NAME,
PREVIEWER_DBUS_PATH,
- PREVIEWER_DBUS_IFACE,
+ PREVIEWER2_DBUS_IFACE,
"Close",
NULL,
NULL,
G_DBUS_CALL_FLAGS_NO_AUTO_START,
-1,
NULL,
- previewer_close_ready_cb,
+ previewer2_method_ready_cb,
NULL);
}
diff --git a/src/nautilus-previewer.h b/src/nautilus-previewer.h
index 1c45653b1..e9e399fbc 100644
--- a/src/nautilus-previewer.h
+++ b/src/nautilus-previewer.h
@@ -27,6 +27,7 @@
G_BEGIN_DECLS
void nautilus_previewer_call_show_file (const gchar *uri,
+ const gchar *window_handle,
guint xid,
gboolean close_if_already_visible);
void nautilus_previewer_call_close (void);
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]