Δημοσιεύτηκε: 18 Απρ 2015, 09:38
από taxiarchis
ασχολούμαι αρκετό καιρό με linux , μπαίνω συχνά στο forum διαβάζω , αλλά δεν προλαβαίνω να ποστάρω
μετά από καιρό ασχολίας με το conky έφτιαξα και εγώ ένα δικό μου ,
καταρχήν αρχάριος σε προγραμματισμό , απλά είναι copy paste η όλη δουλεία



όποιος θέλει να το χρησιμοποίησει , να το βελτιώσει ή να το αλλάξει εδώ είναι το conky

conkyrc
Spoiler: show
# Use double buffering (reduces flicker, may not work for everyone)
double_buffer yes

# Use Xft?
use_xft yes
xftfont Ubuntu:size=10

# Update interval in seconds
update_interval 1

# This is the number of times Conky will update before quitting.
# Set to zero to run forever.
total_run_times 0

# Create own window instead of using desktop (required in nautilus)
own_window yes
own_window_transparent yes
own_window_type normal
own_window_hints undecorated,below,sticky,skip_taskbar,skip_pager

#Minimum size of text area
#minimum_size 320 45

#maximum_width 500

# Draw shades?
draw_shades no

# Draw outlines?
draw_outline no

# Draw borders around text
draw_borders no

# Stippled borders?
stippled_borders 0

# border width
border_width 0

# Default colors and also border colors
default_color 303030
#default_shade_color white
#default_outline_color black
own_window_colour 262524

# Text alignment, other possible values are commented
#alignment top_middle
#alignment top_right
alignment top_right
#alignment bottom_left
#alignment bottom_right

# Gap between borders of screen and text
# same thing as passing -x at command line gap_y 44
gap_x 5
gap_y 190

# Subtract file system buffers from used memory?
no_buffers yes

# set to yes if you want all text to be in uppercase
uppercase no

# number of cpu samples to average
# set to 1 to disable averaging
cpu_avg_samples 2

# number of net samples to average
# set to 1 to disable averaging
net_avg_samples 2

# Force UTF8? note that UTF8 support required XFT
override_utf8_locale yes

# Add spaces to keep things from moving about? This only affects certain objects.
#use_spacer no

color0 93e7dc # Light blue
color1 ffffff # default white
color2 ebf6f4 # light grey

own_window_argb_value 0
own_window_argb_visual no
minimum_size 0 0

# SET THE PATH TO THE SCRIPT HERE
lua_load ~/.conky/tax/bargraph.lua
lua_draw_hook_pre main_bars

lua_load ~/.conky/tax/rings-var.lua
lua_draw_hook_post main_pie


TEXT
${color0}${goto 90}${voffset 1}${font D3 Euronism:size=28}${time %I}${color red}:${color2}${time %M}
${color0}${goto 10}${font Ubuntu:size=10}Hostname :${color2}$nodename
${color0}${goto 10}Date : ${color2}${time %A %d %b. %Y}
${color0}${goto 10}Uptime : ${color2}$uptime_short
${color0}${goto 10}Distro : ${color2}${exec cat /etc/issue.net | cut -c1-19}
${color0}${goto 10}Kernel : ${color2}$kernel

${color0}${goto 10}Proc :${color2}${exec cat /proc/cpuinfo | grep "model name" | uniq | cut -c13-39}
${color0}${goto 10}Core 1:${goto 260}${color2}${cpu cpu0}%
${color0}${goto 10}Core 2:${goto 260}${color2}${cpu cpu2}%

${color0}${goto 20}MBTemp${goto 105}Temp 1${goto 190}Temp 2
${color2}${goto 23}${hwmon 0 temp 2}°C${goto 108}${hwmon 1 temp 3}°C${goto 195}${hwmon 1 temp 2}°C



${color0}${goto 40}Memory${goto 160}Fan Speed
${font Ubuntu:size=8}${color2}${goto 30}Total $memmax${goto 180}${hwmon 0 fan 1} rm
#----------------------------------------------------------------------------------------------------------------------------------------
# Network
#----------------------------------------------------------------------------------------------------------------------------------------





${font Ubuntu:size=10}${color0}IP: ${color2}${addr eth0}
${color0}Current: ${color2}${execi 10 /sbin/iwconfig eth0|grep Rate|cut -d"M" -f1|cut -b20-24} Mbits/sec
${color0}Down: ${color2}${downspeed eth0}${color2} k/s ${alignr}${font Ubuntu:size=10}${color0}Up:${color2}${upspeed eth0} k/s
${downspeedgraph eth0 30,120 000000 0ABFFF} ${alignr}${upspeedgraph eth0 30,120 000000 0ABFFF}$color
${color0}Total:${color2}${totaldown eth0} ${alignr}${font Ubuntu:size=10}${color0}Total:${color2}${totalup eth0}
#----------------------------------------------------------------------------------------------------------------------------------------
# Running processes
#----------------------------------------------------------------------------------------------------------------------------------------

${color0}${voffset 5}NAME${goto 155}PID${goto 220}CPU%${goto 270}MEM%${color2}${voffset 5}
${top name 1}${goto 150}${top pid 1}${goto 200}${top cpu 1}${goto 250}${top mem 1}
${top name 2}${goto 150}${top pid 2}${goto 200}${top cpu 2}${goto 250}${top mem 2}
${top name 3}${goto 150}${top pid 3}${goto 200}${top cpu 3}${goto 250}${top mem 3}
${top name 5}${goto 150}${top pid 5}${goto 200}${top cpu 5}${goto 250}${top mem 5}
${top name 6}${goto 150}${top pid 6}${goto 200}${top cpu 6}${goto 250}${top mem 6}


όπως και τα ring και bar lua που χρησιμοποίησα

rings-var.lua

Spoiler: show
--RINGS VARIATIONS by Wlourf 05 june 2010
--A mod of the widget : this one cut the arc into portions
--In fact, there is a loop which create the pie_table settings
--with multiple arc


--[[PIE CHART WIDGET BY WLOURF v1.2 26 may 2010

This widget draw a pie chart or a ring in a conky window.
More info on the parameters with pictures on this page :
http://u-scripts.blogspot.com/2010/04/p ... idget.html


v1.0 10/04/2010 original release
v1.1 15/05/2010 the parameters are in a table (pie_settings), only the values in pie_settings.tableV are mandatory
added an option to draw values like a ring (type_arc="l")
v1.2 26/05/2010 add inverse_l parameter (for type_arc="l")
bug fix : line_lgth problem
read_df function improved
]]

require 'cairo'


function set_settings()

