Make libcanberra optional

libcanberra is an old abandoned project whose last release
was well over a decade ago, despite getting some few fixes
on its master branch since then, which are unreleased.

My problem with libcanberra is that it can't be built on
pure wayland systems (no X11 headers) which are becoming
more common nowadays.

It is the only thing keeping pavucontrol tied to X11, all
other dependencies (eg gtk+) build fine on pure wayland.

Since canberra is not a core part of the project, let's
make it optional so pavucontrol can build & work on
pure wayland systems.

Ideally in the future libcanberra can be replaced with
something else, however I don't have the bandwidth to
take this on for now, so I'm just making it optional.

Signed-off-by: Adrian Ratiu <adrian.ratiu@collabora.com>
This commit is contained in:
Adrian Ratiu 2024-03-25 02:19:42 +02:00
parent 44f984883f
commit 22b04fff6e
4 changed files with 17 additions and 4 deletions

View File

@ -10,7 +10,7 @@ cpp = meson.get_compiler('cpp')
gtkmm_dep = dependency('gtkmm-4.0', version : '>= 4.0', required : true)
sigcpp_dep = dependency('sigc++-2.0', required : true)
canberragtk_dep = dependency('libcanberra', version : '>= 0.16', required : true)
canberragtk_dep = dependency('libcanberra', version : '>= 0.16', required : false)
libpulse_dep = dependency('libpulse', version : '>= 5.0', required : true)
libpulsemlglib_dep = dependency('libpulse-mainloop-glib', version : '>= 0.9.16', required : true)
@ -41,6 +41,8 @@ cdata.set_quoted('GETTEXT_PACKAGE', 'pavucontrol')
cdata.set_quoted('LOCALEDIR', localedir)
cdata.set_quoted('GLADE_FILE', join_paths(datadir, 'pavucontrol', 'pavucontrol.glade'))
cdata.set('HAVE_LIBCANBERRA', canberragtk_dep.found())
# Now generate config.h from everything above
configure_file(output : 'config.h', configuration : cdata)

View File

@ -76,9 +76,10 @@ MainWindow::MainWindow(BaseObjectType* cobject, const Glib::RefPtr<Gtk::Builder>
canRenameDevices(false),
m_connected(false),
m_config_filename(NULL) {
#ifdef HAVE_LIBCANBERRA
ca_context_create(&canberraContext);
ca_context_set_driver(canberraContext, "pulse");
#endif
cardsVBox = x->get_widget<Gtk::Box>("cardsVBox");
streamsVBox = x->get_widget<Gtk::Box>("streamsVBox");
recsVBox = x->get_widget<Gtk::Box>("recsVBox");
@ -271,8 +272,9 @@ finish:
g_free(i->second);
clientNames.erase(i);
}
#ifdef HAVE_LIBCANBERRA
ca_context_destroy(canberraContext);
#endif
}
static void set_icon_name_default(Gtk::Image *i, const char *name) {

View File

@ -29,7 +29,9 @@ class MainWindow;
# include <pulse/ext-device-restore.h>
#endif
#ifdef HAVE_LIBCANBERRA
#include <canberra.h>
#endif
#include <unordered_map>
@ -118,7 +120,9 @@ public:
bool canRenameDevices;
#ifdef HAVE_LIBCANBERRA
ca_context *canberraContext;
#endif
protected:
virtual void on_realize();

View File

@ -24,7 +24,10 @@
#include "sinkwidget.h"
#ifdef HAVE_LIBCANBERRA
#include <canberra.h>
#endif
#if HAVE_EXT_DEVICE_RESTORE_API
# include <pulse/format.h>
# include <pulse/ext-device-restore.h>
@ -111,7 +114,6 @@ SinkWidget* SinkWidget::create(MainWindow* mainWindow) {
void SinkWidget::executeVolumeUpdate() {
pa_operation* o;
char dev[64];
int playing = 0;
if (!(o = pa_context_set_sink_volume_by_index(get_context(), index, &volume, NULL, NULL))) {
show_error(this, _("pa_context_set_sink_volume_by_index() failed"));
@ -122,6 +124,8 @@ void SinkWidget::executeVolumeUpdate() {
snprintf(dev, sizeof(dev), "%lu", (unsigned long) index);
#ifdef HAVE_LIBCANBERRA
int playing = 0;
ca_context_playing(mpMainWindow->canberraContext, 2, &playing);
if (playing)
return;
@ -137,6 +141,7 @@ void SinkWidget::executeVolumeUpdate() {
NULL);
ca_context_change_device(mpMainWindow->canberraContext, NULL);
#endif
}
void SinkWidget::onMuteToggleButton() {