- 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 == "yes"
- then
- pulsebar._muted = true
- pulsebar.tooltip:set_text (" [Muted] ")
- pulsebar.bar:set_color(pulsebar.colors.mute)
+
+ 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
+ end
+ end)
+ end
+
+ function pulsebar.notify()
+ pulsebar.update(function()
+ local preset = pulsebar.notification_preset
+
+ if pulsebar._muted then
+ preset.title = string.format("Sink %s - Muted", pulsebar.sink)
+ else
+ preset.title = string.format("%s - %s%%", pulsebar.sink, pulsebar._current_level)
+ end
+
+ int = math.modf((pulsebar._current_level / 100) * awful.screen.focused().mywibox.height)
+ preset.text = string.format("[%s%s]", string.rep("|", int),
+ string.rep(" ", awful.screen.focused().mywibox.height - int))
+
+ if pulsebar.followtag then preset.screen = awful.screen.focused() end
+
+ if not pulsebar.notification then
+ pulsebar.notification = naughty.notify {
+ preset = preset,
+ destroy = function() pulsebar.notification = nil end
+ }