--[[ Ring Meters by londonali1010 (2009) This script draws percentage meters as rings. It is fully customisable; all options are described in the script. IMPORTANT: if you are using the 'cpu' function, it will cause a segmentation fault if it tries to draw a ring straight away. The if statement on line 145 uses a delay to make sure that this doesn t happen. It calculates the length of the delay by the number of updates since Conky started. Generally, a value of 5s is long enough, so if you update Conky every 1s, use update_num > 5 in that if statement (the default). If you only update Conky every 2s, you should change it to update_num > 3; conversely if you update Conky every 0.5s, you should use update_num > 10. ALSO, if you change your Conky, is it best to use "killall conky; conky" to update it, otherwise the update_num will not be reset and you will get an error. To call this script in Conky, use the following (assuming that you save this script to ~/scripts/rings.lua): lua_load ~/scripts/rings-v1.2.1.lua lua_draw_hook_pre ring_stats Changelog: + v1.2.1 -- Fixed minor bug that caused script to crash if conky_parse() -- returns a nil value (20.10.2009) + v1.2 -- Added option for the ending angle of the rings (07.10.2009) + v1.1 -- Added options for the starting angle of the rings, and added -- the "max" variable, to allow for variables that output a -- numerical value rather than a percentage (29.09.2009) + v1.0 -- Original release (28.09.2009) ]] conky_background_color = 0x151515 conky_background_alpha = 0 unique_color = 0xFFFFFF --~ unique_color = 0x000000 ring_background_color = unique_color ring_background_alpha = 0.2 ring_foreground_color = unique_color ring_foreground_alpha = 0.7 text_color = unique_color text_alpha = 0.7 ring_threshold1_color = 0xc20040 ring_threshold2_color = 0xff0000 ring_foreground_color3 = 0xff0000 rad1 = 25 rad2 = 35 ystart = 125 yoff = 96 conky_width = 160 --conky_width = conky_window.width device_fonts = 'Tidy Hand' device_fonts = 'Arial' device_fonts = 'Hand of Sean' device_fonts = 'Prototype' device_fonts = 'Ubuntu' --device_fonts = 'Virgo 01' --device_fonts = 'Rabiohead' --device_fonts = 'Note this' --device_fonts = 'HighlandGothicFLF' --device_fonts = 'Hand of Sean' --device_fonts = 'Golden Girdle' --device_fonts = 'Denne Kitten Heels' --device_fonts = 'Terminus' device_font_size = 13 settings_table = { --[[ { -- Edit this table to customise your rings. -- You can create more rings simply by adding more elements to settings_table. -- "name" is the type of stat to display; you can choose from 'cpu', -- 'memperc', 'fs_used_perc', 'battery_used_perc'. name='time', -- "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 ''. arg='%I.%M', -- "max" is the maximum value of the ring. If the Conky variable outputs a -- percentage, use 100. max=12, -- "bg_colour" is the colour of the base ring. bg_colour=0xffffff, -- "bg_alpha" is the alpha value of the base ring. bg_alpha=0.1, -- "fg_colour" is the colour of the indicator part of the ring. fg_colour=0xffffff, -- "fg_alpha" is the alpha value of the indicator part of the ring. fg_alpha=0.2, -- "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. x=165, y=170, -- "radius" is the radius of the ring. radius=50, -- "thickness" is the thickness of the ring, centred around the radius. thickness=5, -- "start_angle" is the starting angle of the ring, in degrees, clockwise -- from top. Value can be either positive or negative. start_angle=0, -- "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 (e.g. -- more clockwise) than start_angle. end_angle=360 },]] --[[{ type='conky', id='cpu1', name='cpu', arg='cpu1', max=100, offset=0, bg_colour=ring_background_color, bg_alpha=ring_background_alpha, fg_colour=ring_foreground_color, fg_alpha=ring_foreground_alpha, x=conky_width, y=ystart, radius=rad1, thickness=9, threshold1 = 85, threshold2 = 95, start_angle=180, end_angle=360 },]] { type='conky', id='CPU', name='cpu', arg='cpu0', max=100, offset=0, units='%', bg_colour=ring_background_color, bg_alpha=ring_background_alpha, fg_colour=ring_foreground_color, fg_alpha=ring_foreground_alpha, x=conky_width, y=ystart, radius=rad1, thickness=21, threshold1 = 85, threshold2 = 95, start_angle=180, end_angle=360 }, { type='conky', id='RAM', name='memperc', arg='', max=100, offset=0, units='%', bg_colour=ring_background_color, bg_alpha=ring_background_alpha, fg_colour=ring_foreground_color, fg_alpha=ring_foreground_alpha, x=conky_width, y=ystart+yoff, radius=rad1, thickness=21, threshold1 = 100, threshold2 = 100, start_angle=180, end_angle=360 }, { type='conky', id='/data', name='fs_used_perc', arg='/data', max=100, offset=0, units='%', bg_colour=ring_background_color, bg_alpha=ring_background_alpha, fg_colour=ring_foreground_color, fg_alpha=ring_foreground_alpha, x=conky_width, y=ystart+2*yoff, radius=rad1, thickness=10, threshold1 = 94, threshold2 = 97, start_angle=180, end_angle=360 }, { type='conky', id='/', name='fs_used_perc', arg='/', max=100, offset=0, units='%', bg_colour=ring_background_color, bg_alpha=ring_background_alpha, fg_colour=ring_foreground_color, fg_alpha=ring_foreground_alpha, x=conky_width, y=ystart+2*yoff, radius=rad2+1, thickness=9, threshold1 = 90, threshold2 = 95, start_angle=180, end_angle=360 }, { type='conky', id='eth0', name='downspeedf', arg='eth0', max=512, offset=0, units='kB/s', bg_colour=ring_background_color, bg_alpha=ring_background_alpha, fg_colour=ring_foreground_color, fg_alpha=ring_foreground_alpha, x=conky_width, y=ystart+3*yoff, radius=rad1, thickness=9, threshold1 = 100, threshold2 = 200, start_angle=180, end_angle=360 }, { type='conky', id='wlan0', name='downspeedf', arg='wlan0', max=512, offset=0, units='kB/s', bg_colour=ring_background_color, bg_alpha=ring_background_alpha, fg_colour=ring_foreground_color, fg_alpha=ring_foreground_alpha, x=conky_width, y=ystart+3*yoff, radius=rad2+1, thickness=9, threshold1 = 100, threshold2 = 200, start_angle=180, end_angle=360 }, { type='file', id='power', name='/sys/class/power_supply/BAT0/power_now', arg='', -- to match in file max=61.6, offset=0, units='W', scaling=0.001, bg_colour=ring_background_color, bg_alpha=ring_background_alpha, fg_colour=ring_foreground_color, fg_alpha=ring_foreground_alpha, x=conky_width, y=ystart+4*yoff, radius=rad1, thickness=9, threshold1 = 40, threshold2 = 70, start_angle=180, end_angle=360 }, { type='file', id='charge', name='/sys/class/power_supply/BAT0/energy_now', arg='', -- to match in file max=61.6, offset=0, units='Wh', scaling=0.000001, bg_colour=ring_background_color, bg_alpha=ring_background_alpha, fg_colour=ring_foreground_color, fg_alpha=ring_foreground_alpha, x=conky_width, y=ystart+4*yoff, radius=rad2+1, thickness=9, threshold1 = 400, threshold2 = 700, start_angle=180, end_angle=360 }, --~ { --~ type='conky', --~ id='fan', --~ name='hwmon', --~ arg='fan 1', --~ max=7000, --~ offset=0, --~ units='rpm', --~ bg_colour=ring_background_color, --~ bg_alpha=ring_background_alpha, --~ fg_colour=ring_foreground_color, --~ fg_alpha=ring_foreground_alpha, --~ x=conky_width, y=ystart+5*yoff, --~ radius=rad1, --~ thickness=21, --~ threshold1 = 85, --~ threshold2 = 95, --~ start_angle=180, --~ end_angle=360 --~ }, --~ { --~ type='conky', --~ id='T1', --~ name='hwmon', --~ arg='temp 4', --~ max=100, --~ offset=0, --~ units='C', --~ bg_colour=ring_background_color, --~ bg_alpha=ring_background_alpha, --~ fg_colour=ring_foreground_color, --~ fg_alpha=ring_foreground_alpha, --~ x=conky_width, y=ystart+6*yoff, --~ radius=rad1, --~ thickness=9, --~ threshold1 = 85, --~ threshold2 = 95, --~ start_angle=180, --~ end_angle=360 --~ }, --~ { --~ type='conky', --~ id='T2', --~ name='hwmon', --~ arg='temp 19', --~ max=100, --~ offset=0, --~ units='C', --~ bg_colour=ring_background_color, --~ bg_alpha=ring_background_alpha, --~ fg_colour=ring_foreground_color, --~ fg_alpha=ring_foreground_alpha, --~ x=conky_width, y=ystart+6*yoff, --~ radius=rad2+1, --~ thickness=9, --~ threshold1 = 85, --~ threshold2 = 95, --~ start_angle=180, --~ end_angle=360 --~ }, } require 'cairo' function rgb_to_r_g_b(colour,alpha) return ((colour / 0x10000) % 0x100) / 255., ((colour / 0x100) % 0x100) / 255., (colour % 0x100) / 255., alpha end function draw_ring(cr,t,pt) local w,h=conky_window.width,conky_window.height local xc,yc,ring_r,ring_w,sa,ea=pt['x'],pt['y'],pt['radius'],pt['thickness'], pt['start_angle'],pt['end_angle'] local bgc, bga, fgc, fga=pt['bg_colour'], pt['bg_alpha'], pt['fg_colour'], pt['fg_alpha'] local angle_0=sa*(2*math.pi/360)-math.pi/2 local angle_f=ea*(2*math.pi/360)-math.pi/2 local t_arc=t*(angle_f-angle_0) -- Draw background ring cairo_arc(cr,xc,yc,ring_r,angle_0,angle_f) cairo_set_source_rgba(cr,rgb_to_r_g_b(bgc,bga)) cairo_set_line_width(cr,ring_w) cairo_stroke(cr) -- Draw indicator ring cairo_arc(cr,xc,yc,ring_r,angle_0,angle_0+t_arc) cairo_set_source_rgba(cr,rgb_to_r_g_b(fgc,fga)) cairo_stroke(cr) end function draw_name(cr,t,pt) local w,h=conky_window.width,conky_window.height pt['fg_alpha'] = text_alpha pt['fg_colour'] = text_color local angle=(360-60.)*(math.pi/180)-math.pi/2 -- local xpos=pt['x']+math.cos(angle)*pt['radius']*2 local xpos=w-32 local ypos=pt['y']+math.sin(angle)*pt['radius']*2.8+2 local extents = cairo_text_extents_t:create() -- write pt['id'] -- write pt['max'] local text = pt['id'] .. " " .. tostring(t*pt['max']) ..pt['units'] cairo_select_font_face (cr, device_fonts, CAIRO_FONT_SLANT_NORMAL, CAIRO_FONT_WEIGHT_BOLD) cairo_set_font_size (cr, device_font_size) cairo_text_extents(cr,text,extents) xpos = xpos-extents.width cairo_move_to(cr,xpos,ypos) cairo_show_text(cr,text) cairo_set_source_rgba(cr,rgb_to_r_g_b(pt['fg_colour'],pt['fg_alpha'])) cairo_stroke(cr) end function conky_ring_stats() local function setup_rings(cr,pt) local str='' local value=0 if pt['type'] == 'file' then local f = assert(io.open(pt['name'], "r")) if pt['arg'] == '' then value = f:read("*number")*pt['scaling'] f:close() else value = f:read("*all") f:close() -- hack hack hack. don't display power when battery is charging if pt['id'] == 'power' then if not string.match(value,'discharging') then value='present rate: 0' end end i,j=string.find(value,pt['arg'] .. "%s*%d*") value = string.sub(value,i+string.len(pt['arg']),j) value = tonumber(value)*pt['scaling'] end else str=string.format('${%s %s}',pt['name'],pt['arg']) str=conky_parse(str) value=tonumber(str) end if value == nil then value = 0 end if pt['id'] == 'power' then value = math.floor(value/1000.) end pct=value/pt['max'] local fg_color_orig = pt['fg_colour'] if (pct*100) > pt['threshold1'] then pt['fg_colour'] = ring_threshold1_color end if (pct*100) > pt['threshold2'] then pt['fg_colour'] = ring_threshold2_color end pt['fg_alpha'] = ring_foreground_alpha; draw_ring(cr,pct,pt) pt['fg_alpha'] = text_alpha; pt['fg_colour'] = text_color; draw_name(cr,pct,pt) pt['fg_colour'] = fg_color_orig end if conky_window==nil then return end local cs=cairo_xlib_surface_create(conky_window.display, conky_window.drawable,conky_window.visual, conky_window.width,conky_window.height) local cr=cairo_create(cs) -- local cr2=cairo_create(cs) local updates=conky_parse('${updates}') update_num=tonumber(updates) if update_num>=1 then for i in pairs(settings_table) do setup_rings(cr,settings_table[i]) end end end