-- ------------------PARAMETERS TO SET-----------------------
--[[available parameters for pie chart widget
-- table of labels and values {{label,conky_variable,conky_argument,convert to Go-Mo-Ko units (true/false) or unit},
-- this table is mandatory, others parameters are optionals
example
tableV={
{"cpu","cpu","",100,"%"},
{"mem","memperc","",100,"%"},
},
xc=50, -- x center of the pie, default = conky_window.width/2
yc=700, -- y center of the pie, default = conky_window.height/2
int_radius=30, -- internal radius in pixel, default = conky_window.width/6
radius=45, -- external radius in pixel, default = conky_window.width/4
first_angle=0, -- first angle of the pie (in degrees), default=0
last_angle=360, -- last angle of the pie (in degrees), default=360
type_arc="l", -- fill the arc in a linear way (ring) or radial way (pie), values l or r, default=l
inverse_l_arc=false, -- inverse arc for rings (true/false), default=false
proportional=false, -- display proportional sectors (true/false); default =false
gradient_effect=true, -- gradient effect (true/false), default=true
line_lgth=50, -- length for horizontal line (from radius to end of line), default=radius
line_width=0, -- width of line, default=1
line_space=10, -- vertical space between two lines, default=10 pixels
extend_line=true, -- grow up the line (true/false) if length of text> line_lgth, default=true
nb_decimals=0, -- number of decimals for numbers, default=1
show_text=true,-- display text (true/false), default=true
txt_font=font_name, -- font, default "Japan"
font_size=12, -- font size, default=12
font_color=colbg, -- font color (for gradient) or nil (for constant color), default = nil
font_alpha=0.5, -- font alpha, default=1
txt_offset=1, -- space between text and line, default=1
txt_format="&l &v", -- string for formatting text, possibles values are : default = "&l : &v"
-- &l for label
-- &o for occupied percentage
-- &f for free percentage
-- &v for value
-- &n for free value (non-occupied)
-- &m for max value
-- &p for percentage value of full graph
tablebg={ -- table of tables of colours for background {colors,alpha}
{colbg,0.5},
},
tablefg={ -- table of tables of colours for foreground {colors,alpha}
{col2,1},
},
},

]]


--in the table mod_settings, we store parameters for each circle
--they define the way the circle will be drawn on the conky window

--if some parameters are missing, this is not a problem, default values will be used

