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
12 local wibox = require("wibox")
14 local io = { popen = io.popen }
15 local string = { match = string.match,
16 format = string.format }
18 local setmetatable = setmetatable
24 local function worker(args)
25 local args = args or {}
26 local card = args.card or "0"
27 local timeout = args.timeout or 5
28 local channel = args.channel or "Master"
29 local settings = args.settings or function() end
31 alsa.widget = wibox.widget.textbox('')
33 function alsa.update()
34 local f = assert(io.popen(string.format("amixer -c %s -M get %s", card, channel)))
35 local mixer = f:read("*a")
40 volume_now.level, volume_now.status = string.match(mixer, "([%d]+)%%.*%[([%l]*)")
42 if volume_now.level == nil
44 volume_now.level = "0"
45 volume_now.status = "off"
48 if volume_now.status == ""
50 if volume_now.level == "0"
52 volume_now.status = "off"
54 volume_now.status = "on"
62 newtimer("alsa", timeout, alsa.update)
64 return setmetatable(alsa, { __index = alsa.widget })
67 return setmetatable(alsa, { __call = function(_, ...) return worker(...) end })