[mutter/wip/carlosg/xwayland-startup-side-channel: 2/7] core: Make meta_display_init_x11() an async function



commit 132ef07de26d9a50980c24f88f4a1138bd08e8a7
Author: Carlos Garnacho <carlosg gnome org>
Date:   Tue Nov 19 17:32:27 2019 +0100

    core: Make meta_display_init_x11() an async function
    
    This ATM completes the task right away, but we will want to do
    further things here that are asynchronous in nature, so prepare
    for this operation being async.
    
    Since the X11 backend doesn't really need this, make it go on
    the fast lane and open the MetaX11Display right away, the case
    of mandatory Xwayland on a wayland session is now handled
    separately.

 src/core/display-private.h  | 10 +++++--
 src/core/display.c          | 69 +++++++++++++++++++++++++++++++++++++++++----
 src/wayland/meta-xwayland.c | 16 ++++++++++-
 3 files changed, 86 insertions(+), 9 deletions(-)
---
diff --git a/src/core/display-private.h b/src/core/display-private.h
index 1541a6318..d8064f12e 100644
--- a/src/core/display-private.h
+++ b/src/core/display-private.h
@@ -426,8 +426,14 @@ MetaWindow *meta_display_get_window_from_id (MetaDisplay *display,
                                              uint64_t     window_id);
 uint64_t    meta_display_generate_window_id (MetaDisplay *display);
 
-gboolean meta_display_init_x11     (MetaDisplay  *display,
-                                    GError      **error);
+void meta_display_init_x11 (MetaDisplay         *display,
+                            GCancellable        *cancellable,
+                            GAsyncReadyCallback  callback,
+                            gpointer             user_data);
+gboolean meta_display_init_x11_finish (MetaDisplay   *display,
+                                       GAsyncResult  *result,
+                                       GError       **error);
+
 void     meta_display_shutdown_x11 (MetaDisplay  *display);
 
 #endif
diff --git a/src/core/display.c b/src/core/display.c
index b18f5a558..e06dec772 100644
--- a/src/core/display.c
+++ b/src/core/display.c
@@ -657,13 +657,44 @@ on_ui_scaling_factor_changed (MetaSettings *settings,
   meta_display_reload_cursor (display);
 }
 
+static gboolean
+meta_display_init_x11_display (MetaDisplay  *display,
+                               GError      **error)
+{
+  MetaX11Display *x11_display;
+
+  x11_display = meta_x11_display_new (display, error);
+  if (!x11_display)
+    return FALSE;
+
+  display->x11_display = x11_display;
+  g_signal_emit (display, display_signals[X11_DISPLAY_SETUP], 0);
+
+  meta_x11_display_create_guard_window (x11_display);
+
+  if (!display->display_opening)
+    {
+      g_signal_emit (display, display_signals[X11_DISPLAY_OPENED], 0);
+      meta_display_manage_all_xwindows (display);
+      meta_compositor_redirect_x11_windows (display->compositor);
+    }
+
+  return TRUE;
+}
+
 gboolean
-meta_display_init_x11 (MetaDisplay  *display,
-                       GError      **error)
+meta_display_init_x11_finish (MetaDisplay   *display,
+                              GAsyncResult  *result,
+                              GError       **error)
 {
   MetaX11Display *x11_display;
 
-  g_assert (display->x11_display == NULL);
+  g_assert (g_task_get_source_tag (G_TASK (result)) == meta_display_init_x11);
+
+  if (!g_task_propagate_boolean (G_TASK (result), error))
+    return FALSE;
+  if (display->x11_display)
+    return TRUE;
 
   x11_display = meta_x11_display_new (display, error);
   if (!x11_display)
@@ -684,6 +715,21 @@ meta_display_init_x11 (MetaDisplay  *display,
   return TRUE;
 }
 
+void
+meta_display_init_x11 (MetaDisplay         *display,
+                       GCancellable        *cancellable,
+                       GAsyncReadyCallback  callback,
+                       gpointer             user_data)
+{
+  GTask *task;
+
+  task = g_task_new (display, cancellable, callback, user_data);
+  g_task_set_source_tag (task, meta_display_init_x11);
+
+  g_task_return_boolean (task, TRUE);
+  g_object_unref (task);
+}
+
 void
 meta_display_shutdown_x11 (MetaDisplay *display)
 {
@@ -695,6 +741,15 @@ meta_display_shutdown_x11 (MetaDisplay *display)
   g_clear_object (&display->x11_display);
 }
 
+static void
+on_x11_initialized (MetaDisplay  *display,
+                    GAsyncResult *result,
+                    gpointer      user_data)
+{
+  if (!meta_display_init_x11_finish (display, result, NULL))
+    g_critical ("Failed to init X11 display");
+}
+
 /**
  * meta_display_open:
  *
@@ -791,15 +846,17 @@ meta_display_open (void)
   display->selection = meta_selection_new (display);
   meta_clipboard_manager_init (display);
 
-  if (meta_get_x11_display_policy () == META_DISPLAY_POLICY_MANDATORY)
+  if (!meta_is_wayland_compositor () && META_IS_BACKEND_X11 (backend))
     {
-      if (!meta_display_init_x11 (display, &error))
-        g_error ("Failed to start Xwayland: %s", error->message);
+      if (!meta_display_init_x11_display (display, &error))
+        g_error ("Failed to init X11 display: %s", error->message);
 
       timestamp = display->x11_display->timestamp;
     }
   else
     {
+      if (meta_get_x11_display_policy () == META_DISPLAY_POLICY_MANDATORY)
+        meta_display_init_x11 (display, NULL, on_x11_initialized, NULL);
       timestamp = meta_display_get_current_time_roundtrip (display);
     }
 
diff --git a/src/wayland/meta-xwayland.c b/src/wayland/meta-xwayland.c
index f1ad12aa3..2dfba1145 100644
--- a/src/wayland/meta-xwayland.c
+++ b/src/wayland/meta-xwayland.c
@@ -593,6 +593,17 @@ xserver_finished_init (MetaXWaylandManager *manager)
   g_clear_pointer (&manager->init_loop, g_main_loop_unref);
 }
 
+static void
+on_init_x11_cb (MetaDisplay  *display,
+                GAsyncResult *result,
+                gpointer      user_data)
+{
+  g_autoptr (GError) error = NULL;
+
+  if (!meta_display_init_x11_finish (display, result, &error))
+    g_warning ("Failed to initialize X11 display: %s\n", error->message);
+}
+
 static gboolean
 on_displayfd_ready (int          fd,
                     GIOCondition condition,
@@ -608,7 +619,10 @@ on_displayfd_ready (int          fd,
   xserver_finished_init (manager);
 
   if (meta_get_x11_display_policy () == META_DISPLAY_POLICY_ON_DEMAND)
-    meta_display_init_x11 (display, NULL);
+    {
+      meta_display_init_x11 (display, NULL,
+                             (GAsyncReadyCallback) on_init_x11_cb, NULL);
+    }
 
   return G_SOURCE_REMOVE;
 }


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