[mutter/bilelmoussaoui/make-canberra-a-plugin] Core: Make sound player feature optional




commit 9d547b70f69c9976bd3c1d4f3d638cfab7ae822d
Author: Bilal Elmoussaoui <belmouss redhat com>
Date:   Tue Apr 26 15:00:46 2022 +0200

    Core: Make sound player feature optional
    
    Mutter can play sounds in some contexts and also provides an API
    for libmutter users to do so using libcanberra internally.
    
    In some specific use cases of Mutter, we would like to not depend
    on libcanberra and not have any sound playing feature by default.
    
    The changes keeps the sound player API but make it no-op if the
    sound_player feature is disabled to not make it possible to break
    a gnome-shell build.
    
    See https://gitlab.gnome.org/GNOME/gnome-shell/-/merge_requests/2270
    for relevant discussion

 config.h.meson               |  3 ++
 meson.build                  |  8 +++-
 meson_options.txt            |  6 +++
 src/core/meta-sound-player.c | 97 ++++++++++++++++++++++++++------------------
 src/meson.build              |  7 +++-
 5 files changed, 79 insertions(+), 42 deletions(-)
---
diff --git a/config.h.meson b/config.h.meson
index 9119ad864e..0fadabb469 100644
--- a/config.h.meson
+++ b/config.h.meson
@@ -49,6 +49,9 @@
 /* Defined if gnome-desktop is enabled */
 #mesondefine HAVE_GNOME_DESKTOP
 
+/* Defined if sound player is enabled */
+#mesondefine HAVE_SOUND_PLAYER
+
 /* Building with SM support */
 #mesondefine HAVE_SM
 
diff --git a/meson.build b/meson.build
index a10232bbb7..38e74671e8 100644
--- a/meson.build
+++ b/meson.build
@@ -140,7 +140,6 @@ xinerama_dep = dependency('xinerama')
 xau_dep = dependency('xau')
 ice_dep = dependency('ice')
 atk_dep = dependency('atk', version: atk_req)
-libcanberra_dep = dependency('libcanberra', version: libcanberra_req)
 dbus_dep = dependency('dbus-1')
 
 # For now always require X11 support
@@ -152,6 +151,11 @@ if have_gnome_desktop
   gnome_desktop_dep = dependency('gnome-desktop-3.0')
 endif
 
+have_sound_player = get_option('sound_player')
+if have_sound_player
+  libcanberra_dep = dependency('libcanberra', version: libcanberra_req)
+endif
+
 have_gl = get_option('opengl')
 if have_gl
   gl_dep = dependency('gl')
@@ -459,6 +463,7 @@ cdata.set('HAVE_LIBSYSTEMD', have_libsystemd)
 cdata.set('HAVE_NATIVE_BACKEND', have_native_backend)
 cdata.set('HAVE_REMOTE_DESKTOP', have_remote_desktop)
 cdata.set('HAVE_GNOME_DESKTOP', have_gnome_desktop)
+cdata.set('HAVE_SOUND_PLAYER', have_sound_player)
 cdata.set('HAVE_EGL_DEVICE', have_egl_device)
 cdata.set('HAVE_WAYLAND_EGLSTREAM', have_wayland_eglstream)
 cdata.set('HAVE_LIBGUDEV', have_libgudev)
@@ -610,6 +615,7 @@ summary('Native Backend', have_native_backend, section: 'Options')
 summary('EGL Device', have_egl_device, section: 'Options')
 summary('Remote desktop', have_remote_desktop, section: 'Options')
 summary('libgnome-desktop', have_gnome_desktop, section: 'Options')
+summary('Sound player', have_sound_player, section: 'Options')
 summary('gudev', have_libgudev, section: 'Options')
 summary('Wacom', have_libwacom, section: 'Options')
 summary('SM', have_sm, section: 'Options')
diff --git a/meson_options.txt b/meson_options.txt
index da755393c7..dbdc71ab3e 100644
--- a/meson_options.txt
+++ b/meson_options.txt
@@ -93,6 +93,12 @@ option('libwacom',
   description: 'Enable libwacom support'
 )
 
