[mutter/bilelmoussaoui/without-xwayland: 6/10] build: Allow disabling xwayland




commit 5ebdbbf31dfbf1d4d90c1df52aeb3a8b55a939d5
Author: Bilal Elmoussaoui <belmouss redhat com>
Date:   Mon Jun 13 10:09:26 2022 +0200

    build: Allow disabling xwayland
    
    Mostly moving things around to allow a build without xwayland.
    Note that more work might still be needed once the x11 build option
    lands as that would allow us to have a proper xwayland only build
    without the x server part.
    
    Rleated: https://gitlab.gnome.org/GNOME/mutter/-/issues/2272

 meson.build                                    |  2 +-
 meson_options.txt                              |  6 +++++
 src/core/display.c                             | 21 ++++++++++++++---
 src/core/window.c                              |  7 +++++-
 src/wayland/meta-wayland-actor-surface.c       |  5 +++++
 src/wayland/meta-wayland-cursor-surface.c      |  6 +++++
 src/wayland/meta-wayland-pointer-constraints.c | 21 ++++++++++++-----
 src/wayland/meta-wayland-pointer.c             |  3 +++
 src/wayland/meta-wayland-surface.c             |  5 +++++
 src/wayland/meta-wayland.c                     | 31 +++++++++++---------------
 src/wayland/meta-wayland.h                     |  2 ++
 src/wayland/meta-xwayland-private.h            |  5 +++++
 src/wayland/meta-xwayland.c                    | 18 +++++++++++++++
 src/x11/events.c                               |  6 ++---
 src/x11/meta-x11-display.c                     |  6 ++---
 15 files changed, 110 insertions(+), 34 deletions(-)
---
diff --git a/meson.build b/meson.build
index d5d719f161..c4420fa80f 100644
--- a/meson.build
+++ b/meson.build
@@ -128,7 +128,7 @@ dbus_dep = dependency('dbus-1')
 have_wayland = get_option('wayland')
 # For now always require X11 support
 have_x11 = true
-have_xwayland = have_wayland # for now default to have_wayland
+have_xwayland = get_option('xwayland')
 have_x11_client = have_x11 or have_xwayland
 
 if have_xwayland and not have_wayland
diff --git a/meson_options.txt b/meson_options.txt
index da755393c7..21953e162b 100644
--- a/meson_options.txt
+++ b/meson_options.txt
@@ -39,6 +39,12 @@ option('wayland',
   description: 'Enable Wayland support'
 )
 
