require 'cairo'
function conky_draw_colordot()
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)
cr = cairo_create(cs)
local updates=tonumber(conky_parse('${updates}'))
if updates>5 then
--#########################################################################################################
--#########################################################################################################
--avg cpu indicator---------------------------------------
local co=conky_parse("${cpu}") --type conky object to be parsed within the quotes
local alpha=1 --alpha for dot
local mv=100 --max value for conky object
local rv=100 --red at value
local rad=5 --radius of dot
--position (dot position)
local xpos=100
local ypos=100
--label
local text="CPU_AVG" --text for label in quotes
local font="White Rabbit" --font for label in quotes
local fsize=12 --fontsize
local gap=10 --gap between dot edge and text
local label="L" --set to which side you want the text label
colordot(co,mv,rv,alpha,rad,xpos,ypos,text,font,fsize,gap,label) --call drawing function
-----------------------------------------------------------
--core1 indicator---------------------------------------
local co=conky_parse("${cpu cpu1}")
local alpha=1
local mv=100
local rv=100
local rad=5
--position
local xpos=100
local ypos=120
--label
local text="CORE_1"
local font="White Rabbit"
local fsize=12
local gap=10
local label="L"
colordot(co,mv,rv,alpha,rad,xpos,ypos,text,font,fsize,gap,label)
-----------------------------------------------------------
--core2 indicator---------------------------------------
local co=conky_parse("${cpu cpu2}")
local alpha=1
local mv=100
local rv=100
local rad=5
--position
local xpos=100
local ypos=140
--label
local text="CORE_2"
local font="White Rabbit"
local fsize=12
local gap=10
local label="L"
colordot(co,mv,rv,alpha,rad,xpos,ypos,text,font,fsize,gap,label)
-----------------------------------------------------------
--core3 indicator---------------------------------------
local co=conky_parse("${cpu cpu3}")
local alpha=1
local mv=100
local rv=100
local rad=5
--position
local xpos=100
local ypos=160
--label
local text="CORE_3"
local font="White Rabbit"
local fsize=12
local gap=10
local label="L"
colordot(co,mv,rv,alpha,rad,xpos,ypos,text,font,fsize,gap,label)
-----------------------------------------------------------
--memory indicator---------------------------------------
local co=conky_parse("${memperc}")
local alpha=1
local mv=100
local rv=100
local rad=5
--position
local xpos=120
local ypos=100
--label
local text="MEMORY"
local font="White Rabbit"
local fsize=12
local gap=10
local label="R"
colordot(co,mv,rv,alpha,rad,xpos,ypos,text,font,fsize,gap,label)
-----------------------------------------------------------
--root hdd indicator---------------------------------------
local co=conky_parse("${fs_used_perc /}")
local alpha=1
local mv=100
local rv=100
local rad=5
--position
local xpos=120
local ypos=120
--label
local text="HDD_ROOT"
local font="White Rabbit"
local fsize=12
local gap=10
local label="R"
colordot(co,mv,rv,alpha,rad,xpos,ypos,text,font,fsize,gap,label)
-----------------------------------------------------------
--home hdd indicator---------------------------------------
local co=conky_parse("${fs_used_perc /home}")
local alpha=1
local mv=100
local rv=100
local rad=5
--position
local xpos=120
local ypos=140
--label
local text="HDD_HOME"
local font="White Rabbit"
local fsize=12
local gap=10
local label="R"
colordot(co,mv,rv,alpha,rad,xpos,ypos,text,font,fsize,gap,label)
-----------------------------------------------------------
--win xp hdd indicator---------------------------------------
local co=conky_parse("${fs_used_perc /media/00508FE1508FDC32}")
local alpha=1
local mv=100
local rv=100
local rad=5
--position
local xpos=120
local ypos=160
--label
local text="HDD_WINXP"
local font="White Rabbit"
local fsize=12
local gap=10
local label="R"
colordot(co,mv,rv,alpha,rad,xpos,ypos,text,font,fsize,gap,label)
-----------------------------------------------------------
--#########################################################################################################
--#########################################################################################################
end-- if updates>5
cairo_destroy(cr)
cairo_surface_destroy(cs)
cr=nil
end-- end main function
function colordot(co,mv,rv,alpha,rad,xpos,ypos,text,font,fsize,gap,label)
local cv=tonumber(co)
if cv==nil then cv=0 end
--start color = green
local str=0
local stg=1
local stb=0
--middle color = yellow
local mr=1
local mg=1
local mb=0
--finish color = red
local fr=1
local fg=0
local fb=0
if cv>=rv then
colr=fr
colg=fg
colb=fb
elseif cv<rv then
mv=mv-(mv-rv)
if cv<(mv/2) then
colr=((mr-str)*(cv/(mv/2)))+str
colg=((mg-stg)*(cv/(mv/2)))+stg
colb=((mb-stb)*(cv/(mv/2)))+stb
elseif cv>=(mv/2) then
colr=((fr-mr)*((cv-(mv/2))/(mv/2)))+mr
colg=((fg-mg)*((cv-(mv/2))/(mv/2)))+mg
colb=((fb-mb)*((cv-(mv/2))/(mv/2)))+mb
end
end
--draw dot
cairo_arc (cr,xpos,ypos,rad,0,2*math.pi)
cairo_set_source_rgba (cr,colr,colg,colb,alpha)
cairo_fill (cr)
--draw label
cairo_select_font_face (cr, font, CAIRO_FONT_SLANT_NORMAL, CAIRO_FONT_WEIGHT_NORMAL);
cairo_set_font_size (cr, fsize)
extents=cairo_text_extents_t:create()
cairo_text_extents(cr,text,extents)
local width=extents.width
local height=extents.height
cairo_set_source_rgba (cr,1,1,1,1)
if label=="L" then
cairo_move_to (cr,xpos-rad-gap-width,ypos+(height/2))
else
cairo_move_to (cr,xpos+rad+gap,ypos+(height/2))
end
cairo_show_text (cr,text)
cairo_stroke (cr)
end
It's hard to find something if you don't know what you're looking for.
I have a blog, it's mostly about conky and lua stuff... go
here.