diff options
author | Karel Kočí <cynerd@email.cz> | 2022-02-21 21:54:09 +0100 |
---|---|---|
committer | Karel Kočí <cynerd@email.cz> | 2022-06-10 14:05:48 +0200 |
commit | 93b0545d11bf8c7f065203f7f3eaf1d0e3730dce (patch) | |
tree | da93fa5fcd14c493d8ccd86c98f40d26c9697869 /pkgs/patches | |
download | nixos-personal-93b0545d11bf8c7f065203f7f3eaf1d0e3730dce.tar.gz nixos-personal-93b0545d11bf8c7f065203f7f3eaf1d0e3730dce.tar.bz2 nixos-personal-93b0545d11bf8c7f065203f7f3eaf1d0e3730dce.zip |
Add initial version
Diffstat (limited to 'pkgs/patches')
-rw-r--r-- | pkgs/patches/0001-wpctl-Add-get-volume-command-and-functionality.patch | 123 | ||||
-rw-r--r-- | pkgs/patches/0002-wpctl-allow-modifying-volume-levels-using-percentage.patch | 118 |
2 files changed, 241 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 + diff --git a/pkgs/patches/0002-wpctl-allow-modifying-volume-levels-using-percentage.patch b/pkgs/patches/0002-wpctl-allow-modifying-volume-levels-using-percentage.patch new file mode 100644 index 0000000..9e51797 --- /dev/null +++ b/pkgs/patches/0002-wpctl-allow-modifying-volume-levels-using-percentage.patch @@ -0,0 +1,118 @@ +From 43d8753c5ef4cbd4d2f6558182b290d083644521 Mon Sep 17 00:00:00 2001 +From: Varnit Singh <varnitcls@gmail.com> +Date: Wed, 8 Jun 2022 09:25:45 +0000 +Subject: [PATCH 2/2] wpctl: allow modifying volume levels using + percentage/step amount. + +--- + src/tools/wpctl.c | 63 ++++++++++++++++++++++++++++++++++++++++++++--- + 1 file changed, 59 insertions(+), 4 deletions(-) + +diff --git a/src/tools/wpctl.c b/src/tools/wpctl.c +index 9f7c6bb..0f5bc8c 100644 +--- a/src/tools/wpctl.c ++++ b/src/tools/wpctl.c +@@ -45,6 +45,7 @@ static struct { + guint64 id; + gfloat volume; + gboolean is_pid; ++ gchar type; + } set_volume; + + struct { +@@ -846,11 +847,38 @@ set_volume_parse_positional (gint argc, gchar ** argv, GError **error) + { + if (argc < 4) { + g_set_error (error, wpctl_error_domain_quark(), 0, +- "ID and VOL are required"); ++ "ID and VOL[%%][-/+] are required"); ++ return FALSE; ++ } ++ ++ GRegex *regex = g_regex_new ("^(\\d*\\.?\\d*)(%?)([-+]?)$", 0, 0, NULL); ++ GMatchInfo *info = NULL; ++ ++ if (g_regex_match(regex, argv[3], 0, &info)) { ++ cmdline.set_volume.volume = strtof(g_match_info_fetch(info, 1), NULL); ++ cmdline.set_volume.type = 'a'; ++ ++ if (g_strcmp0(g_match_info_fetch(info, 2), "%") == 0) { ++ cmdline.set_volume.type = 'p'; ++ } ++ ++ if (g_strcmp0(g_match_info_fetch(info, 3), "-") == 0) { ++ cmdline.set_volume.volume = -(cmdline.set_volume.volume); ++ if (cmdline.set_volume.type != 'p') { ++ cmdline.set_volume.type = 's'; ++ } ++ } else if (g_strcmp0(g_match_info_fetch(info, 3), "+") == 0 && cmdline.set_volume.type != 'p') { ++ cmdline.set_volume.type = 's'; ++ } ++ g_match_info_free (info); ++ g_regex_unref (regex); ++ } else { ++ g_regex_unref (regex); ++ g_set_error (error, wpctl_error_domain_quark(), 0, ++ "Invalid volume argument. See wpctl set-volume --help"); + return FALSE; + } + +- cmdline.set_volume.volume = strtof (argv[3], NULL); + return parse_id (!cmdline.set_volume.is_pid, false, argv[2], + &cmdline.set_volume.id, error); + } +@@ -874,6 +902,7 @@ do_set_volume (WpCtl * self, WpPipewireObject *proxy) + g_autoptr (GError) error = NULL; + GVariant *variant = NULL; + gboolean res = FALSE; ++ gdouble curr_volume = 1.0; + guint32 id = wp_proxy_get_bound_id (WP_PROXY (proxy)); + + if (WP_IS_ENDPOINT (proxy)) { +@@ -885,6 +914,27 @@ do_set_volume (WpCtl * self, WpPipewireObject *proxy) + id = atoi (str); + } + ++ g_signal_emit_by_name (mixer_api, "get-volume", id, &variant); ++ if (!variant) { ++ fprintf (stderr, "Node %d does not support volume\n", id); ++ g_clear_pointer (&variant, g_variant_unref); ++ return FALSE; ++ } ++ g_variant_lookup (variant, "volume", "d", &curr_volume); ++ g_clear_pointer (&variant, g_variant_unref); ++ ++ if (cmdline.set_volume.type == 'a') { ++ cmdline.set_volume.volume = cmdline.set_volume.volume; ++ } else if (cmdline.set_volume.type == 's') { ++ cmdline.set_volume.volume = (cmdline.set_volume.volume + curr_volume); ++ } else if (cmdline.set_volume.type == 'p') { ++ gfloat delta = (cmdline.set_volume.volume) * (curr_volume); ++ cmdline.set_volume.volume = (curr_volume + delta); ++ } ++ if (cmdline.set_volume.volume < 0) { ++ cmdline.set_volume.volume = 0.0; ++ } ++ + g_variant_builder_add (&b, "{sv}", "volume", + g_variant_new_double (cmdline.set_volume.volume)); + variant = g_variant_builder_end (&b); +@@ -1266,8 +1316,13 @@ static const struct subcommand { + }, + { + .name = "set-volume", +- .positional_args = "ID VOL", +- .summary = "Sets the volume of ID to VOL (floating point, 1.0 is 100%%)", ++ .positional_args = "ID VOL[%%][-/+]", ++ .summary = "Sets the volume of ID from specified argument. " ++ "(floating point, 1.0 is 100%%)\n VOL%%[-/+] - " ++ "Step up/down volume by specified percent (Example:" ++ " 0.5%%+)\n VOL[-/+] - Step up/down volume by" ++ " specified value (Example: 0.5+)\n VOL - Set " ++ "volume as the specified value (Example: 0.5)", + .description = NULL, + .entries = { + { "pid", 'p', G_OPTION_FLAG_NONE, G_OPTION_ARG_NONE, +-- +2.36.1 + |