209 lines
4.2 KiB
Lua
209 lines
4.2 KiB
Lua
local volume = req_rel(..., "util")
|
|
|
|
return function(s)
|
|
local widget = wibox.widget {
|
|
{
|
|
{
|
|
{
|
|
{ -- Icon and margins
|
|
nil,
|
|
{
|
|
nil,
|
|
{
|
|
id = "icon",
|
|
forced_height = beautiful.dpi(100),
|
|
image = beautiful.icons.volume.high,
|
|
widget = wibox.widget.imagebox
|
|
},
|
|
nil,
|
|
expand = "none",
|
|
id = "icon_margin2",
|
|
layout = wibox.layout.align.vertical
|
|
},
|
|
nil,
|
|
id = "icon_margin1",
|
|
expand = "none",
|
|
layout = wibox.layout.align.horizontal
|
|
},
|
|
{ -- Text and percentage
|
|
{
|
|
id = "label",
|
|
text = "Volume",
|
|
align = "left",
|
|
valign = "center",
|
|
widget = wibox.widget.textbox
|
|
},
|
|
nil,
|
|
{
|
|
id = "value",
|
|
text = "0%",
|
|
align = "center",
|
|
valign = "center",
|
|
widget = wibox.widget.textbox
|
|
},
|
|
id = "label_value_layout",
|
|
forced_height = beautiful.dpi(48),
|
|
layout = wibox.layout.align.horizontal,
|
|
},
|
|
{ -- Progress bar
|
|
{
|
|
id = "volume_bar",
|
|
shape = gears.shape.rounded_bar,
|
|
forced_height = beautiful.dpi(10),
|
|
background_color = "#AAAAAA88",
|
|
bar_color = "#ffffff",
|
|
color = "#ffffff",
|
|
bar_shape = gears.shape.rounded_bar,
|
|
max_value = 100,
|
|
widget = wibox.widget.progressbar
|
|
},
|
|
id = "bar_layout",
|
|
forced_height = beautiful.dpi(24),
|
|
widget = wibox.container.place
|
|
},
|
|
id = "icon_bar_layout",
|
|
spacing = beautiful.dpi(0),
|
|
layout = wibox.layout.align.vertical
|
|
},
|
|
id = "popup_layout",
|
|
layout = wibox.layout.align.vertical,
|
|
},
|
|
id = "container",
|
|
left = beautiful.dpi(20),
|
|
right = beautiful.dpi(20),
|
|
top = beautiful.dpi(10),
|
|
bottom = beautiful.dpi(10),
|
|
widget = wibox.container.margin
|
|
},
|
|
bg ="#000000AA",
|
|
widget = wibox.container.background,
|
|
ontop = true,
|
|
visible = true,
|
|
type = "notification",
|
|
forced_height = beautiful.dpi(180),
|
|
forced_width = beautiful.dpi(300),
|
|
offset = beautiful.dpi(5),
|
|
}
|
|
|
|
local popup_container = awful.popup {
|
|
widget = wibox.container.background,
|
|
ontop = true,
|
|
bg = "#00000000",
|
|
stretch = false,
|
|
visible = false,
|
|
screen = s,
|
|
|
|
placement = function(c)
|
|
awful.placement.centered(
|
|
c,
|
|
{
|
|
honor_workarea = true,
|
|
margins = {
|
|
top = beautiful.dpi(200)
|
|
}
|
|
}
|
|
)
|
|
end,
|
|
|
|
-- Only set corner radius here.
|
|
shape = function(cr, width, height)
|
|
gears.shape.rounded_rect(
|
|
cr,
|
|
width,
|
|
height,
|
|
beautiful.dpi(20)
|
|
)
|
|
end
|
|
}
|
|
|
|
popup_container:setup {
|
|
widget,
|
|
layout = wibox.layout.fixed.horizontal
|
|
}
|
|
|
|
|
|
local function update_popup()
|
|
volume.commands:get(function(status)
|
|
|
|
awesome.emit_signal("widget::volume")
|
|
widget.
|
|
container.
|
|
popup_layout.
|
|
icon_bar_layout.
|
|
label_value_layout.
|
|
value:set_text(status.value .. "%")
|
|
|
|
awesome.emit_signal(
|
|
"widget::volume:update",
|
|
status.value
|
|
)
|
|
|
|
local icon
|
|
if status.mute then
|
|
icon = beautiful.icons.volume.mute
|
|
elseif status.value < 1 then
|
|
icon = beautiful.icons.volume.off
|
|
elseif status.value >= 1 and status.value < 34 then
|
|
icon = beautiful.icons.volume.low
|
|
elseif status.value >= 34 and status.value < 67 then
|
|
icon = beautiful.icons.volume.medium
|
|
elseif status.value >= 67 then
|
|
icon = beautiful.icons.volume.high
|
|
end
|
|
|
|
widget.
|
|
container.
|
|
popup_layout.
|
|
icon_bar_layout.
|
|
icon_margin1.
|
|
icon_margin2.
|
|
icon:set_image(icon)
|
|
end)
|
|
end
|
|
|
|
local update_slider = function()
|
|
volume.commands:get(function(status)
|
|
widget.
|
|
container.
|
|
popup_layout.
|
|
icon_bar_layout.
|
|
bar_layout.
|
|
volume_bar:set_value(status.value)
|
|
update_popup()
|
|
end)
|
|
end
|
|
|
|
update_slider()
|
|
|
|
local hide_popup_timer = gears.timer {
|
|
timeout = 1,
|
|
autostart = true,
|
|
callback = function()
|
|
popup_container.visible = false
|
|
end
|
|
}
|
|
|
|
awesome.connect_signal("module::volume_popup:show",
|
|
function()
|
|
update_slider()
|
|
if s == mouse.screen then
|
|
popup_container.visible = true
|
|
end
|
|
|
|
if hide_popup_timer.started then
|
|
hide_popup_timer:again()
|
|
else
|
|
hide_popup_timer:start()
|
|
end
|
|
end
|
|
)
|
|
|
|
popup_container:connect_signal("button::press",
|
|
function()
|
|
popup_container.visible = false
|
|
hide_popup_timer:stop()
|
|
end
|
|
)
|
|
end
|
|
|