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