summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorHui Wang <hui.wang@canonical.com>2014-09-22 11:50:49 +0800
committerDavid Henningsson <david.henningsson@canonical.com>2014-09-22 13:26:32 +0200
commit1ff4f1b67a813d1772f04f4d394588a0a4483c28 (patch)
treef1f0810e42c0f0c9fa438cc7f9651b472e15d6d5
parent84ce398ea829e932269cf30af1aff5b1fe846316 (diff)
module-switch-on-connect: add an argument for conditionally connecting
On a machine without fixed connecting audio devices like internal microphone or internal speaker, and when there is no external audio devices plugging in, the default source/sink is alsa_input/alsa_output and there is no input devices/output devices listed in the gnome sound-setting. Under this situation, if we connect a bluetooth headset, the gnome sound-setting will list bluez input/output devices, but they are not active devices by default. This looks very weird that sound-setting lists only one input device and one output device, but they are not active. To change this situation, we add an argument, the policy is if a new source/sink is connected and current default source/sink's active_port is AVAILABLE_NO, we let the new added one switch to default one. BugLink: http://bugs.launchpad.net/bugs/1369476 Signed-off-by: Hui Wang <hui.wang@canonical.com>
-rw-r--r--src/modules/module-switch-on-connect.c32
1 files changed, 31 insertions, 1 deletions
diff --git a/src/modules/module-switch-on-connect.c b/src/modules/module-switch-on-connect.c
index d9275d31b..90b86d1b9 100644
--- a/src/modules/module-switch-on-connect.c
+++ b/src/modules/module-switch-on-connect.c
@@ -38,11 +38,15 @@
#include "module-switch-on-connect-symdef.h"
PA_MODULE_AUTHOR("Michael Terry");
-PA_MODULE_DESCRIPTION("When a sink/source is added, switch to it");
+PA_MODULE_DESCRIPTION("When a sink/source is added, switch to it or conditionally switch to it");
PA_MODULE_VERSION(PACKAGE_VERSION);
PA_MODULE_LOAD_ONCE(true);
+PA_MODULE_USAGE(
+ "only_from_unavailable=<boolean, only switch from unavailable ports> "
+);
static const char* const valid_modargs[] = {
+ "only_from_unavailable",
NULL,
};
@@ -50,6 +54,7 @@ struct userdata {
pa_hook_slot
*sink_put_slot,
*source_put_slot;
+ bool only_from_unavailable;
};
static pa_hook_result_t sink_put_hook_callback(pa_core *c, pa_sink *sink, void* userdata) {
@@ -57,9 +62,11 @@ static pa_hook_result_t sink_put_hook_callback(pa_core *c, pa_sink *sink, void*
uint32_t idx;
pa_sink *def;
const char *s;
+ struct userdata *u = userdata;
pa_assert(c);
pa_assert(sink);
+ pa_assert(userdata);
/* Don't want to run during startup or shutdown */
if (c->state != PA_CORE_RUNNING)
@@ -77,6 +84,10 @@ static pa_hook_result_t sink_put_hook_callback(pa_core *c, pa_sink *sink, void*
if (def == sink)
return PA_HOOK_OK;
+ if (u->only_from_unavailable)
+ if (!def->active_port || def->active_port->available != PA_AVAILABLE_NO)
+ return PA_HOOK_OK;
+
/* Actually do the switch to the new sink */
pa_namereg_set_default_sink(c, sink);
@@ -106,9 +117,11 @@ static pa_hook_result_t source_put_hook_callback(pa_core *c, pa_source *source,
uint32_t idx;
pa_source *def;
const char *s;
+ struct userdata *u = userdata;
pa_assert(c);
pa_assert(source);
+ pa_assert(userdata);
/* Don't want to run during startup or shutdown */
if (c->state != PA_CORE_RUNNING)
@@ -130,6 +143,10 @@ static pa_hook_result_t source_put_hook_callback(pa_core *c, pa_source *source,
if (def == source)
return PA_HOOK_OK;
+ if (u->only_from_unavailable)
+ if (!def->active_port || def->active_port->available != PA_AVAILABLE_NO)
+ return PA_HOOK_OK;
+
/* Actually do the switch to the new source */
pa_namereg_set_default_source(c, source);
@@ -171,8 +188,21 @@ int pa__init(pa_module*m) {
u->sink_put_slot = pa_hook_connect(&m->core->hooks[PA_CORE_HOOK_SINK_PUT], PA_HOOK_LATE+30, (pa_hook_cb_t) sink_put_hook_callback, u);
u->source_put_slot = pa_hook_connect(&m->core->hooks[PA_CORE_HOOK_SOURCE_PUT], PA_HOOK_LATE+20, (pa_hook_cb_t) source_put_hook_callback, u);
+ if (pa_modargs_get_value_boolean(ma, "only_from_unavailable", &u->only_from_unavailable) < 0) {
+ pa_log("Failed to get a boolean value for only_from_unavailable.");
+ goto fail;
+ }
+
pa_modargs_free(ma);
return 0;
+
+fail:
+ if (ma)
+ pa_modargs_free(ma);
+
+ pa__done(m);
+
+ return -1;
}
void pa__done(pa_module*m) {