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 local format_cmd = string.format("%s get %s", alsa.cmd, alsa.channel)
32 if alsa.togglechannel then
33 format_cmd = { shell, "-c", string.format("%s get %s; %s get %s",
34 alsa.cmd, alsa.channel, alsa.cmd, alsa.togglechannel) }
39 function alsa.update()
40 helpers.async(format_cmd, function(mixer)
41 local l,s = string.match(mixer, "([%d]+)%%.*%[([%l]*)")
42 if alsa.last.level ~= l or alsa.last.status ~= s then
43 volume_now = { level = l, status = s }
46 alsa.last = volume_now
51 helpers.newtimer(string.format("alsa-%s-%s", alsa.cmd, alsa.channel), timeout, alsa.update)
56 return setmetatable(alsa, { __call = function(_, ...) return worker(...) end })