- local s = read_pipe(pulsebar.cmd)
-
- volume_now = {}
- volume_now.left = tonumber(string.match(s, ":.-(%d+)%%"))
- volume_now.right = tonumber(string.match(s, ":.-(%d+)%%"))
- volume_now.muted = string.match(s, "muted: (%S+)")
-
- local volu = volume_now.left
- local mute = volume_now.muted
-
- if (volu and volu ~= pulsebar._current_level) or (mute and mute ~= pulsebar._muted)
- then
- pulsebar._current_level = volu
- pulsebar.bar:set_value(pulsebar._current_level / 100)
- if not mute and volu == 0 or mute == "no"
- then
- pulsebar._muted = true
- pulsebar.tooltip:set_text (" [Muted] ")
- pulsebar.bar:set_color(pulsebar.colors.mute)
- else
- pulsebar._muted = false
- pulsebar.tooltip:set_text(string.format(" %s:%s ", pulsebar.sink, volu))
- pulsebar.bar:set_color(pulsebar.colors.unmute)
+
+ helpers.async({ awful.util.shell, "-c", pulsebar.cmd }, function(s)
+ volume_now = {
+ index = string.match(s, "index: (%S+)") or "N/A",
+ sink = string.match(s, "device.string = \"(%S+)\"") or "N/A",
+ muted = string.match(s, "muted: (%S+)") or "N/A"
+ }
+
+ local ch = 1
+ volume_now.channel = {}
+ for v in string.gmatch(s, ":.-(%d+)%%") do
+ volume_now.channel[ch] = v
+ ch = ch + 1
+ end
+
+ volume_now.left = volume_now.channel[1] or "N/A"
+ volume_now.right = volume_now.channel[2] or "N/A"
+
+ local volu = volume_now.left
+ local mute = volume_now.muted
+
+ if (volu and volu ~= pulsebar._current_level) or (mute and mute ~= pulsebar._muted) then
+ pulsebar._current_level = volu
+ pulsebar.bar:set_value(pulsebar._current_level / 100)
+ if (not mute and volu == 0) or mute == "yes" then
+ pulsebar._muted = true
+ pulsebar.tooltip:set_text ("[Muted]")
+ pulsebar.bar.color = pulsebar.colors.mute
+ else
+ pulsebar._muted = false
+ pulsebar.tooltip:set_text(string.format("%s: %s", pulsebar.sink, volu))
+ pulsebar.bar.color = pulsebar.colors.unmute
+ end
+
+ settings()
+
+ if type(callback) == "function" then callback() end