[mutter/wip/carlosg/xwayland-on-demand: 21/27] wayland: Add tracking of X11 windows



commit c1f39514caa8290b7a7e557ad63c2b32d85347a9
Author: Carlos Garnacho <carlosg gnome org>
Date:   Fri May 24 21:09:32 2019 +0200

    wayland: Add tracking of X11 windows
    
    This is unused ATM, but will be used to check whether it is safe to
    shut Xwayland down.

 src/wayland/meta-wayland-private.h |  2 ++
 src/wayland/meta-xwayland.c        | 34 ++++++++++++++++++++++++++++++++++
 2 files changed, 36 insertions(+)
---
diff --git a/src/wayland/meta-wayland-private.h b/src/wayland/meta-wayland-private.h
index 594088535..6acbafc1f 100644
--- a/src/wayland/meta-wayland-private.h
+++ b/src/wayland/meta-wayland-private.h
@@ -58,6 +58,8 @@ typedef struct
   GSubprocess *proc;
   GMainLoop *init_loop;
 
+  GList *x11_windows;
+
   MetaXWaylandDnd *dnd;
 } MetaXWaylandManager;
 
diff --git a/src/wayland/meta-xwayland.c b/src/wayland/meta-xwayland.c
index aba16413a..3e1d5e455 100644
--- a/src/wayland/meta-xwayland.c
+++ b/src/wayland/meta-xwayland.c
@@ -620,6 +620,30 @@ meta_xwayland_start_xserver (MetaXWaylandManager *manager)
   return TRUE;
 }
 
+static void
+window_unmanaged_cb (MetaWindow          *window,
+                     MetaXWaylandManager *manager)
+{
+  manager->x11_windows = g_list_remove (manager->x11_windows, window);
+  g_signal_handlers_disconnect_by_func (window,
+                                        window_unmanaged_cb,
+                                        manager);
+}
+
+static void
+window_created_cb (MetaDisplay         *display,
+                   MetaWindow          *window,
+                   MetaXWaylandManager *manager)
+{
+  if (window->xwindow &&
+      meta_window_get_client_pid (window) != getpid ())
+    {
+      manager->x11_windows = g_list_prepend (manager->x11_windows, window);
+      g_signal_connect (window, "unmanaged",
+                        G_CALLBACK (window_unmanaged_cb), manager);
+    }
+}
+
 gboolean
 meta_xwayland_init (MetaXWaylandManager *manager,
                     struct wl_display   *wl_display)
@@ -647,6 +671,9 @@ on_x11_display_closing (MetaDisplay *display)
 void
 meta_xwayland_complete_init (MetaDisplay *display)
 {
+  MetaWaylandCompositor *compositor = meta_wayland_compositor_get_default ();
+  MetaXWaylandManager *manager = &compositor->xwayland_manager;
+
   /* We install an X IO error handler in addition to the child watch,
      because after Xlib connects our child watch may not be called soon
      enough, and therefore we won't crash when X exits (and most important
@@ -657,6 +684,9 @@ meta_xwayland_complete_init (MetaDisplay *display)
   g_signal_connect (display, "x11-display-closing",
                     G_CALLBACK (on_x11_display_closing), NULL);
   meta_xwayland_init_dnd ();
+
+  g_signal_connect (meta_get_display (), "window-created",
+                    G_CALLBACK (window_created_cb), manager);
 }
 
 void
@@ -664,6 +694,10 @@ meta_xwayland_shutdown (MetaXWaylandManager *manager)
 {
   char path[256];
 
+  g_signal_handlers_disconnect_by_func (meta_get_display (),
+                                        window_created_cb,
+                                        manager);
+
   g_cancellable_cancel (manager->xserver_died_cancellable);
   g_clear_object (&manager->proc);
   g_clear_object (&manager->xserver_died_cancellable);


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]