[mutter/bilelmoussaoui/x11-build-guards: 19/21] core/display: Guard X11 types




commit 787344379802193f166bb4af39767175961f6453
Author: Bilal Elmoussaoui <belmouss redhat com>
Date:   Tue May 31 11:57:37 2022 +0200

    core/display: Guard X11 types
    
    This also moves a couple of function calls to
    MetaDisplay::x11-display-opened a signal handler
    
    Related https://gitlab.gnome.org/GNOME/mutter/-/issues/2272

 src/core/display-private.h |  5 ++++
 src/core/display.c         | 75 +++++++++++++++++++++++++++++++++++-----------
 src/x11/meta-x11-display.c | 13 ++++++++
 3 files changed, 75 insertions(+), 18 deletions(-)
---
diff --git a/src/core/display-private.h b/src/core/display-private.h
index 37932095b8..760e25b2dc 100644
--- a/src/core/display-private.h
+++ b/src/core/display-private.h
@@ -256,7 +256,10 @@ struct _MetaDisplayClass
 MetaDisplay * meta_display_new (MetaContext  *context,
                                 GError      **error);
 
+#ifdef HAVE_X11_CLIENT
 void meta_display_manage_all_xwindows (MetaDisplay *display);
+#endif
+
 void meta_display_unmanage_windows   (MetaDisplay *display,
                                       guint32      timestamp);
 
@@ -300,7 +303,9 @@ META_EXPORT_TEST
 GSList*     meta_display_list_windows        (MetaDisplay          *display,
                                               MetaListWindowsFlags  flags);
 
+#ifdef HAVE_X11_CLIENT
 MetaDisplay* meta_display_for_x_display  (Display     *xdisplay);
+#endif
 
 META_EXPORT_TEST
 MetaDisplay* meta_get_display            (void);
diff --git a/src/core/display.c b/src/core/display.c
index b57c6e3fae..9b349f8118 100644
--- a/src/core/display.c
+++ b/src/core/display.c
@@ -33,12 +33,15 @@
 #include <stdlib.h>
 #include <string.h>
 #include <unistd.h>
+
+#ifdef HAVE_X11_CLIENT
 #include <X11/Xatom.h>
 #include <X11/Xcursor/Xcursor.h>
 #include <X11/extensions/shape.h>
 #include <X11/extensions/Xcomposite.h>
 #include <X11/extensions/Xdamage.h>
 #include <X11/extensions/Xfixes.h>
+#endif
 
 #include "backends/meta-backend-private.h"
 #include "backends/meta-cursor-sprite-xcursor.h"
@@ -46,13 +49,7 @@
 #include "backends/meta-input-device-private.h"
 #include "backends/meta-input-mapper-private.h"
 #include "backends/meta-stage-private.h"
-#include "backends/x11/meta-backend-x11.h"
-#include "backends/x11/meta-clutter-backend-x11.h"
-#include "backends/x11/meta-event-x11.h"
-#include "backends/x11/cm/meta-backend-x11-cm.h"
-#include "backends/x11/nested/meta-backend-x11-nested.h"
 #include "compositor/compositor-private.h"
-#include "compositor/meta-compositor-x11.h"
 #include "cogl/cogl.h"
 #include "core/bell.h"
 #include "core/boxes-private.h"
@@ -71,12 +68,21 @@
 #include "meta/meta-backend.h"
 #include "meta/meta-enum-types.h"
 #include "meta/meta-sound-player.h"
-#include "meta/meta-x11-errors.h"
 #include "meta/prefs.h"
+
+#ifdef HAVE_X11_CLIENT
+#include "backends/x11/meta-backend-x11.h"
+#include "backends/x11/meta-clutter-backend-x11.h"
+#include "backends/x11/meta-event-x11.h"
+#include "backends/x11/cm/meta-backend-x11-cm.h"
+#include "backends/x11/nested/meta-backend-x11-nested.h"
+#include "compositor/meta-compositor-x11.h"
+#include "meta/meta-x11-errors.h"
 #include "x11/meta-startup-notification-x11.h"
 #include "x11/meta-x11-display-private.h"
 #include "x11/window-x11.h"
 #include "x11/xprops.h"
+#endif
 
 #ifdef HAVE_WAYLAND
 #include "compositor/meta-compositor-native.h"
@@ -621,10 +627,16 @@ create_compositor (MetaDisplay *display)
   if (META_IS_BACKEND_NATIVE (backend))
     return META_COMPOSITOR (meta_compositor_native_new (display, backend));
 #endif
+#ifdef HAVE_XWAYLAND
   if (META_IS_BACKEND_X11_NESTED (backend))
     return META_COMPOSITOR (meta_compositor_server_new (display, backend));
 #endif
+#endif/* HAVE_WAYLAND */
+#ifdef HAVE_X11
   return META_COMPOSITOR (meta_compositor_x11_new (display, backend));
+#else
+  g_assert_not_reached ();
+#endif
 }
 
 static void
@@ -713,13 +725,13 @@ meta_display_init_x11_display (MetaDisplay  *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;
 }
