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.
3 Licensed under GNU General Public License v2
4 * (c) 2016, Luke Bonham
8 local helpers = require("lain.helpers")
9 local shell = require("awful.util").shell
10 local wibox = require("wibox")
11 local string = { gmatch = string.gmatch,
13 format = string.format }
16 -- lain.widget.pulseaudio
18 local function factory(args)
19 local pulseaudio = { widget = wibox.widget.textbox() }
20 local args = args or {}
21 local timeout = args.timeout or 5
22 local settings = args.settings or function() end
23 local scallback = args.scallback
25 pulseaudio.device = "N/A"
26 pulseaudio.devicetype = args.devicetype or "sink"
27 pulseaudio.cmd = args.cmd or "pacmd list-" .. pulseaudio.devicetype .. "s | sed -n -e '/*/,$!d' -e '/index/p' -e '/base volume/d' -e '/volume:/p' -e '/muted:/p' -e '/device\\.string/p'"
29 function pulseaudio.update()
30 if scallback then pulseaudio.cmd = scallback() end
32 helpers.async({ shell, "-c", pulseaudio.cmd }, function(s)
34 index = string.match(s, "index: (%S+)") or "N/A",
35 device = string.match(s, "device.string = \"(%S+)\"") or "N/A",
36 sink = device, -- legacy API
37 muted = string.match(s, "muted: (%S+)") or "N/A"
40 pulseaudio.device = volume_now.index
43 volume_now.channel = {}
44 for v in string.gmatch(s, ":.-(%d+)%%") do
45 volume_now.channel[ch] = v
49 volume_now.left = volume_now.channel[1] or "N/A"
50 volume_now.right = volume_now.channel[2] or "N/A"
52 widget = pulseaudio.widget
58 helpers.newtimer("pulseaudio", timeout, pulseaudio.update)