[nautilus] Move X11/Wayland export code to NautilusWindow
- From: António Fernandes <antoniof src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [nautilus] Move X11/Wayland export code to NautilusWindow
- Date: Tue, 27 Aug 2019 10:19:07 +0000 (UTC)
commit 77c613bf9a33ac67c6f136c04ce0dbf9bf4953e2
Author: Cosimo Cecchi <cosimoc gnome org>
Date: Tue Jul 2 21:11:56 2019 -0700
Move X11/Wayland export code to NautilusWindow
We want to reuse this code for the previewer window under Wayland,
so move it to a common place.
src/nautilus-program-choosing.c | 109 +++-------------------------------
src/nautilus-window.c | 126 ++++++++++++++++++++++++++++++++++++++--
src/nautilus-window.h | 10 ++++
3 files changed, 141 insertions(+), 104 deletions(-)
---
diff --git a/src/nautilus-program-choosing.c b/src/nautilus-program-choosing.c
index 7ce31ffe4..047a78c2b 100644
--- a/src/nautilus-program-choosing.c
+++ b/src/nautilus-program-choosing.c
@@ -26,6 +26,7 @@
#include "nautilus-global-preferences.h"
#include "nautilus-icon-info.h"
#include "nautilus-ui-utilities.h"
+#include "nautilus-window.h"
#include <eel/eel-vfs-extensions.h>
#include <gtk/gtk.h>
#include <glib/gi18n.h>
@@ -34,7 +35,6 @@
#include <stdlib.h>
#include <gdk/gdk.h>
-#include <gdk/gdkx.h>
static void
add_file_to_recent (NautilusFile *file,
@@ -492,105 +492,13 @@ nautilus_launch_desktop_file (GdkScreen *screen,
* nor returns a useful value.
*/
-#ifdef GDK_WINDOWING_WAYLAND
-#include <gdk/gdkwayland.h>
-#endif
-
-typedef void (*GtkWindowHandleExported) (GtkWindow *window,
- const char *handle,
- gpointer user_data);
-
-#ifdef GDK_WINDOWING_WAYLAND
-typedef struct
-{
- GtkWindow *window;
- GtkWindowHandleExported callback;
- gpointer user_data;
-} WaylandWindowHandleExportedData;
-
-static void
-wayland_window_handle_exported (GdkWindow *window,
- const char *wayland_handle_str,
- gpointer user_data)
-{
- WaylandWindowHandleExportedData *data = user_data;
- char *handle_str;
-
- handle_str = g_strdup_printf ("wayland:%s", wayland_handle_str);
- data->callback (data->window, handle_str, data->user_data);
- g_free (handle_str);
-}
-#endif
-
-static gboolean
-window_export_handle (GtkWindow *window,
- GtkWindowHandleExported callback,
- gpointer user_data)
-{
-#ifdef GDK_WINDOWING_X11
- if (GDK_IS_X11_DISPLAY (gtk_widget_get_display (GTK_WIDGET (window))))
- {
- GdkWindow *gdk_window = gtk_widget_get_window (GTK_WIDGET (window));
- char *handle_str;
- guint32 xid = (guint32) gdk_x11_window_get_xid (gdk_window);
-
- handle_str = g_strdup_printf ("x11:%x", xid);
- callback (window, handle_str, user_data);
-
- return TRUE;
- }
-#endif
-#ifdef GDK_WINDOWING_WAYLAND
- if (GDK_IS_WAYLAND_DISPLAY (gtk_widget_get_display (GTK_WIDGET (window))))
- {
- GdkWindow *gdk_window = gtk_widget_get_window (GTK_WIDGET (window));
- WaylandWindowHandleExportedData *data;
-
- data = g_new0 (WaylandWindowHandleExportedData, 1);
- data->window = window;
- data->callback = callback;
- data->user_data = user_data;
-
- if (!gdk_wayland_window_export_handle (gdk_window,
- wayland_window_handle_exported,
- data,
- g_free))
- {
- g_free (data);
- return FALSE;
- }
- else
- {
- return TRUE;
- }
- }
-#endif
-
- g_warning ("Couldn't export handle, unsupported windowing system");
-
- return FALSE;
-}
-
-static void
-gtk_window_unexport_handle (GtkWindow *window)
-{
-#ifdef GDK_WINDOWING_WAYLAND
- if (GDK_IS_WAYLAND_DISPLAY (gtk_widget_get_display (GTK_WIDGET (window))))
- {
- GdkWindow *gdk_window = gtk_widget_get_window (GTK_WIDGET (window));
-
- gdk_wayland_window_unexport_handle (gdk_window);
- }
-#endif
-}
-
static void
on_launch_default_for_uri (GObject *source,
GAsyncResult *result,
gpointer data)
{
GTask *task;
- GtkWindow *window;
+ NautilusWindow *window;
gboolean success;
GError *error = NULL;
@@ -601,7 +509,7 @@ on_launch_default_for_uri (GObject *source,
if (window)
{
- gtk_window_unexport_handle (window);
+ nautilus_window_unexport_handle (window);
}
if (success)
@@ -613,13 +521,14 @@ on_launch_default_for_uri (GObject *source,
g_task_return_error (task, error);
}
- /* Reffed in the call to window_export_handle */
+ /* Reffed in the call to nautilus_window_export_handle */
g_object_unref (task);
}
static void
-on_window_handle_export (GtkWindow *window,
+on_window_handle_export (NautilusWindow *window,
const char *handle_str,
+ guint xid,
gpointer user_data)
{
GTask *task = user_data;
@@ -688,9 +597,9 @@ nautilus_launch_default_for_uri_async (const char *uri,
{
gboolean handle_exported;
- handle_exported = window_export_handle (parent_window,
- on_window_handle_export,
- g_object_ref (task));
+ handle_exported = nautilus_window_export_handle (NAUTILUS_WINDOW (parent_window),
+ on_window_handle_export,
+ g_object_ref (task));
if (handle_exported)
{
diff --git a/src/nautilus-window.c b/src/nautilus-window.c
index 5ea21b1d8..ace8f1d3c 100644
--- a/src/nautilus-window.c
+++ b/src/nautilus-window.c
@@ -31,12 +31,19 @@
#include <eel/eel-vfs-extensions.h>
#include <gdk-pixbuf/gdk-pixbuf.h>
#include <gdk/gdkkeysyms.h>
-#include <gdk/gdkx.h>
#include <glib/gi18n.h>
#include <gtk/gtk.h>
#include <math.h>
#include <sys/time.h>
+#ifdef GDK_WINDOWING_WAYLAND
+#include <gdk/gdkwayland.h>
+#endif
+
+#ifdef GDK_WINDOWING_X11
+#include <gdk/gdkx.h>
+#endif
+
#define DEBUG_FLAG NAUTILUS_DEBUG_WINDOW
#include "nautilus-debug.h"
@@ -135,6 +142,9 @@ struct _NautilusWindow
/* focus widget before the location bar has been shown temporarily */
GtkWidget *last_focus_widget;
+ /* Handle when exported */
+ gchar *export_handle;
+
guint sidebar_width_handler_id;
guint bookmarks_id;
@@ -1214,6 +1224,19 @@ action_restore_tab (GSimpleAction *action,
free_restore_tab_data (data, NULL);
}
+static guint
+get_window_xid (NautilusWindow *window)
+{
+#ifdef GDK_WINDOWING_X11
+ if (GDK_IS_X11_DISPLAY (gtk_widget_get_display (GTK_WIDGET (window))))
+ {
+ GdkWindow *gdk_window = gtk_widget_get_window (GTK_WIDGET (window));
+ return (guint) gdk_x11_window_get_xid (gdk_window);
+ }
+#endif
+ return 0;
+}
+
static void
action_format (GSimpleAction *action,
GVariant *variant,
@@ -1222,12 +1245,10 @@ action_format (GSimpleAction *action,
NautilusWindow *window = NAUTILUS_WINDOW (user_data);
GAppInfo *app_info;
gchar *cmdline, *device_identifier, *xid_string;
- gint xid;
device_identifier = g_volume_get_identifier (window->selected_volume,
G_VOLUME_IDENTIFIER_KIND_UNIX_DEVICE);
- xid = (gint) gdk_x11_window_get_xid (gtk_widget_get_window (GTK_WIDGET (window)));
- xid_string = g_strdup_printf ("%d", xid);
+ xid_string = g_strdup_printf ("%x", get_window_xid (window));
cmdline = g_strconcat ("gnome-disks ",
"--block-device ", device_identifier, " ",
@@ -2285,6 +2306,8 @@ nautilus_window_destroy (GtkWidget *object)
g_clear_handle_id (&window->in_app_notification_undo_timeout_id, g_source_remove);
+ nautilus_window_unexport_handle (window);
+
GTK_WIDGET_CLASS (nautilus_window_parent_class)->destroy (object);
}
@@ -2524,6 +2547,101 @@ nautilus_window_sync_title (NautilusWindow *window,
nautilus_notebook_sync_tab_label (NAUTILUS_NOTEBOOK (window->notebook), slot);
}
+#ifdef GDK_WINDOWING_WAYLAND
+typedef struct
+{
+ NautilusWindow *window;
+ NautilusWindowHandleExported callback;
+ gpointer user_data;
+} WaylandWindowHandleExportedData;
+
+static void
+wayland_window_handle_exported (GdkWindow *window,
+ const char *wayland_handle_str,
+ gpointer user_data)
+{
+ WaylandWindowHandleExportedData *data = user_data;
+
+ data->window->export_handle = g_strdup_printf ("wayland:%s", wayland_handle_str);
+ data->callback (data->window, data->window->export_handle, 0, data->user_data);
+}
+#endif
+
+gboolean
+nautilus_window_export_handle (NautilusWindow *window,
+ NautilusWindowHandleExported callback,
+ gpointer user_data)
+{
+ guint xid = get_window_xid (window);
+
+ if (window->export_handle != NULL)
+ {
+ callback (window, window->export_handle, xid, user_data);
+ return TRUE;
+ }
+
+#ifdef GDK_WINDOWING_X11
+ if (GDK_IS_X11_DISPLAY (gtk_widget_get_display (GTK_WIDGET (window))))
+ {
+ window->export_handle = g_strdup_printf ("x11:%x", xid);
+ callback (window, window->export_handle, xid, user_data);
+
+ return TRUE;
+ }
+#endif
+#ifdef GDK_WINDOWING_WAYLAND
+ if (GDK_IS_WAYLAND_DISPLAY (gtk_widget_get_display (GTK_WIDGET (window))))
+ {
+ GdkWindow *gdk_window = gtk_widget_get_window (GTK_WIDGET (window));
+ WaylandWindowHandleExportedData *data;
+
+ data = g_new0 (WaylandWindowHandleExportedData, 1);
+ data->window = window;
+ data->callback = callback;
+ data->user_data = user_data;
+
+ if (!gdk_wayland_window_export_handle (gdk_window,
+ wayland_window_handle_exported,
+ data,
+ g_free))
+ {
+ g_free (data);
+ return FALSE;
+ }
+ else
+ {
+ return TRUE;
+ }
+ }
+#endif
+
+ g_warning ("Couldn't export handle, unsupported windowing system");
+
+ return FALSE;
+}
+
+void
+nautilus_window_unexport_handle (NautilusWindow *window)
+{
+ if (window->export_handle == NULL)
+ {
+ return;
+ }
+
+#ifdef GDK_WINDOWING_WAYLAND
+ if (GDK_IS_WAYLAND_DISPLAY (gtk_widget_get_display (GTK_WIDGET (window))))
+ {
+ GdkWindow *gdk_window = gtk_widget_get_window (GTK_WIDGET (window));
+ if (gdk_window != NULL)
+ {
+ gdk_wayland_window_unexport_handle (gdk_window);
+ }
+ }
+#endif
+
+ g_clear_pointer (&window->export_handle, g_free);
+}
+
/**
* nautilus_window_show:
* @widget: GtkWidget
diff --git a/src/nautilus-window.h b/src/nautilus-window.h
index d5a5ecd91..ac8833a20 100644
--- a/src/nautilus-window.h
+++ b/src/nautilus-window.h
@@ -40,6 +40,11 @@ typedef gboolean (* NautilusWindowGoToCallback) (NautilusWindow *window,
GError *error,
gpointer user_data);
+typedef void (* NautilusWindowHandleExported) (NautilusWindow *window,
+ const char *handle,
+ guint xid,
+ gpointer user_data);
+
/* window geometry */
/* Min values are very small, and a Nautilus window at this tiny size is *almost*
* completely unusable. However, if all the extra bits (sidebar, location bar, etc)
@@ -108,4 +113,9 @@ void nautilus_window_initialize_slot (NautilusWindow *window,
NautilusWindowSlot *slot,
NautilusWindowOpenFlags flags);
+gboolean nautilus_window_export_handle (NautilusWindow *window,
+ NautilusWindowHandleExported callback,
+ gpointer user_data);
+void nautilus_window_unexport_handle (NautilusWindow *window);
+
G_END_DECLS
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]