awesomewm/modules/volume/widget.lua

73 lines
1.6 KiB
Lua
Executable File

local volume = req_rel(..., "util")
local widget = {}
local dotgrid = require("widgets.dotgrid")
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)
widget.widget = wibox.widget {
{
widget.dots,
top = beautiful.dpi(2),
bottom = beautiful.dpi(2),
left = beautiful.dpi(2),
right = beautiful.dpi(2),
layout = wibox.container.margin,
},
layout = wibox.container.background,
}
widget.widget:connect_signal("mouse::enter", function(result)
widget.widget.bg = beautiful.color.bar.hover_bg
awesome.emit_signal("module::volume:popup_show_stay")
end)
widget.widget:connect_signal("mouse::leave", function(result)
widget.widget.bg = beautiful.color.transparent
awesome.emit_signal("module::volume:popup_show")
end)
widget.widget:connect_signal("button::press",
function(_, _, _, button, mods)
-- Left-click
if (button == 1) then
volume.toggle_mute()
-- Scroll up
elseif (button == 4) then
volume.volume_up(config.volume.scroll_step)
-- Scroll down
elseif (button == 5) then
volume.volume_down(config.volume.scroll_step)
end
awesome.emit_signal("module::volume:popup_show_stay")
end
)
awesome.connect_signal("module::volume:update",
function(status)
if (status.value == false) then
widget.dots.value = 100
return
end
widget.dots.value = status.value
if (status.mute) then
widget.dots.on_color = {0.7, 0.7, 0.7}
widget.dots.off_color = {0.3, 0.3, 0.3}
else
widget.dots.on_color = {0, 1, 0}
widget.dots.off_color = {0, 0.5, 0}
end
widget.dots:emit_signal("widget::redraw_needed")
end
)
return widget