aboutsummaryrefslogtreecommitdiff
path: root/.config/awesome/ui/statusbar/widgets/battery.lua
blob: f220ff18c68d9987528fc7178307fe6177692a33 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
local gcolor = require "gears.color"
local phosphor = require "assets.phosphor"
local qmath = require "quarrel.math"
local qvars = require "quarrel.vars"
local wibox = require "wibox"

local battery = wibox.widget {
    widget = wibox.container.place,
    valign = "center",
    halign = "center",
    {
        widget = wibox.widget.imagebox,
        image = gcolor.recolor_image(phosphor.battery_vertical_warning_fill, qvars.colors.red),
        forced_width = qvars.char_height,
        forced_height = qvars.char_height
    }
}

awesome.connect_signal("services::battery", function(capacity, status)
    local icon_data = status == "Charging" and { "charging", "green" } or qmath.step_value(capacity, {
        { 0, { "empty", "red" } },
        { 20, { "low", "red" } },
        { 40, { "medium", "yellow" } },
        { 60, { "high", "green" } },
        { 80, { "full", "green" } },
        { 100 }
    })

    battery.widget.image = gcolor.recolor_image(phosphor["battery_vertical_" .. icon_data[1] .. "_fill"], qvars.colors[icon_data[2]])
end)

return battery