summaryrefslogtreecommitdiffstats
path: root/subprojects/shew/src
diff options
context:
space:
mode:
Diffstat (limited to 'subprojects/shew/src')
-rw-r--r--subprojects/shew/src/meson.build29
-rw-r--r--subprojects/shew/src/shew-external-window-wayland.c117
-rw-r--r--subprojects/shew/src/shew-external-window-wayland.h30
-rw-r--r--subprojects/shew/src/shew-external-window-x11.c136
-rw-r--r--subprojects/shew/src/shew-external-window-x11.h30
-rw-r--r--subprojects/shew/src/shew-external-window.c161
-rw-r--r--subprojects/shew/src/shew-external-window.h43
-rw-r--r--subprojects/shew/src/shew-window-exporter.c217
-rw-r--r--subprojects/shew/src/shew-window-exporter.h38
9 files changed, 801 insertions, 0 deletions
diff --git a/subprojects/shew/src/meson.build b/subprojects/shew/src/meson.build
new file mode 100644
index 0000000..e590a46
--- /dev/null
+++ b/subprojects/shew/src/meson.build
@@ -0,0 +1,29 @@
+shew_public_headers = files(
+ 'shew-external-window.h',
+ 'shew-window-exporter.h',
+)
+
+shew_sources = [
+ 'shew-external-window-wayland.c',
+ 'shew-external-window-x11.c',
+ 'shew-external-window.c',
+ 'shew-window-exporter.c',
+]
+
+libshew = library(full_name,
+ sources: shew_sources,
+ dependencies: [gtk_dep, x11_dep],
+ install_dir: pkglibdir,
+ install: true,
+)
+
+libshew_gir = gnome.generate_gir(libshew,
+ sources: shew_sources + shew_public_headers,
+ nsversion: api_version,
+ namespace: 'Shew',
+ includes: ['Gdk-4.0', 'Gtk-4.0'],
+ extra_args: ['--quiet'],
+ install_dir_gir: girdir,
+ install_dir_typelib: typelibdir,
+ install: true,
+)
diff --git a/subprojects/shew/src/shew-external-window-wayland.c b/subprojects/shew/src/shew-external-window-wayland.c
new file mode 100644
index 0000000..3d51aa8
--- /dev/null
+++ b/subprojects/shew/src/shew-external-window-wayland.c
@@ -0,0 +1,117 @@
+/*
+ * Copyright © 2016 Red Hat, Inc
+ *
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 2 of the License, or (at your option) any later version.
+ *
+ * This library is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this library. If not, see <http://www.gnu.org/licenses/>.
+ *
+ * Authors:
+ * Jonas Ådahl <jadahl@redhat.com>
+ */
+
+#include <gdk/gdk.h>
+
+#ifdef GDK_WINDOWING_WAYLAND
+#include <gdk/wayland/gdkwayland.h>
+#endif
+
+#include "shew-external-window-wayland.h"
+
+static GdkDisplay *wayland_display;
+
+struct _ShewExternalWindowWayland
+{
+ ShewExternalWindow parent;
+
+ char *handle_str;
+};
+
+G_DEFINE_TYPE (ShewExternalWindowWayland, shew_external_window_wayland,
+ SHEW_TYPE_EXTERNAL_WINDOW)
+
+static GdkDisplay *
+get_wayland_display (void)
+{
+ if (wayland_display)
+ return wayland_display;
+
+ gdk_set_allowed_backends ("wayland");
+ wayland_display = gdk_display_open (NULL);
+ gdk_set_allowed_backends (NULL);
+
+ if (!wayland_display)
+ g_warning ("Failed to open Wayland display");
+
+ return wayland_display;
+}
+
+ShewExternalWindowWayland *
+shew_external_window_wayland_new (const char *handle_str)
+{
+ ShewExternalWindowWayland *external_window_wayland;
+ GdkDisplay *display;
+
+ display = get_wayland_display ();
+ if (!display)
+ {
+ g_warning ("No Wayland display connection, ignoring Wayland parent");
+ return NULL;
+ }
+
+ external_window_wayland = g_object_new (SHEW_TYPE_EXTERNAL_WINDOW_WAYLAND,
+ "display", display,
+ NULL);
+ external_window_wayland->handle_str = g_strdup (handle_str);
+
+ return external_window_wayland;
+}
+
+static void
+shew_external_window_wayland_set_parent_of (ShewExternalWindow *external_window,
+ GdkSurface *child_surface)
+{
+ ShewExternalWindowWayland *external_window_wayland =
+ SHEW_EXTERNAL_WINDOW_WAYLAND (external_window);
+ char *handle_str = external_window_wayland->handle_str;
+
+#ifdef GDK_WINDOWING_WAYLAND
+ if (!gdk_wayland_toplevel_set_transient_for_exported (GDK_WAYLAND_TOPLEVEL (child_surface), handle_str))
+ g_warning ("Failed to set portal window transient for external parent");
+#endif
+}
+
+static void
+shew_external_window_wayland_dispose (GObject *object)
+{
+ ShewExternalWindowWayland *external_window_wayland =
+ SHEW_EXTERNAL_WINDOW_WAYLAND (object);
+
+ g_free (external_window_wayland->handle_str);
+
+ G_OBJECT_CLASS (shew_external_window_wayland_parent_class)->dispose (object);
+}
+
+static void
+shew_external_window_wayland_init (ShewExternalWindowWayland *external_window_wayland)
+{
+}
+
+static void
+shew_external_window_wayland_class_init (ShewExternalWindowWaylandClass *klass)
+{
+ GObjectClass *object_class = G_OBJECT_CLASS (klass);
+ ShewExternalWindowClass *external_window_class = SHEW_EXTERNAL_WINDOW_CLASS (klass);
+
+ object_class->dispose = shew_external_window_wayland_dispose;
+
+ external_window_class->set_parent_of = shew_external_window_wayland_set_parent_of;
+}
diff --git a/subprojects/shew/src/shew-external-window-wayland.h b/subprojects/shew/src/shew-external-window-wayland.h
new file mode 100644
index 0000000..c9e9fd7
--- /dev/null
+++ b/subprojects/shew/src/shew-external-window-wayland.h
@@ -0,0 +1,30 @@
+/*
+ * Copyright © 2016 Red Hat, Inc
+ *
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 2 of the License, or (at your option) any later version.
+ *
+ * This library is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this library. If not, see <http://www.gnu.org/licenses/>.
+ *
+ * Authors:
+ * Jonas Ådahl <jadahl@redhat.com>
+ */
+
+#pragma once
+
+#include <glib-object.h>
+
+#include "shew-external-window.h"
+
+#define SHEW_TYPE_EXTERNAL_WINDOW_WAYLAND (shew_external_window_wayland_get_type ())
+G_DECLARE_FINAL_TYPE (ShewExternalWindowWayland, shew_external_window_wayland, SHEW, EXTERNAL_WINDOW_WAYLAND, ShewExternalWindow)
+
+ShewExternalWindowWayland *shew_external_window_wayland_new (const char *handle_str);
diff --git a/subprojects/shew/src/shew-external-window-x11.c b/subprojects/shew/src/shew-external-window-x11.c
new file mode 100644
index 0000000..7f08665
--- /dev/null
+++ b/subprojects/shew/src/shew-external-window-x11.c
@@ -0,0 +1,136 @@
+/*
+ * Copyright © 2016 Red Hat, Inc
+ *
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 2 of the License, or (at your option) any later version.
+ *
+ * This library is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this library. If not, see <http://www.gnu.org/licenses/>.
+ *
+ * Authors:
+ * Jonas Ådahl <jadahl@redhat.com>
+ */
+
+#include <errno.h>
+#include <gdk/gdk.h>
+#ifdef GDK_WINDOWING_X11
+#include <gdk/x11/gdkx.h>
+#include <X11/Xlib.h>
+#endif
+#include <stdlib.h>
+
+#include "shew-external-window-x11.h"
+
+static GdkDisplay *x11_display;
+
+struct _ShewExternalWindowX11
+{
+ ShewExternalWindow parent;
+
+ int foreign_xid;
+};
+
+G_DEFINE_TYPE (ShewExternalWindowX11, shew_external_window_x11,
+ SHEW_TYPE_EXTERNAL_WINDOW)
+
+static GdkDisplay *
+get_x11_display (void)
+{
+ if (x11_display)
+ return x11_display;
+
+ gdk_set_allowed_backends ("x11");
+ x11_display = gdk_display_open (NULL);
+ gdk_set_allowed_backends (NULL);
+ if (!x11_display)
+ g_warning ("Failed to open X11 display");
+
+ return x11_display;
+}
+
+static gboolean
+check_foreign_xid (GdkDisplay *display,
+ int xid)
+{
+ gboolean result = FALSE;
+#ifdef GDK_WINDOWING_X11
+ XWindowAttributes attrs;
+
+ gdk_x11_display_error_trap_push (display);
+ result = XGetWindowAttributes (GDK_DISPLAY_XDISPLAY (display), xid, &attrs);
+ if (gdk_x11_display_error_trap_pop (display))
+ return FALSE;
+
+#endif
+ return result;
+}
+
+ShewExternalWindowX11 *
+shew_external_window_x11_new (const char *handle_str)
+{
+ ShewExternalWindowX11 *external_window_x11;
+ GdkDisplay *display;
+ int xid;
+
+ display = get_x11_display ();
+ if (!display)
+ {
+ g_warning ("No X display connection, ignoring X11 parent");
+ return NULL;
+ }
+
+ errno = 0;
+ xid = strtol (handle_str, NULL, 16);
+ if (errno != 0)
+ {
+ g_warning ("Failed to reference external X11 window, invalid XID %s", handle_str);
+ return NULL;
+ }
+
+ if (!check_foreign_xid (display, xid))
+ {
+ g_warning ("Failed to find foreign window for XID %d", xid);
+ return NULL;
+ }
+
+ external_window_x11 = g_object_new (SHEW_TYPE_EXTERNAL_WINDOW_X11,
+ "display", display,
+ NULL);
+ external_window_x11->foreign_xid = xid;
+
+ return external_window_x11;
+}
+
+static void
+shew_external_window_x11_set_parent_of (ShewExternalWindow *external_window,
+ GdkSurface *child_surface)
+{
+ ShewExternalWindowX11 *external_window_x11 =
+ SHEW_EXTERNAL_WINDOW_X11 (external_window);
+
+#ifdef GDK_WINDOWING_X11
+ XSetTransientForHint (GDK_SURFACE_XDISPLAY (child_surface),
+ GDK_SURFACE_XID (child_surface),
+ external_window_x11->foreign_xid);
+#endif
+}
+
+static void
+shew_external_window_x11_init (ShewExternalWindowX11 *external_window_x11)
+{
+}
+
+static void
+shew_external_window_x11_class_init (ShewExternalWindowX11Class *klass)
+{
+ ShewExternalWindowClass *external_window_class = SHEW_EXTERNAL_WINDOW_CLASS (klass);
+
+ external_window_class->set_parent_of = shew_external_window_x11_set_parent_of;
+}
diff --git a/subprojects/shew/src/shew-external-window-x11.h b/subprojects/shew/src/shew-external-window-x11.h
new file mode 100644
index 0000000..ed0bab4
--- /dev/null
+++ b/subprojects/shew/src/shew-external-window-x11.h
@@ -0,0 +1,30 @@
+/*
+ * Copyright © 2016 Red Hat, Inc
+ *
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 2 of the License, or (at your option) any later version.
+ *
+ * This library is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this library. If not, see <http://www.gnu.org/licenses/>.
+ *
+ * Authors:
+ * Jonas Ådahl <jadahl@redhat.com>
+ */
+
+#pragma once
+
+#include <glib-object.h>
+
+#include "shew-external-window.h"
+
+#define SHEW_TYPE_EXTERNAL_WINDOW_X11 (shew_external_window_x11_get_type ())
+G_DECLARE_FINAL_TYPE (ShewExternalWindowX11, shew_external_window_x11, SHEW, EXTERNAL_WINDOW_X11, ShewExternalWindow)
+
+ShewExternalWindowX11 *shew_external_window_x11_new (const char *handle_str);
diff --git a/subprojects/shew/src/shew-external-window.c b/subprojects/shew/src/shew-external-window.c
new file mode 100644
index 0000000..118d93f
--- /dev/null
+++ b/subprojects/shew/src/shew-external-window.c
@@ -0,0 +1,161 @@
+/*
+ * Copyright © 2016 Red Hat, Inc
+ *
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 2 of the License, or (at your option) any later version.
+ *
+ * This library is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this library. If not, see <http://www.gnu.org/licenses/>.
+ *
+ * Authors:
+ * Jonas Ådahl <jadahl@redhat.com>
+ */
+
+#include <string.h>
+
+#include "shew-external-window.h"
+#include "shew-external-window-x11.h"
+#include "shew-external-window-wayland.h"
+
+enum
+{
+ PROP_0,
+
+ PROP_DISPLAY,
+};
+
+typedef struct _ShewExternalWindowPrivate
+{
+ GdkDisplay *display;
+} ShewExternalWindowPrivate;
+
+G_DEFINE_TYPE_WITH_PRIVATE (ShewExternalWindow, shew_external_window, G_TYPE_OBJECT)
+
+ShewExternalWindow *
+shew_external_window_new_from_handle (const char *handle_str)
+{
+#ifdef GDK_WINDOWING_X11
+ {
+ const char x11_prefix[] = "x11:";
+ if (g_str_has_prefix (handle_str, x11_prefix))
+ {
+ ShewExternalWindowX11 *external_window_x11;
+ const char *x11_handle_str = handle_str + strlen (x11_prefix);
+
+ external_window_x11 = shew_external_window_x11_new (x11_handle_str);
+ return SHEW_EXTERNAL_WINDOW (external_window_x11);
+ }
+ }
+#endif
+#ifdef GDK_WINDOWING_WAYLAND
+ {
+ const char wayland_prefix[] = "wayland:";
+ if (g_str_has_prefix (handle_str, wayland_prefix))
+ {
+ ShewExternalWindowWayland *external_window_wayland;
+ const char *wayland_handle_str = handle_str + strlen (wayland_prefix);
+
+ external_window_wayland =
+ shew_external_window_wayland_new (wayland_handle_str);
+ return SHEW_EXTERNAL_WINDOW (external_window_wayland);
+ }
+ }
+#endif
+
+ g_warning ("Unhandled parent window type %s\n", handle_str);
+ return NULL;
+}
+
+void
+shew_external_window_set_parent_of (ShewExternalWindow *external_window,
+ GdkSurface *child_surface)
+{
+ SHEW_EXTERNAL_WINDOW_GET_CLASS (external_window)->set_parent_of (external_window,
+ child_surface);
+}
+
+/**
+ * shew_external_window_get_display:
+ * Returns: (transfer none)
+ */
+GdkDisplay *
+shew_external_window_get_display (ShewExternalWindow *external_window)
+{
+ ShewExternalWindowPrivate *priv =
+ shew_external_window_get_instance_private (external_window);
+
+ return priv->display;
+}
+
+static void
+shew_external_window_set_property (GObject *object,
+ guint prop_id,
+ const GValue *value,
+ GParamSpec *pspec)
+{
+ ShewExternalWindow *external_window = SHEW_EXTERNAL_WINDOW (object);
+ ShewExternalWindowPrivate *priv =
+ shew_external_window_get_instance_private (external_window);
+
+ switch (prop_id)
+ {
+ case PROP_DISPLAY:
+ g_set_object (&priv->display, g_value_get_object (value));
+ break;
+
+ default:
+ G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
+ }
+}
+
+static void
+shew_external_window_get_property (GObject *object,
+ guint prop_id,
+ GValue *value,
+ GParamSpec *pspec)
+{
+ ShewExternalWindow *external_window = SHEW_EXTERNAL_WINDOW (object);
+ ShewExternalWindowPrivate *priv =
+ shew_external_window_get_instance_private (external_window);
+
+ switch (prop_id)
+ {
+ case PROP_DISPLAY:
+ g_value_set_object (value, priv->display);
+ break;
+
+ default:
+ G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
+ }
+}
+
+static void
+shew_external_window_init (ShewExternalWindow *external_window)
+{
+}
+
+static void
+shew_external_window_class_init (ShewExternalWindowClass *klass)
+{
+ GObjectClass *object_class = G_OBJECT_CLASS (klass);
+
+ object_class->get_property = shew_external_window_get_property;
+ object_class->set_property = shew_external_window_set_property;
+
+ g_object_class_install_property (object_class,
+ PROP_DISPLAY,
+ g_param_spec_object ("display",
+ "GdkDisplay",
+ "The GdkDisplay instance",
+ GDK_TYPE_DISPLAY,
+ G_PARAM_READWRITE |
+ G_PARAM_CONSTRUCT_ONLY |
+ G_PARAM_STATIC_STRINGS));
+}
diff --git a/subprojects/shew/src/shew-external-window.h b/subprojects/shew/src/shew-external-window.h
new file mode 100644
index 0000000..ca6671b
--- /dev/null
+++ b/subprojects/shew/src/shew-external-window.h
@@ -0,0 +1,43 @@
+/*
+ * Copyright © 2016 Red Hat, Inc
+ *
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 2 of the License, or (at your option) any later version.
+ *
+ * This library is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this library. If not, see <http://www.gnu.org/licenses/>.
+ *
+ * Authors:
+ * Jonas Ådahl <jadahl@redhat.com>
+ */
+
+#pragma once
+
+#include <glib-object.h>
+#include <gtk/gtk.h>
+
+
+#define SHEW_TYPE_EXTERNAL_WINDOW (shew_external_window_get_type ())
+G_DECLARE_DERIVABLE_TYPE (ShewExternalWindow, shew_external_window, SHEW, EXTERNAL_WINDOW, GObject)
+
+struct _ShewExternalWindowClass
+{
+ GObjectClass parent_class;
+
+ void (*set_parent_of) (ShewExternalWindow *external_window,
+ GdkSurface *child_surface);
+};
+
+ShewExternalWindow *shew_external_window_new_from_handle (const char *handle_str);
+
+void shew_external_window_set_parent_of (ShewExternalWindow *external_window,
+ GdkSurface *child_surface);
+
+GdkDisplay *shew_external_window_get_display (ShewExternalWindow *external_window);
diff --git a/subprojects/shew/src/shew-window-exporter.c b/subprojects/shew/src/shew-window-exporter.c
new file mode 100644
index 0000000..ab84bf8
--- /dev/null
+++ b/subprojects/shew/src/shew-window-exporter.c
@@ -0,0 +1,217 @@
+/*
+ * Copyright © 2020 Red Hat, Inc
+ *
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 2 of the License, or (at your option) any later version.
+ *
+ * This library is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this library. If not, see <http://www.gnu.org/licenses/>.
+ *
+ * Authors:
+ * Florian Müllner <fmuellner@gnome.org>
+ */
+
+#include "shew-window-exporter.h"
+
+#ifdef GDK_WINDOWING_X11
+#include <gdk/x11/gdkx.h>
+#endif
+#ifdef GDK_WINDOWING_WAYLAND
+#include <gdk/wayland/gdkwayland.h>
+#endif
+
+struct _ShewWindowExporter
+{
+ GObject parent;
+
+ GtkWindow *window;
+};
+
+G_DEFINE_TYPE (ShewWindowExporter, shew_window_exporter, G_TYPE_OBJECT)
+
+enum
+{
+ PROP_0,
+
+ PROP_WINDOW,
+};
+
+ShewWindowExporter *
+shew_window_exporter_new (GtkWindow *window)
+{
+ return g_object_new (SHEW_TYPE_WINDOW_EXPORTER,
+ "window", window,
+ NULL);
+}
+
+#ifdef GDK_WINDOWING_WAYLAND
+static void
+wayland_window_exported (GdkToplevel *toplevel,
+ const char *handle,
+ gpointer user_data)
+{
+ g_autoptr (GTask) task = user_data;
+
+ g_task_return_pointer (task, g_strdup_printf ("wayland:%s", handle), g_free);
+}
+#endif
+
+void
+shew_window_exporter_export (ShewWindowExporter *exporter,
+ GAsyncReadyCallback callback,
+ gpointer user_data)
+{
+ g_autoptr (GTask) task = NULL;
+ GtkWidget *widget;
+
+ g_return_if_fail (SHEW_IS_WINDOW_EXPORTER (exporter));
+
+ if (exporter->window == NULL)
+ {
+ g_task_report_new_error (exporter, callback, user_data,
+ shew_window_exporter_export,
+ G_IO_ERROR, G_IO_ERROR_NOT_SUPPORTED,
+ "No window to export");
+ return;
+ }
+
+ task = g_task_new (exporter, NULL, callback, user_data);
+ g_task_set_source_tag (task, shew_window_exporter_export);
+
+ widget = GTK_WIDGET (exporter->window);
+
+#ifdef GDK_WINDOWING_X11
+ if (GDK_IS_X11_DISPLAY (gtk_widget_get_display (widget)))
+ {
+ GdkSurface *s = gtk_native_get_surface (GTK_NATIVE (widget));
+ guint32 xid = (guint32) gdk_x11_surface_get_xid (s);
+
+ g_task_return_pointer (task, g_strdup_printf ("x11:%x", xid), g_free);
+ }
+#endif
+
+#ifdef GDK_WINDOWING_WAYLAND
+ if (GDK_IS_WAYLAND_DISPLAY (gtk_widget_get_display (widget)))
+ {
+ GdkSurface *s = gtk_native_get_surface (GTK_NATIVE (widget));
+ gdk_wayland_toplevel_export_handle (GDK_WAYLAND_TOPLEVEL (s),
+ wayland_window_exported,
+ g_steal_pointer (&task), NULL);
+ }
+#endif
+
+ if (task != NULL && !g_task_get_completed (task))
+ {
+ g_task_return_new_error (task, G_IO_ERROR, G_IO_ERROR_NOT_SUPPORTED,
+ "Unsupported windowing system");
+ }
+}
+
+char *
+shew_window_exporter_export_finish (ShewWindowExporter *exporter,
+ GAsyncResult *result,
+ GError **error)
+{
+ g_return_val_if_fail (SHEW_IS_WINDOW_EXPORTER (exporter), NULL);
+ g_return_val_if_fail (g_async_result_is_tagged (result, shew_window_exporter_export), NULL);
+
+ return g_task_propagate_pointer (G_TASK (result), error);
+}
+
+void
+shew_window_exporter_unexport (ShewWindowExporter *exporter)
+{
+ GtkWidget *widget;
+
+ g_return_if_fail (SHEW_IS_WINDOW_EXPORTER (exporter));
+
+ widget = GTK_WIDGET (exporter->window);
+
+#ifdef GDK_WINDOWING_WAYLAND
+ if (GDK_IS_WAYLAND_DISPLAY (gtk_widget_get_display (widget)))
+ {
+ GdkSurface *s = gtk_native_get_surface (GTK_NATIVE (widget));
+ gdk_wayland_toplevel_unexport_handle (GDK_WAYLAND_TOPLEVEL (s));
+ }
+#endif
+}
+
+static void
+shew_window_exporter_dispose (GObject *object)
+{
+ ShewWindowExporter *exporter = SHEW_WINDOW_EXPORTER (object);
+
+ g_clear_object (&exporter->window);
+
+ G_OBJECT_CLASS (shew_window_exporter_parent_class)->dispose (object);
+}
+
+static void
+shew_window_exporter_set_property (GObject *object,
+ guint prop_id,
+ const GValue *value,
+ GParamSpec *pspec)
+{
+ ShewWindowExporter *exporter = SHEW_WINDOW_EXPORTER (object);
+
+ switch (prop_id)
+ {
+ case PROP_WINDOW:
+ g_set_object (&exporter->window, g_value_get_object (value));
+ break;
+
+ default:
+ G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
+ }
+}
+
+static void
+shew_window_exporter_get_property (GObject *object,
+ guint prop_id,
+ GValue *value,
+ GParamSpec *pspec)
+{
+ ShewWindowExporter *exporter = SHEW_WINDOW_EXPORTER (object);
+
+ switch (prop_id)
+ {
+ case PROP_WINDOW:
+ g_value_set_object (value, exporter->window);
+ break;
+
+ default:
+ G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
+ }
+}
+
+static void
+shew_window_exporter_init (ShewWindowExporter *exporter)
+{
+}
+
+static void
+shew_window_exporter_class_init (ShewWindowExporterClass *klass)
+{
+ GObjectClass *object_class = G_OBJECT_CLASS (klass);
+
+ object_class->get_property = shew_window_exporter_get_property;
+ object_class->set_property = shew_window_exporter_set_property;
+ object_class->dispose = shew_window_exporter_dispose;
+
+ g_object_class_install_property (object_class,
+ PROP_WINDOW,
+ g_param_spec_object ("window",
+ "GtkWindow",
+ "The GtkWindow to export",
+ GTK_TYPE_WINDOW,
+ G_PARAM_READWRITE |
+ G_PARAM_CONSTRUCT_ONLY |
+ G_PARAM_STATIC_STRINGS));
+}
diff --git a/subprojects/shew/src/shew-window-exporter.h b/subprojects/shew/src/shew-window-exporter.h
new file mode 100644
index 0000000..224fff5
--- /dev/null
+++ b/subprojects/shew/src/shew-window-exporter.h
@@ -0,0 +1,38 @@
+/*
+ * Copyright © 2020 Red Hat, Inc
+ *
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 2 of the License, or (at your option) any later version.
+ *
+ * This library is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this library. If not, see <http://www.gnu.org/licenses/>.
+ *
+ * Authors:
+ * Florian Müllner <fmuellner@gnome.org>
+ */
+
+#pragma once
+
+#include <gtk/gtk.h>
+
+#define SHEW_TYPE_WINDOW_EXPORTER (shew_window_exporter_get_type ())
+G_DECLARE_FINAL_TYPE (ShewWindowExporter, shew_window_exporter, SHEW, WINDOW_EXPORTER, GObject)
+
+ShewWindowExporter *shew_window_exporter_new (GtkWindow *window);
+
+void shew_window_exporter_export (ShewWindowExporter *exporter,
+ GAsyncReadyCallback callback,
+ gpointer user_data);
+
+char *shew_window_exporter_export_finish (ShewWindowExporter *exporter,
+ GAsyncResult *result,
+ GError **error);
+
+void shew_window_exporter_unexport (ShewWindowExporter *exporter);