summaryrefslogtreecommitdiffstats
path: root/subprojects/shew/src
diff options
context:
space:
mode:
authorDaniel Baumann <daniel.baumann@progress-linux.org>2024-04-27 15:07:22 +0000
committerDaniel Baumann <daniel.baumann@progress-linux.org>2024-04-27 15:07:22 +0000
commitf9d480cfe50ca1d7a0f0b5a2b8bb9932962bfbe7 (patch)
treece9e8db2d4e8799780fa72ae8f1953039373e2ee /subprojects/shew/src
parentInitial commit. (diff)
downloadgnome-shell-f9d480cfe50ca1d7a0f0b5a2b8bb9932962bfbe7.tar.xz
gnome-shell-f9d480cfe50ca1d7a0f0b5a2b8bb9932962bfbe7.zip
Adding upstream version 3.38.6.upstream/3.38.6upstream
Signed-off-by: Daniel Baumann <daniel.baumann@progress-linux.org>
Diffstat (limited to '')
-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.c133
-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.c216
-rw-r--r--subprojects/shew/src/shew-window-exporter.h38
9 files changed, 797 insertions, 0 deletions
diff --git a/subprojects/shew/src/meson.build b/subprojects/shew/src/meson.build
new file mode 100644
index 0000000..c3b1a6b
--- /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],
+ install_dir: pkglibdir,
+ install: true,
+)
+
+libshew_gir = gnome.generate_gir(libshew,
+ sources: shew_sources + shew_public_headers,
+ nsversion: api_version,
+ namespace: 'Shew',
+ includes: ['Gdk-3.0', 'Gtk-3.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..8298976
--- /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/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,
+ GdkWindow *child_window)
+{
+ 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_window_set_transient_for_exported (child_window, 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..5c4c8e6
--- /dev/null
+++ b/subprojects/shew/src/shew-external-window-x11.c
@@ -0,0 +1,133 @@
+/*
+ * 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/gdkx.h>
+#endif
+#include <stdlib.h>
+
+#include "shew-external-window-x11.h"
+
+static GdkDisplay *x11_display;
+
+struct _ShewExternalWindowX11
+{
+ ShewExternalWindow parent;
+
+ GdkWindow *foreign_gdk_window;
+};
+
+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;
+}
+
+ShewExternalWindowX11 *
+shew_external_window_x11_new (const char *handle_str)
+{
+ ShewExternalWindowX11 *external_window_x11;
+ GdkDisplay *display;
+ int xid;
+ GdkWindow *foreign_gdk_window = NULL;
+
+ 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;
+ }
+
+#ifdef GDK_WINDOWING_X11
+ foreign_gdk_window = gdk_x11_window_foreign_new_for_display (display, xid);
+#endif
+
+ if (!foreign_gdk_window)
+ {
+ g_warning ("Failed to create 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_gdk_window = foreign_gdk_window;
+
+ return external_window_x11;
+}
+
+static void
+shew_external_window_x11_set_parent_of (ShewExternalWindow *external_window,
+ GdkWindow *child_window)
+{
+ ShewExternalWindowX11 *external_window_x11 =
+ SHEW_EXTERNAL_WINDOW_X11 (external_window);
+
+ gdk_window_set_transient_for (child_window,
+ external_window_x11->foreign_gdk_window);
+}
+
+static void
+shew_external_window_x11_dispose (GObject *object)
+{
+ ShewExternalWindowX11 *external_window_x11 = SHEW_EXTERNAL_WINDOW_X11 (object);
+
+ g_clear_object (&external_window_x11->foreign_gdk_window);
+
+ G_OBJECT_CLASS (shew_external_window_x11_parent_class)->dispose (object);
+}
+
+static void
+shew_external_window_x11_init (ShewExternalWindowX11 *external_window_x11)
+{
+}
+
+static void
+shew_external_window_x11_class_init (ShewExternalWindowX11Class *klass)
+{
+ GObjectClass *object_class = G_OBJECT_CLASS (klass);
+ ShewExternalWindowClass *external_window_class = SHEW_EXTERNAL_WINDOW_CLASS (klass);
+
+ object_class->dispose = shew_external_window_x11_dispose;
+
+ 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..f468346
--- /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,
+ GdkWindow *child_window)
+{
+ SHEW_EXTERNAL_WINDOW_GET_CLASS (external_window)->set_parent_of (external_window,
+ child_window);
+}
+
+/**
+ * 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..105a849
--- /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,
+ GdkWindow *child_window);
+};
+
+ShewExternalWindow *shew_external_window_new_from_handle (const char *handle_str);
+
+void shew_external_window_set_parent_of (ShewExternalWindow *external_window,
+ GdkWindow *child_window);
+
+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..f950682
--- /dev/null
+++ b/subprojects/shew/src/shew-window-exporter.c
@@ -0,0 +1,216 @@
+/*
+ * 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/gdkx.h>
+#endif
+#ifdef GDK_WINDOWING_WAYLAND
+#include <gdk/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 (GdkWindow *window,
+ 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)))
+ {
+ GdkWindow *w = gtk_widget_get_window (widget);
+ guint32 xid = (guint32) gdk_x11_window_get_xid (w);
+
+ 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)))
+ {
+ GdkWindow *w = gtk_widget_get_window (widget);
+ gdk_wayland_window_export_handle (w, 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)))
+ {
+ GdkWindow *w = gtk_widget_get_window (widget);
+ gdk_wayland_window_unexport_handle (w);
+ }
+#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);