Advertisement
constantin-net

volume indicator pulseaudio

Jul 10th, 2019
185
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 2.13 KB | None | 0 0
  1. -- Volume indicator pa
  2. volumecfg = {}
  3. volumecfg.sink = " alsa_output.pci-0000_00_1b.0.analog-stereo"
  4. volumecfg.widget = widget( { type = "textbox", name = "volumecfg.widget", align = "right" } )
  5. volumecfg.mixercommand = function (command)
  6.     closeLastNoti()
  7.     local fd = io.popen(command .. " && pacmd dump |grep -e set-sink-volume -e set-sink-mute")
  8.     local status = fd:read("*all")
  9.     fd:close()
  10.     local volume = string.match(status, "(0x%x%x%x?%x)")
  11.     volume_f = tonumber(string.format("%04x", volume),"16")
  12.     volume = math.ceil(volume_f/655)
  13.     if string.find(status, " no", 1, true) then
  14.         volume = "<span color='#4E99E6'>♫</span>" .. volume .. "% "
  15.     else
  16.         volume = "♩" .. volume .. "m"
  17.     end
  18.     volumecfg.widget.text = volume
  19.     naughty.notify({font = "Droid Sans 36", position = "bottom_right", screen = screen.count(),  border_width = 0, timeout = 2, hover_timeout = 1, title = "Громкость", text = volumecfg.widget.text })
  20. end
  21. volumecfg.update = function ()
  22.     volumecfg.mixercommand("pactl set-sink-volume " .. volumecfg.sink .. " +0")
  23. end
  24. volumecfg.up = function ()
  25.     local add_volume = " +1000"
  26.     if (volume_f+1000)> 65535 then add_volume = " 65500" end
  27.     volumecfg.mixercommand("pactl set-sink-volume " .. volumecfg.sink .. add_volume)
  28. end
  29. volumecfg.down = function ()
  30.     volumecfg.mixercommand("pactl set-sink-volume " .. volumecfg.sink .. " -1000")
  31. end
  32. volumecfg.toggle = function ()
  33.     volumecfg.mixercommand("pactl set-sink-mute " .. volumecfg.sink .. " toggle")
  34. end
  35.  
  36. volumecfg.widget:buttons(awful.util.table.join(
  37.     awful.button({ }, 4, function () volumecfg.up() end),
  38.     awful.button({ }, 5, function () volumecfg.down() end),
  39.     awful.button({ }, 3, function () awful.util.spawn("/usr/bin/pavucontrol") end),
  40.     awful.button({ }, 1, function () volumecfg.toggle() end)
  41. ))
  42. volumecfg.update()
  43.  
  44. volumecfg.widget.border_width = 0
  45. --volumecfg.widget.width = 80
  46. volumecfg.widget.border_color = beautiful.fg_focus
  47. --volumecfg_t = awful.tooltip({ objects = { volumecfg.widget },})
  48. --volumecfg_t:set_text( "Громкость" )
  49. --volumecfg_t.border_width = 0
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement