wpctl: add option to limit set-volume final value

This commit is contained in:
Jason Nader 2022-08-16 23:57:20 +09:00
parent 6e85b1a3ec
commit b1b5bf2f5f
No known key found for this signature in database
GPG key ID: EE220FCAA09AF23D

View file

@ -44,6 +44,7 @@ static struct {
struct {
guint64 id;
gfloat volume;
gdouble limit;
gboolean is_pid;
gchar type;
} set_volume;
@ -935,6 +936,11 @@ do_set_volume (WpCtl * self, WpPipewireObject *proxy)
if (cmdline.set_volume.volume < 0) {
cmdline.set_volume.volume = 0.0;
}
if (cmdline.set_volume.limit > 0) {
if (cmdline.set_volume.volume > cmdline.set_volume.limit) {
cmdline.set_volume.volume = cmdline.set_volume.limit;
}
}
g_variant_builder_add (&b, "{sv}", "volume",
g_variant_new_double (cmdline.set_volume.volume));
@ -1324,6 +1330,9 @@ static const struct subcommand {
{ "pid", 'p', G_OPTION_FLAG_NONE, G_OPTION_ARG_NONE,
&cmdline.set_volume.is_pid,
"Selects all nodes associated to the given PID number", NULL },
{ "limit", 'l', G_OPTION_FLAG_NONE, G_OPTION_ARG_DOUBLE,
&cmdline.set_volume.limit,
"Limits the final volume percentage to below this value. (floating point, 1.0 is 100%)", NULL },
{ NULL }
},
.parse_positional = set_volume_parse_positional,