114 lines
2.5 KiB
Lua
114 lines
2.5 KiB
Lua
local P = {}
|
|
|
|
function P:set_value(value)
|
|
-- Set widget value. (0 - 100)
|
|
self.progressbar.value = value
|
|
|
|
if value > 60 then
|
|
self.progressbar.color = beautiful.color.battery.good
|
|
elseif value > 40 then
|
|
self.progressbar.color = beautiful.color.battery.low
|
|
elseif value <= 40 then
|
|
self.progressbar.color = beautiful.color.battery.danger
|
|
end
|
|
|
|
if (self.state == "discharging") then
|
|
self.rotator.direction = "east"
|
|
else
|
|
self.rotator.direction = "west"
|
|
end
|
|
|
|
if (self.state == "charging") and (value > 90) then
|
|
self.progressbar.border_color = beautiful.color.battery.good
|
|
elseif (self.state == "discharging") and (value <= 25) then
|
|
self.progressbar.border_color = beautiful.color.battery.danger
|
|
else
|
|
self.progressbar.border_color = beautiful.color.bar.active
|
|
end
|
|
|
|
end
|
|
|
|
function P:set_state(state)
|
|
if (state == "discharging") then
|
|
self.state = "discharging"
|
|
elseif (state == "charging") then
|
|
self.state = "charging"
|
|
elseif (state == "error") then
|
|
self.state = "error"
|
|
else
|
|
error("Invalid state " .. state)
|
|
end
|
|
end
|
|
|
|
function P:set_tooltip(text)
|
|
-- Set widget value. (0 - 100)
|
|
self.tooltip.text = text
|
|
end
|
|
|
|
function P:new()
|
|
local widget = {
|
|
state = "error"
|
|
}
|
|
setmetatable(widget, self)
|
|
self.__index = self
|
|
|
|
widget.progressbar = wibox.widget {
|
|
max_value = 100,
|
|
widget = wibox.widget.progressbar,
|
|
paddings = beautiful.dpi(2),
|
|
color = beautiful.color.bar.active,
|
|
background_color = beautiful.color.transparent,
|
|
border_color = beautiful.color.bar.active,
|
|
border_width = beautiful.dpi(1),
|
|
margins = beautiful.dpi(3)
|
|
}
|
|
|
|
widget.rotator = wibox.widget {
|
|
widget.progressbar,
|
|
forced_width = beautiful.dpi(15),
|
|
direction = "east",
|
|
layout = wibox.container.rotate,
|
|
}
|
|
|
|
widget.widget = wibox.widget {
|
|
{
|
|
{ -- Right space
|
|
widget = wibox.widget.separator,
|
|
color = beautiful.color.transparent,
|
|
forced_width = beautiful.dpi(3)
|
|
},
|
|
{
|
|
widget.rotator,
|
|
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,
|
|
}
|
|
|
|
widget.tooltip = awful.tooltip {
|
|
objects = { widget.widget },
|
|
text = ""
|
|
}
|
|
|
|
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
|