mod_settings={

{--MB temp
xc=60,
yc=270,
int_radius=10,
radius=25,
first_angle=0,
last_angle=270,
--if we use the default value, it is not necessary to call the parameter
--gradient_effect=true,
tablebg = {{0xFFFFFF,0.25}},

--theses parameters are for this mod only
nbPortions = 10,
--value to display, example
--value = tonumber(conky_parse("${cpu}")),
value = tonumber(conky_parse("${hwmon 0 temp 2}")),


--maximum value of the ring
maxValue=100,
--space between two portions, don't push too far, but it accepts negatives values
delta=3,
--color at beginning red, green, blue ,alpha
rgba0 = {0,255,0,1},
--color at the end : red, green, blue ,alpha
rgba1 = {255,0,0,1},
--fillPortion : if true, draw only full portions
fillPortion=true,},

{--CPU 1 temp
xc=145,
yc=270,
int_radius=10,
radius=25,
first_angle=0,
last_angle=270,
--if we use the default value, it is not necessary to call the parameter
--gradient_effect=true,
tablebg = {{0xFFFFFF,0.25}},

--theses parameters are for this mod only
nbPortions = 10,
--value to display, example
--value = tonumber(conky_parse("${cpu}")),
value = tonumber(conky_parse("${hwmon 1 temp 3}")),


--maximum value of the ring
maxValue=100,
--space between two portions, don't push too far, but it accepts negatives values
delta=3,
--color at beginning red, green, blue ,alpha
rgba0 = {0,255,0,1},
--color at the end : red, green, blue ,alpha
rgba1 = {255,0,0,1},
--fillPortion : if true, draw only full portions
fillPortion=true,},

{--CPU Temp 2
xc=230,
yc=270,
int_radius=10,
radius=25,
first_angle=0,
last_angle=270,
--if we use the default value, it is not necessary to call the parameter
--gradient_effect=true,
tablebg = {{0xFFFFFF,0.25}},

--theses parameters are for this mod only
nbPortions = 10,
--value to display, example
--value = tonumber(conky_parse("${cpu}")),
value = tonumber(conky_parse("${hwmon 1 temp 2}")),


--maximum value of the ring
maxValue=100,
--space between two portions, don't push too far, but it accepts negatives values
delta=3,
--color at beginning red, green, blue ,alpha
rgba0 = {0,255,0,1},
--color at the end : red, green, blue ,alpha
rgba1 = {255,0,0,1},
--fillPortion : if true, draw only full portions
fillPortion=true,},

{--fan speed
xc=230,
yc=345,
int_radius=15,
radius=30,
first_angle=0,
last_angle=270,
gradient_effect=false,
tablebg = {{0xffffff,0.75}},

--theses parameters are for this mod only
--nb of portions (>15 or effect won't be nice)
nbPortions = 25,
--value to display
value = tonumber(conky_parse("${hwmon 0 fan 1}")),

--maximum value of the ring
maxValue=2500,
--space between two portions, don't push too far, but it accepts negatives values
delta=3,
--here we have constant color for each portion: red
--color at beginning red, green, blue ,alpha
rgba0 = {255,255,0,1},
--color at the end : red, green, blue ,alpha
rgba1 = {255,0,255,1},
--fillPortion : if true, draw only full portions
fillPortion=false,},

{--memory
xc=100,
yc=345,
int_radius=15,
radius=30,
first_angle=0,
last_angle=270,
gradient_effect=false,
tablebg = {{0xffffff,0.75}},

--theses parameters are for this mod only
--nb of portions (>15 or effect won't be nice)
nbPortions = 20,
--value to display
value = tonumber(conky_parse("${memperc}")),

--maximum value of the ring
maxValue=100,
--space between two portions, don't push too far, but it accepts negatives values
delta=3,
--here we have constant color for each portion: red
--color at beginning red, green, blue ,alpha
rgba0 = {255,255,0,1},
--color at the end : red, green, blue ,alpha
rgba1 = {255,0,255,1},
--fillPortion : if true, draw only full portions
fillPortion=false,},
}

--END OF PARAMETERS HERE, at line 1101, there is a script to display text



end

function create_pie_settings(tt)
--default values, just in case
--theses one are needed to compute the portions used in the table pie_chart
if tt.first_angle==nil then tt.first_angle=0 end
if tt.last_angle==nil then tt.last_angle=0 end
if tt.xc==nil then tt.xc=conky_window.width/2 end
if tt.yc==nil then tt.yc=conky_window.height/2 end
if tt.int_radius ==nil then tt.int_radius =conky_window.width/6 end
if tt.radius ==nil then tt.radius =conky_window.width/4 end
if tt.gradient_effect==nil then tt.gradient_effect=true end
if tt.tablebg==nil then tt.tablebg={{0xFFFFFF,0.5}} end

--compute
local deltaR = (tt.rgba1[1]-tt.rgba0[1])/tt.nbPortions
local deltaG = (tt.rgba1[2]-tt.rgba0[2])/tt.nbPortions
local deltaB = (tt.rgba1[3]-tt.rgba0[3])/tt.nbPortions
local deltaA = (tt.rgba1[4]-tt.rgba0[4])/tt.nbPortions
local portion = tt.maxValue/tt.nbPortions
local anglePortion=(tt.last_angle-tt.first_angle)/tt.nbPortions


--create the pie_settings table
for i = 1,tt.nbPortions do
--compute the values for a block i
local value2=0
if tt.value== nil then tt.value=0 end
if tt.value<i*portion and tt.value>(i-1)*portion then
if tt.fillPortion then
value2=1
else
value2 = (tt.value-(i-1)*portion)/portion
end
end
if tt.value>=i*portion then value2 = 1 end

--create the table
local t={}
table.insert(pie_settings,t)
pie_settings[i].tableV={
--elements in the table
--{"label","conky variable","conky arg","max value", "unit"}
{"","",value2,1,""},
}
pie_settings[i].int_radius = tt.int_radius
pie_settings[i].radius = tt.radius
pie_settings[i].gradient_effect=tt.gradient_effect
pie_settings[i].first_angle = tt.first_angle+(i-1)*anglePortion
pie_settings[i].last_angle = tt.first_angle+i*anglePortion--1
pie_settings[i].show_text = false
local alpha=((pie_settings[i].last_angle+pie_settings[i].first_angle)/2)*math.pi/180

pie_settings[i].xc = tt.xc+tt.delta*math.sin(alpha)
pie_settings[i].yc = tt.yc-tt.delta*math.cos(alpha)
local color = string.format("0x" .. Dec2Hex(tt.rgba0[1]+deltaR*i) .. Dec2Hex(tt.rgba0[2]+deltaG*i) .. Dec2Hex(tt.rgba0[3]+deltaB*i) )
pie_settings[i].tablefg={
{color,tt.rgba0[4]+deltaA*i},
}
pie_settings[i].tablebg = tt.tablebg

end
end

function Dec2Hex(nValue)
--http://www.indigorose.com/forums/threads/10192-Convert-Hexadecimal-to-Decimal
if type(nValue) == "string" then
nValue = String.ToNumber(nValue);
end
nHexVal = string.format("%X", nValue); -- %X returns uppercase hex, %x gives lowercase letters
local prefix=""
if #nHexVal==1 then prefix="0" end
sHexVal = prefix..nHexVal.."";
return sHexVal;
end


--main function
function conky_main_pie()
if conky_window==nil then return end

pie_settings={}
set_settings()

local w=conky_window.width
local h=conky_window.height
local cs=cairo_xlib_surface_create(conky_window.display, conky_window.drawable, conky_window.visual, w, h)
cr=cairo_create(cs)

if tonumber(conky_parse('${updates}'))>5 then
--mod here : create multiple pie_settngs tables
for m in pairs(mod_settings) do

create_pie_settings(mod_settings[m])
for i in pairs(pie_settings) do
--print ("i",i)
draw_pie(pie_settings[i])
end
--reset pie_settings
pie_settings={}
end
end

--begin of mod for text
--I am lazy today, I will draw labels with the pie chart widget but with invisible rings
pie_settings={
{
tableV={{"fan","exec sensors | grep 'CPU Fan' | cut -c13-16","",1500,"rpm"},},
tablebg={{0xFFFFFF,0}},
tablefg={{0xFF0000,1}},
radius=0,
int_radius=0,
line_width=0,
xc=150,
yc=conky_window.height-20,
line_lgth=100,
nb_decimals=0,
font_color=0xFFFF00,
},
{
tableV={{"cpu","exec sensors | grep 'Sys Temp' | cut -c15-16","",100,"°C"},},
tablebg={{0xFFFFFF,0}},
tablefg={{0xFF0000,1}},
radius=0,
int_radius=0,
line_width=0,
xc=270,
yc=conky_window.height-20,
line_lgth=100,
nb_decimals=0,
font_color=0xFFFF00,
},
{
tableV={{"mem","memperc","",100,"%"},},
tablebg={{0xFFFFFF,0}},
tablefg={{0xFF0000,1}},
radius=0,
int_radius=0,
line_width=0,
xc=390,
yc=conky_window.height-20,
line_lgth=100,
nb_decimals=0,
font_color=0xFFFF00,
},
{
tableV={{"cpu","cpu","",100,"%"},},
tablebg={{0xFFFFFF,0}},
tablefg={{0xFF0000,1}},
radius=0,
int_radius=0,
line_width=0,
xc=510,
yc=conky_window.height-20,
line_lgth=100,
nb_decimals=0,
font_color=0xFFFF00,
},
{
tableV={{"ul","upspeedf","eth1",2000,"kb/s"},
{"dl","downspeedf","eth1",100,"kb/s"},
},
tablebg={{0xFFFFFF,0}},
tablefg={{0xFF0000,1}},
radius=10,
first_angle=180,
last_angle=360,
int_radius=0,
line_width=0,
xc=630,
yc=conky_window.height-20,
line_lgth=90,
nb_decimals=0,
font_color=0xFFFF00,
},
{
--conky_parse("${fs_used /home}")
tableV={{"/home : " .. conky_parse("${fs_used /home}"),"","",1,""},
{"/ : " .. conky_parse("${fs_used /}"),"","",1,""},
},
tablebg={{0xFFFFFF,0}},
tablefg={{0xFF0000,1}},
radius=10,
first_angle=180,
last_angle=360,
int_radius=0,
line_width=0,
xc=750,
yc=conky_window.height-20,
line_lgth=90,
txt_format="&l",
font_color=0xFFFF00,
},
}
for i in pairs(pie_settings) do
--print ("i",i)
--draw_pie(pie_settings[i])
end

--draw separator
--cairo_set_line_width(cr,5)
--cairo_set_source_rgba(cr,0.5,0.5,0.5,0.5)
--cairo_move_to(cr,0,170)
--cairo_line_to(cr,conky_window.width,170)
--cairo_stroke(cr)

--end of mod for texts
cairo_destroy(cr)
end



function string:split(delimiter)
--source for the split function : http://www.wellho.net/resources/ex.php4?item=u108/split
local result = { }
local from = 1
local delim_from, delim_to = string.find( self, delimiter, from )
while delim_from do
table.insert( result, string.sub( self, from , delim_from-1 ) )
from = delim_to + 1
delim_from, delim_to = string.find( self, delimiter, from )
end
table.insert( result, string.sub( self, from ) )
return result
end


function rgb_to_r_g_b(colour, alpha)
return ((colour / 0x10000) % 0x100) / 255., ((colour / 0x100) % 0x100) / 255., (colour % 0x100) / 255., alpha
end

function round(num, idp)
local mult = 10^(idp or 0)
return math.floor(num * mult + 0.5) / mult
end

function size_to_text(size,nb_dec)
local txt_v
if nb_dec<0 then nb_dec=0 end
size = tonumber(size)
if size>1024*1024*1024 then
txt_v=string.format("%."..nb_dec.."f Go",size/1024/1024/1024)
elseif size>1024*1024 then
txt_v=string.format("%."..nb_dec.."f Mo",size/1024/1024)
elseif size>1024 then
txt_v=string.format("%."..nb_dec.."f Ko",size/1024)
else
txt_v=string.format("%."..nb_dec.."f o",size)
end
return txt_v
end



function read_df(show_media,sort_table)
--read output of command df and return arrays of value for files systems
--reurn array of table {file syst, "", occupied space , total space , convert to G, M, K ...}

local f = io.popen("df")

local results={}

while true do
local line = f:read("*l")
if line == nil then break end
while string.match(line," ") do
line=string.gsub(line," "," ")
end
local arr_l=string.split(line," ")
local match = string.match(arr_l[1],"/")

if string.match(arr_l[1],"/") then
if not show_media then arr_l[6]=string.gsub(arr_l[6],"/media/","",1) end
table.insert(results,{arr_l[6],"",(arr_l[2]-arr_l[4])*1024,arr_l[2]*1024,true})
end
end

f:close()

if sort_table then
--how to sort table into table?
local flagS=true
while flagS do
for k=2, #results do
flagS=false
if tonumber(results[1][3])>tonumber(results[2][3]) then
local tmpV = results[1]
results[1] = results[2]
results[2] = tmpV
flagS=true
end
if tonumber(results[k][3])<tonumber(results[k-1][3]) then
local tmpV = results[k-1]
results[k-1] = results[k]
results[k] = tmpV
flagS=true
end
end
end
end

return results --array {file syst, occupied space , total space }
end


function draw_pie(t)
if t.tableV==nil then
print ("No input values ...")
return
else
tableV=t.tableV
end

if t.xc==nil then t.xc=conky_window.width/2 end
if t.yc==nil then t.yc=conky_window.height/2 end
if t.int_radius ==nil then t.int_radius =conky_window.width/6 end
if t.radius ==nil then t.radius =conky_window.width/4 end
if t.first_angle==nil then t.first_angle =0 end
if t.last_angle==nil then t.last_angle=360 end
if t.proportional==nil then t.proportional=false end
if t.tablebg==nil then t.tablebg={{0xFFFFFF,0.5},{0xFFFFFF,0.5}} end
if t.tablefg==nil then t.tablefg={{0xFF0000,1},{0x00FF00,1}} end
if t.gradient_effect==nil then t.gradient_effect=true end
if t.show_text==nil then t.show_text=true end
if t.line_lgth==nil then t.line_lgth=t.int_radius end
if t.line_space==nil then t.line_space=10 end
if t.line_width==nil then t.line_width=1 end
if t.extend_line==nil then t.extend_line=true end
if t.txt_font==nil then t.txt_font="Japan" end
if t.font_size==nil then t.font_size=12 end
--if t.font_color==nil then t.font_color=0xFFFFFF end
if t.font_alpha==nil then t.font_alpha = 1 end
if t.txt_offset==nil then t.txt_offset = 1 end
if t.txt_format==nil then t.txt_format = "&l : &v" end
if t.nb_decimals==nil then t.nb_decimals=1 end
if t.type_arc==nil then t.type_arc="l" end
if t.inverse_l_arc==nil then t.inverse_l_arc=false end

local function draw_sector(tablecolor,colorindex,pc,lastAngle,angle,radius,int_radius,gradient_effect,type_arc,inverse_l_arc)
--draw a portion of arc
radiuspc=(radius-int_radius)*pc+int_radius
angle0=lastAngle
val=1
if type_arc=="l" then
val=pc;radiuspc=radius
end
angle1=angle*val

if type_arc=="l" and inverse_l_arc then

cairo_save(cr)

cairo_rotate(cr,angle0+angle)

if gradient_effect then
local pat = cairo_pattern_create_radial (0,0, int_radius, 0,0,radius)
cairo_pattern_add_color_stop_rgba (pat, 0, rgb_to_r_g_b(tablecolor[colorindex][1],0))
cairo_pattern_add_color_stop_rgba (pat, 0.5, rgb_to_r_g_b(tablecolor[colorindex][1],tablecolor[colorindex][2]))
cairo_pattern_add_color_stop_rgba (pat, 1, rgb_to_r_g_b(tablecolor[colorindex][1],0))
cairo_set_source (cr, pat)
cairo_pattern_destroy(pat)
else
cairo_set_source_rgba(cr,rgb_to_r_g_b(tablecolor[colorindex][1],tablecolor[colorindex][2]))
end
cairo_move_to(cr,0,-int_radius)
cairo_line_to(cr,0,-radiuspc)
cairo_rotate(cr,-math.pi/2)

cairo_arc_negative(cr,0,0,radiuspc,0,-angle1)
cairo_rotate(cr,-math.pi/2-angle1)
cairo_line_to(cr,0,int_radius)
cairo_rotate(cr,math.pi/2)
cairo_arc(cr,0,0,int_radius,0,angle1)
cairo_close_path (cr);
cairo_fill(cr)

cairo_restore(cr)
else

cairo_save(cr)

cairo_rotate(cr,angle0)

if gradient_effect then
local pat = cairo_pattern_create_radial (0,0, int_radius, 0,0,radius)
cairo_pattern_add_color_stop_rgba (pat, 0, rgb_to_r_g_b(tablecolor[colorindex][1],0))
cairo_pattern_add_color_stop_rgba (pat, 0.5, rgb_to_r_g_b(tablecolor[colorindex][1],tablecolor[colorindex][2]))
cairo_pattern_add_color_stop_rgba (pat, 1, rgb_to_r_g_b(tablecolor[colorindex][1],0))
cairo_set_source (cr, pat)
cairo_pattern_destroy(pat)
else
cairo_set_source_rgba(cr,rgb_to_r_g_b(tablecolor[colorindex][1],tablecolor[colorindex][2]))
end
cairo_move_to(cr,0,-int_radius)
cairo_line_to(cr,0,-radiuspc)
cairo_rotate(cr,-math.pi/2)

cairo_arc(cr,0,0,radiuspc,0,angle1)
cairo_rotate(cr,angle1-math.pi/2)
cairo_line_to(cr,0,int_radius)
cairo_rotate(cr,math.pi/2)
cairo_arc_negative(cr,0,0,int_radius,0,-angle1)
cairo_close_path (cr);
cairo_fill(cr)

cairo_restore(cr)
end


end

function draw_lines(idx,nbArcs,angle,table_colors,idx_color,adjust,line_lgth,length_txt,txt_offset,radius,line_width,line_space,font_color,font_alpha)
--draw lines

local x0=radiuspc*math.sin(lastAngle+angle/2)
local y0=-radiuspc*math.cos(lastAngle+angle/2)
local x1=1.2*radius*math.sin(lastAngle+angle/2)
local y1=-1.2*radius*math.cos(lastAngle+angle/2)

local x2=line_lgth
local y2=y1
local x3,y3=nil,nil
if x0<=0 then
x2=-x2
end

if adjust then
if x0>0 and x2-x1<length_txt then x2=x1+length_txt end
if x0<=0 and x1-x2<length_txt then x2=x1-length_txt end
end

if idx>1 then
local dY = math.abs(y2-lastPt2[2])
if dY < line_space and lastPt2[1]*x1>0 then
if x0>0 then
y2 = line_space+lastPt2[2]
else
y2 = -line_space+lastPt2[2]
end
if (y2>y1 and x0>0) or (y2<y1 and x0<0 ) then
--x3 is for vertical segment if needed
x3,y3=x2,y2
x2=x1
if x3>0 then x3=x3+txt_offset end
else
Z=intercept({x0,y0},{x1,y1},{0,y2},{1,y2})
x1,y1=Z[1],Z[2]
end
end
else
--remind x2,y2 of first value
x2first,y2first = x2,y2
end

if font_color==nil then
cairo_set_source_rgba(cr,rgb_to_r_g_b(table_colors[idx_color][1],table_colors[idx_color][2]))
else
local pat = cairo_pattern_create_linear (x2,y2, x0,y0)
cairo_pattern_add_color_stop_rgba (pat, 0, rgb_to_r_g_b(font_color,font_alpha))
cairo_pattern_add_color_stop_rgba (pat, 1, rgb_to_r_g_b(table_colors[idx_color][1],table_colors[idx_color][2]))
cairo_set_source (cr, pat)
cairo_pattern_destroy(pat)
end


cairo_move_to(cr,x0,y0)
cairo_line_to(cr,x1,y1)
cairo_line_to(cr,x2,y2)
if x3~=nil then
cairo_line_to(cr,x3,y3)
x2,y2=x3,y3
end
cairo_set_line_width(cr,line_width)
cairo_stroke(cr)
--lastAngle=lastAngle+angle
return {x2,y2}
end

function intercept(p11,p12,p21,p22)
--calculate interscetion of two lines and return coordinates
a1=(p12[2]-p11[2])/(p12[1]-p11[1])

a2=(p22[2]-p21[2])/(p22[1]-p21[1])

b1=p11[2]-a1*p11[1]

b2=p21[2]-a2*p21[1]

X=(b2-b1)/(a1-a2)

Y=a1*X+b1
return {X,Y}
end

--some checks
if t.first_angle>=t.last_angle then
local tmp_angle=t.last_angle
--t.last_angle=t.first_angle
--t.first_angle=tmp_angle
print ("inversed angles")
end

if t.last_angle-t.first_angle>360 and t.first_angle>0 then
t.last_angle=360+t.first_angle
print ("reduce angles")
end

if t.last_angle+t.first_angle>360 and t.first_angle<=0 then
t.last_angle=360+t.first_angle
print ("reduce angles")
end

if t.int_radius<0 then t.int_radius =0 end
if t.int_radius>t.radius then
local tmp_radius=t.radius
t.radius=t.int_radius
t.int_radius=tmp_radius
print ("inversed angles")
end
if t.int_radius==t.radius then
t.int_radius=0
-- print ("int radius set to 0")
end
--end of checks

cairo_save(cr)
cairo_translate(cr,t.xc,t.yc)
cairo_set_line_join (cr, CAIRO_LINE_JOIN_ROUND)
cairo_set_line_cap (cr, CAIRO_LINE_CAP_ROUND)

local nbArcs=#tableV
local anglefull= (t.last_angle-t.first_angle)*math.pi/180
local fullsize = 0
for i= 1,nbArcs do
fullsize=fullsize+tableV[i][4]
end

local cb,cf,angle=0,0,anglefull/nbArcs
lastAngle=t.first_angle*math.pi/180
lastPt2={nil,nil}

for i =1, nbArcs do
if t.proportional then
angle=tableV[i][4]/fullsize*anglefull
end
--set colours
cb,cf=cb+1,cf+1
if cb>#t.tablebg then cb=1 end
if cf>#t.tablefg then cf=1 end

if tableV[i][2]~="" then
str=string.format('${%s %s}',tableV[i][2],tableV[i][3])
else
str = tableV[i][3]
end
str=conky_parse(str)
value=tonumber(str)
if value==nil then value=0 end

--draw sectors
draw_sector(t.tablebg,cb,1,lastAngle,angle,t.radius,t.int_radius,t.gradient_effect,t.type_arc,t.inverse_l_arc)
--print (t.tablefg,cf,tableV[i][2],tableV[i][3],lastAngle,angle,t.radius,t.int_radius)
--print (cf,tableV[i],tableV[i][2],tableV[i][3])
draw_sector(t.tablefg,cf,value/tableV[i][4],lastAngle,angle,t.radius,t.int_radius,t.gradient_effect,t.type_arc,t.inverse_l_arc)

if t.show_text then
--draw text
local txt_l = tableV[i][1]
local txt_opc = round(100*value/tableV[i][4],t.nb_decimals).."%%"
local txt_fpc = round(100*(tableV[i][4]-value/tableV[i][4]),t.nb_decimals).."%%"
local txt_ov,txt_fv,txt_max
if tableV[i][5]==true then
txt_ov = size_to_text(value,t.nb_decimals)
txt_fv = size_to_text(tableV[i][4]-value,t.nb_decimals)
txt_max = size_to_text(tableV[i][4],t.nb_decimals)
else
if tableV[i][5]=="%" then tableV[i][5]="%%" end
txt_ov=string.format("%."..t.nb_decimals.."f ",value)..tableV[i][5]
txt_fv=string.format("%."..t.nb_decimals.."f",tableV[i][4]-value)..tableV[i][5]
txt_max=string.format("%."..t.nb_decimals.."f",tableV[i][4])..tableV[i][5]
end
txt_pc = string.format("%."..t.nb_decimals.."f",100*tableV[i][4]/fullsize).."%%"
local txt_out = t.txt_format
txt_out = string.gsub(txt_out,"&l",txt_l) --label
txt_out = string.gsub(txt_out,"&o",txt_opc)--occ. %
txt_out = string.gsub(txt_out,"&f",txt_fpc)--free %
txt_out = string.gsub(txt_out,"&v",txt_ov) --occ. value
txt_out = string.gsub(txt_out,"&n",txt_fv) --free value
txt_out = string.gsub(txt_out,"&m",txt_max)--max
txt_out = string.gsub(txt_out,"&p",txt_pc)--percent

local te=cairo_text_extents_t:create()
cairo_set_font_size(cr,t.font_size)
cairo_select_font_face(cr, t.txt_font, CAIRO_FONT_SLANT_NORMAL, CAIRO_FONT_WEIGHT_NORMAL)
cairo_text_extents (cr,txt_out,te)

--draw lines
lastPt2=draw_lines(i,nbArcs,angle,t.tablefg,cf,t.extend_line,t.line_lgth+t.radius,
te.width + te.x_bearing,t.txt_offset,t.radius,t.line_width,t.line_space,t.font_color,t.font_alpha)

local xA=lastPt2[1]
local yA=lastPt2[2]-t.line_width-t.txt_offset
if xA>0 then xA = xA-(te.width + te.x_bearing) end
cairo_move_to(cr,xA,yA)
cairo_show_text(cr,txt_out)
end

lastAngle=lastAngle+angle
end
cairo_restore(cr)
end


--[[END OF PIE CHART WIDGET]]


και bargraph.lua
Spoiler: show
--[[ BARGRAPH WIDGET
v2.1 by wlourf (07 Jan. 2011)
this widget draws a bargraph with different effects
http://u-scripts.blogspot.com/2010/07/b ... idget.html

To call the script in a conky, use, before TEXT
lua_load /path/to/the/script/bargraph.lua
lua_draw_hook_pre main_rings
and add one line (blank or not) after TEXT


Parameters are :
3 parameters are mandatory
name - the name of the conky variable to display, for example for {$cpu cpu0}, just write name="cpu"
arg - the argument of the above variable, for example for {$cpu cpu0}, just write arg="cpu0"
arg can be a numerical value if name=""
max - the maximum value the above variable can reach, for example, for {$cpu cpu0}, just write max=100

Optional parameters:
x,y - coordinates of the starting point of the bar, default = middle of the conky window
cap - end of cap line, ossibles values are r,b,s (for round, butt, square), default="b"
http://www.cairographics.org/samples/set_line_cap/
angle - angle of rotation of the bar in degress, default = 0 (i.e. a vertical bar)
set to 90 for an horizontal bar
skew_x - skew bar around x axis, default = 0
skew_y - skew bar around y axis, default = 0
blocks - number of blocks to display for a bar (values >0) , default= 10
height - height of a block, default=10 pixels
width - width of a block, default=20 pixels
space - space between 2 blocks, default=2 pixels
angle_bar - this angle is used to draw a bar on a circular way (ok, this is no more a bar !) default=0
radius - for cicular bars, internal radius, default=0
with radius, parameter width has no more effect.

Colours below are defined into braces {colour in hexadecimal, alpha}
fg_colour - colour of a block ON, default= {0x00FF00,1}
bg_colour - colour of a block OFF, default = {0x00FF00,0.5}
alarm - threshold, values after this threshold will use alarm_colour colour , default=max
alarm_colour - colour of a block greater than alarm, default=fg_colour
smooth - (true or false), create a gradient from fg_colour to bg_colour, default=false
mid_colour - colours to add to gradient, with this syntax {position into the gradient (0 to1), colour hexa, alpha}
for example, this table {{0.25,0xff0000,1},{0.5,0x00ff00,1},{0.75,0x0000ff,1}} will add
3 colurs to gradient created by fg_colour and alarm_colour, default=no mid_colour
led_effect - add LED effects to each block, default=no led_effect
if smooth=true, led_effect is not used
possibles values : "r","a","e" for radial, parallelel, perdendicular to the bar (just try!)
led_effect has to be used with theses colours :
fg_led - middle colour of a block ON, default = fg_colour
bg_led - middle colour of a block OFF, default = bg_colour
alarm_led - middle colour of a block > ALARM, default = alarm_colour

reflection parameters, not avaimable for circular bars
reflection_alpha - add a reflection effect (values from 0 to 1) default = 0 = no reflection
other values = starting opacity
reflection_scale - scale of the reflection (default = 1 = height of text)
reflection_length - length of reflection, define where the opacity will be set to zero
calues from 0 to 1, default =1
reflection - position of reflection, relative to a vertical bar, default="b"
possibles values are : "b","t","l","r" for bottom, top, left, right
draw_me - if set to false, text is not drawn (default = true or 1)
it can be used with a conky string, if the string returns 1, the text is drawn :
example : "${if_empty ${wireless_essid wlan0}}${else}1$endif",

v1.0 (10 Feb. 2010) original release
v1.1 (13 Feb. 2010) numeric values can be passed instead conky stats with parameters name="", arg = numeric_value
v1.2 (28 Feb. 2010) just renamed the widget to bargraph
v1.3 (03 Mar. 2010) added parameters radius & angle_bar to draw the bar in a circular way
v2.0 (12 Jul. 2010) rewrite script + add reflection effects and parameters are now set into tables
v2.1 (07 Jan. 2011) Add draw_me parameter and correct memory leaks, thanks to "Creamy Goodness"

-- This program is free software; you can redistribute it and/or modify
-- it under the terms of the GNU General Public License as published by
-- the Free Software Foundation version 3 (GPLv3)
--
-- This program is distributed in the hope that it will be useful,
-- but WITHOUT ANY WARRANTY; without even the implied warranty of
-- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
-- GNU General Public License for more details.
--
-- You should have received a copy of the GNU General Public License
-- along with this program; if not, write to the Free Software
-- Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
-- MA 02110-1301, USA.

]]

require 'cairo'

----------------START OF PARAMETERS ----------
function conky_main_bars()
local bars_settings={
{
name="cpu cpu0",
arg="cpu cpu0",
max=100,
angle=90,
bg_colour={0x00ffff,0.5},
fg_colour={0x00ffff,0.5},
led_effect="e",
bg_led ={0x0000ff,1},
fg_led ={0xffff00,1},
x=75,y=182,
blocks=45,
height=2,width=13,

},
{
name="cpu cpu2",
arg="cpu cpu2",
max=100,
angle=90,
bg_colour={0x00ffff,0.5},
fg_colour={0x00ffff,0.5},
led_effect="e",
bg_led ={0x0000ff,1},
fg_led ={0xffff00,1},
x=75,y=199,
blocks=45,
height=2,width=13,

},

}

-----------END OF PARAMETERS--------------



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)
--prevent segmentation error when reading cpu state
if tonumber(conky_parse('${updates}'))>3 then
for i in pairs(bars_settings) do

draw_multi_bar_graph(bars_settings[i])

end
end
cairo_destroy(cr)
cairo_surface_destroy(cs)
cr=nil

end



function draw_multi_bar_graph(t)
cairo_save(cr)
--check values
if t.draw_me == true then t.draw_me = nil end
if t.draw_me ~= nil and conky_parse(tostring(t.draw_me)) ~= "1" then return end
if t.name==nil and t.arg==nil then
print ("No input values ... use parameters 'name' with 'arg' or only parameter 'arg' ")
return
end
if t.max==nil then
print ("No maximum value defined, use 'max'")
return
end
if t.name==nil then t.name="" end
if t.arg==nil then t.arg="" end

--set default values
if t.x == nil then t.x = conky_window.width/2 end
if t.y == nil then t.y = conky_window.height/2 end
if t.blocks == nil then t.blocks=10 end
if t.height == nil then t.height=10 end
if t.angle == nil then t.angle=0 end
t.angle = t.angle*math.pi/180
--line cap style
if t.cap==nil then t.cap = "b" end
local cap="b"
for i,v in ipairs({"s","r","b"}) do
if v==t.cap then cap=v end
end
local delta=0
if t.cap=="r" or t.cap=="s" then delta = t.height end
if cap=="s" then cap = CAIRO_LINE_CAP_SQUARE
elseif cap=="r" then
cap = CAIRO_LINE_CAP_ROUND
elseif cap=="b" then
cap = CAIRO_LINE_CAP_BUTT
end
--end line cap style
--if t.led_effect == nil then t.led_effect="r" end
if t.width == nil then t.width=20 end
if t.space == nil then t.space=2 end
if t.radius == nil then t.radius=0 end
if t.angle_bar == nil then t.angle_bar=0 end
t.angle_bar = t.angle_bar*math.pi/360 --halt angle

--colours
if t.bg_colour == nil then t.bg_colour = {0x00FF00,0.5} end
if #t.bg_colour~=2 then t.bg_colour = {0x00FF00,0.5} end
if t.fg_colour == nil then t.fg_colour = {0x00FF00,1} end
if #t.fg_colour~=2 then t.fg_colour = {0x00FF00,1} end
if t.alarm_colour == nil then t.alarm_colour = t.fg_colour end
if #t.alarm_colour~=2 then t.alarm_colour = t.fg_colour end

if t.mid_colour ~= nil then
for i=1, #t.mid_colour do
if #t.mid_colour[i]~=3 then
print ("error in mid_color table")
t.mid_colour[i]={1,0xFFFFFF,1}
end
end
end

if t.bg_led ~= nil and #t.bg_led~=2 then t.bg_led = t.bg_colour end
if t.fg_led ~= nil and #t.fg_led~=2 then t.fg_led = t.fg_colour end
if t.alarm_led~= nil and #t.alarm_led~=2 then t.alarm_led = t.fg_led end

if t.led_effect~=nil then
if t.bg_led == nil then t.bg_led = t.bg_colour end
if t.fg_led == nil then t.fg_led = t.fg_colour end
if t.alarm_led == nil then t.alarm_led = t.fg_led end
end


if t.alarm==nil then t.alarm = t.max end --0.8*t.max end
if t.smooth == nil then t.smooth = false end

if t.skew_x == nil then
t.skew_x=0
else
t.skew_x = math.pi*t.skew_x/180
end
if t.skew_y == nil then
t.skew_y=0
else
t.skew_y = math.pi*t.skew_y/180
end

if t.reflection_alpha==nil then t.reflection_alpha=0 end
if t.reflection_length==nil then t.reflection_length=1 end
if t.reflection_scale==nil then t.reflection_scale=1 end

--end of default values


local function rgb_to_r_g_b(col_a)
return ((col_a[1] / 0x10000) % 0x100) / 255., ((col_a[1] / 0x100) % 0x100) / 255., (col_a[1] % 0x100) / 255., col_a[2]
end


--functions used to create patterns

local function create_smooth_linear_gradient(x0,y0,x1,y1)
local pat = cairo_pattern_create_linear (x0,y0,x1,y1)
cairo_pattern_add_color_stop_rgba (pat, 0, rgb_to_r_g_b(t.fg_colour))
cairo_pattern_add_color_stop_rgba (pat, 1, rgb_to_r_g_b(t.alarm_colour))
if t.mid_colour ~=nil then
for i=1, #t.mid_colour do
cairo_pattern_add_color_stop_rgba (pat, t.mid_colour[i][1], rgb_to_r_g_b({t.mid_colour[i][2],t.mid_colour[i][3]}))
end
end
return pat
end

local function create_smooth_radial_gradient(x0,y0,r0,x1,y1,r1)
local pat = cairo_pattern_create_radial (x0,y0,r0,x1,y1,r1)
cairo_pattern_add_color_stop_rgba (pat, 0, rgb_to_r_g_b(t.fg_colour))
cairo_pattern_add_color_stop_rgba (pat, 1, rgb_to_r_g_b(t.alarm_colour))
if t.mid_colour ~=nil then
for i=1, #t.mid_colour do
cairo_pattern_add_color_stop_rgba (pat, t.mid_colour[i][1], rgb_to_r_g_b({t.mid_colour[i][2],t.mid_colour[i][3]}))
end
end
return pat
end

local function create_led_linear_gradient(x0,y0,x1,y1,col_alp,col_led)
local pat = cairo_pattern_create_linear (x0,y0,x1,y1) ---delta, 0,delta+ t.width,0)
cairo_pattern_add_color_stop_rgba (pat, 0.0, rgb_to_r_g_b(col_alp))
cairo_pattern_add_color_stop_rgba (pat, 0.5, rgb_to_r_g_b(col_led))
cairo_pattern_add_color_stop_rgba (pat, 1.0, rgb_to_r_g_b(col_alp))
return pat
end

