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) 2016, Luke Bonham
9 local read_pipe = require("lain.helpers").read_pipe
10 local newtimer = require("lain.helpers").newtimer
11 local wibox = require("wibox")
12 local string = { gmatch = string.gmatch,
14 format = string.format }
15 local setmetatable = setmetatable
18 -- lain.widgets.pulseaudio
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
25 local scallback = args.scallback
27 pulseaudio.cmd = args.cmd or string.format("pacmd list-sinks | sed -n -e '0,/*/d' -e '/base volume/d' -e '/volume:/p' -e '/muted:/p' -e '/device\\.string/p'")
28 pulseaudio.widget = wibox.widget.textbox()
30 function pulseaudio.update()
31 if scallback then pulseaudio.cmd = scallback() end
32 local s = read_pipe(pulseaudio.cmd)
35 volume_now.index = string.match(s, "index: (%S+)") or "N/A"
36 volume_now.sink = string.match(s, "device.string = \"(%S+)\"") or "N/A"
37 volume_now.muted = string.match(s, "muted: (%S+)") or "N/A"
40 volume_now.channel = {}
41 for v in string.gmatch(s, ":.-(%d+)%%") do
42 volume_now.channel[ch] = v
46 volume_now.left = volume_now.channel[1] or "N/A"
47 volume_now.right = volume_now.channel[2] or "N/A"
49 widget = pulseaudio.widget
53 newtimer(string.format("pulseaudio-%s", timeout), timeout, pulseaudio.update)
55 return setmetatable(pulseaudio, { __index = pulseaudio.widget })
58 return setmetatable(pulseaudio, { __call = function(_, ...) return worker(...) end })