+option('xwayland',
+  type: 'boolean',
+  value: true,
+  description: 'Enable Xwayland support'
+)
+
 option('systemd',
   type: 'boolean',
   value: true,
diff --git a/src/core/display.c b/src/core/display.c
index ee1c372bf8..e6316aab8e 100644
--- a/src/core/display.c
+++ b/src/core/display.c
@@ -81,9 +81,17 @@
 #ifdef HAVE_WAYLAND
 #include "compositor/meta-compositor-native.h"
 #include "compositor/meta-compositor-server.h"
-#include "wayland/meta-xwayland-private.h"
+#include "wayland/meta-wayland.h"
+#include "wayland/meta-wayland-input-device.h"
+#include "wayland/meta-wayland-private.h"
 #include "wayland/meta-wayland-tablet-seat.h"
 #include "wayland/meta-wayland-tablet-pad.h"
+#include "wayland/meta-wayland-tablet-manager.h"
+#include "wayland/meta-wayland-touch.h"
+#endif
+
+#ifdef HAVE_XWAYLAND
+#include "wayland/meta-xwayland-private.h"
 #endif
 
 #ifdef HAVE_NATIVE_BACKEND
@@ -760,6 +768,7 @@ meta_display_init_x11_finish (MetaDisplay   *display,
   return TRUE;
 }
 
+#ifdef HAVE_XWAYLAND
 static void
 on_xserver_started (MetaXWaylandManager *manager,
                     GAsyncResult        *result,
@@ -788,6 +797,7 @@ on_xserver_started (MetaXWaylandManager *manager,
       g_task_return_boolean (task, TRUE);
     }
 }
+#endif /* HAVE_XWAYLAND */
 
 void
 meta_display_init_x11 (MetaDisplay         *display,
@@ -795,17 +805,22 @@ meta_display_init_x11 (MetaDisplay         *display,
                        GAsyncReadyCallback  callback,
                        gpointer             user_data)
 {
-  MetaWaylandCompositor *compositor = meta_wayland_compositor_get_default ();
-
   g_autoptr (GTask) task = NULL;
+#ifdef HAVE_XWAYLAND
+  MetaWaylandCompositor *compositor;
+#endif
 
   task = g_task_new (display, cancellable, callback, user_data);
   g_task_set_source_tag (task, meta_display_init_x11);
 
+#ifdef HAVE_XWAYLAND
+  compositor = meta_wayland_compositor_get_default ();
+
   meta_xwayland_start_xserver (&compositor->xwayland_manager,
                                cancellable,
                                (GAsyncReadyCallback) on_xserver_started,
                                g_steal_pointer (&task));
+#endif 
 }
 
 static void
diff --git a/src/core/window.c b/src/core/window.c
index 95a8e33e04..f6597228a9 100644
--- a/src/core/window.c
+++ b/src/core/window.c
@@ -94,6 +94,9 @@
 #include "wayland/meta-wayland-private.h"
 #include "wayland/meta-wayland-surface.h"
 #include "wayland/meta-window-wayland.h"
+#endif
+
+#ifdef HAVE_XWAYLAND
 #include "wayland/meta-window-xwayland.h"
 #endif
 
@@ -986,9 +989,11 @@ _meta_window_shared_new (MetaDisplay         *display,
 
   if (client_type == META_WINDOW_CLIENT_TYPE_X11 && !meta_is_wayland_compositor ())
     window = g_object_new (META_TYPE_WINDOW_X11, NULL);
-#ifdef HAVE_WAYLAND
+#ifdef HAVE_XWAYLAND
   else if (client_type == META_WINDOW_CLIENT_TYPE_X11)
     window = g_object_new (META_TYPE_WINDOW_XWAYLAND, NULL);
+#endif
+#ifdef HAVE_WAYLAND
   else if (client_type == META_WINDOW_CLIENT_TYPE_WAYLAND)
     window = g_object_new (META_TYPE_WINDOW_WAYLAND, NULL);
 #endif
diff --git a/src/wayland/meta-wayland-actor-surface.c b/src/wayland/meta-wayland-actor-surface.c
index 697fff53d0..2afd9e4fc6 100644
--- a/src/wayland/meta-wayland-actor-surface.c
+++ b/src/wayland/meta-wayland-actor-surface.c
@@ -31,7 +31,10 @@
 #include "wayland/meta-wayland-buffer.h"
 #include "wayland/meta-wayland-surface.h"
 #include "wayland/meta-window-wayland.h"
+
+#ifdef HAVE_XWAYLAND
 #include "wayland/meta-xwayland-surface.h"
+#endif
 
 typedef struct _MetaWaylandActorSurfacePrivate MetaWaylandActorSurfacePrivate;
 
@@ -223,6 +226,7 @@ meta_wayland_actor_surface_real_sync_actor_state (MetaWaylandActorSurface *actor
       meta_surface_actor_set_input_region (surface_actor, NULL);
     }
 
+#ifdef HAVE_XWAYLAND
   if (!META_IS_XWAYLAND_SURFACE (surface_role))
     {
       if (!meta_shaped_texture_has_alpha (stex))
@@ -247,6 +251,7 @@ meta_wayland_actor_surface_real_sync_actor_state (MetaWaylandActorSurface *actor
           meta_surface_actor_set_opaque_region (surface_actor, NULL);
         }
     }
+#endif
 
   meta_shaped_texture_set_transform (stex, surface->buffer_transform);
 
diff --git a/src/wayland/meta-wayland-cursor-surface.c b/src/wayland/meta-wayland-cursor-surface.c
index 87d55535cb..994b0e47d0 100644
--- a/src/wayland/meta-wayland-cursor-surface.c
+++ b/src/wayland/meta-wayland-cursor-surface.c
@@ -31,7 +31,10 @@
 #include "wayland/meta-wayland-buffer.h"
 #include "wayland/meta-wayland-presentation-time-private.h"
 #include "wayland/meta-wayland-private.h"
+
+#ifdef HAVE_XWAYLAND
 #include "wayland/meta-xwayland.h"
+#endif
 
 typedef struct _MetaWaylandCursorSurfacePrivate MetaWaylandCursorSurfacePrivate;
 
@@ -89,6 +92,7 @@ cursor_sprite_prepare_at (MetaCursorSprite         *cursor_sprite,
   MetaWaylandSurfaceRole *role = META_WAYLAND_SURFACE_ROLE (cursor_surface);
   MetaWaylandSurface *surface = meta_wayland_surface_role_get_surface (role);
 
+#ifdef HAVE_XWAYLAND
   if (!meta_xwayland_is_xwayland_surface (surface))
     {
       MetaBackend *backend = meta_get_backend ();
@@ -111,6 +115,8 @@ cursor_sprite_prepare_at (MetaCursorSprite         *cursor_sprite,
           meta_cursor_sprite_set_texture_scale (cursor_sprite, texture_scale);
         }
     }
+#endif
+
   meta_wayland_surface_update_outputs (surface);
 }
 
diff --git a/src/wayland/meta-wayland-pointer-constraints.c b/src/wayland/meta-wayland-pointer-constraints.c
index 965b95ddad..cd43da5134 100644
--- a/src/wayland/meta-wayland-pointer-constraints.c
+++ b/src/wayland/meta-wayland-pointer-constraints.c
@@ -40,7 +40,10 @@
 #include "wayland/meta-wayland-region.h"
 #include "wayland/meta-wayland-seat.h"
 #include "wayland/meta-wayland-surface.h"
+
+#ifdef HAVE_XWAYLAND
 #include "wayland/meta-xwayland.h"
+#endif
 
 #include "pointer-constraints-unstable-v1-server-protocol.h"
 
@@ -155,6 +158,7 @@ connect_window (MetaWaylandSurfacePointerConstraintsData *data,
                       G_CALLBACK (window_raised), NULL);
 }
 
+#ifdef HAVE_XWAYLAND
 static void
 window_associated (MetaWaylandSurfaceRole                   *surface_role,
                    MetaWaylandSurfacePointerConstraintsData *data)
@@ -168,6 +172,7 @@ window_associated (MetaWaylandSurfaceRole                   *surface_role,
 
   meta_wayland_pointer_constraint_maybe_enable_for_window (window);
 }
+#endif
 
 static MetaWaylandSurfacePointerConstraintsData *
 surface_constraint_data_new (MetaWaylandSurface *surface)
@@ -184,6 +189,7 @@ surface_constraint_data_new (MetaWaylandSurface *surface)
     {
       connect_window (data, window);
     }
+#ifdef HAVE_XWAYLAND
   else if (meta_xwayland_is_xwayland_surface (surface))
     {
       data->window_associated_handler_id =
@@ -191,6 +197,7 @@ surface_constraint_data_new (MetaWaylandSurface *surface)
                           G_CALLBACK (window_associated),
                           data);
     }
+#endif
   else
     {
       /* TODO: Support constraints on non-toplevel windows, such as subsurfaces.
@@ -458,6 +465,7 @@ should_constraint_be_enabled (MetaWaylandPointerConstraint *constraint)
   MetaWindow *window;
 
   window = meta_wayland_surface_get_window (constraint->surface);
+#ifdef HAVE_XWAYLAND
   if (!window)
     {
       /*
@@ -467,6 +475,7 @@ should_constraint_be_enabled (MetaWaylandPointerConstraint *constraint)
       g_warn_if_fail (meta_xwayland_is_xwayland_surface (constraint->surface));
       return FALSE;
     }
+#endif
 
   if (window->unmanaging)
     return FALSE;
@@ -474,6 +483,7 @@ should_constraint_be_enabled (MetaWaylandPointerConstraint *constraint)
   if (constraint->seat->pointer->focus_surface != constraint->surface)
     return FALSE;
 
+#ifdef HAVE_XWAYLAND
   if (meta_xwayland_is_xwayland_surface (constraint->surface))
     {
       MetaDisplay *display = meta_get_display ();
@@ -496,11 +506,10 @@ should_constraint_be_enabled (MetaWaylandPointerConstraint *constraint)
           display->focus_window->client_type != META_WINDOW_CLIENT_TYPE_X11)
         return FALSE;
     }
-  else
-    {
-      if (!meta_window_appears_focused (window))
-        return FALSE;
-    }
+#endif
+
+  if (!meta_window_appears_focused (window))
+    return FALSE;
 
   return TRUE;
 }
@@ -618,7 +627,9 @@ meta_wayland_pointer_constraint_calculate_effective_region (MetaWaylandPointerCo
       MetaFrame *frame = window->frame;
       int actual_width, actual_height;
 
+#ifdef HAVE_XWAYLAND
       g_assert (meta_xwayland_is_xwayland_surface (constraint->surface));
+#endif
 
       actual_width = window->buffer_rect.width - (frame->child_x +
                                                   frame->right_width);
diff --git a/src/wayland/meta-wayland-pointer.c b/src/wayland/meta-wayland-pointer.c
index 81a16fe6ef..47969ea1ef 100644
--- a/src/wayland/meta-wayland-pointer.c
+++ b/src/wayland/meta-wayland-pointer.c
@@ -62,7 +62,10 @@
 #include "wayland/meta-wayland-private.h"
 #include "wayland/meta-wayland-seat.h"
 #include "wayland/meta-wayland-surface.h"
+
+#ifdef HAVE_XWAYLAND
 #include "wayland/meta-xwayland.h"
+#endif
 
 #ifdef HAVE_NATIVE_BACKEND
 #include "backends/native/meta-backend-native.h"
diff --git a/src/wayland/meta-wayland-surface.c b/src/wayland/meta-wayland-surface.c
index aad2dc35cf..0ef2a5921c 100644
--- a/src/wayland/meta-wayland-surface.c
+++ b/src/wayland/meta-wayland-surface.c
@@ -51,8 +51,11 @@
 #include "wayland/meta-wayland-viewporter.h"
 #include "wayland/meta-wayland-xdg-shell.h"
 #include "wayland/meta-window-wayland.h"
+
+#ifdef HAVE_XWAYLAND
 #include "wayland/meta-xwayland-private.h"
 #include "wayland/meta-xwayland-private.h"
+#endif
 
 enum
 {
@@ -1534,7 +1537,9 @@ meta_wayland_surface_create (MetaWaylandCompositor *compositor,
 
   wl_list_init (&surface->presentation_time.feedback_list);
 
+#ifdef HAVE_XWAYLAND
   meta_wayland_compositor_notify_surface_id (compositor, id, surface);
+#endif
 
   return surface;
 }
diff --git a/src/wayland/meta-wayland.c b/src/wayland/meta-wayland.c
index 677300d907..9a0014ba48 100644
--- a/src/wayland/meta-wayland.c
+++ b/src/wayland/meta-wayland.c
@@ -47,9 +47,12 @@
 #include "wayland/meta-wayland-subsurface.h"
 #include "wayland/meta-wayland-tablet-manager.h"
 #include "wayland/meta-wayland-xdg-foreign.h"
+
+#ifdef HAVE_XWAYLAND
 #include "wayland/meta-xwayland-grab-keyboard.h"
 #include "wayland/meta-xwayland-private.h"
 #include "wayland/meta-xwayland.h"
+#endif
 
 #ifdef HAVE_NATIVE_BACKEND
 #include "backends/native/meta-renderer-native.h"
@@ -413,7 +416,9 @@ void
 meta_wayland_compositor_init_display (MetaWaylandCompositor *compositor,
                                       MetaDisplay           *display)
 {
+#ifdef HAVE_XWAYLAND
   meta_xwayland_init_display (&compositor->xwayland_manager, display);
+#endif
 }
 
 static void meta_wayland_log_func (const char *, va_list) G_GNUC_PRINTF (1, 0);
@@ -430,12 +435,14 @@ meta_wayland_log_func (const char *fmt,
 void
 meta_wayland_compositor_prepare_shutdown (MetaWaylandCompositor *compositor)
 {
+#ifdef HAVE_XWAYLAND
   MetaX11DisplayPolicy x11_display_policy;
 
   x11_display_policy =
     meta_context_get_x11_display_policy (compositor->context);
   if (x11_display_policy != META_X11_DISPLAY_POLICY_DISABLED)
     meta_xwayland_shutdown (&compositor->xwayland_manager);
+#endif
 
   if (compositor->wayland_display)
     wl_display_destroy_clients (compositor->wayland_display);
@@ -477,23 +484,6 @@ meta_wayland_compositor_class_init (MetaWaylandCompositorClass *klass)
   object_class->finalize = meta_wayland_compositor_finalize;
 }
 
-static bool
-meta_xwayland_global_filter (const struct wl_client *client,
-                             const struct wl_global *global,
-                             void                   *data)
-{
-  MetaWaylandCompositor *compositor = (MetaWaylandCompositor *) data;
-  MetaXWaylandManager *xwayland_manager = &compositor->xwayland_manager;
-
-  /* Keyboard grabbing protocol is for Xwayland only */
-  if (client != xwayland_manager->client)
-    return (wl_global_get_interface (global) !=
-            &zwp_xwayland_keyboard_grab_manager_v1_interface);
-
-  /* All others are visible to all clients */
-  return true;
-}
-
 void
 meta_wayland_override_display_name (const char *display_name)
 {
@@ -621,11 +611,13 @@ meta_wayland_compositor_new (MetaContext *context)
   meta_wayland_init_presentation_time (compositor);
   meta_wayland_activation_init (compositor);
 
+#ifdef HAVE_XWAYLAND
   /* Xwayland specific protocol, needs to be filtered out for all other clients */
   if (meta_xwayland_grab_keyboard_init (compositor))
     wl_display_set_global_filter (compositor->wayland_display,
                                   meta_xwayland_global_filter,
                                   compositor);
+#endif
 
 #ifdef HAVE_WAYLAND_EGLSTREAM
   {
@@ -650,6 +642,7 @@ meta_wayland_compositor_new (MetaContext *context)
 
   x11_display_policy =
     meta_context_get_x11_display_policy (compositor->context);
+#ifdef HAVE_XWAYLAND
   if (x11_display_policy != META_X11_DISPLAY_POLICY_DISABLED)
     {
       g_autoptr (GError) error = NULL;
@@ -660,6 +653,7 @@ meta_wayland_compositor_new (MetaContext *context)
                                &error))
         g_error ("Failed to start X Wayland: %s", error->message);
     }
+#endif
 
   if (_display_name_override)
     {
@@ -794,7 +788,7 @@ meta_wayland_compositor_schedule_surface_association (MetaWaylandCompositor *com
   g_hash_table_insert (compositor->scheduled_surface_associations,
                        GINT_TO_POINTER (id), window);
 }
-
+#ifdef HAVE_XWAYLAND
 void
 meta_wayland_compositor_notify_surface_id (MetaWaylandCompositor *compositor,
                                            int                    id,
@@ -810,6 +804,7 @@ meta_wayland_compositor_notify_surface_id (MetaWaylandCompositor *compositor,
       meta_wayland_compositor_remove_surface_association (compositor, id);
     }
 }
+#endif
 
 gboolean
 meta_wayland_compositor_is_egl_display_bound (MetaWaylandCompositor *compositor)
diff --git a/src/wayland/meta-wayland.h b/src/wayland/meta-wayland.h
index 6528a02baa..0c5c2c02c1 100644
--- a/src/wayland/meta-wayland.h
+++ b/src/wayland/meta-wayland.h
@@ -90,9 +90,11 @@ void                    meta_wayland_compositor_schedule_surface_association (Me
                                                                               int                    id,
                                                                               MetaWindow            *window);
 
+#ifdef HAVE_XWAYLAND
 void                    meta_wayland_compositor_notify_surface_id (MetaWaylandCompositor *compositor,
                                                                    int                    id,
                                                                    MetaWaylandSurface    *surface);
+#endif
 
 META_EXPORT_TEST
 MetaXWaylandManager *   meta_wayland_compositor_get_xwayland_manager (MetaWaylandCompositor *compositor);
diff --git a/src/wayland/meta-xwayland-private.h b/src/wayland/meta-xwayland-private.h
index 90f36497c9..b8bafc783f 100644
--- a/src/wayland/meta-xwayland-private.h
+++ b/src/wayland/meta-xwayland-private.h
@@ -60,4 +60,9 @@ gboolean meta_xwayland_start_xserver_finish (MetaXWaylandManager  *manager,
                                              GAsyncResult         *result,
                                              GError              **error);
 
+bool
+meta_xwayland_global_filter (const struct wl_client *client,
+                             const struct wl_global *global,
+                             void                   *data);
+
 #endif /* META_XWAYLAND_PRIVATE_H */
diff --git a/src/wayland/meta-xwayland.c b/src/wayland/meta-xwayland.c
index 968467558f..70f4b42793 100644
--- a/src/wayland/meta-xwayland.c
+++ b/src/wayland/meta-xwayland.c
@@ -51,6 +51,7 @@
 #include "meta/main.h"
 #include "meta/meta-backend.h"
 #include "meta/meta-x11-errors.h"
+#include "wayland/meta-xwayland-grab-keyboard.h"
 #include "wayland/meta-xwayland-surface.h"
 #include "x11/meta-x11-display-private.h"
 
@@ -1276,6 +1277,23 @@ meta_xwayland_handle_xevent (XEvent *event)
   return FALSE;
 }
 
+bool
+meta_xwayland_global_filter (const struct wl_client *client,
+                             const struct wl_global *global,
+                             void                   *data)
+{
+  MetaWaylandCompositor *compositor = (MetaWaylandCompositor *) data;
+  MetaXWaylandManager *xwayland_manager = &compositor->xwayland_manager;
+
+  /* Keyboard grabbing protocol is for Xwayland only */
+  if (client != xwayland_manager->client)
+    return (wl_global_get_interface (global) !=
+            &zwp_xwayland_keyboard_grab_manager_v1_interface);
+
+  /* All others are visible to all clients */
+  return true;
+}
+
 gboolean
 meta_xwayland_signal (MetaXWaylandManager  *manager,
                       int                   signum,
diff --git a/src/x11/events.c b/src/x11/events.c
index 2c574d5755..437952b517 100644
--- a/src/x11/events.c
+++ b/src/x11/events.c
@@ -50,7 +50,7 @@
 #include "x11/window-x11.h"
 #include "x11/xprops.h"
 
-#ifdef HAVE_WAYLAND
+#ifdef HAVE_XWAYLAND
 #include "wayland/meta-wayland-private.h"
 #include "wayland/meta-xwayland-private.h"
 #include "wayland/meta-xwayland.h"
@@ -1652,7 +1652,7 @@ handle_other_xevent (MetaX11Display *x11_display,
     case ClientMessage:
       if (window)
         {
-#ifdef HAVE_WAYLAND
+#ifdef HAVE_XWAYLAND
           if (event->xclient.message_type == x11_display->atom_WL_SURFACE_ID)
             {
               guint32 surface_id = event->xclient.data.l[0];
@@ -1896,7 +1896,7 @@ meta_x11_display_handle_xevent (MetaX11Display *x11_display,
       goto out;
     }
 
-#ifdef HAVE_WAYLAND
+#ifdef HAVE_XWAYLAND
   if (meta_is_wayland_compositor () &&
       meta_xwayland_handle_xevent (event))
     {
diff --git a/src/x11/meta-x11-display.c b/src/x11/meta-x11-display.c
index bb5f4bf50b..1f9f88a487 100644
--- a/src/x11/meta-x11-display.c
+++ b/src/x11/meta-x11-display.c
@@ -67,7 +67,7 @@
 #include "x11/window-props.h"
 #include "x11/xprops.h"
 
-#ifdef HAVE_WAYLAND
+#ifdef HAVE_XWAYLAND
 #include "wayland/meta-xwayland-private.h"
 #endif
 
@@ -1007,7 +1007,7 @@ set_work_area_hint (MetaDisplay    *display,
 const gchar *
 meta_x11_get_display_name (void)
 {
-#ifdef HAVE_WAYLAND
+#ifdef HAVE_XWAYLAND
   if (meta_is_wayland_compositor ())
     {
       MetaWaylandCompositor *compositor;
@@ -1171,7 +1171,7 @@ meta_x11_display_new (MetaDisplay *display, GError **error)
 
   XSynchronize (xdisplay, meta_context_is_x11_sync (context));
 
-#ifdef HAVE_WAYLAND
+#ifdef HAVE_XWAYLAND
   if (meta_is_wayland_compositor ())
     {
       MetaWaylandCompositor *compositor =


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