awesomewm/modules/volume/widget.lua

73 lines
1.6 KiB
Lua
Raw Normal View History

2022-07-16 15:44:14 -07:00
local volume = req_rel(..., "util")
2021-08-01 07:24:26 -07:00
local widget = {}
2023-08-26 17:34:37 -07:00
local dotgrid = require("widgets.dotgrid")
2021-08-01 07:24:26 -07:00
2023-08-26 17:34:37 -07:00
widget.dots = dotgrid:new();
widget.dots.on_color = {1, 0, 0}
widget.dots.off_color = {0.5, 0, 0}
widget.dots.spacing = beautiful.dpi(2)
2021-08-01 07:24:26 -07:00
widget.widget = wibox.widget {
{
2023-08-26 17:34:37 -07:00
widget.dots,
top = beautiful.dpi(2),
bottom = beautiful.dpi(2),
left = beautiful.dpi(2),
right = beautiful.dpi(2),
layout = wibox.container.margin,
2021-08-01 07:24:26 -07:00
},
layout = wibox.container.background,
}
widget.widget:connect_signal("mouse::enter", function(result)
widget.widget.bg = beautiful.color.bar.hover_bg
2023-09-03 09:27:26 -07:00
--awesome.emit_signal("module::volume:popup_show_stay")
2021-08-01 07:24:26 -07:00
end)
widget.widget:connect_signal("mouse::leave", function(result)
widget.widget.bg = beautiful.color.transparent
2023-09-03 09:27:26 -07:00
--awesome.emit_signal("module::volume:popup_show")
2021-08-01 07:24:26 -07:00
end)
widget.widget:connect_signal("button::press",
function(_, _, _, button, mods)
2022-11-05 11:31:12 -07:00
-- Left-click
if (button == 1) then
2022-07-16 15:44:14 -07:00
volume.toggle_mute()
2021-08-01 07:24:26 -07:00
-- Scroll up
elseif (button == 4) then
2022-11-05 09:54:25 -07:00
volume.volume_up(config.volume.scroll_step)
2021-08-01 07:24:26 -07:00
-- Scroll down
elseif (button == 5) then
2022-11-05 09:54:25 -07:00
volume.volume_down(config.volume.scroll_step)
2021-08-01 07:24:26 -07:00
end
2023-09-03 09:27:26 -07:00
--awesome.emit_signal("module::volume:popup_show_stay")
2021-08-01 07:24:26 -07:00
end
)
2022-11-05 09:47:15 -07:00
awesome.connect_signal("module::volume:update",
function(status)
if (status.value == false) then
2023-08-26 17:34:37 -07:00
widget.dots.value = 100
2022-11-05 09:47:15 -07:00
return
end
2021-08-01 07:24:26 -07:00
2023-08-26 17:34:37 -07:00
widget.dots.value = status.value
2022-11-05 09:47:15 -07:00
if (status.mute) then
2023-08-26 17:34:37 -07:00
widget.dots.on_color = {0.7, 0.7, 0.7}
widget.dots.off_color = {0.3, 0.3, 0.3}
2022-11-05 09:47:15 -07:00
else
2023-08-26 17:34:37 -07:00
widget.dots.on_color = {0, 1, 0}
widget.dots.off_color = {0, 0.5, 0}
2021-08-01 07:24:26 -07:00
end
2023-08-26 17:34:37 -07:00
widget.dots:emit_signal("widget::redraw_needed")
2021-08-01 07:24:26 -07:00
end
)
2022-07-16 15:44:14 -07:00
return widget