[mutter/bilelmoussaoui/without-xwayland: 3/3] build: Allow disabling XWayland




commit ee6bc6cd2bdf58c4d49406aef6318e66f50b4a49
Author: Bilal Elmoussaoui <belmouss redhat com>
Date:   Tue May 3 12:21:12 2022 +0200

    build: Allow disabling XWayland

 config.h.meson                                 |  2 ++
 meson.build                                    |  2 +-
 meson_options.txt                              |  6 ++++++
 src/core/display.c                             |  8 ++++++--
 src/core/window.c                              |  4 +++-
 src/wayland/meta-wayland-actor-surface.c       |  2 ++
 src/wayland/meta-wayland-cursor-surface.c      |  3 +++
 src/wayland/meta-wayland-pointer-constraints.c | 18 +++++++++++++-----
 src/wayland/meta-wayland.c                     | 12 ++++++++++++
 src/x11/events.c                               |  4 ++--
 src/x11/meta-x11-display.c                     |  2 +-
 11 files changed, 51 insertions(+), 12 deletions(-)
---
diff --git a/config.h.meson b/config.h.meson
index 9119ad864e..dd7a23684d 100644
--- a/config.h.meson
+++ b/config.h.meson
@@ -43,6 +43,8 @@
 /* Define if you want to enable Wayland support */
 #mesondefine HAVE_WAYLAND
 
+#mesondefine HAVE_XWAYLAND
+
 /* Defined if screen cast and remote desktop support is enabled */
 #mesondefine HAVE_REMOTE_DESKTOP
 
diff --git a/meson.build b/meson.build
index 47421f7437..863928cd34 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_backend = true
-have_xwayland = have_wayland # for now default to have_wayland
+have_xwayland = get_option('xwayland')
 have_x11_client = have_x11_backend or have_xwayland
 
 if have_xwayland and not have_wayland
diff --git a/meson_options.txt b/meson_options.txt
index da755393c7..21e66357fb 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 058d09f2a5..3d82370d7d 100644
--- a/src/core/display.c
+++ b/src/core/display.c
@@ -754,6 +754,7 @@ meta_display_init_x11_finish (MetaDisplay   *display,
   return TRUE;
 }
 
+#ifdef HAVE_XWAYLAND
 static void
 on_xserver_started (MetaXWaylandManager *manager,
                     GAsyncResult        *result,
@@ -782,6 +783,7 @@ on_xserver_started (MetaXWaylandManager *manager,
       g_task_return_boolean (task, TRUE);
     }
 }
+#endif /* HAVE_XWAYLAND */
 
 void
 meta_display_init_x11 (MetaDisplay         *display,
@@ -789,17 +791,19 @@ meta_display_init_x11 (MetaDisplay         *display,
                        GAsyncReadyCallback  callback,
                        gpointer             user_data)
 {
-  MetaWaylandCompositor *compositor = meta_wayland_compositor_get_default ();
-
   g_autoptr (GTask) task = NULL;
 
   task = g_task_new (display, cancellable, callback, user_data);
   g_task_set_source_tag (task, meta_display_init_x11);
 
+#ifdef HAVE_XWAYLAND
+  MetaWaylandCompositor *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 e22bd5a0e3..a623c9c6d0 100644
--- a/src/core/window.c
+++ b/src/core/window.c
@@ -986,9 +986,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 b6d26fdc11..754eaaa080 100644
--- a/src/wayland/meta-wayland-actor-surface.c
+++ b/src/wayland/meta-wayland-actor-surface.c
@@ -223,6 +223,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 +248,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..e476d8ba09 100644
--- a/src/wayland/meta-wayland-cursor-surface.c
+++ b/src/wayland/meta-wayland-cursor-surface.c
@@ -89,6 +89,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 +112,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..844cbe371b 100644
--- a/src/wayland/meta-wayland-pointer-constraints.c
+++ b/src/wayland/meta-wayland-pointer-constraints.c
@@ -155,6 +155,7 @@ connect_window (MetaWaylandSurfacePointerConstraintsData *data,
                       G_CALLBACK (window_raised), NULL);
 }
 
+#ifdef HAVE_XWAYLAND
 static void
 window_associated (MetaWaylandSurfaceRole                   *surface_role,
                    MetaWaylandSurfacePointerConstraintsData *data)
@@ -168,6 +169,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 +186,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 +194,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 +462,7 @@ should_constraint_be_enabled (MetaWaylandPointerConstraint *constraint)
   MetaWindow *window;
 
   window = meta_wayland_surface_get_window (constraint->surface);
+#ifdef HAVE_XWAYLAND
   if (!window)
     {
       /*
@@ -467,6 +472,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 +480,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 +503,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 +624,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.c b/src/wayland/meta-wayland.c
index 6e2b56dd44..756741bd6a 100644
--- a/src/wayland/meta-wayland.c
+++ b/src/wayland/meta-wayland.c
@@ -407,7 +407,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);
@@ -424,12 +426,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);
@@ -471,6 +475,7 @@ meta_wayland_compositor_class_init (MetaWaylandCompositorClass *klass)
   object_class->finalize = meta_wayland_compositor_finalize;
 }
 
+#ifdef HAVE_XWAYLAND
 static bool
 meta_xwayland_global_filter (const struct wl_client *client,
                              const struct wl_global *global,
@@ -487,6 +492,7 @@ meta_xwayland_global_filter (const struct wl_client *client,
   /* All others are visible to all clients */
   return true;
 }
+#endif
 
 void
 meta_wayland_override_display_name (const char *display_name)
@@ -612,11 +618,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
   {
@@ -641,6 +649,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;
@@ -651,6 +660,7 @@ meta_wayland_compositor_new (MetaContext *context)
                                &error))
         g_error ("Failed to start X Wayland: %s", error->message);
     }
+#endif
 
   if (_display_name_override)
     {
@@ -797,7 +807,9 @@ meta_wayland_compositor_notify_surface_id (MetaWaylandCompositor *compositor,
                                 GINT_TO_POINTER (id));
   if (window)
     {
+#ifdef HAVE_XWAYLAND
       meta_xwayland_associate_window_with_surface (window, surface);
+#endif
       meta_wayland_compositor_remove_surface_association (compositor, id);
     }
 }
diff --git a/src/x11/events.c b/src/x11/events.c
index 8882baac4e..fd4e998282 100644
--- a/src/x11/events.c
+++ b/src/x11/events.c
@@ -1644,7 +1644,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];
@@ -1888,7 +1888,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 5343633ce4..9699ca61cd 100644
--- a/src/x11/meta-x11-display.c
+++ b/src/x11/meta-x11-display.c
@@ -1168,7 +1168,7 @@ meta_x11_display_new (MetaDisplay *display, GError **error)
   gdk_display = g_steal_pointer (&prepared_gdk_display);
   xdisplay = GDK_DISPLAY_XDISPLAY (gdk_display);
 
-#ifdef HAVE_WAYLAND
+#ifdef HAVE_XWAYLAND
   if (meta_is_wayland_compositor ())
     {
       MetaContext *context = meta_display_get_context (display);


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