local function create_led_radial_gradient(x0,y0,r0,x1,y1,r1,col_alp,col_led,mode)
local pat = cairo_pattern_create_radial (x0,y0,r0,x1,y1,r1)
if mode==3 then
cairo_pattern_add_color_stop_rgba (pat, 0, rgb_to_r_g_b(col_alp))
cairo_pattern_add_color_stop_rgba (pat, 0.5, rgb_to_r_g_b(col_led))
cairo_pattern_add_color_stop_rgba (pat, 1, rgb_to_r_g_b(col_alp))
else
cairo_pattern_add_color_stop_rgba (pat, 0, rgb_to_r_g_b(col_led))
cairo_pattern_add_color_stop_rgba (pat, 1, rgb_to_r_g_b(col_alp))
end
return pat
end






local function draw_single_bar()
--this fucntion is used for bars with a single block (blocks=1) but
--the drawing is cut in 3 blocks : value/alarm/background
--not zvzimzblr for circular bar
local function create_pattern(col_alp,col_led,bg)
local pat

if not t.smooth then
if t.led_effect=="e" then
pat = create_led_linear_gradient (-delta, 0,delta+ t.width,0,col_alp,col_led)
elseif t.led_effect=="a" then
pat = create_led_linear_gradient (t.width/2, 0,t.width/2,-t.height,col_alp,col_led)
elseif t.led_effect=="r" then
pat = create_led_radial_gradient (t.width/2, -t.height/2, 0, t.width/2,-t.height/2,t.height/1.5,col_alp,col_led,2)
else
pat = cairo_pattern_create_rgba (rgb_to_r_g_b(col_alp))
end
else
if bg then
pat = cairo_pattern_create_rgba (rgb_to_r_g_b(t.bg_colour))
else
pat = create_smooth_linear_gradient(t.width/2, 0, t.width/2,-t.height)
end
end
return pat
end

