2 # Clock Rings by Linux Mint (2012) reEdited by Altin.
4 # https://github.com/altinukshini/conky_blue
6 # This script draws percentage meters as rings, and also draws clock hands if you want!
7 # It is fully customisable; all options are described in the script.
8 # This script is based off a combination of my clock.lua script and my rings.lua script.
10 # IMPORTANT: If you are using the 'cpu' function, it will cause a segmentation fault if it tries to draw a ring straight away.
11 # The if statement on line 324 uses a delay to make sure that this doesn't happen.
12 # It calculates the length of the delay by the number of updates since Conky started.
13 # Generally, a value of 5s is long enough, so if you update Conky every 1s,
14 # use update_num>5 in that if statement (the default).
15 # If you only update Conky every 2s, you should change it to update_num>3;
16 # conversely if you update Conky every 0.5s, you should use update_num>10.
17 # ALSO, if you change your Conky, is it best to use "killall conky; conky" to update it,
18 # otherwise the update_num will not be reset and you will get an error.
20 # To call this script in Conky, use the following in your conkyrc:
22 # lua_load ~/.conky/clock01_rings.lua
23 # lua_draw_hook_pre clock_rings
26 # * v1.0 --> Original release (30.09.2009)
27 # * v1.1p --> Jpope edit londonali1010 (05.10.2009)
28 # * vX 2011mint --> reEdit despot77 (18.02.2011)
29 # * vX 2012 --> Altin reEdit (22.07.2012)
30 # * Added weather function (Accu Weather)
31 # * Added battery monitoring
33 # * Running processes monitoring
35 # * Exctra network functions/monitoring
41 -- Edit this table to customise your rings.
42 -- You can create more rings simply by adding more elements to settings_table.
43 -- "name" is the type of stat to display; you can choose from 'cpu', 'memperc', 'fs_used_perc', 'battery_used_perc'.
45 -- "arg" is the argument to the stat type, e.g. if in Conky you would write ${cpu cpu0}, 'cpu0' would be the argument. If you would not use an argument in the Conky variable, use ''.
47 -- "max" is the maximum value of the ring. If the Conky variable outputs a percentage, use 100.
49 -- "bg_colour" is the colour of the base ring.
51 -- "bg_alpha" is the alpha value of the base ring.
53 -- "fg_colour" is the colour of the indicator part of the ring.
55 -- "fg_alpha" is the alpha value of the indicator part of the ring.
57 -- "x" and "y" are the x and y coordinates of the centre of the ring, relative to the top left corner of the Conky window.
59 -- "radius" is the radius of the ring.
61 -- "thickness" is the thickness of the ring, centred around the radius.
63 -- "start_angle" is the starting angle of the ring, in degrees, clockwise from top. Value can be either positive or negative.
65 -- "end_angle" is the ending angle of the ring, in degrees, clockwise from top. Value can be either positive or negative, but must be larger than start_angle.
70 name='battery_percent',
212 -- Use these settings to define the origin and extent of your clock.
216 -- "clock_x" and "clock_y" are the coordinates of the centre of the clock, in pixels, from the top left of the Conky window.
221 show_seconds=false -- Change to true if you want the seconds hand
225 function rgb_to_r_g_b(colour,alpha)
226 return ((colour / 0x10000) % 0x100) / 255., ((colour / 0x100) % 0x100) / 255., (colour % 0x100) / 255., alpha
229 function window_background(colour,alpha)
230 return ((colour / 0x10000) % 0x100) / 255., ((colour / 0x100) % 0x100) / 255., (colour % 0x100) / 255., alpha
233 function draw_ring(cr,t,pt)
234 local w,h=conky_window.width,conky_window.height
236 local xc,yc,ring_r,ring_w,sa,ea=pt['x'],pt['y'],pt['radius'],pt['thickness'],pt['start_angle'],pt['end_angle']
237 local bgc, bga, fgc, fga=pt['bg_colour'], pt['bg_alpha'], pt['fg_colour'], pt['fg_alpha']
239 local angle_0=sa*(2*math.pi/360)-math.pi/2
240 local angle_f=ea*(2*math.pi/360)-math.pi/2
241 local t_arc=t*(angle_f-angle_0)
243 -- Draw background ring
245 cairo_arc(cr,xc,yc,ring_r,angle_0,angle_f)
246 cairo_set_source_rgba(cr,rgb_to_r_g_b(bgc,bga))
247 cairo_set_line_width(cr,ring_w)
250 -- Draw indicator ring
252 cairo_arc(cr,xc,yc,ring_r,angle_0,angle_0+t_arc)
253 cairo_set_source_rgba(cr,rgb_to_r_g_b(fgc,fga))
257 function draw_clock_hands(cr,xc,yc)
258 local secs,mins,hours,secs_arc,mins_arc,hours_arc
259 local xh,yh,xm,ym,xs,ys
265 secs_arc=(2*math.pi/60)*secs
266 mins_arc=(2*math.pi/60)*mins+secs_arc/60
267 hours_arc=(2*math.pi/12)*hours+mins_arc/12
271 xh=xc+0.76*clock_r*math.sin(hours_arc)
272 yh=yc-0.72*clock_r*math.cos(hours_arc)
273 cairo_move_to(cr,xc,yc)
274 cairo_line_to(cr,xh,yh)
276 cairo_set_line_cap(cr,CAIRO_LINE_CAP_ROUND)
277 cairo_set_line_width(cr,5)
278 cairo_set_source_rgba(cr,1.0,1.0,1.0,1.0)
283 xm=xc+0.98*clock_r*math.sin(mins_arc)
284 ym=yc-1.02*clock_r*math.cos(mins_arc)
285 cairo_move_to(cr,xc,yc)
286 cairo_line_to(cr,xm,ym)
288 cairo_set_line_width(cr,3)
294 xs=xc+1.1*clock_r*math.sin(secs_arc)
295 ys=yc-clock_r*math.cos(secs_arc)
296 cairo_move_to(cr,xc,yc)
297 cairo_line_to(cr,xs,ys)
299 cairo_set_line_width(cr,1)
304 function conky_clock_rings()
305 local function setup_rings(cr,pt)
309 str=string.format('${%s %s}',pt['name'],pt['arg'])
318 -- Check that Conky has been running for at least 5s
320 if conky_window==nil then return end
321 local cs=cairo_xlib_surface_create(conky_window.display,conky_window.drawable,conky_window.visual, conky_window.width,conky_window.height)
323 local cr=cairo_create(cs)
325 local updates=conky_parse('${updates}')
326 update_num=tonumber(updates)
329 for i in pairs(settings_table) do
330 setup_rings(cr,settings_table[i])
334 draw_clock_hands(cr,clock_x,clock_y)