pactl: Add a command for setting the default sink/source.

This adds two new commands to pactl:
    set-default-sink
    set-default-source

This command has been part of the native protocol for a long time,
no reason not to expose it in pactl.
This commit is contained in:
poljar (Damir Jelić) 2013-01-30 18:51:57 +01:00 committed by Tanu Kaskinen
parent a5af95f83d
commit 831cae16d4
2 changed files with 41 additions and 0 deletions

View file

@ -162,11 +162,21 @@ USA.
<optdesc><p>Set the specified card (identified by its symbolic name or numerical index) to the specified profile (identified by its symbolic name).</p></optdesc>
</option>
<option>
<p><opt>set-default-sink</opt> <arg>SINK</arg></p>
<optdesc><p>Make the specified sink (identified by its symbolic name) the default sink.</p></optdesc>
</option>
<option>
<p><opt>set-sink-port</opt> <arg>SINK</arg> <arg>PORT</arg></p>
<optdesc><p>Set the specified sink (identified by its symbolic name or numerical index) to the specified port (identified by its symbolic name).</p></optdesc>
</option>
<option>
<p><opt>set-default-source</opt> <arg>SOURCE</arg></p>
<optdesc><p>Make the specified source (identified by its symbolic name) the default source.</p></optdesc>
</option>
<option>
<p><opt>set-source-port</opt> <arg>SOURCE</arg> <arg>PORT</arg></p>
<optdesc><p>Set the specified source (identified by its symbolic name or numerical index) to the specified port (identified by its symbolic name).</p></optdesc>

View file

@ -114,7 +114,9 @@ static enum {
SUSPEND_SOURCE,
SET_CARD_PROFILE,
SET_SINK_PORT,
SET_DEFAULT_SINK,
SET_SOURCE_PORT,
SET_DEFAULT_SOURCE,
SET_SINK_VOLUME,
SET_SOURCE_VOLUME,
SET_SINK_INPUT_VOLUME,
@ -1284,10 +1286,18 @@ static void context_state_callback(pa_context *c, void *userdata) {
pa_operation_unref(pa_context_set_sink_port_by_name(c, sink_name, port_name, simple_callback, NULL));
break;
case SET_DEFAULT_SINK:
pa_operation_unref(pa_context_set_default_sink(c, sink_name, simple_callback, NULL));
break;
case SET_SOURCE_PORT:
pa_operation_unref(pa_context_set_source_port_by_name(c, source_name, port_name, simple_callback, NULL));
break;
case SET_DEFAULT_SOURCE:
pa_operation_unref(pa_context_set_default_source(c, source_name, simple_callback, NULL));
break;
case SET_SINK_MUTE:
if (mute == TOGGLE_MUTE)
pa_operation_unref(pa_context_get_sink_info_by_name(c, sink_name, sink_toggle_mute_callback, NULL));
@ -1491,6 +1501,7 @@ static void help(const char *argv0) {
printf("%s %s %s %s\n", argv0, _("[options]"), "move-(sink-input|source-output)", _("#N SINK|SOURCE"));
printf("%s %s %s %s\n", argv0, _("[options]"), "suspend-(sink|source)", _("NAME|#N 1|0"));
printf("%s %s %s %s\n", argv0, _("[options]"), "set-card-profile ", _("CARD PROFILE"));
printf("%s %s %s %s\n", argv0, _("[options]"), "set-default-(sink|source)", _("NAME"));
printf("%s %s %s %s\n", argv0, _("[options]"), "set-(sink|source)-port", _("NAME|#N PORT"));
printf("%s %s %s %s\n", argv0, _("[options]"), "set-(sink|source)-volume", _("NAME|#N VOLUME"));
printf("%s %s %s %s\n", argv0, _("[options]"), "set-(sink-input|source-output)-volume", _("#N VOLUME"));
@ -1779,6 +1790,16 @@ int main(int argc, char *argv[]) {
sink_name = pa_xstrdup(argv[optind+1]);
port_name = pa_xstrdup(argv[optind+2]);
} else if (pa_streq(argv[optind], "set-default-sink")) {
action = SET_DEFAULT_SINK;
if (argc != optind+2) {
pa_log(_("You have to specify a sink name"));
goto quit;
}
sink_name = pa_xstrdup(argv[optind+1]);
} else if (pa_streq(argv[optind], "set-source-port")) {
action = SET_SOURCE_PORT;
@ -1790,6 +1811,16 @@ int main(int argc, char *argv[]) {
source_name = pa_xstrdup(argv[optind+1]);
port_name = pa_xstrdup(argv[optind+2]);
} else if (pa_streq(argv[optind], "set-default-source")) {
action = SET_DEFAULT_SOURCE;
if (argc != optind+2) {
pa_log(_("You have to specify a source name"));
goto quit;
}
source_name = pa_xstrdup(argv[optind+1]);
} else if (pa_streq(argv[optind], "set-sink-volume")) {
action = SET_SINK_VOLUME;