summaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rw-r--r--src/canberra.h16
-rw-r--r--src/common.c17
2 files changed, 31 insertions, 2 deletions
diff --git a/src/canberra.h b/src/canberra.h
index fc9ef0a..3a3b88f 100644
--- a/src/canberra.h
+++ b/src/canberra.h
@@ -353,6 +353,19 @@ extern "C" {
#define CA_PROP_CANBERRA_XDG_THEME_OUTPUT_PROFILE "canberra.xdg-theme.output-profile"
/**
+ * CA_PROP_CANBERRA_ENABLE:
+ *
+ * A special property that can be used to control whether any sounds
+ * are played at all. If this property is "1" or unset sounds are
+ * played as normal. However, if it is "0" all calls to
+ * ca_context_play() will fail with CA_ERROR_DISABLED.
+ *
+ * If the list of properties is handed on to the sound server this
+ * property is stripped from it.
+ */
+#define CA_PROP_CANBERRA_ENABLE "canberra.enable"
+
+/**
* ca_context:
*
* A libcanberra context object.
@@ -399,7 +412,8 @@ enum {
CA_ERROR_ACCESS = -13,
CA_ERROR_IO = -14,
CA_ERROR_INTERNAL = -15,
- _CA_ERROR_MAX = -16
+ CA_ERROR_DISABLED = -16,
+ _CA_ERROR_MAX = -17
};
/**
diff --git a/src/common.c b/src/common.c
index b285514..71b887a 100644
--- a/src/common.c
+++ b/src/common.c
@@ -518,6 +518,8 @@ int ca_context_play(ca_context *c, uint32_t id, ...) {
int ca_context_play_full(ca_context *c, uint32_t id, ca_proplist *p, ca_finish_callback_t cb, void *userdata) {
int ret;
+ const char *t;
+ ca_bool_t enabled = TRUE;
ca_return_val_if_fail(c, CA_ERROR_INVALID);
ca_return_val_if_fail(p, CA_ERROR_INVALID);
@@ -528,6 +530,18 @@ int ca_context_play_full(ca_context *c, uint32_t id, ca_proplist *p, ca_finish_c
ca_return_val_if_fail_unlock(ca_proplist_contains(p, CA_PROP_EVENT_ID) ||
ca_proplist_contains(c->props, CA_PROP_EVENT_ID), CA_ERROR_INVALID, c->mutex);
+ ca_mutex_lock(c->props->mutex);
+ if ((t = ca_proplist_gets_unlocked(c->props, CA_PROP_CANBERRA_ENABLE)))
+ enabled = !streq(t, "0");
+ ca_mutex_unlock(c->props->mutex);
+
+ ca_mutex_lock(p->mutex);
+ if ((t = ca_proplist_gets_unlocked(p, CA_PROP_CANBERRA_ENABLE)))
+ enabled = !streq(t, "0");
+ ca_mutex_unlock(p->mutex);
+
+ ca_return_val_if_fail_unlock(enabled, CA_ERROR_DISABLED, c->mutex);
+
if ((ret = context_open_unlocked(c)) < 0)
goto finish;
@@ -674,7 +688,8 @@ const char *ca_strerror(int code) {
[-CA_ERROR_NOTAVAILABLE] = "Not available",
[-CA_ERROR_ACCESS] = "Access forbidden",
[-CA_ERROR_IO] = "IO error",
- [-CA_ERROR_INTERNAL] = "Internal error"
+ [-CA_ERROR_INTERNAL] = "Internal error",
+ [-CA_ERROR_DISABLED] = "Sounds disabled"
};
ca_return_val_if_fail(code <= 0, NULL);