aboutsummaryrefslogtreecommitdiff
path: root/pkgs/patches/0001-wpctl-Add-get-volume-command-and-functionality.patch
diff options
context:
space:
mode:
Diffstat (limited to 'pkgs/patches/0001-wpctl-Add-get-volume-command-and-functionality.patch')
-rw-r--r--pkgs/patches/0001-wpctl-Add-get-volume-command-and-functionality.patch123
1 files changed, 123 insertions, 0 deletions
diff --git a/pkgs/patches/0001-wpctl-Add-get-volume-command-and-functionality.patch b/pkgs/patches/0001-wpctl-Add-get-volume-command-and-functionality.patch
new file mode 100644
index 0000000..4bae05f
--- /dev/null
+++ b/pkgs/patches/0001-wpctl-Add-get-volume-command-and-functionality.patch
@@ -0,0 +1,123 @@
+From c44a369a14a13045462018e55595f1e2d83e1d6b Mon Sep 17 00:00:00 2001
+From: Varnit Singh <varnitcls@gmail.com>
+Date: Wed, 8 Jun 2022 09:18:34 +0000
+Subject: [PATCH 1/2] wpctl: Add get-volume command and functionality
+
+---
+ src/tools/wpctl.c | 86 +++++++++++++++++++++++++++++++++++++++++++++++
+ 1 file changed, 86 insertions(+)
+
+diff --git a/src/tools/wpctl.c b/src/tools/wpctl.c
+index ca5ea01..9f7c6bb 100644
+--- a/src/tools/wpctl.c
++++ b/src/tools/wpctl.c
+@@ -47,6 +47,10 @@ static struct {
+ gboolean is_pid;
+ } set_volume;
+
++ struct {
++ guint64 id;
++ } get_volume;
++
+ struct {
+ guint64 id;
+ guint mute;
+@@ -471,6 +475,78 @@ status_run (WpCtl * self)
+ g_main_loop_quit (self->loop);
+ }
+
++/* get-volume */
++
++static gboolean
++get_volume_parse_positional (gint argc, gchar ** argv, GError **error)
++{
++ if (argc < 3) {
++ g_set_error (error, wpctl_error_domain_quark(), 0,
++ "ID is required");
++ return FALSE;
++ } else {
++ return parse_id (true, false, argv[2], &cmdline.get_volume.id, error);
++ }
++}
++
++static gboolean
++get_volume_prepare (WpCtl * self, GError ** error)
++{
++ wp_object_manager_add_interest (self->om, WP_TYPE_NODE, NULL);
++ wp_object_manager_request_object_features (self->om, WP_TYPE_GLOBAL_PROXY,
++ WP_PIPEWIRE_OBJECT_FEATURES_MINIMAL);
++ return TRUE;
++}
++
++static void
++do_print_volume (WpCtl * self, WpPipewireObject *proxy)
++{
++ g_autoptr (WpPlugin) mixer_api = wp_plugin_find (self->core, "mixer-api");
++ GVariant *variant = NULL;
++ gboolean mute = FALSE;
++ gdouble volume = 1.0;
++ guint32 id = wp_proxy_get_bound_id (WP_PROXY (proxy));
++
++ g_signal_emit_by_name (mixer_api, "get-volume", id, &variant);
++ if (!variant) {
++ fprintf (stderr, "Node %d does not support volume\n", id);
++ return;
++ }
++ g_variant_lookup (variant, "volume", "d", &volume);
++ g_variant_lookup (variant, "mute", "b", &mute);
++ g_clear_pointer (&variant, g_variant_unref);
++
++ printf ("Volume: %.2f%s", volume, mute ? " [MUTED]\n" : "\n");
++}
++
++static void
++get_volume_run (WpCtl * self)
++{
++ g_autoptr (WpPlugin) def_nodes_api = NULL;
++ g_autoptr (GError) error = NULL;
++ g_autoptr (WpPipewireObject) proxy = NULL;
++ guint32 id;
++
++ def_nodes_api = wp_plugin_find (self->core, "default-nodes-api");
++
++ if (!translate_id (def_nodes_api, cmdline.get_volume.id, &id, &error)) {
++ fprintf(stderr, "Translate ID error: %s\n\n", error->message);
++ goto out;
++ }
++
++ proxy = wp_object_manager_lookup (self->om, WP_TYPE_GLOBAL_PROXY,
++ WP_CONSTRAINT_TYPE_G_PROPERTY, "bound-id", "=u", id, NULL);
++ if (!proxy) {
++ fprintf (stderr, "Node '%d' not found\n", id);
++ goto out;
++ }
++
++ do_print_volume (self, proxy);
++
++out:
++ g_main_loop_quit (self->loop);
++}
++
+ /* inspect */
+
+ static gboolean
+@@ -1150,6 +1226,16 @@ static const struct subcommand {
+ .prepare = status_prepare,
+ .run = status_run,
+ },
++ {
++ .name = "get-volume",
++ .positional_args = "ID",
++ .summary = "Displays volume information about the specified node in PipeWire",
++ .description = NULL,
++ .entries = { { NULL } },
++ .parse_positional = get_volume_parse_positional,
++ .prepare = get_volume_prepare,
++ .run = get_volume_run,
++ },
+ {
+ .name = "inspect",
+ .positional_args = "ID",
+--
+2.36.1
+