Skip to content

Commit

Permalink
volume: allow to pass multiple arguments to amixer (#44)
Browse files Browse the repository at this point in the history
* 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
  • Loading branch information
bhartshorn authored and Mic92 committed Oct 8, 2017
1 parent 983253a commit 750532a
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 3 deletions.
6 changes: 4 additions & 2 deletions README.md
Expand Up @@ -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
Expand Down
11 changes: 10 additions & 1 deletion widgets/volume_linux.lua
Expand Up @@ -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()

Expand Down

0 comments on commit 750532a

Please sign in to comment.