local y1=-t.height*pct/100
local y2,y3
if pct>(100*t.alarm/t.max) then
y1 = -t.height*t.alarm/100
y2 = -t.height*pct/100
if t.smooth then y1=y2 end
end

if t.angle_bar==0 then

--block for fg value
local pat = create_pattern(t.fg_colour,t.fg_led,false)
cairo_set_source(cr,pat)
cairo_rectangle(cr,0,0,t.width,y1)
cairo_fill(cr)
cairo_pattern_destroy(pat)

-- block for alarm value
if not t.smooth and y2 ~=nil then
pat = create_pattern(t.alarm_colour,t.alarm_led,false)
cairo_set_source(cr,pat)
cairo_rectangle(cr,0,y1,t.width,y2-y1)
cairo_fill(cr)
y3=y2
cairo_pattern_destroy(pat)
else
y2,y3=y1,y1
end
-- block for bg value
cairo_rectangle(cr,0,y2,t.width,-t.height-y3)
pat = create_pattern(t.bg_colour,t.bg_led,true)
cairo_set_source(cr,pat)
cairo_pattern_destroy(pat)
cairo_fill(cr)
end
end --end single bar






local function draw_multi_bar()
--function used for bars with 2 or more blocks
for pt = 1,t.blocks do
--set block y
local y1 = -(pt-1)*(t.height+t.space)
local light_on=false

