summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorTanu Kaskinen <tanuk@iki.fi>2020-01-04 08:50:34 +0200
committerTanu Kaskinen <tanuk@iki.fi>2021-08-25 18:51:36 +0300
commit880bc732557f1b653c8d8f17a668212561e3dcf2 (patch)
treea7d3e9faa2e989f9e59de4eb4572f992d379180c
parent4dadcc77ddf96998d31b4f54eaa1810b51507c06 (diff)
Update module directory logic
PulseAudio 16.0 will change the module directory, and this patch adds support for the new directory in paprefs, while retaining compatibility with older PulseAudio versions too. Part-of: <https://gitlab.freedesktop.org/pulseaudio/paprefs/-/merge_requests/7>
-rw-r--r--src/paprefs.cc68
1 files changed, 53 insertions, 15 deletions
diff --git a/src/paprefs.cc b/src/paprefs.cc
index c492e64..390f961 100644
--- a/src/paprefs.cc
+++ b/src/paprefs.cc
@@ -673,26 +673,64 @@ void MainWindow::readFromGSettings() {
}
gchar * MainWindow::modulePath(const gchar *name) {
- gchar *path, **versions;
+ /* PulseAudio 16.0 dropped the version number from the module directory.
+ * The old module directory looked like "${libdir}/pulse-X.Y/modules", the
+ * new directory looks like "${libdir}/pulseaudio/modules". To deal with
+ * the change, we have three cases:
+ *
+ * 1) If MODDIR ends with "/pulseaudio/modules", we assume it's can be used
+ * as is.
+ *
+ * 2) Otherwise paprefs might be built against an older PulseAudio version,
+ * but the running PulseAudio version might be newer, so we check if
+ * "${libdir}/pulseaudio/modules" exists, in which case we use it. We
+ * don't actually use libdir in the check, though, we use MODDIR with
+ * the last two components removed (the removed part is assumed to be
+ * "/pulse-X.Y/modules"). In the usual case that will be the same as
+ * libdir, but PulseAudio might be built with a custom module directory,
+ * so it's better to use MODDIR.
+ *
+ * 3) Otherwise we assume that MODDIR ends with "/pulse-X.Y/modules" and we
+ * use that, except we replace the version number with the version
+ * reported by pa_get_library_version().
+ *
+ * FIXME: It would be better to connect to the PulseAudio server and ask
+ * its version, but that would require adding a "connecting to PulseAudio"
+ * phase to startup (requiring UI changes), so implementing it requires
+ * more work. */
+
+ gchar *libdir = NULL, *search, *moddir = NULL, *path, **versions;
+
+ /* Case 1: */
+ if (g_str_has_suffix(MODDIR, G_DIR_SEPARATOR_S "pulseaudio" G_DIR_SEPARATOR_S "modules"))
+ return g_build_filename(MODDIR, name, NULL);
+
+ /* Case 2: */
+ libdir = g_strdup(MODDIR);
+ if ((search = g_strrstr(libdir, G_DIR_SEPARATOR_S))) {
+ *search = '\0';
+ if ((search = g_strrstr(libdir, G_DIR_SEPARATOR_S)))
+ *search = '\0';
+ }
- versions = g_strsplit(pa_get_library_version(), ".", 3);
- if (versions[0] && versions[1]) {
- gchar *pulsedir, *search;
+ moddir = g_build_filename(libdir, "pulseaudio", "modules", NULL);
+ if (g_file_test(moddir, G_FILE_TEST_IS_DIR)) {
+ path = g_build_filename(moddir, name, NULL);
+ goto finish;
+ }
- /* Remove the "/pulse-x.y/modules" suffix so we can dynamically inject
- * it again with runtime library version numbers */
- pulsedir = g_strdup_printf ("%s", MODDIR);
- if ((search = g_strrstr (pulsedir, G_DIR_SEPARATOR_S))) {
- *search = '\0';
- if ((search = g_strrstr (pulsedir, G_DIR_SEPARATOR_S)))
- *search = '\0';
- }
- path = g_strdup_printf ("%s" G_DIR_SEPARATOR_S "pulse-%s.%s" G_DIR_SEPARATOR_S "modules" G_DIR_SEPARATOR_S "%s", pulsedir, versions[0], versions[1], name);
- g_free (pulsedir);
- } else
+ /* Case 3: */
+ versions = g_strsplit(pa_get_library_version(), ".", 3);
+ if (versions[0] && versions[1])
+ path = g_strdup_printf("%s" G_DIR_SEPARATOR_S "pulse-%s.%s" G_DIR_SEPARATOR_S "modules" G_DIR_SEPARATOR_S "%s", libdir, versions[0], versions[1], name);
+ else
path = g_build_filename (MODDIR, name, NULL);
g_strfreev(versions);
+finish:
+ g_free(moddir);
+ g_free(libdir);
+
return path;
}