My configuration files for Debian/Ubuntu applications
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 
 
 
 

59 lines
1.7 KiB

  1. --[[
  2. Licensed under GNU General Public License v2
  3. * (c) 2016, Luca CPZ
  4. --]]
  5. local helpers = require("lain.helpers")
  6. local shell = require("awful.util").shell
  7. local wibox = require("wibox")
  8. local string = string
  9. local type = type
  10. -- PulseAudio volume
  11. -- lain.widget.pulse
  12. local function factory(args)
  13. args = args or {}
  14. local pulse = { widget = args.widget or wibox.widget.textbox(), device = "N/A" }
  15. local timeout = args.timeout or 5
  16. local settings = args.settings or function() end
  17. pulse.devicetype = args.devicetype or "sink"
  18. pulse.cmd = args.cmd or "pacmd list-" .. pulse.devicetype .. "s | sed -n -e '/*/,$!d' -e '/index/p' -e '/base volume/d' -e '/volume:/p' -e '/muted:/p' -e '/device\\.string/p'"
  19. function pulse.update()
  20. helpers.async({ shell, "-c", type(pulse.cmd) == "string" and pulse.cmd or pulse.cmd() },
  21. function(s)
  22. volume_now = {
  23. index = string.match(s, "index: (%S+)") or "N/A",
  24. device = string.match(s, "device.string = \"(%S+)\"") or "N/A",
  25. muted = string.match(s, "muted: (%S+)") or "N/A"
  26. }
  27. pulse.device = volume_now.index
  28. local ch = 1
  29. volume_now.channel = {}
  30. for v in string.gmatch(s, ":.-(%d+)%%") do
  31. volume_now.channel[ch] = v
  32. ch = ch + 1
  33. end
  34. volume_now.left = volume_now.channel[1] or "N/A"
  35. volume_now.right = volume_now.channel[2] or "N/A"
  36. widget = pulse.widget
  37. settings()
  38. end)
  39. end
  40. helpers.newtimer("pulse", timeout, pulse.update)
  41. return pulse
  42. end
  43. return factory