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 helpers = require("lain.helpers")
11 local shell = require("awful.util").shell
12 local wibox = require("wibox")
13 local string = { match = string.match,
14 format = string.format }
15 local setmetatable = setmetatable
19 local alsa = helpers.make_widget_textbox()
21 local function worker(args)
22 local args = args or {}
23 local timeout = args.timeout or 5
24 local settings = args.settings or function() end
26 alsa.cmd = args.cmd or "amixer"
27 alsa.channel = args.channel or "Master"
28 alsa.togglechannel = args.togglechannel
30 if alsa.togglechannel then
31 alsa.cmd = { shell, "-c", string.format("%s get %s; %s get %s",
32 alsa.cmd, alsa.channel, alsa.cmd, alsa.togglechannel) }
37 function alsa.update()
38 helpers.async(alsa.cmd, function(mixer)
39 local l,s = string.match(mixer, "([%d]+)%%.*%[([%l]*)")
40 if alsa.last.level ~= l or alsa.last.status ~= s then
41 volume_now = { level = l, status = s }
44 alsa.last = volume_now
49 timer_id = string.format("alsa-%s-%s", alsa.cmd, alsa.channel)
51 helpers.newtimer(timer_id, timeout, alsa.update)
56 return setmetatable(alsa, { __call = function(_, ...) return worker(...) end })