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")
13 local string = { match = string.match,
14 format = string.format }
16 local setmetatable = setmetatable
19 -- lain.widgets.pulseaudio
22 local function worker(args)
23 local args = args or {}
24 local timeout = args.timeout or 5
25 local settings = args.settings or function() end
26 local scallback = args.scallback or nil
28 pulseaudio.sink = args.sink or 0 -- user defined or first one
29 pulseaudio.cmd = args.cmd or string.format("pacmd list-sinks | sed -n -e '/base volume/d' -e '/index: %d/p' -e '/volume:/p' -e '/muted:/p' | sed -n -e '/index: %d/,+2p'",
30 pulseaudio.sink, pulseaudio.sink)
31 pulseaudio.widget = wibox.widget.textbox('')
33 function pulseaudio.update()
34 local s = read_pipe(pulseaudio.cmd)
37 volume_now.left = tonumber(string.match(s, "left.-(%d+)%%")) or tonumber(string.match(s, "0:.-(%d+)%%"))
38 volume_now.right = tonumber(string.match(s, "right.-(%d+)%%")) or tonumber(string.match(s, "1:.-(%d+)%%"))
39 volume_now.muted = string.match(s, "muted: (%S+)")
41 if scallback ~= nil then
42 pulseaudio.sink = scallback()
45 widget = pulseaudio.widget
49 newtimer(string.format("pulseaudio-%s", pulseaudio.sink), timeout, pulseaudio.update)
51 return setmetatable(pulseaudio, { __index = pulseaudio.widget })
54 return setmetatable(pulseaudio, { __call = function(_, ...) return worker(...) end })