From 750532a1d8ec2b4d637566f44b663ea6344426bc Mon Sep 17 00:00:00 2001 From: Brandon Hartshorn Date: Sun, 8 Oct 2017 08:33:32 -0600 Subject: [PATCH] volume: allow to pass multiple arguments to amixer (#44) * Added option for a table to configure volume widget, allowing device specification also. * Updated README.md with new configuration options for volume widget * volume: allow passing a list of commandline arguments --- README.md | 6 ++++-- widgets/volume_linux.lua | 11 ++++++++++- 2 files changed, 14 insertions(+), 3 deletions(-) diff --git a/README.md b/README.md index 985a2cc..a246c3f 100644 --- a/README.md +++ b/README.md @@ -447,8 +447,10 @@ Provides volume levels and state of requested mixers. Supported platforms: Linux (required tool: amixer), FreeBSD. - Arguments (per platform): - * Linux: takes the ALSA mixer control as an argument, i.e. `"Master"`, - optionally append the card ID or other options, i.e. `"PCM -c 0"` + * Linux: takes either a single argument containing the ALSA mixer control as + an argument, i.e. `"Master"`, or a table passed as command line arguments + to [amixer(1)](https://linux.die.net/man/1/amixer), + i.e `{"PCM", "-c", "0"}` or `{"Master", "-D", "pulse"}`. * FreeBSD: takes the mixer control as an argument, i.e. `"vol"` - Returns: * Linux: returns 1st value as the volume level and 2nd as the mute state of diff --git a/widgets/volume_linux.lua b/widgets/volume_linux.lua index c7751d4..0fd6820 100644 --- a/widgets/volume_linux.lua +++ b/widgets/volume_linux.lua @@ -26,8 +26,17 @@ local function worker(format, warg) ["off"] = "♩" -- "M" } + if type(warg) ~= "table" then + warg = { warg } + end + + local cmd = "amixer -M get " + for _, arg in ipairs(warg) do + cmd = cmd .. " " .. helpers.shellquote(arg) + end + -- Get mixer control contents - local f = io.popen("amixer -M get " .. helpers.shellquote(warg)) + local f = io.popen(cmd) local mixer = f:read("*all") f:close()