-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcircle.lua
218 lines (186 loc) · 7.09 KB
/
circle.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
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
--
-- Author: James Dyke
-- Date: 2017/05/01
--
require 'cairo'
local FONT, ICON_FONT = "Mono", "StyleBats"
function init_cairo()
if conky_window == nil then
return false
end
cs = cairo_xlib_surface_create(conky_window.display,
conky_window.drawable,
conky_window.visual,
conky_window.width,
conky_window.height)
cr = cairo_create(cs)
cairo_select_font_face(cr, FONT, CAIRO_FONT_SLANT_NORMAL, CAIRO_FONT_WEIGHT_NORMAL)
cairo_set_source_rgba(cr, 0.933, 0.905, 0.894, 1)
return true
end
function conky_main()
if (not init_cairo()) then
return
end
draw_date_and_time()
draw_disk_usage()
draw_cpu_usage()
draw_memory_usage()
end
function draw_date_and_time()
-- Time
cairo_set_font_size(cr, 130)
cairo_move_to(cr, 750, 170)
cairo_show_text(cr, conky_parse("${time %H:%M}"))
cairo_stroke(cr)
-- Date
cairo_set_font_size(cr, 55)
cairo_move_to(cr, 778, 250)
cairo_show_text(cr, conky_parse("${time %Y/%m/%d}"))
cairo_stroke(cr)
end
function draw_disk_usage()
cairo_set_font_size(cr, 18)
cairo_move_to(cr, 25, 380)
cairo_show_text(cr, "DISK USAGE")
cairo_move_to(cr, 25, 385)
cairo_line_to(cr, 170, 385)
cairo_stroke(cr)
cairo_move_to(cr, 40, 510)
cairo_set_font_size(cr, 30)
cairo_show_text(cr, conky_parse("/ at ${fs_used_perc /}%"))
local diskRoot = (tonumber(conky_parse("${exec df -h / | grep -w / | awk '{print $5}' | sed 's/%//g'}")) / 100 * 360)
cairo_stroke(cr)
-- cairo_arc requires radions
local angle2 = diskRoot
local center_x = 110
local center_y = 500
local radius = 85
local start_angle = 0
cairo_set_source_rgba(cr, 1, 0.2, 0.2, 0.6)
cairo_set_line_width(cr, 6.0)
cairo_arc(cr, center_x, center_y, radius, (start_angle - 180) * (math.pi / 180), (angle2 - 180) * (math.pi / 180))
cairo_line_to(cr, center_x, center_y)
cairo_stroke(cr)
cairo_set_source_rgba(cr, 0.933, 0.905, 0.894, 1)
local center_x = 110
local center_y = 500
local radius = 90
local start_angle = 0
cairo_set_line_width(cr, 5.0)
cairo_arc(cr, center_x, center_y, radius, (start_angle - 180) * (math.pi / 180), 180 * (math.pi / 180))
cairo_stroke(cr)
end
function draw_cpu_usage()
local base_x = 645
local base_y = 905
local cpu_count = tonumber(conky_parse("${exec grep -c ^processor /proc/cpuinfo}"))
print("cpu count " .. cpu_count)
if cpu_count > 4 then
cairo_move_to(cr, base_x - 27, base_y + 120)
local cpu = tonumber(conky_parse("${cpu cpu" .. 0 .. "}"))
cairo_show_text(cr, "Average")
cairo_stroke(cr)
cairo_set_source_rgba(cr, 1, 1, 0.2, 0.6)
local angle2 = (cpu / 100) * 360
local center_x = (base_x + 37)
local center_y = 900
local radius = 85
local start_angle = 0
cairo_set_line_width(cr, 6.0)
cairo_arc(cr, center_x, center_y, radius, (start_angle - 180) * (math.pi / 180), (angle2 - 180) * (math.pi / 180))
cairo_line_to(cr, center_x, center_y)
cairo_stroke(cr)
cairo_set_source_rgba(cr, 0.933, 0.905, 0.894, 1)
cairo_set_line_width(cr, 5.0)
cairo_arc(cr, center_x, center_y, radius + 5, (start_angle - 180) * (math.pi / 180), 180 * (math.pi / 180))
cairo_stroke(cr)
cairo_move_to(cr, base_x + 25, base_y)
cairo_show_text(cr, cpu .. "%")
for dx = 1, cpu_count / 2, 1
do
for dy = 1, 2, 1
do
local cpu_num = dx + ((dy - 1) * 4)
print(cpu_num)
cairo_set_font_size(cr, 16)
cairo_move_to(cr, base_x + 42 + (120 * dx), (base_y - 308) + (205 * dy))
local cpu = tonumber(conky_parse("${cpu cpu" .. cpu_num .. "}"))
cairo_show_text(cr, "Cpu" .. cpu_num)
cairo_stroke(cr)
cairo_set_source_rgba(cr, 1, 1, 0.2, 0.6)
local angle2 = (cpu / 100) * 360
local center_x = (base_x + 65) + (120 * dx)
local center_y = (base_y - 155) + (100 * dy)
local radius = 35
local start_angle = 0
cairo_set_line_width(cr, 6.0)
cairo_arc(cr, center_x, center_y, radius, (start_angle - 180) * (math.pi / 180), (angle2 - 180) * (math.pi / 180))
cairo_line_to(cr, center_x, center_y)
cairo_stroke(cr)
cairo_set_source_rgba(cr, 0.933, 0.905, 0.894, 1)
cairo_set_line_width(cr, 5.0)
cairo_arc(cr, center_x, center_y, radius + 5, (start_angle - 180) * (math.pi / 180), 180 * (math.pi / 180))
cairo_stroke(cr)
cairo_move_to(cr, (base_x + 60) + (120 * dx), (base_y - 150) + (100 * dy))
cairo_show_text(cr, cpu .. "%")
end
end
else
for i = 0, 4, 1
do
cairo_move_to(cr, base_x + 5 + (i * 200), base_y + 120)
local cpu = tonumber(conky_parse("${cpu cpu" .. i .. "}"))
cairo_show_text(cr, "Cpu" .. i)
cairo_stroke(cr)
cairo_set_source_rgba(cr, 1, 1, 0.2, 0.6)
local angle2 = (cpu / 100) * 360
local center_x = (base_x + 37) + (i * 200)
local center_y = 900
local radius = 85
local start_angle = 0
cairo_set_line_width(cr, 6.0)
cairo_arc(cr, center_x, center_y, radius, (start_angle - 180) * (math.pi / 180), (angle2 - 180) * (math.pi / 180))
cairo_line_to(cr, center_x, center_y)
cairo_stroke(cr)
cairo_set_source_rgba(cr, 0.933, 0.905, 0.894, 1)
cairo_set_line_width(cr, 5.0)
cairo_arc(cr, center_x, center_y, radius + 5, (start_angle - 180) * (math.pi / 180), 180 * (math.pi / 180))
cairo_stroke(cr)
cairo_move_to(cr, base_x + 20 + (i * 200), base_y)
cairo_show_text(cr, cpu .. "%")
end
end
end
function draw_memory_usage()
cairo_set_font_size(cr, 18)
cairo_move_to(cr, 1735, 380)
cairo_show_text(cr, "MEMORY USAGE")
cairo_set_line_width(cr, 2.0)
cairo_move_to(cr, 1735, 385)
cairo_line_to(cr, 1900, 385)
cairo_stroke(cr)
cairo_move_to(cr, 1785, 510)
cairo_set_font_size(cr, 30)
cairo_show_text(cr, conky_parse("${memperc}%"))
cairo_stroke(cr)
local memusage = (100 - tonumber(conky_parse("${memperc}"))) / 100 * 360
local start_angle = 0 * (math.pi / 180)
local end_angle = memusage * (math.pi / 180)
local radius = 85
local center_y = 500
local center_x = 1810
cairo_set_source_rgba(cr, 1, 0.2, 0.2, 0.6)
cairo_set_line_width(cr, 6.0)
cairo_line_to(cr, center_x, center_y)
cairo_arc(cr, center_x, center_y, radius, end_angle, start_angle)
cairo_stroke(cr)
cairo_set_source_rgba(cr, 0.933, 0.905, 0.894, 1)
local center_x = 1810
local center_y = 500
local radius = 90
local start_angle = 0
cairo_set_line_width(cr, 5.0)
cairo_arc(cr, center_x, center_y, radius, (start_angle - 180) * (math.pi / 180), 180 * (math.pi / 180))
cairo_stroke(cr)
end