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.

108 lines
4.0 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 beautiful = require("beautiful")
  14. local ask = require("asckey")
  15. local test_pactl = os.execute("pactl --version")
  16. local pactl_found = test_pactl
  17. if _VERSION:match("5.1") then
  18. pactl_found = (test_pactl == 0)
  19. end
  20. local test_amixer = os.execute("amixer --version")
  21. local amixer_found = test_amixer
  22. if _VERSION:match("5.1") then
  23. amixer_found = (test_amixer == 0)
  24. end
  25. if (not (amixer_found or pactl_found)) then
  26. return
  27. end
  28. local try_launch = [[which pavucontrol && pavucontrol || which pulsemixer && ]]..global.terminal..[[ -e pulsemixer || which alsamixer && ]]..global.terminal..[[ -e alsamixer ]]
  29. local function get_icon(percent)
  30. if percent >= 66 then
  31. return beautiful["volume-high-symbolic"]
  32. elseif percent >= 33 then
  33. return beautiful["volume-medium-symbolic"]
  34. elseif percent > 0 then
  35. return beautiful["volume-low-symbolic"]
  36. else
  37. return beautiful["volume-muted-symbolic"]
  38. end
  39. end
  40. return function(args)
  41. local style = awmtk2.create_style("volume",
  42. awmtk2.generic.oneline_widget, args.style)
  43. local templates = awmtk2.create_template_lib("volume",awmtk2.templates,args.templates)
  44. local t = awmtk2.build_templates(templates,style,args.vertical)
  45. local widget = wibox.widget({
  46. t.button(t.icon({
  47. image = get_icon(0),
  48. id = "volume_icon",
  49. resize = true,
  50. })),
  51. t.container({
  52. t.slider({
  53. minimum = 0,
  54. maximum = 100,
  55. id = "volume",
  56. value = -1
  57. }),
  58. layout = (args.vertical and wibox.layout.fixed.vertical) or
  59. wibox.layout.fixed.horizontal
  60. },{
  61. visible = false,
  62. id = "slidercontainer"
  63. }),
  64. t.textbox({
  65. markup = "nassal"
  66. }),
  67. layout = (args.veritcal and wibox.layout.fixed.vertical) or
  68. wibox.layout.fixed.horizontal
  69. })
  70. local icon = widget:get_children_by_id("volume_icon")[1]
  71. local slider = widget:get_children_by_id("volume")[1]
  72. local container = widget:get_children_by_id("slidercontainer")[1]
  73. -- Alsa master handle
  74. args.device = args.device or "default"
  75. gears.timer {
  76. autostart = true,
  77. timeout = 0.5,
  78. call_now = true,
  79. callback = function()
  80. awful.spawn.easy_async_with_shell("amixer -D "..args.device.." sget Master",function(stdout)
  81. local volume_percent = stdout:match("%[(%d+)%%%]")
  82. volume_percent = tonumber(volume_percent)
  83. if not volume_percent then
  84. return
  85. end
  86. slider.value = volume_percent
  87. icon.image = get_icon(volume_percent)
  88. end)
  89. end
  90. }
  91. slider:connect_signal("widget::redraw_needed",function()
  92. awful.spawn("amixer -D "..args.device.." sset Master "..slider.value.."%")
  93. icon.image = get_icon(slider.value)
  94. end)
  95. icon:connect_signal("button::press",function(self,lx,ly,button)
  96. if button == 1 then
  97. container.visible = not container.visible
  98. end
  99. if button == 2 then
  100. awful.spawn.with_shell(args.mixer or try_launch)
  101. end
  102. end)
  103. return widget
  104. end