]> git.rmz.io Git - dotfiles.git/blob - awesome/widgets/battery_widget.lua
lazyvim: delete noice
[dotfiles.git] / awesome / widgets / battery_widget.lua
1 local wibox = require("wibox")
2 local vicious = require("vicious")
3 local naughty = require("naughty")
4 local beautiful = require("beautiful")
5 local pairs = pairs
6
7 -- Battery (based on https://bitbucket.org/skrattaren/awesome/src/)
8
9 local limits = { {25, 5},
10 {12, 3},
11 { 7, 1},
12 {0}}
13
14 local function getnextlim (num)
15 for ind, pair in pairs(limits) do
16 lim = pair[1]; step = pair[2]; nextlim = limits[ind+1][1] or 0
17 if num > nextlim then
18 repeat
19 lim = lim - step
20 until num > lim
21 if lim < nextlim then
22 lim = nextlim
23 end
24 return lim
25 end
26 end
27 end
28
29 local function batclosure ()
30 local nextlim = limits[1][1]
31 return function (_, args)
32 local state, charge = args[1], args[2]
33 if not charge then return end
34 if state == "-" then
35 dirsign = "↓"
36 if charge <= nextlim then
37 naughty.notify({title = "⚡ Warning! ⚡",
38 text = "Battery has leaked most of its power ( ⚡ "..charge.."%)!",
39 timeout = 7,
40 position = "top_right",
41 fg = beautiful.fg_focus,
42 bg = beautiful.bg_focus
43 })
44 nextlim = getnextlim(charge)
45 end
46 elseif state == "+" then
47 dirsign = "↑"
48 nextlim = limits[1][1]
49 else
50 return " ⚡ "
51 end
52 if dir ~= 0 then charge = charge.."%" end
53 return " "..dirsign..charge..dirsign.." "
54 end
55 end
56
57 batterywidget = wibox.widget.textbox()
58 vicious.register(batterywidget, vicious.widgets.bat, batclosure(), 5, "BAT0")
59
60 return batterywidget