aboutsummaryrefslogtreecommitdiff
path: root/.config/awesome/ui/statusbar/panel/widgets/brightness_bar.lua
blob: 7d3e5f0980fc257f1a1967568d0cfdc6982ae942 (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
33
34
35
36
37
38
39
40
41
42
43
44
45
46
local qmath = require "quarrel.math"
local qvars = require "quarrel.vars"
local wibox = require "wibox"

local brightness_bar = wibox.widget {
    widget = wibox.container.place,
    forced_height = qvars.char_height,
    {
        {
            widget = wibox.widget.textbox,
            text = "0%",
            id = "text"
        },
        nil,
        {
            widget = wibox.container.margin,
            margins = {
                left = qvars.padding
            },
            {
                widget = wibox.container.place,
                {
                    widget = wibox.widget.progressbar,
                    max_value = 100,
                    value = 0,
                    forced_height = qvars.char_height / 4,
                    shape = qvars.shape,
                    background_color = qvars.colors.black,
                    color = qvars.colors.fg,
                }
            },
            id = "bar"
        },
        layout = wibox.layout.align.horizontal,
    }
}

awesome.connect_signal("services::brightness", function(brightness)
    brightness = math.floor(qmath.translate_range(brightness, 0, 255, 0, 100))

    brightness_bar.widget.bar.widget.widget.value = brightness

    brightness_bar.widget.text.text = brightness .. "%"
end)

return brightness_bar