Reno is the second iteration of the AWMTK-powered AwesomeWM config.
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.

106 lines
3.9 KiB

  1. -- This file is part of Reno desktop.
  2. --
  3. -- Reno desktop is free software: you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version.
  4. --
  5. -- Reno desktop is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details.
  6. --
  7. -- You should have received a copy of the GNU General Public License along with Reno desktop. If not, see <https://www.gnu.org/licenses/>.
  8. -- Pulseaudio per-client volume setting
  9. local awful = require("awful")
  10. local gears = require("gears")
  11. local wibox = require("wibox")
  12. local awmtk2 = require("awmtk2")
  13. local fastyaml = require("parsers").fast_split_yaml
  14. local beautiful = require("beautiful")
  15. local ask = require("asckey")
  16. local pactl_data = {}
  17. local test_pactl = os.execute("pactl --version")
  18. local pactl_found = test_pactl
  19. if _VERSION:match("5.1") then
  20. pactl_found = (test_pactl == 0)
  21. end
  22. local test_amixer = os.execute("amixer --version")
  23. local amixer_found = test_amixer
  24. if _VERSION:match("5.1") then
  25. amixer_found = (test_amixer == 0)
  26. end
  27. if (not (amixer_found or pactl_found)) then
  28. return
  29. end
  30. local try_launch = [[which pavucontrol && pavucontrol || which pulsemixer && ]]..global.terminal..[[ -e pulsemixer || which alsamixer && ]]..global.terminal..[[ -e alsamixer ]]
  31. local function get_icon(percent)
  32. if percent >= 66 then
  33. return beautiful["volume-high-symbolic"]
  34. elseif percent >= 33 then
  35. return beautiful["volume-medium-symbolic"]
  36. elseif percent > 0 then
  37. return beautiful["volume-low-symbolic"]
  38. else
  39. return beautiful["volume-muted-symbolic"]
  40. end
  41. end
  42. return function(args)
  43. local style = awmtk2.create_style("volume",
  44. awmtk2.generic.oneline_widget, args.style)
  45. local templates = awmtk2.create_template_lib("volume",awmtk2.templates,args.templates)
  46. local t = awmtk2.build_templates(templates,style)
  47. local widget = wibox.widget({
  48. t.button({
  49. image = get_icon(0),
  50. id = "volume_icon",
  51. resize = true,
  52. widget = wibox.widget.imagebox
  53. }),
  54. t.container({
  55. t.slider({
  56. minimum = 0,
  57. maximum = 100,
  58. id = "volume",
  59. value = -1
  60. }),
  61. layout = wibox.layout.fixed.horizontal
  62. },{
  63. visible = false,
  64. id = "slidercontainer"
  65. }),
  66. layout = wibox.layout.fixed.horizontal
  67. })
  68. local icon = widget:get_children_by_id("volume_icon")[1]
  69. local slider = widget:get_children_by_id("volume")[1]
  70. local container = widget:get_children_by_id("slidercontainer")[1]
  71. -- Alsa master handle
  72. args.device = args.device or "default"
  73. gears.timer {
  74. autostart = true,
  75. timeout = 0.5,
  76. call_now = true,
  77. callback = function()
  78. awful.spawn.easy_async_with_shell("amixer -D "..args.device.." sget Master",function(stdout)
  79. local volume_percent = stdout:match("%[(%d+)%%%]")
  80. volume_percent = tonumber(volume_percent)
  81. if not volume_percent then
  82. return
  83. end
  84. slider.value = volume_percent
  85. icon.image = get_icon(volume_percent)
  86. end)
  87. end
  88. }
  89. slider:connect_signal("widget::redraw_needed",function()
  90. awful.spawn("amixer -D "..args.device.." sset Master "..slider.value.."%")
  91. icon.image = get_icon(slider.value)
  92. end)
  93. icon:connect_signal("button::press",function(self,lx,ly,button)
  94. if button == 1 then
  95. container.visible = not container.visible
  96. end
  97. if button == 2 then
  98. awful.spawn.with_shell(args.mixer or try_launch)
  99. end
  100. end)
  101. return widget
  102. end