Skip to content

Commit 750532a

Browse files
bhartshornMic92
authored andcommitted
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
1 parent 983253a commit 750532a

File tree

2 files changed

+14
-3
lines changed

2 files changed

+14
-3
lines changed

README.md

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -447,8 +447,10 @@ Provides volume levels and state of requested mixers.
447447
Supported platforms: Linux (required tool: amixer), FreeBSD.
448448

449449
- Arguments (per platform):
450-
* Linux: takes the ALSA mixer control as an argument, i.e. `"Master"`,
451-
optionally append the card ID or other options, i.e. `"PCM -c 0"`
450+
* Linux: takes either a single argument containing the ALSA mixer control as
451+
an argument, i.e. `"Master"`, or a table passed as command line arguments
452+
to [amixer(1)](https://linux.die.net/man/1/amixer),
453+
i.e `{"PCM", "-c", "0"}` or `{"Master", "-D", "pulse"}`.
452454
* FreeBSD: takes the mixer control as an argument, i.e. `"vol"`
453455
- Returns:
454456
* Linux: returns 1st value as the volume level and 2nd as the mute state of

widgets/volume_linux.lua

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,8 +26,17 @@ local function worker(format, warg)
2626
["off"] = "" -- "M"
2727
}
2828

29+
if type(warg) ~= "table" then
30+
warg = { warg }
31+
end
32+
33+
local cmd = "amixer -M get "
34+
for _, arg in ipairs(warg) do
35+
cmd = cmd .. " " .. helpers.shellquote(arg)
36+
end
37+
2938
-- Get mixer control contents
30-
local f = io.popen("amixer -M get " .. helpers.shellquote(warg))
39+
local f = io.popen(cmd)
3140
local mixer = f:read("*all")
3241
f:close()
3342

0 commit comments

Comments
 (0)