+option('sound_player',
+  type: 'boolean',
+  value: true,
+  description: 'Enable sound player support using libcanberra',
+)
+
 option('pango_ft2',
   type: 'boolean',
   value: true,
diff --git a/src/core/meta-sound-player.c b/src/core/meta-sound-player.c
index e2d1038933..649c498e6d 100644
--- a/src/core/meta-sound-player.c
+++ b/src/core/meta-sound-player.c
@@ -21,33 +21,26 @@
 
 #include "config.h"
 
+#ifdef HAVE_SOUND_PLAYER
 #include <canberra.h>
+#endif
 
 #include "meta/meta-sound-player.h"
 
 #define EVENT_SOUNDS_KEY "event-sounds"
 #define THEME_NAME_KEY   "theme-name"
 
-typedef struct _MetaPlayRequest MetaPlayRequest;
-
 struct _MetaSoundPlayer
 {
   GObject parent;
   GThreadPool *queue;
   GSettings *settings;
+#ifdef HAVE_SOUND_PLAYER
   ca_context *context;
+#endif
   uint32_t id_pool;
 };
 
-struct _MetaPlayRequest
-{
-  ca_proplist *props;
-  uint32_t id;
-  gulong cancel_id;
-  GCancellable *cancellable;
-  MetaSoundPlayer *player;
-};
-
 const char * const cache_allow_list[] = {
   "bell-window-system",
   "desktop-switch-left",
@@ -59,6 +52,42 @@ const char * const cache_allow_list[] = {
 
 G_DEFINE_TYPE (MetaSoundPlayer, meta_sound_player, G_TYPE_OBJECT)
 
+static void
+meta_sound_player_finalize (GObject *object)
+{
+  MetaSoundPlayer *player = META_SOUND_PLAYER (object);
+
+  g_object_unref (player->settings);
+  g_thread_pool_free (player->queue, FALSE, TRUE);
+
+#ifdef HAVE_SOUND_PLAYER
+  ca_context_destroy (player->context);
+#endif
+
+  G_OBJECT_CLASS (meta_sound_player_parent_class)->finalize (object);
+}
+
+static void
+meta_sound_player_class_init (MetaSoundPlayerClass *klass)
+{
+  GObjectClass *object_class = G_OBJECT_CLASS (klass);
+
+  object_class->finalize = meta_sound_player_finalize;
+}
+
+#ifdef HAVE_SOUND_PLAYER
+
+typedef struct _MetaPlayRequest MetaPlayRequest;
+
+struct _MetaPlayRequest
+{
+  ca_proplist *props;
+  uint32_t id;
+  gulong cancel_id;
+  GCancellable *cancellable;
+  MetaSoundPlayer *player;
+};
+
 static MetaPlayRequest *
 meta_play_request_new (MetaSoundPlayer *player,
                        ca_proplist     *props,
@@ -82,26 +111,6 @@ meta_play_request_free (MetaPlayRequest *req)
   g_free (req);
 }
 
-static void
-meta_sound_player_finalize (GObject *object)
-{
-  MetaSoundPlayer *player = META_SOUND_PLAYER (object);
-
-  g_object_unref (player->settings);
-  g_thread_pool_free (player->queue, FALSE, TRUE);
-  ca_context_destroy (player->context);
-
-  G_OBJECT_CLASS (meta_sound_player_parent_class)->finalize (object);
-}
-
-static void
-meta_sound_player_class_init (MetaSoundPlayerClass *klass)
-{
-  GObjectClass *object_class = G_OBJECT_CLASS (klass);
-
-  object_class->finalize = meta_sound_player_finalize;
-}
-
 static void
 cancelled_cb (GCancellable    *cancellable,
               MetaPlayRequest *req)
@@ -204,9 +213,21 @@ create_context (GSettings *settings)
   return context;
 }
 
+static void
+build_ca_proplist (ca_proplist  *props,
+                   const char   *event_property,
+                   const char   *event_id,
+                   const char   *event_description)
+{
+  ca_proplist_sets (props, event_property, event_id);
+  ca_proplist_sets (props, CA_PROP_EVENT_DESCRIPTION, event_description);
+}
+#endif
+
 static void
 meta_sound_player_init (MetaSoundPlayer *player)
 {
+#ifdef HAVE_SOUND_PLAYER
   player->queue = g_thread_pool_new ((GFunc) play_sound,
                                     player, 1, FALSE, NULL);
   player->settings = g_settings_new ("org.gnome.desktop.sound");
@@ -214,17 +235,9 @@ meta_sound_player_init (MetaSoundPlayer *player)
 
   g_signal_connect (player->settings, "changed",
                     G_CALLBACK (settings_changed_cb), player);
+#endif
 }
 
-static void
-build_ca_proplist (ca_proplist  *props,
-                   const char   *event_property,
-                   const char   *event_id,
-                   const char   *event_description)
-{
-  ca_proplist_sets (props, event_property, event_id);
-  ca_proplist_sets (props, CA_PROP_EVENT_DESCRIPTION, event_description);
-}
 
 /**
  * meta_sound_player_play_from_theme:
@@ -241,6 +254,7 @@ meta_sound_player_play_from_theme (MetaSoundPlayer *player,
                                    const char      *description,
                                    GCancellable    *cancellable)
 {
+#ifdef HAVE_SOUND_PLAYER
   MetaPlayRequest *req;
   ca_proplist *props;
 
@@ -258,6 +272,7 @@ meta_sound_player_play_from_theme (MetaSoundPlayer *player,
 
   req = meta_play_request_new (player, props, cancellable);
   g_thread_pool_push (player->queue, req, NULL);
+#endif
 }
 
 /**
@@ -275,6 +290,7 @@ meta_sound_player_play_from_file (MetaSoundPlayer *player,
                                   const char      *description,
                                   GCancellable    *cancellable)
 {
+#ifdef HAVE_SOUND_PLAYER
   MetaPlayRequest *req;
   ca_proplist *props;
   char *path;
@@ -293,4 +309,5 @@ meta_sound_player_play_from_file (MetaSoundPlayer *player,
 
   req = meta_play_request_new (player, props, cancellable);
   g_thread_pool_push (player->queue, req, NULL);
+#endif
 }
diff --git a/src/meson.build b/src/meson.build
index 7b456f524f..d92ea188fd 100644
--- a/src/meson.build
+++ b/src/meson.build
@@ -25,7 +25,6 @@ mutter_pkg_private_deps = [
   gmodule_no_export_dep,
   gnome_settings_daemon_dep,
   json_glib_dep,
-  libcanberra_dep,
   xkbcommon_dep,
 ]
 
@@ -35,6 +34,12 @@ if have_gnome_desktop
   ]
 endif
 
+if have_sound_player
+  mutter_pkg_private_deps += [
+    libcanberra_dep,
+  ]
+endif
+
 if have_gl
   mutter_pkg_deps += [
     gl_dep,


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