--set colors
local col_alp = t.bg_colour
local col_led = t.bg_led
if pct>=(100/t.blocks) or pct>0 then --ligth on or not the block
if pct>=(pcb*(pt-1)) then
light_on = true
col_alp = t.fg_colour
col_led = t.fg_led
if pct>=(100*t.alarm/t.max) and (pcb*pt)>(100*t.alarm/t.max) then
col_alp = t.alarm_colour
col_led = t.alarm_led
end
end
end

--set colors
--have to try to create gradients outside the loop ?
local pat

if not t.smooth then
if t.angle_bar==0 then
if t.led_effect=="e" then
pat = create_led_linear_gradient (-delta, 0,delta+ t.width,0,col_alp,col_led)
elseif t.led_effect=="a" then
pat = create_led_linear_gradient (t.width/2, -t.height/2+y1,t.width/2,0+t.height/2+y1,col_alp,col_led)
elseif t.led_effect=="r" then
pat = create_led_radial_gradient (t.width/2, y1, 0, t.width/2,y1,t.width/1.5,col_alp,col_led,2)
else
pat = cairo_pattern_create_rgba (rgb_to_r_g_b(col_alp))
end
else
if t.led_effect=="a" then
pat = create_led_radial_gradient (0, 0, t.radius+(t.height+t.space)*(pt-1),
0, 0, t.radius+(t.height+t.space)*(pt),
col_alp,col_led,3)
else
pat = cairo_pattern_create_rgba (rgb_to_r_g_b(col_alp))
end

