awesomewm/classes/volume/arc_widget.lua

103 lines
2.2 KiB
Lua
Raw Normal View History

2022-04-23 21:13:35 -07:00
local P = {}
2022-04-24 08:27:47 -07:00
function P:set_value(value)
-- Set widget value. (0 - 100)
self.arc.value = value
if value > 70 then
self.icon.image = beautiful.icons.volume.high
elseif value > 40 then
self.icon.image = beautiful.icons.volume.medium
elseif value > 0 then
self.icon.image = beautiful.icons.volume.low
elseif value == 0 then
self.icon.image = beautiful.icons.volume.off
end
end
function P:set_state(state)
-- Set widget value. (0 - 100)
if (state == "error") then
self.icon.image = beautiful.icons.volume.error
elseif (state == "muted") then
self.icon.image = beautiful.icons.volume.mute
elseif (state == "unmuted") then
return
end
end
function P:set_tooltip(text)
-- Set widget value. (0 - 100)
self.tooltip.text = text
end
function P:new()
2022-04-24 10:12:00 -07:00
local widget = {}
2022-04-24 08:27:47 -07:00
setmetatable(widget, self)
self.__index = self
2022-04-23 21:13:35 -07:00
widget.icon = wibox.widget {
resize = true,
image = beautiful.icons.volume.mute,
widget = wibox.widget.imagebox
}
widget.arc = wibox.widget {
{
widget.icon,
top = beautiful.dpi(1),
bottom = beautiful.dpi(1),
layout = wibox.container.margin,
},
2022-04-24 08:27:47 -07:00
max_value = 100,
2022-04-23 21:13:35 -07:00
thickness = beautiful.dpi(4),
start_angle = 4.71238898, -- 2pi*3/4
--forced_height = beautiful.dpi(16),
--forced_width = beautiful.dpi(16),
colors = {"#27D4CC", "#00446B"},
bg = "#FFFFFF30",
paddings = beautiful.dpi(2),
widget = wibox.container.arcchart
}
widget.widget = wibox.widget {
{
{ -- Right space
widget = wibox.widget.separator,
color = beautiful.color.transparent,
forced_width = beautiful.dpi(3)
},
{
widget.arc,
top = beautiful.dpi(2),
bottom = beautiful.dpi(2),
layout = wibox.container.margin,
},
{ -- Left space
widget = wibox.widget.separator,
color = beautiful.color.transparent,
forced_width = beautiful.dpi(3)
},
layout = wibox.layout.align.horizontal,
},
layout = wibox.container.background,
}
2022-04-24 08:27:47 -07:00
widget.tooltip = awful.tooltip {
objects = { widget.widget },
text = ""
}
2022-04-23 21:13:35 -07:00
widget.widget:connect_signal("mouse::enter", function(result)
widget.widget.bg = beautiful.color.bar.hover_bg
end)
widget.widget:connect_signal("mouse::leave", function(result)
widget.widget.bg = beautiful.color.transparent
end)
return widget
end
return P