+#endif
 
+#ifdef HAVE_XWAYLAND
 gboolean
 meta_display_init_x11_finish (MetaDisplay   *display,
                               GAsyncResult  *result,
@@ -752,9 +764,6 @@ meta_display_init_x11_finish (MetaDisplay   *display,
   if (!display->display_opening)
     {
       g_signal_emit (display, display_signals[X11_DISPLAY_OPENED], 0);
-      meta_x11_display_set_cm_selection (x11_display);
-      meta_display_manage_all_xwindows (display);
-      meta_compositor_redirect_x11_windows (display->compositor);
     }
 
   return TRUE;
@@ -818,7 +827,7 @@ on_x11_initialized (MetaDisplay  *display,
   if (!meta_display_init_x11_finish (display, result, &error))
     g_critical ("Failed to init X11 display: %s", error->message);
 }
-#endif /* HAVE_X11_CLIENT */
+#endif /* HAVE_XWAYLAND */
 
 void
 meta_display_shutdown_x11 (MetaDisplay *display)
@@ -840,7 +849,9 @@ meta_display_new (MetaContext  *context,
   MetaDisplayPrivate *priv;
   int i;
   guint32 timestamp;
+#ifdef HAVE_X11_CLIENT
   Window old_active_xwindow = None;
+#endif
   MetaMonitorManager *monitor_manager;
   MetaSettings *settings;
 
@@ -970,11 +981,13 @@ meta_display_new (MetaContext  *context,
   display->last_focus_time = timestamp;
   display->last_user_time = timestamp;
 
+#ifdef HAVE_X11
   if (!meta_is_wayland_compositor ())
     meta_prop_get_window (display->x11_display,
                           display->x11_display->xroot,
                           display->x11_display->atom__NET_ACTIVE_WINDOW,
                           &old_active_xwindow);
+#endif
 
   if (!meta_compositor_do_manage (display->compositor, error))
     {
@@ -982,12 +995,14 @@ meta_display_new (MetaContext  *context,
       return NULL;
     }
 
+#ifdef HAVE_X11_CLIENT
   if (display->x11_display)
     {
       g_signal_emit (display, display_signals[X11_DISPLAY_OPENED], 0);
       meta_x11_display_restore_active_workspace (display->x11_display);
       meta_x11_display_create_guard_window (display->x11_display);
     }
+#endif
 
   /* Set up touch support */
   display->gesture_tracker = meta_gesture_tracker_new ();
@@ -997,6 +1012,7 @@ meta_display_new (MetaContext  *context,
   /* We know that if mutter is running as a Wayland compositor,
    * we start out with no windows.
    */
+#ifdef HAVE_X11_CLIENT
   if (!meta_is_wayland_compositor ())
     meta_display_manage_all_xwindows (display);
 
@@ -1014,6 +1030,10 @@ meta_display_new (MetaContext  *context,
     {
       meta_display_unset_input_focus (display, timestamp);
     }
+#else
+  meta_display_unset_input_focus (display, timestamp);
+#endif
+
 
   display->sound_player = g_object_new (META_TYPE_SOUND_PLAYER, NULL);
 
@@ -1057,6 +1077,7 @@ meta_display_list_windows (MetaDisplay          *display,
 
   winlist = NULL;
 
+#ifdef HAVE_X11_CLIENT
   if (display->x11_display)
     {
       g_hash_table_iter_init (&iter, display->x11_display->xids);
@@ -1072,6 +1093,7 @@ meta_display_list_windows (MetaDisplay          *display,
             winlist = g_slist_prepend (winlist, window);
         }
     }
+#endif
 
   g_hash_table_iter_init (&iter, display->wayland_windows);
   while (g_hash_table_iter_next (&iter, &key, &value))
@@ -1207,6 +1229,7 @@ meta_display_close (MetaDisplay *display,
  * Returns: The singleton X display, or %NULL if @xdisplay isn't the one
  *          we're managing.
  */
+#ifdef HAVE_X11_CLIENT
 MetaDisplay*
 meta_display_for_x_display (Display *xdisplay)
 {
@@ -1218,6 +1241,7 @@ meta_display_for_x_display (Display *xdisplay)
 
   return NULL;
 }
+#endif
 
 /**
  * meta_get_display:
@@ -1345,7 +1369,11 @@ meta_display_get_current_time_roundtrip (MetaDisplay *display)
     /* Xwayland uses monotonic clock, so lets use it here as well */
     return (guint32) (g_get_monotonic_time () / 1000);
   else
+#ifdef HAVE_X11_CLIENT
     return meta_x11_display_get_current_time_roundtrip (display->x11_display);
+#else
+    g_assert_not_reached ();
+#endif
 }
 
 /**
@@ -1436,9 +1464,11 @@ meta_display_sync_wayland_input_focus (MetaDisplay *display)
   MetaStage *stage = META_STAGE (meta_backend_get_stage (backend));
   gboolean is_no_focus_xwindow = FALSE;
 
+#ifdef HAVE_X11_CLIENT
   if (display->x11_display)
     is_no_focus_xwindow = meta_x11_display_xwindow_is_a_no_focus_window (display->x11_display,
                                                                          
display->x11_display->focus_xwindow);
+#endif
 
   if (!meta_display_windows_are_interactable (display))
     focus_window = NULL;
@@ -1572,11 +1602,13 @@ meta_display_set_input_focus (MetaDisplay *display,
   if (meta_display_timestamp_too_old (display, &timestamp))
     return;
 
+#ifdef HAVE_X11_CLIENT
   if (display->x11_display)
     {
       meta_x11_display_set_input_focus (display->x11_display, window,
                                         focus_frame, timestamp);
     }
+#endif
 
   meta_display_update_focus_window (display, window);
 
@@ -1637,6 +1669,7 @@ MetaWindow*
 meta_display_lookup_stack_id (MetaDisplay *display,
                               guint64      stack_id)
 {
+#ifdef HAVE_X11_CLIENT
   if (META_STACK_ID_IS_X11 (stack_id))
     {
       if (!display->x11_display)
@@ -1644,10 +1677,8 @@ meta_display_lookup_stack_id (MetaDisplay *display,
       return meta_x11_display_lookup_x_window (display->x11_display,
                                                (Window)stack_id);
     }
-  else
-    {
-      return meta_display_lookup_stamp (display, stack_id);
-    }
+#endif
+  return meta_display_lookup_stamp (display, stack_id);
 }
 
 /* We return a pointer into a ring of static buffers. This is to make
@@ -1919,6 +1950,7 @@ meta_display_begin_grab_op (MetaDisplay *display,
   if (pointer_already_grabbed)
     display->grab_have_pointer = TRUE;
 
+#ifdef HAVE_X11_CLIENT
   if (META_IS_BACKEND_X11 (meta_get_backend ()) && display->x11_display)
     {
       /* Since grab operations often happen as a result of implicit
@@ -1930,6 +1962,7 @@ meta_display_begin_grab_op (MetaDisplay *display,
                       timestamp);
       XSync (display->x11_display->xdisplay, False);
     }
+#endif
 
   if (meta_backend_grab_device (backend, META_VIRTUAL_CORE_POINTER_ID, timestamp))
     display->grab_have_pointer = TRUE;
@@ -2158,12 +2191,14 @@ meta_is_syncing (void)
 void
 meta_set_syncing (gboolean setting)
 {
+#ifdef HAVE_X11_CLIENT
   if (setting != is_syncing)
     {
       is_syncing = setting;
       if (meta_get_display ())
         XSynchronize (meta_get_display ()->x11_display->xdisplay, is_syncing);
     }
+#endif
 }
 
 /**
@@ -2665,6 +2700,7 @@ meta_resize_gravity_from_grab_op (MetaGrabOp op)
   return gravity;
 }
 
+#ifdef HAVE_X11_CLIENT
 void
 meta_display_manage_all_xwindows (MetaDisplay *display)
 {
@@ -2689,6 +2725,7 @@ meta_display_manage_all_xwindows (MetaDisplay *display)
   g_free (children);
   meta_stack_thaw (display->stack);
 }
+#endif
 
 void
 meta_display_unmanage_windows (MetaDisplay *display,
@@ -2880,13 +2917,15 @@ meta_display_supports_extended_barriers (MetaDisplay *display)
     return TRUE;
 #endif
 
+#ifdef HAVE_X11_CLIENT
   if (META_IS_BACKEND_X11_CM (meta_get_backend ()))
     {
-      if (meta_is_wayland_compositor())
+      if (meta_is_wayland_compositor ())
         return FALSE;
 
       return META_X11_DISPLAY_HAS_XINPUT_23 (display->x11_display);
     }
+#endif
 
   return FALSE;
 }
diff --git a/src/x11/meta-x11-display.c b/src/x11/meta-x11-display.c
index a1b2cbd9d0..19732adc56 100644
--- a/src/x11/meta-x11-display.c
+++ b/src/x11/meta-x11-display.c
@@ -254,6 +254,15 @@ meta_x11_display_dispose (GObject *object)
   G_OBJECT_CLASS (meta_x11_display_parent_class)->dispose (object);
 }
 
+static void
+on_x11_display_opened (MetaDisplay    *display, 
+                       MetaX11Display *x11_display)
+{
+  meta_x11_display_set_cm_selection (x11_display);
+  meta_display_manage_all_xwindows (display);
+  meta_x11_display_redirect_windows (x11_display);
+}
+
 static void
 meta_x11_display_class_init (MetaX11DisplayClass *klass)
 {
@@ -1260,6 +1269,10 @@ meta_x11_display_new (MetaDisplay *display, GError **error)
                            G_CALLBACK (on_window_visibility_updated),
                            x11_display, 0);
 
+  g_signal_connect_after (display, 
+                          "x11-display-opened",
+                          G_CALLBACK (on_x11_display_opened), 
+                          x11_display);
   update_cursor_theme (x11_display);
 
   x11_display->xids = g_hash_table_new (meta_unsigned_long_hash,


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