end
else

if light_on then
if t.angle_bar==0 then
pat = create_smooth_linear_gradient(t.width/2, t.height/2, t.width/2,-(t.blocks-0.5)*(t.height+t.space))
else
pat = create_smooth_radial_gradient(0, 0, (t.height+t.space), 0,0,(t.blocks+1)*(t.height+t.space),2)
end
else
pat = cairo_pattern_create_rgba (rgb_to_r_g_b(t.bg_colour))
end
end
cairo_set_source (cr, pat)
cairo_pattern_destroy(pat)

--draw a block
if t.angle_bar==0 then
cairo_move_to(cr,0,y1)
cairo_line_to(cr,t.width,y1)
else
cairo_arc( cr,0,0,
t.radius+(t.height+t.space)*(pt)-t.height/2,
-t.angle_bar -math.pi/2 ,
t.angle_bar -math.pi/2)
end
cairo_stroke(cr)
end
end




local function setup_bar_graph()
--function used to retrieve the value to display and to set the cairo structure
if t.blocks ~=1 then t.y=t.y-t.height/2 end

local value = 0
if t.name ~="" then
value = tonumber(conky_parse(string.format('${%s %s}', t.name, t.arg)))
--$to_bytes doesn't work when value has a decimal point,
--https://garage.maemo.org/plugins/ggit/browse.php/?p=monky;a=commitdiff;h=174c256c81a027a2ea406f5f37dc036fac0a524b;hp=d75e2db5ed3fc788fb8514121f67316ac3e5f29f
--http://sourceforge.net/tracker/index.php?func=detail&aid=3000865&group_id=143975&atid=757310
--conky bug?
--value = (conky_parse(string.format('${%s %s}', t.name, t.arg)))
--if string.match(value,"%w") then
-- value = conky_parse(string.format('${to_bytes %s}',value))
--end
else
value = tonumber(t.arg)
end

