-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathbattery.lua
50 lines (37 loc) · 1.12 KB
/
battery.lua
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
47
48
49
50
require 'cairo'
require './_main'
function conky_main ()
if conky_window == nil then
return
end
local surface = cairo_xlib_surface_create(
conky_window.display,
conky_window.drawable,
conky_window.visual,
conky_window.width,
conky_window.height)
draw_bg_triangle(conky_window, surface)
offset = 10
percentage = conky_parse('$battery_percent')
top = 90
left = offset
right = conky_window.width - 11 * offset + 4
bottom = conky_window.height - 3 * offset + 4
local canvas = cairo_create(surface)
cairo_set_source_rgba(canvas, el_red, el_green, el_blue, el_alpha)
cairo_move_to(canvas, left, top)
cairo_line_to(canvas, right, top)
cairo_line_to(canvas, left, bottom)
cairo_line_to(canvas, left, top)
cairo_stroke(canvas)
top_p = map_range(0, 100, bottom, top, percentage)
right_p = map_range(0, 100, offset, right, percentage)
cairo_move_to(canvas, left, top_p)
cairo_line_to(canvas, right_p, top_p)
cairo_line_to(canvas, left, bottom)
cairo_line_to(canvas, left, top_p)
cairo_fill(canvas)
end
function conky_format_battery ()
for word in conky_parse('$battery'):gmatch("%w+") do return word end
end