local qmath = require "quarrel.math" local qvars = require "quarrel.vars" local wibox = require "wibox" local battery_bar = wibox.widget { widget = wibox.container.place, forced_height = qvars.char_height, { { widget = wibox.container.constraint, width = qvars.char_width * 4, strategy = "exact", { 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.red, } }, id = "bar" }, layout = wibox.layout.align.horizontal, -- expand = "outside" } } awesome.connect_signal("services::battery", function(capacity) local color = qmath.step_value(capacity, { { 0, "red" }, { 20, "red" }, { 40, "yellow" }, { 60, "green" }, { 80, "green" }, { 100 } }) battery_bar.widget.bar.widget.widget.color = qvars.colors[color] battery_bar.widget.bar.widget.widget.value = capacity battery_bar.widget.text.widget.text = capacity .. "%" end) return battery_bar