if value==nil then value =0 end

pct = 100*value/t.max
pcb = 100/t.blocks

cairo_set_line_width (cr, t.height)
cairo_set_line_cap (cr, cap)
cairo_translate(cr,t.x,t.y)
cairo_rotate(cr,t.angle)

local matrix0 = cairo_matrix_t:create()
tolua.takeownership(matrix0)
cairo_matrix_init (matrix0, 1,t.skew_y,t.skew_x,1,0,0)
cairo_transform(cr,matrix0)



--call the drawing function for blocks
if t.blocks==1 and t.angle_bar==0 then
draw_single_bar()
if t.reflection=="t" or t.reflection=="b" then cairo_translate(cr,0,-t.height) end
else
draw_multi_bar()
end

--dot for reminder
--[[
if t.blocks ~=1 then
cairo_set_source_rgba(cr,1,0,0,1)
cairo_arc(cr,0,t.height/2,3,0,2*math.pi)
cairo_fill(cr)
else
cairo_set_source_rgba(cr,1,0,0,1)
cairo_arc(cr,0,0,3,0,2*math.pi)
cairo_fill(cr)
end]]

--call the drawing function for reflection and prepare the mask used
if t.reflection_alpha>0 and t.angle_bar==0 then
local pat2
local matrix1 = cairo_matrix_t:create()
tolua.takeownership(matrix1)
if t.angle_bar==0 then
pts={-delta/2,(t.height+t.space)/2,t.width+delta,-(t.height+t.space)*(t.blocks)}
if t.reflection=="t" then
cairo_matrix_init (matrix1,1,0,0,-t.reflection_scale,0,-(t.height+t.space)*(t.blocks-0.5)*2*(t.reflection_scale+1)/2)
pat2 = cairo_pattern_create_linear (t.width/2,-(t.height+t.space)*(t.blocks),t.width/2,(t.height+t.space)/2)
elseif t.reflection=="r" then
cairo_matrix_init (matrix1,-t.reflection_scale,0,0,1,delta+2*t.width,0)
pat2 = cairo_pattern_create_linear (delta/2+t.width,0,-delta/2,0)
elseif t.reflection=="l" then
cairo_matrix_init (matrix1,-t.reflection_scale,0,0,1,-delta,0)
pat2 = cairo_pattern_create_linear (-delta/2,0,delta/2+t.width,-0)
else --bottom
cairo_matrix_init (matrix1,1,0,0,-1*t.reflection_scale,0,(t.height+t.space)*(t.reflection_scale+1)/2)
pat2 = cairo_pattern_create_linear (t.width/2,(t.height+t.space)/2,t.width/2,-(t.height+t.space)*(t.blocks))
end
end
cairo_transform(cr,matrix1)

if t.blocks==1 and t.angle_bar==0 then
draw_single_bar()
cairo_translate(cr,0,-t.height/2)
else
draw_multi_bar()
end


cairo_set_line_width(cr,0.01)
cairo_pattern_add_color_stop_rgba (pat2, 0,0,0,0,1-t.reflection_alpha)
cairo_pattern_add_color_stop_rgba (pat2, t.reflection_length,0,0,0,1)
if t.angle_bar==0 then
cairo_rectangle(cr,pts[1],pts[2],pts[3],pts[4])
end
cairo_clip_preserve(cr)
cairo_set_operator(cr,CAIRO_OPERATOR_CLEAR)
cairo_stroke(cr)
cairo_mask(cr,pat2)
cairo_pattern_destroy(pat2)
cairo_set_operator(cr,CAIRO_OPERATOR_OVER)

end --reflection
pct,pcb=nil
end --setup_bar_graph()

--start here !
setup_bar_graph()
cairo_restore(cr)
end