All patches and comments are welcome. Please squash your changes to logical
commits before using git-format-patch and git-send-email to
patches@git.madduck.net.
If you'd read over the Git project's submission guidelines and adhered to them,
I'd be especially grateful.
4 Licensed under GNU General Public License v2
5 * (c) 2013, Luke Bonham
6 * (c) 2010, Adrian C. <anrxc@sysphere.org>
10 local newtimer = require("lain.helpers").newtimer
11 local read_pipe = require("lain.helpers").read_pipe
13 local wibox = require("wibox")
15 local string = { match = string.match,
16 format = string.format }
18 local setmetatable = setmetatable
22 local alsa = { last_level = "0", last_status = "" }
24 local function worker(args)
25 local args = args or {}
26 local timeout = args.timeout or 5
27 local settings = args.settings or function() end
29 alsa.cmd = args.cmd or "amixer"
30 alsa.channel = args.channel or "Master"
31 alsa.togglechannel = args.togglechannel
32 alsa.widget = wibox.widget.textbox('')
34 function alsa.update()
35 mixer = read_pipe(string.format("%s get %s", alsa.cmd, alsa.channel))
36 l,s = string.match(mixer, "([%d]+)%%.*%[([%l]*)")
38 -- HDMIs can have a channel different from Master for toggling mute
39 if alsa.togglechannel then
40 s = string.match(read_pipe(string.format("%s get %s", alsa.cmd, alsa.togglechannel)), "%[(%a+)%]")
43 if alsa.last_level ~= l or alsa.last_status ~= s then
44 volume_now = { level = l, status = s }
53 timer_id = string.format("alsa-%s-%s", alsa.cmd, alsa.channel)
54 newtimer(timer_id, timeout, alsa.update)
56 return setmetatable(alsa, { __index = alsa.widget })
59 return setmetatable(alsa, { __call = function(_, ...) return worker(...) end })