aboutsummaryrefslogtreecommitdiff
path: root/pkgs/patches/0001-wpctl-Add-get-volume-command-and-functionality.patch
blob: 4bae05f646e2f888e89f1d9248cd691062e01d4c (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
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