SEARCH

Enter your search query in the box above ^, or use the forum search tool.

You are not logged in.

#5426 2013-05-23 18:25:57

tmq
#! Member
Registered: 2012-05-30
Posts: 84

Re: Conky v1.9 Thread

I can't seem to figure out how to make Conky's background semi-transparent...what variables do I need to change? I'm aiming for something like Pinguy's background setup - http://pinguyos.com/wp-content/uploads/ … esktop.jpg  Goal: make sure Conky shows up regardless of the wallpaper being used.

Offline

Help fund CrunchBang, donate to the project!

#5427 2013-05-24 07:26:01

easysid
#! CrunchBanger
From: India
Registered: 2013-01-25
Posts: 150

Re: Conky v1.9 Thread

tmq wrote:

I can't seem to figure out how to make Conky's background semi-transparent...what variables do I need to change? I'm aiming for something like Pinguy's background setup - http://pinguyos.com/wp-content/uploads/ … esktop.jpg  Goal: make sure Conky shows up regardless of the wallpaper being used.

If you are running a compositing WM, use in conkyrc

own_window_argb_visual yes
own_window_argb_value 70 #some value in [0,255]
own_window_color fd2310 # some color
own_window_transparent no

or, use this lua script, which does not require a compositing manager.
From Sector11's post at pinguyos. The guy is everywhere big_smile big_smile

draw-bg.lua

--[[Background originally by londonali1010 (2009)
ability to set any size for background mrpeachy 2011
ability to set variables for bg in conkyrc dk75

the change is that if you set width and/or height to 0
then it assumes the width and/or height of the conky window

so:

Above and After TEXT (requires a composite manager or it blinks!)

lua_load ~/wea_conky/draw_bg.lua
TEXT
${lua conky_draw_bg 10 0 0 0 0 0x000000 0.4}

OR Both above TEXT (no composite manager required - no blinking!)

lua_load ~/wea_conky/draw_bg.lua
lua_draw_hook_pre draw_bg 10 0 0 0 0 0x000000 0.5
TEXT

Note
${lua conky_draw_bg 20 0 0 0 0 0x000000 0.4}
See below: 1 2 3 4 5 6 7

${lua conky_draw_bg corner_radius x_position y_position width height color alpha}

covers the whole window and will change if you change the minimum_size setting

1 = 20 corner_radius
2 = 0 x_position
3 = 0 y_position
3 = 0 width
5 = 0 height
6 = 0x000000 color
7 = 0.4 alpha

######### calendar function ##################################################

then to use it, you activate the calendar function BELOW TEXT like this

${lua luacal {settings}}

#${lua luacal {x=,y=,tf="",tfs=,tc=,ta=,bf="",bfs=,bc=,ba=,hf="",hfs=,hc=,ha=,sp="",gh=,gt=,gv=,sd=}}
# x=x position top left
# y=y position top left
# tf=title font, eg "mono" must be in quotes
# tfs=title font size
# tc=title color
# ta=title alpha
# bf=body font, eg "mono" must be in quotes
# bfs=body font size
# bc=body color
# ba=body alpha
# hf=highlight font, eg "mono" must be in quotes
# hfs=highlight font size
# hc=highlight color
# ha=highlight alpha
# sp=spacer, eg " " or sp="0"... 0,1 or 2 spaces can help with positioning of non-monospaced fonts

# gt=gap from title to body
# gh=gap horizontal between columns
# gv=gap vertical between rows
# sd=start day, 0=Sun, 1=Mon

# hstyle = heading style, 0=just days, 1=date insert
# tdf=title date font, eg "mono" must be in quotes
# tdfs=title date font size
# tdc=title date color
# tda=title date alpha

# test line
-- ${lua luacal {x=10,y=100,tf="Purisa",tfs=24,tc=0xf67e16,ta=1,bf="First Order",bfs=26,bc=0xecd32a,ba=1,hf="Purisa",hfs=18,hc=0xf67e16,ha=1,sp=" ",gh=40,gt=25,gv=20,sd=0,hstyle=1,tdf="First Order",tdfs=28,tdc=0xff0000,tda=1}}


]]

require 'cairo'
local cs, cr = nil
function rgb_to_r_g_b(colour,alpha)
return ((colour / 0x10000) % 0x100) / 255., ((colour / 0x100) % 0x100) / 255., (colour % 0x100) / 255., alpha
end
function conky_draw_bg(r,x,y,w,h,color,alpha)
if conky_window == nil then return end
if cs == nil then cairo_surface_destroy(cs) end
if cr == nil then cairo_destroy(cr) 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)
w=w
h=h
if w=="0" then w=tonumber(conky_window.width) end
if h=="0" then h=tonumber(conky_window.height) end
cairo_set_source_rgba (cr,rgb_to_r_g_b(color,alpha))
--top left mid circle
local xtl=x+r
local ytl=y+r
--top right mid circle
local xtr=(x+r)+((w)-(2*r))
local ytr=y+r
--bottom right mid circle
local xbr=(x+r)+((w)-(2*r))
local ybr=(y+r)+((h)-(2*r))
--bottom right mid circle
local xbl=(x+r)
local ybl=(y+r)+((h)-(2*r))
-----------------------------
cairo_move_to (cr,xtl,ytl-r)
cairo_line_to (cr,xtr,ytr-r)
cairo_arc(cr,xtr,ytr,r,((2*math.pi/4)*3),((2*math.pi/4)*4))
cairo_line_to (cr,xbr+r,ybr)
cairo_arc(cr,xbr,ybr,r,((2*math.pi/4)*4),((2*math.pi/4)*1))
cairo_line_to (cr,xbl,ybl+r)
cairo_arc(cr,xbl,ybl,r,((2*math.pi/4)*1),((2*math.pi/4)*2))
cairo_line_to (cr,xtl-r,ytl)
cairo_arc(cr,xtl,ytl,r,((2*math.pi/4)*2),((2*math.pi/4)*3))
cairo_close_path(cr)
cairo_fill (cr)
------------------------------------------------------------
cairo_surface_destroy(cs)
cairo_destroy(cr)
return ""
end
-- ###### calendar function ##################################################
function conky_luacal(caltab) -- {x=,y=,tf="",tfs=,tc=,ta=,bf="",bfs=,bc=,ba=,hf="",hfs=,hc=,ha=,sp="",gt=,gh=,gv=,sd=,hstyle=,tdf=,tdfs=,tdc=,tda=}
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)
--############################################################################
if caltab.x==nil then
caltab=loadstring("return" .. caltab)()
end
local cal_x=caltab.x
local cal_y=caltab.y
local tfont=caltab.tf or "mono"
local tfontsize=caltab.tfs    or 12
local tc=caltab.tc or 0xffffff
local ta=caltab.ta or 1
local bfont=caltab.bf or "mono"
local bfontsize=caltab.bfs    or 12
local bc=caltab.bc or 0xffffff
local ba=caltab.ba or 1
local hfont=caltab.hf or "mono"
local hfontsize=caltab.hfs    or 12
local hc=caltab.hc or 0xff0000
local ha=caltab.ha or 1
local spacer=caltab.sp or " "
local gaph=caltab.gh or 20
local gapt=caltab.gt or 15
local gapl=caltab.gv or 15
local sday=caltab.sd or 0
local hstyle=caltab.hstyle    or 0
--convert colors
--local font=string.gsub(font,"_"," ")
local tred,tgreen,tblue,talpha=rgb_to_r_g_b(tc,ta)
--main body text color
local bred,bgreen,bblue,balpha=rgb_to_r_g_b(bc,ba)
--highlight text color
local hred,hgreen,hblue,halpha=rgb_to_r_g_b(hc,ha)
--############################################################################
--calendar calcs
local year=os.date("%G")
local today=tonumber(os.date("%d"))
local t1 = os.time( { year=year,month=03,day=01,hour=00,min=0,sec=0} );
local t2 = os.time( { year=year,month=02,day=01,hour=00,min=0,sec=0} );
local feb=(os.difftime(t1,t2))/(24*60*60)
local monthdays={ 31, feb, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31 }
local day=tonumber(os.date("%w"))+1-sday
local day_num = today
local remainder=day_num % 7
local start_day=day-(day_num % 7)
if start_day<0 then start_day=7+start_day end
local month=os.date("%m")
local mdays=monthdays[tonumber(month)]
local x=mdays+start_day
local dnum={}
local dnumh={}
if mdays+start_day<36 then
dlen=35
plen=29
else
dlen=42
plen=36
end
for i=1,dlen do
if i<=start_day then
dnum[i]=" "
else
dn=i-start_day
if dn=="nil" then dn=0 end
if dn<=9 then dn=(spacer .. dn) end
if i>x then dn="" end
dnum[i]=dn
dnumh[i]=dn
if dn==(spacer .. today) or dn==today then
dnum[i]=""
end
if dn==(spacer .. today) or dn==today then
dnumh[i]=dn
place=i
else dnumh[i]=" "
end
end
end--for
cairo_select_font_face (cr, tfont, CAIRO_FONT_SLANT_NORMAL, CAIRO_FONT_WEIGHT_NORMAL);
cairo_set_font_size (cr, tfontsize);
cairo_set_source_rgba (cr,tred,tgreen,tblue,talpha)
local extents=cairo_text_extents_t:create()
tolua.takeownership(extents)
if hstyle==0 then
if tonumber(sday)==0 then
dys={"SU","MO","TU","WE","TH","FR","SA"}
else
dys={"MO","TU","WE","TH","FR","SA","SU"}
end
--draw calendar titles
elseif hstyle==1 then
if tonumber(sday)==0 then
dys={"SU","MO"," "," "," ","FR","SA"}
cairo_text_extents(cr,"MO",extents)
local s=extents.x_advance+gaph
local f=gaph*5
local tdfont=caltab.tdf or "mono"
local tdfontsize=caltab.tdfs or 12
local tdc=caltab.tdc or 0xffffff
local tda=caltab.tda or 1
cairo_select_font_face (cr, tdfont, CAIRO_FONT_SLANT_NORMAL, CAIRO_FONT_WEIGHT_NORMAL);
cairo_set_font_size (cr, tdfontsize);
local tdred,tdgreen,tdblue,tdalpha=rgb_to_r_g_b(tdc,tda)
cairo_set_source_rgba (cr,tdred,tdgreen,tdblue,tdalpha)
local insert=os.date("%b %y")
cairo_text_extents(cr,insert,extents)
local w=extents.x_advance
cairo_move_to (cr, cal_x+((s+f)/2)-(w/2), cal_y)
cairo_show_text (cr,insert)
cairo_stroke (cr)
else
dys={"MO","TU"," "," "," ","SA","SU"}
cairo_text_extents(cr,"TU",extents)
local s=extents.x_advance+gaph
local f=gaph*5
local tdfont=caltab.tdf or "mono"
local tdfontsize=caltab.tdfs or 12
local tdc=caltab.tdc or 0xffffff
local tda=caltab.tda or 1
cairo_select_font_face (cr, tdfont, CAIRO_FONT_SLANT_NORMAL, CAIRO_FONT_WEIGHT_NORMAL);
cairo_set_font_size (cr, tdfontsize);
local tdred,tdgreen,tdblue,tdalpha=rgb_to_r_g_b(tdc,tda)
cairo_set_source_rgba (cr,tdred,tdgreen,tdblue,tdalpha)
local insert=os.date("%b %y")
cairo_text_extents(cr,insert,extents)
local w=extents.x_advance
cairo_move_to (cr, cal_x+((s+f)/2)-(w/2), cal_y)
cairo_show_text (cr,insert)
cairo_stroke (cr)
end
end
--draw calendar titles
for i=1,7 do
cairo_select_font_face (cr, tfont, CAIRO_FONT_SLANT_NORMAL, CAIRO_FONT_WEIGHT_NORMAL);
cairo_set_font_size (cr, tfontsize);
cairo_set_source_rgba (cr,tred,tgreen,tblue,talpha)
cairo_move_to (cr, cal_x+(gaph*(i-1)), cal_y)
cairo_show_text (cr, dys[i])
cairo_stroke (cr)
end
--draw calendar body
cairo_select_font_face (cr, bfont, CAIRO_FONT_SLANT_NORMAL, CAIRO_FONT_WEIGHT_NORMAL);
cairo_set_font_size (cr, bfontsize);
cairo_set_source_rgba (cr,bred,bgreen,bblue,balpha)
for i=1,plen,7 do
local fn=i
for i=fn,fn+6 do
cairo_move_to (cr, cal_x+(gaph*(i-fn)),cal_y+gapt+(gapl*((fn-1)/7)))
cairo_show_text (cr, dnum[i])
cairo_stroke (cr)
end
end
--highlight
cairo_select_font_face (cr, hfont, CAIRO_FONT_SLANT_NORMAL, CAIRO_FONT_WEIGHT_NORMAL);
cairo_set_font_size (cr, hfontsize);
cairo_set_source_rgba (cr,hred,hgreen,hblue,halpha)
for i=1,plen,7 do
local fn=i
for i=fn,fn+6 do
cairo_move_to (cr, cal_x+(gaph*(i-fn)),cal_y+gapt+(gapl*((fn-1)/7)))
cairo_show_text (cr, dnumh[i])
cairo_stroke (cr)
end
end
--############################################################################
caltab=nil
dlen=nil
plen=nil
cairo_destroy(cr)
cairo_surface_destroy(cs)
cr=nil
return ""
end
-- end main function #########################################################

Offline

#5428 2013-05-25 17:19:30

Nili
#! Die Hard
From: 127.0.0.1
Registered: 2013-03-20
Posts: 811
Website

Re: Conky v1.9 Thread

Hello, could anyone help me with this Cal code

${color FFFFFF}${font monospace:size=5.6}${execpi 60 VinDSL_Cal_8=`date +%-d`; cal -h | sed -e '1d' -e 's/\<'"$VinDSL_Cal_8"'\>/${color FF668C}&${color 336699}/' -e 's/^/${offset 3}/'}${font}${color}

i want to add color on the actual day as it is per date.

Thanks in Advance!


# Debian GNU/Linux 8:8.2 (netinst/stable)
# Packages Installed: 541
# Linux debian 3.16.0-4-686-pae #1 SMP Debian 3.16.7-ckt11-1+deb8u4 (2015-09-19) i686 GNU/Linux
# Startup finished in 2.850s (kernel) + 6.473s (userspace) = 9.324s

Offline

#5429 2013-05-25 21:39:39

Sector11
#!'er to BL'er
From: SR11 Cockpit
Registered: 2010-05-05
Posts: 15,667
Website

Re: Conky v1.9 Thread

Nili wrote:

Hello, could anyone help me with this Cal code

${color FFFFFF}${font monospace:size=5.6}${execpi 60 VinDSL_Cal_8=`date +%-d`; cal -h | sed -e '1d' -e 's/\<'"$VinDSL_Cal_8"'\>/${color FF668C}&${color 336699}/' -e 's/^/${offset 3}/'}${font}${color}

i want to add color on the actual day as it is per date.

Thanks in Advance!

${color FFFFFF}${font monospace:size=5.6}${execpi 60 VinDSL_Cal_8=`date +%-d`; cal -h | sed -e '1d' -e 's/\<'"$VinDSL_Cal_8"'\>/${color FF668C}&${color FFFFFF}/' -e 's/^/${offset 3}/'}${font}${color}

make the start and end colour the same ${color FFFFFF} any colour you want

Today's colour above is: ${color FF668C} - change that for whatever colour you want.

Mine is different but the principle is the same:

${goto 30}SU MO ${color6}${time %b %Y}${color} FR SA
${goto 30}${color}${execp LAR=`date +%-d`; ncal -bh | sed '2d' | sed -e '1d' -e 's/\<'$LAR'\>/${color6}&${color}/' | sed ':a;N;$!ba;s/\n/\n${goto 30}/g'}

abfHr4rr.jpg


·  ↓   ↓   ↓   ↓   ↓   ↓  ·
BunsenLabs Forums now Open for Registration
·  ↑   ↑   ↑   ↑   ↑   ↑  · BL ModSquad

Offline

#5430 2013-05-26 01:43:43

Folg
Member
Registered: 2013-05-25
Posts: 15

Re: Conky v1.9 Thread

Simple setup, I like to keep it clean. If I remember correctly most of the code came from Andreas his setup, removed the weather forecast part and edited the cpu and battery stats to show current running speed and battery time remaining.

# Use Xft?
use_xft yes
xftfont Trebuchet MS:size=8
xftalpha 0.8
text_buffer_size 2048

# 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 desktop
    own_window_hints undecorated,below,sticky,skip_taskbar,skip_pager
    

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

# Minimum size of text area
minimum_size 180 0

# Draw shades?
draw_shades no

# Draw outlines?
draw_outline no

# Draw borders around text
draw_borders no

# Stippled borders?
stippled_borders 0

# border margins
border_margin 5

# border width
border_width 1

# Default colors and also border colors
default_color white
own_window_colour white

# Text alignment, other possible values are commented
alignment top_right

# Gap between borders of screen and text
# same thing as passing -x at command line
gap_x 35
gap_y 50

# 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 1

# 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 none

TEXT
SYSTEM ${hr 2}

Kernel:  ${alignr}${kernel}
CPU1: ${freq_g cpu0}/${cpu cpu0}% ${alignr}${cpubar 8,60 cpu}
CPU2: ${freq_g cpu1}/${cpu cpu1}% ${alignr}${cpubar 8,60 cpu}
RAM: $mem/$memperc% ${alignr}${membar 8,60}
Battery: ${battery_percent BAT0}% ${alignr}${battery_bar 8,60 BAT0}
Time remaining: ${alignr}${battery_time BAT0}
Uptime: ${alignr}${uptime}

DATE ${hr 2}

${alignc 35}${font Trebuchet MS:size=26}${time %H:%M}${font}
${alignc}${time %a %d %b %Y}

HD ${hr 2}

Home:
${fs_free /home}/${fs_size /home} ${alignr}${fs_bar 8,60 /home}

${if_existing /proc/net/route wlan0}NETWORK ${hr 2}

Up: ${upspeed wlan0} kb/s ${alignr}${upspeedgraph wlan0 8,60 789E2D A7CC5C}
Down: ${downspeed wlan0} kb/s ${alignr}${downspeedgraph wlan0 8,60 789E2D A7CC5C}
Upload: ${alignr}${totalup wlan0}
Download: ${alignr}${totaldown wlan0}
Signal: ${wireless_link_qual wlan0}% ${alignr}${wireless_link_bar 8,60 wlan0}${else}${if_existing /proc/net/route eth0}
Up: ${upspeed eth0} kb/s ${alignr}${upspeedgraph eth0 8,60 789E2D A7CC5C}
Down: ${downspeed eth0} kb/s ${alignr}${downspeedgraph eth0 8,60 789E2D A7CC5C}
Upload: ${alignr}${totalup eth0}
Download: ${alignr}${totaldown eth0}${endif}${else}${if_existing /proc/net/route eth1}
Up: ${upspeed eth1} kb/s ${alignr}${upspeedgraph eth1 8,60 789E2D A7CC5C}
Down: ${downspeed eth1} kb/s ${alignr}${downspeedgraph eth1 8,60 789E2D A7CC5C}
Upload: ${alignr}${totalup eth1}
Download: ${alignr}${totaldown eth1}${endif}${else}${font PizzaDude Bullets:size=14}4${font}   Network Unavailable${endif}
  

screenshot-05262013-032502am.php

Edit: changed the code slightly so when there's no network connection that part doesn't show.

Last edited by Folg (2013-05-26 07:44:22)

Offline

#5431 2013-05-26 05:43:51

chepioq
#! Member
Registered: 2013-01-09
Posts: 79

Re: Conky v1.9 Thread

Here my calendar with moon phase
1369546220.png

It's a calendar in lua (create by wlourf), with moon phase image from static.die.net.

The conkyrc

# -- Conky settings -- #
background no
total_run_times 0
update_interval 3600

cpu_avg_samples 2
net_avg_samples 2

override_utf8_locale yes

double_buffer yes
no_buffers yes

text_buffer_size 2048
imlib_cache_size 0

# -- Window specifications -- #

own_window yes
#own_window_type normal
own_window_transparent yes
own_window_hints undecorate,skip_taskbar,skip_pager,below
own_window_argb_visual yes
#own_window_colour FFFFFF
#own_window_title square to round

border_inner_margin 0
border_outer_margin 0

minimum_size 300 220

alignment tr
gap_y 30
gap_x 50

# -- Text settings -- #
use_xft yes
xftfont Santana:size=12
xftalpha 0.5

uppercase no

default_color 000000
text_buffer_size 2048 
imlib_cache_size 0 
#--- LUA ---
lua_load ~/.conkyrc/conky15/square_to_round.lua /home/dominique/.conkyrc/conky15/calendar.lua
lua_draw_hook_pre calendar_box
lua_draw_hook_post main /home/dominique/.conkyrc/conky15/moon-phase/moon.jpg

TEXT
${time %t}
${execpi 3600 ~/.conkyrc/conky15/get_image.sh}
${font URW Chancery L:size=11}${color #30BAFF}${voffset 120}${execpi 3600 ~/.conkyrc/conky15/phase.sh}

calendar.lua

--[[Calendar Box by wlourf v.1.0 15/05/2010:
Parameters are explained with images on this page :
http://u-scripts.blogspot.com/2010/05/calendar-box.html

This widget draw a calendar in your conky.
You need conky 1.8.0+ to run it. and set theses conky settings:
own_window_transparent yes
own_window_argb_visual yes

In the conky, before TEXT section:
lua_load ~/scripts/calendar/calendar.lua
lua_draw_hook_pre calendar_box

]]

require 'cairo'


calendar_file= "/home/dominique/.conkyrc/conky15/calendar.txt"	

function conky_calendar_box()

--settings are set in this table, cal_settings, 4 parameters are mandatory :
--x,y,font and font_size,
--others parameters are optionals
 	
	cal_settings={
	
		{
		x=120,		--x of top left corner, relative to conky window
		y=10,		--y of top left corner, relative to conky window
		font="MgOpen Modata",		--font to use
		font_size=12,		--font size to use
			
		month_format="%B %Y", --month format, see http://www.lua.org/pil/22.1.html for available formats, default="%B"
		days_number=2,		  --number of letters for days (monday ...), default = 1

		days_position="t",		-- position of boxes "Days" (t/b) top or bottom, default=t
		month_position="t",		-- position of box "Month" (t/b/l/r) top, bottom, left or right, default=t
		two_digits=false,		-- display numbers with two digits (true/false), default=false
		alignment="c",			-- alignment of days numbers (c/r/l), default= c
			
		month_offset=0,		-- month offset relative to actual month, default=0
		
		display_others_days=false, --display days numbers of previous and next months, default=true
		
		hpadding=1,		--horizontal space beetween border and text, default=2 pixels
		vpadding=0,		--vertical space beetween border and text, default=2 pixels
		border=0,		--border size, default=0 pixels
		gap=4,			--space betwwen 2 boxes, default=2 pixels
		radius=0,		--radius of corners, default=0 pixels
		--orientation ="nn", -- orientation of gradient, possibles values = nn, ne,ee,se,ss,sw,ww,nw, default="nn"
		--gradient=0,  --default linear(=0) or radial gradient percentage (0-1) of box side
	
		--colors tables
		--format for boxes  {colour1, colour2, alpha1,alpha2,border1,border2,alpha border1,alpha border2}
		--format for texts  {colour1, colour2, alpha1,alpha2}

		--colBox = {0xFFFFFF,0x0000FF,1,1,0x0000FF,0x00FFFF,0.5,0.5}, --color of standard box
		colBoxText  ={0x30BAFF,0x30BAFF,1,1},    					--color of text numbers
		colBoxTextOM = {0x000000,0x000000,0.0,0.5},   				--color of numbers for other month
	
		--colDays = {0xFFFFFF,0xFF0000,1,1,0x0000FF,0x00FF00,1,1},    --color of boxes "Days" (Monday ...)
		colDaysText  ={0x0003E5,0x09EFFF,1,1},     				--color of days (Monday ...)
	
		--colBoxTD  = {0xFFFFFF,0x00FF00,1,1,0xFF00FF,0x00FF00,1,1},  --color of box "Today"
		colBoxTextTD = {0xF21804,0xAA0B02,1,1},	   				--color of text "today"
	
		--colBoxBH  = {0xFFFFFF,0xFF0000,1,1,0xFF00FF,0x00FF00,1,1}, --color of box "Bank holiday"
		colBoxTextBH = {0x30BAFF,0x30BAFF,1,1},	   				--color of text holiday
	
		--colMonth = {0xFFFFFF,0x00FFFF,1,1,0x0000FF,0x00FF00,1,1},   --color of box "Month"
		colMonthText  = {0x0003E5,0x09EFFF,1,1},   					--color of text "Month"
	
		display_info_box=true,			--affiche la boite info (default=false)
		file_info="/tmp/info.txt",		--read first line of this file and display it box "info"
										--if file not found, use calendar.txt
		--colInfo = {0xFF0000,0x0000FF,1,1,0x0000FF,0x00FFFF,0.5,0.5}, --color of box "info"
		colInfoText = {0x30BAFF,0x30BAFF,1,1},						--color of text "info"
		info_position="b",   			--position of box info  (t/b/l/r) top, bottom, left or right, default=b
		display_empty_info_box=true,	--if no info to display , display or not info the box, default=false	
		},

	}

--FIN DES PARAMETRES ------------------


	if conky_window == nil then return end
	--if tonumber(conky_parse("$updates"))<3 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)
	
    for i,v in pairs(cal_settings) do
        x,y=draw_calendar(v)
	end
	    
	cairo_destroy(cr)
	cairo_surface_destroy(cs)
	collectgarbage()

end



function draw_square(cr,x,y,width,height,radius)
	local degrees = math.pi / 180.0
	radius=tonumber(radius)

	cairo_new_sub_path (cr);
	if radius>0 then
		cairo_arc (cr, x + width - radius, y + radius, radius, -90 * degrees, 0 * degrees);
		cairo_arc (cr, x + width - radius, y + height - radius, radius, 0 * degrees, 90 * degrees);
		cairo_arc (cr, x + radius, y + height - radius, radius, 90 * degrees, 180 * degrees);
		cairo_arc (cr, x + radius, y+ radius, radius, 180 * degrees, 270 * degrees);
	else
		cairo_rectangle(cr,x,y,width,height)
	end
	cairo_close_path (cr);

	return 
end


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


function create_pattern(cr,x,y,w,h,tCol,orientation,gradient)
	if gradient~=0  then
		create_pattern_radial(cr,x,y,w,h,tCol,orientation,gradient)
	else
		create_pattern_linear(cr,x,y,w,h,tCol,orientation)
	end
end

function create_pattern_linear(cr,x,y,w,h,tCol,orientation)
	col0,col1,alpha0,alpha1=tCol[1],tCol[2],tCol[3],tCol[4]

	if orientation=="nn" then
		p={x+w/2,y,x+w/2,y+h}
	elseif orientation=="ne" then
		p={x+w,y,x,y+h}
	elseif orientation=="ee" then
		p={x+w,y+h/2,x,y+h/2}		
	elseif orientation=="se" then
		p={x+w,y+h,x,y}		
	elseif orientation=="ss" then
		p={x+w/2,y+h,x+w/2,y}
	elseif orientation=="sw" then
		p={x,y+h,x+w,y}
	elseif orientation=="ww" then
		p={x,y+h/2,x+w,y+h/2}
	else
		p={x,y,x+w,y+h}	
	end
		
	local pat = cairo_pattern_create_linear (p[1],p[2],p[3],p[4])
	cairo_pattern_add_color_stop_rgba (pat, 0, rgb_to_r_g_b(col0,alpha0))
	cairo_pattern_add_color_stop_rgba (pat, 1, rgb_to_r_g_b(col1,alpha1))
	cairo_set_source (cr, pat)
	cairo_pattern_destroy(pat)
end

function create_pattern_radial(cr,x,y,w,h,tCol,orientation,gradient)
	local col0,col1,alpha0,alpha1=tCol[1],tCol[2],tCol[3],tCol[4]
	local decn=gradient
	local dec=1-decn
	if orientation=="nn" then
		p={x+w/2,y+h*decn}
	elseif orientation=="ne" then
		p={x+w*dec,y+h*decn}
	elseif orientation=="ee" then
		p={x+w*dec,y+h/2}		
	elseif orientation=="se" then
		p={x+w*dec,y+h*dec}		
	elseif orientation=="ss" then
		p={x+w/2,y+h*dec}
	elseif orientation=="sw" then
		p={x+w*decn,y+h*dec}
	elseif orientation=="ww" then
		p={x+w*decn,y+h/2}
	else
		p={x+w*(1-dec),y+h*(1-dec)}	
	end

	local radius = w/dec 
	if h>w then radius=h/dec end
	local pat = cairo_pattern_create_radial (p[1],p[2],0,p[1],p[2],radius)
	cairo_pattern_add_color_stop_rgba (pat, 0, rgb_to_r_g_b(col0,alpha0))
	cairo_pattern_add_color_stop_rgba (pat, 1, rgb_to_r_g_b(col1,alpha1));
	cairo_set_source (cr, pat);
	cairo_pattern_destroy(pat)
end

function draw_frame (x0,y0,width,height,tCol,radius,border,orientation,gradient)

	cairo_set_operator(cr,CAIRO_OPERATOR_SOURCE)
	create_pattern(cr,x0,y0,width,height,{tCol[5],tCol[6],tCol[7],tCol[8]},orientation,gradient)
	draw_square(cr,x0,y0,width,height,radius)
	cairo_set_line_width(cr,border)
	cairo_fill (cr)

	--cairo_set_operator(cr,CAIRO_OPERATOR_CLEAR)
	create_pattern(cr,x0,y0,width,height,{tCol[1],tCol[2],tCol[3],tCol[4]},orientation,gradient)
	draw_square(cr,x0+border,y0+border,width-border*2,height-border*2,radius)
	cairo_fill (cr)
	cairo_set_operator(cr,CAIRO_OPERATOR_OVER)	
	
	if tCol[2]>0 or tCol[3]>0 then
		cairo_set_operator(cr,CAIRO_OPERATOR_OVER)
	else
		cairo_set_operator(cr,CAIRO_OPERATOR_CLEAR)
	end
	create_pattern(cr,x0,y0,width,height,{tCol[1],tCol[2],tCol[3],tCol[4]},orientation,gradient)
	draw_square(cr,x0+border,y0+border,width-border*2,height-border*2,radius)
	cairo_fill (cr)
	cairo_set_operator(cr,CAIRO_OPERATOR_OVER)

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 draw_calendar(t)
	local te=cairo_text_extents_t:create()
	if t.font==nil or t.x==nil or t.y == nil or t.font_size == nil then
		print ("Error in settings")
		return 
	end
	
	--check values or set default values
	x0,y0=t.x,t.y
	if t.two_digits then str_format="%02d" else str_format="%d" end
	if t.month_format==nil then t.month_format = "%B" end
	if t.hpadding==nil then t.hpadding=2 end
	if t.vpadding==nil then t.vpadding=2 end
	if t.border==nil then t.border=0 end		
	if t.month_offset==nil then t.month_offset=0 end
	if t.gap==nil then t.gap=2 end
	if t.radius==nil then t.radius=0 end
	if t.days_number==nil then t.days_number=1 end
	if t.display_others_days==nil then t.display_others_days=true end
	if t.gradient==nil then t.gradient=0 end
	if t.display_info_box == nil then t.display_info_box=false end
	if t.display_empty_info_box == nil then t.display_empty_info_box=false end

	local orientation="nn"
	for i,v in ipairs({"nn","ne","ee","se","ss","sw","ww","nw"}) do 
		if v==t.orientation then orientation=v end
	end
	local alignment ="c"
	for i,v in ipairs({"l","c","r"}) do 
		if v==t.alignment then alignment=v end
	end
	local month_position="t"
	for i,v in ipairs({"t","b","l","r"}) do 
		if v==t.month_position then month_position=v end
	end
	local days_position="t"
	for i,v in ipairs({"t","b","l","r"}) do 
		if v==t.days_position then days_position=v end
	end
	local info_position="b"
	for i,v in ipairs({"t","b","l","r"}) do 
		if v==t.info_position then info_position=v end
	end
	
	function table.copy(t)
		local t2 = {}
		for k,v in pairs(t) do
			t2[k] = v
		end
		return t2
	end

	if t.colBox ~= nil and #t.colBox ~=8 then t.colBox=nil end
	if t.colDays ~= nil and #t.colDays ~=8 then t.colDays=nil end	
	if t.colMonth ~= nil and#t.colMonth ~=8 then t.colMonth=nil end	
	if t.colBoxTD ~= nil and #t.colBoxTD ~=8 then t.colBoxTD=nil end
	if t.colBoxBH ~= nil and #t.colBoxBH ~=8 then t.colBoxBH=nil end
	if t.colInfo ~= nil and #t.colInfo ~=8 then t.colInfo=nil end	
	if t.colBoxText ~= nil and #t.colBoxText ~= 4 then t.colBoxText=nil end
	if t.colBoxTextOM ~= nil and #t.colBoxTextOM ~=4 then t.colBoxText=nil end
	if t.colBoxTextTD ~= nil and #t.colBoxTextTD ~= 4 then t.colBoxTextTD=nil end
		
	if t.colDaysText ~= nil and #t.colDaysText ~= 4 then t.colDaysText=nil end
	if t.colMonthText ~= nil and #t.colMonthText ~= 4 then t.colMonthText=nil end
	if t.colInfoText ~= nil and #t.colInfoText ~= 4 then t.colInfoText=nil end	

	if t.colBox == nil then t.colBox = {0x000000,0xFFFFFF,0,0,0xFFFFFF,0x000000,0,0} end
	if t.colDays == nil then t.colDays = table.copy(t.colBox) end
	if t.colMonth == nil then t.colMonth = table.copy(t.colBox) end
	if t.colInfo == nil then t.colInfo = t.colBox end
	if t.colBoxTD == nil then t.colBoxTD = {t.colBox[2],t.colBox[1],t.colBox[3],t.colBox[4],t.colBox[6],t.colBox[5],t.colBox[7],t.colBox[8]}end
	if t.colBoxBH == nil then t.colBoxBH = t.colBox end
	if t.colBoxText == nil	then t.colBoxText = {0x000000,0x000000,1,1} end
	if t.colBoxTextOM == nil then t.colBoxTextOM = {0x000000,0x000000,0.2,0.2} end
	if t.colBoxTextTD == nil then t.colBoxTextTD = {0x0000FF,0x0000FF,1,1} end
	if t.colBoxTextBH == nil then t.colBoxTextBH = {0xFF0000,0xFF0000,1,1} end
	if t.colDaysText == nil	then t.colDaysText = {0x999999,0x999999,1,1} end
	if t.colMonthText == nil	then t.colMonthText = {0x333333,0x333333,1,1} end
	if t.colInfoText == nil	then t.colInfoText = {0x333333,0x333333,1,1} end
	
	--calculate maximum size of a square
	local maxSide=0
	cairo_select_font_face(cr, t.font, CAIRO_FONT_SLANT_NORMAL, CAIRO_FONT_WEIGHT_NORMAL)
	cairo_set_font_size(cr,t.font_size)
	for d=1,31 do
		cairo_text_extents (cr,string.format(str_format,d),te)
		maxSide = math.max(maxSide,te.width+te.x_bearing+2*t.hpadding,te.height+te.y_bearing+2*t.vpadding)
	end
	maxSide=maxSide+2*t.border

	

   -- Compute what day it was the first of the month (0=Monday)
   -- from conky wiki
   dtable = os.date("*t")
   --this month table
   mtable=dtable
   mtable.month=dtable.month+t.month_offset
   mtable = os.date("*t",os.time(mtable))
   day,wday = mtable.day, mtable.wday
   first_day = wday - 2 - (day-1) % 7
   if first_day < 0 then first_day = first_day + 7 end
   
   local txt_month = os.date(t.month_format, os.time(mtable))
   txt_month = string.upper(string.sub(txt_month,1,1)) .. string.sub(txt_month,2)
   
	function get_days_in_month(month, year)
		local days_in_month = { 31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31 }   
		local d = days_in_month[month]

		-- check for leap year
		if (month == 2) then
			if (math.mod(year,4) == 0) then
				if (math.mod(year,100) == 0)then                
					if (math.mod(year,400) == 0) then                    
						d = 29
					end
				else                
					d = 29
				end
			end
		end

		return d  
	end
	last_day=get_days_in_month(mtable.month, mtable.year)
	
	lpdtable=mtable
    lpdtable.month=lpdtable.month-1
    mtable = os.date("*t",os.time(lpdtable))
    if lpdtable.month==0 then lpdtable.month=12 end
	
    last_p_day=get_days_in_month(lpdtable.month,lpdtable.year)
   	mtable.month=lpdtable.month+1
   	mtable = os.date("*t",os.time(mtable))

	--read the calendar file
	local file = io.open(calendar_file,"r")	
	local tabcal={}	
	local idx=1
	local line,lineok="",""
	local txt_info=""
	if file ~= nil then
		while true do
		 	line = file:read("*l")
			if line == nil then break end
			lineok = string.split(line,";")
			if (#lineok)==3 then
				tabcal[idx]={lineok[1],lineok[2],lineok[3]}
				idx=idx+1
				if lineok[1] == os.date("%m%d", os.time()) then
					txt_info=lineok[3]
				end
			end
		end
	end
	
	if not t.display_empty_info_box and txt_info=="" then
		t.display_info_box =false
	end
	if not t.display_info_box then 	info_position="b" end
	
	local nblines=idx-1
	io.close()
	
	
	
	--define text for days
	tdays={}
	for i=4,11 do
		table.insert(tdays,os.date("%A", os.time{year=2010, month=1, day=i}))
	end
	for i=1,7 do
		tdays[i]=string.upper(string.sub(tdays[i],1,1)) .. string.sub(tdays[i],2)
		tdays[i]=(string.sub(tdays[i],1,math.max(t.days_number,1)))
	end

	local display_day=true
	--draw numbers boxes
    local flagEnd=0
    d=0
	for r=0,5 do
		if flagEnd>0 then break end
		for c=0,6 do
			d=d+1
			X=x0+c*maxSide+t.gap*c
			Y=y0+r*maxSide+t.gap*r
			if month_position=="t" then	
				Y=Y+maxSide+t.gap 
			elseif month_position=="l" then
				X=X+maxSide+t.gap
			end
			if info_position=="t" then	
				Y=Y+maxSide+t.gap 
			elseif info_position=="l" then
				X=X+maxSide+t.gap
			end

			if days_position=="t" then
				Y=Y+maxSide+t.gap 
			end

			--bank holiday or not ?
			mtable.day=d-first_day
			md = os.date("%m%d", os.time(mtable))
			local flagBH = false
			for idy=1,nblines do
				if tabcal[idy][1] == md then
					if tabcal[idy][2] == "1" then
						flagBH = true
					end
					break
				end
			end
							
			--draw frames
			local colorBox=t.colBox
			if dtable.day == d-first_day and t.month_offset==0 then
				colorBox=t.colBoxTD
			elseif flagBH then
				colorBox=t.colBoxBH
			end
			draw_frame (X,Y,maxSide,maxSide,colorBox,t.radius,t.border,orientation,t.gradient)			
			
			--format _text
			if d<=first_day  then  									--days before
				create_pattern(cr,X,Y,maxSide*(1-t.gradient),maxSide*(1-t.gradient),t.colBoxTextOM,orientation,t.gradient)
				txt_date=last_p_day-first_day+d
				display_day=t.display_others_days
			elseif d-first_day>0 and d-first_day<=last_day then      -- days of the month
				txt_date=d-first_day
				local colorText= t.colBoxText
				if txt_date==dtable.day and t.month_offset==0 then
					colorText=t.colBoxTextTD
				elseif flagBH then
					colorText=t.colBoxTextBH
				end
				create_pattern(cr,X,Y,maxSide*(1-t.gradient),maxSide*(1-t.gradient),colorText,orientation,t.gradient)
				
				display_day=true
			else												--days after
				txt_date=d-first_day-last_day
				create_pattern(cr,X,Y,maxSide*(1-t.gradient),maxSide*(1-t.gradient),t.colBoxTextOM,orientation,t.gradient)
				display_day=t.display_others_days
			end
			
			--show text or not
			if display_day then
				cairo_text_extents (cr,string.format(str_format,txt_date),te)
				if alignment=="r" then
					delta=maxSide-te.width-te.x_bearing-t.border-t.hpadding
				elseif alignment=="c" then
					delta=(maxSide-te.width)/2-te.x_bearing
				else
					delta=t.border+t.hpadding
				end
				if c==0 or d-first_day==1 then teheight= te.height end
				cairo_move_to(cr,X+delta,Y+(maxSide)/2+teheight/2)
				cairo_show_text(cr,string.format(str_format,txt_date))
			end
			
			if d-first_day>=last_day then
				flagEnd=r
			end
		end

	end
	
	--show days (monday, thuesday ...)
	if days_position=="t" then
		Y=y0
		if month_position=="t" then Y=Y+maxSide+t.gap end
		if info_position=="t" then Y=Y+maxSide+t.gap end
	else
		Y=y0+(flagEnd+1)*(maxSide+t.gap)
	end
	
	deltaX=0
	
	if month_position=="l" then	deltaX=deltaX+maxSide+t.gap end
	if info_position=="l" then	deltaX=deltaX+maxSide+t.gap end	
	flagEnd=flagEnd+1
	for c =0,6 do
		X=x0+c*maxSide+t.gap*c+deltaX
		draw_frame (X,Y,maxSide,maxSide,t.colDays,t.radius,t.border,orientation,t.gradient)
		cairo_save(cr)
		cairo_text_extents (cr,tdays[c+1],te)
		local ratio=(maxSide-2*t.border-2*t.hpadding)/(te.width+te.x_bearing + t.border + t.hpadding)
		if ratio>1 then ratio=1 end
		local xm = X+t.hpadding+(maxSide-2*t.hpadding-te.width)/2-te.x_bearing--+t.hpadding/2
		
		local ym = Y+(maxSide+te.height)/2
		if ratio<1 then xm=X+t.border+t.hpadding end
		
		if alignment=="r" then
			delta=maxSide-te.width-te.x_bearing-t.border-t.hpadding
		elseif alignment=="c" then
			delta=(maxSide-te.width)/2-te.x_bearing
		else
			delta=t.border+t.hpadding
		end

		cairo_move_to(cr,xm,ym)
		create_pattern(cr,X,Y,maxSide,maxSide,t.colDaysText,orientation,t.gradient)
		cairo_save(cr)
		cairo_scale(cr,ratio,1)
		cairo_show_text(cr,tdays[c+1])
		cairo_restore(cr)	
	end

	function show_big_box(txt,box,position)
		cairo_text_extents (cr,txt,te)
		hbox={ width  = maxSide*7+t.gap*6,  height  = maxSide}
		vbox={ width  = maxSide,  height  = maxSide*(flagEnd+1)+t.gap*flagEnd}
		local deltaY = 0
		local deltaX = 0
	
		if box=="month" then
			tColor=t.colMonth
			tColorText=t.colMonthText
			if info_position=="l" or info_position=="r" then
				hbox={ width  = maxSide*8+t.gap*7,  height = maxSide}
			end
			if info_position=="l" then
				deltaX = (maxSide+t.gap)
			end 
			if info_position=="t"  and month_position=="t" then
				deltaY = (maxSide+t.gap)
			end
			if (month_position=="l" or month_position=="r") and (info_position=="t") then
				deltaY=(maxSide+t.gap)
			end
			if (month_position=="b") and (info_position=="t") then
				deltaY=(maxSide+t.gap)
			end	
		elseif box=="info" then
			tColor=t.colInfo
			tColorText=t.colInfoText
			if month_position=="l" or month_position=="r"then
				hbox={ width  = maxSide*8+t.gap*7,  height  = maxSide}
			end 	
			if month_position=="r" and info_position=="r" then 
				deltaX=(maxSide+t.gap)
			end
			if (month_position=="t") and (info_position=="l" or info_position=="r") then
				deltaY=(maxSide+t.gap)
			end
			if (month_position=="t") and (info_position=="b") then
				deltaY=(maxSide+t.gap)
			end			
			if (month_position=="b") then
				vbox={ width  = maxSide,  height  = maxSide*(flagEnd)+t.gap*(flagEnd-1)}
			end
		else
			return	
		end
	
		if position=="b" then	
			flagEnd=flagEnd+1
			draw_frame (x0,y0+flagEnd*(maxSide+t.gap)+deltaY,hbox.width,hbox.height,tColor,t.radius,t.border,orientation,t.gradient)
		elseif position=="l" then
			draw_frame (x0+deltaX,y0+deltaY,vbox.width, vbox.height,tColor,t.radius,t.border,orientation,t.gradient)
		elseif position=="r" then
			draw_frame (x0+7*(maxSide+t.gap)+deltaX,y0+deltaY,vbox.width,vbox.height,tColor,t.radius,t.border,orientation,t.gradient)
		else
			draw_frame (x0,y0+deltaY,hbox.width,hbox.height,tColor,t.radius,t.border,orientation,t.gradient)
		end

		if position=="t" or position=="b" then
			cairo_save(cr)
			local ratio=(hbox.width-2*t.border-2*t.hpadding)/(te.width + te.x_bearing)
			if ratio>1 then ratio=1 end
		
			local xm = x0+hbox.width/2-(te.width/2 + te.x_bearing)
			local ym = y0+hbox.height/2-(te.height/2+ te.y_bearing)
			if ratio<1 then xm=x0+t.border +t.hpadding end
			y1=y0
			if position=="b" then 
				ym = ym + flagEnd*(maxSide+t.gap)
				y1 = y0 + flagEnd*(maxSide+t.gap)
			end
			
			create_pattern(cr,x0,y1 ,hbox.width,hbox.height,tColorText,orientation,t.gradient)
			cairo_translate(cr,xm,ym+deltaY)
			cairo_scale(cr,ratio,1)
			cairo_show_text(cr,txt)
			cairo_restore(cr)
		end
	
		if position=="l" or position=="r" then
			cairo_save(cr)
			--ajuster la taille, à faire avec cairo_set_scaled_font ??
			local ratio=(vbox.height-2*t.border-2*t.hpadding)/(te.width + te.x_bearing)
			if ratio>1 then ratio=1 end
		
			local xm = x0+vbox.width/2-(te.height/2 + te.y_bearing)+deltaX
			local ym = y0+vbox.height/2+(te.width/2+ te.x_bearing)
			if ratio<1 then ym= y0 + vbox.height - t.border -t.hpadding end 
			if position=="r" then xm=xm + 7*(maxSide+t.gap) end

			--hum hum ...
			create_pattern(cr,xm-hbox.height+te.height,ym-te.width- te.x_bearing,hbox.height,te.width+ te.x_bearing,tColorText,orientation,t.gradient)
			cairo_translate(cr,xm,ym+deltaY)
			cairo_rotate(cr,-math.pi/2)
			cairo_scale(cr,ratio,1)
			cairo_show_text(cr,txt)
			cairo_restore(cr)
		end
	
	end

	local yZ=y0+(flagEnd+1)*(maxSide+t.gap)
	show_big_box(txt_month,"month",month_position)
	if month_position =="t" or  month_position =="b" then yZ=yZ+(maxSide+t.gap) end
	
	if t.display_info_box  then 
		if t.file_info ~= nil then
			local file = io.open(t.file_info,"r")
			if file ~= nil then txt_info = file:read("*l") end
		end
		show_big_box(txt_info,"info",info_position)
		if info_position =="t" or  info_position =="b" then yZ=yZ+(maxSide+t.gap) end
	end
	
	return x0,yZ--X,Y
end

calendar.txt

#format of in this text file
#MMDD;N;TEXT
#MMDD = month day
#N    = 0 or 1 (1 to display colours of bank holidays)
#TEXT = Text to display

0307;1;Anniversaire Hailey 
0320;1;Anniversaire Guillaume
0513;1;Anniversaire Patricia
0925;1;Anniversaire Samantha
1019;1;Anniversaire Lili
1021;1;Anniversaire Maman
1105;1;Anniversaire André
0526;1;texte a afficher

get_image.sh

#!/bin/sh
dir="/home/dominique/.conkyrc/conky15/moon-phase"
mkdir -p $dir
cd $dir
wget --user-agent="Mozilla" http://static.die.net/moon/576.jpg -O "$dir/moon.jpg"

square_to_round.lua

--[[ SQUARE_TO_ROUND WIDGET by Wlourf (07 April 2010, version 1.0.1)
http://u-scripts.blogspot.com/

This widget display a rounded image on your conky from a square image only.

Parameters are
filename        --nom de l'image carrée en entrée
xc,yc           --coordonnées du centre de l'image ronde par rapport au coin en haut à gauche de la fenêtre conky
radius           --rayon du cercle final
angle           --angle de rotation de l'image
radius_crop       --dans l'image carrée, pourcentage du cercle à extraire par rapport au côté du carré(1-100)
period       --converti l'image de carré à rond toutes les  'period' secondes

]]

require 'cairo'
require 'imlib2'

function convert_square(fileIn,fileOut,radius,angle,radius_crop)
    --convert Input file from jpg to png, scale it and rotate it
    local imageInput = imlib_load_image(fileIn)
    local out_size = radius*2/(radius_crop/100)
    imlib_context_set_image(imageInput)
    w = imlib_image_get_width();
    h = imlib_image_get_height();
    imlib_image_set_format("png")
    buffer = imlib_create_image(out_size,out_size);
    imlib_context_set_image(buffer);

    imlib_blend_image_onto_image(imageInput, 0, 
                                               0, 0, w, h, 
                                               0,0, out_size,out_size)
    rot_img=imlib_create_rotated_image(angle*math.pi/180)
    imlib_context_set_image(rot_img)  
    imlib_save_image(fileOut)
    imlib_free_image()
    
    imlib_context_set_image(buffer)
    imlib_free_image()
    imlib_context_set_image(imageInput)
    imlib_free_image()
end

function crop_square_to_round(filename,xc,yc,radius)
    local surface = cairo_image_surface_create_from_png(filename)
    local img_w = cairo_image_surface_get_width (surface);
    
    local cw,ch = conky_window.width, conky_window.height
    local cs=cairo_xlib_surface_create(conky_window.display, conky_window.drawable, conky_window.visual, cw,ch)
    local cr=cairo_create(cs)
    cairo_translate(cr,xc-img_w/2,yc-img_w/2)
    cairo_arc (cr, img_w/2,img_w/2, radius, 0, 2*math.pi)
    cairo_clip (cr)
    cairo_new_path (cr)    
    cairo_set_source_surface (cr, surface, 0, 0)

    cairo_paint (cr)
    cairo_destroy(cr)
    cairo_surface_destroy (cs)
    cairo_surface_destroy (surface)
    
end

function display_round(filename,xc,yc,radius,angle,radius_crop,period)
    if conky_window == nil then return end

    --if tonumber(conky_parse('${updates}')) <2  then return end
    local filepng = filename .. ".png"
    local actual_time  = os.time()
    
    if last_time == nil then last_time=0 end
    local actual_img = io.open(filepng,"r")    
    if  last_time+period < actual_time or last_time == 0 or actual_img == nil then
        print ('convert image ' .. filename)
        convert_square(filename,filepng,radius,angle,radius_crop)
        last_time=actual_time
    end
    crop_square_to_round(filepng,xc,yc,radius)
    io.close()
end


--[[END OF SQUARE TO ROUND WIDGET]]

function conky_main(filename)
    if conky_window == nil then return end
    display_round(filename,
                58,95,55,  --xc,yc,radius
                0,            --angle
                98,           --radius_crop (1-100)
                3600        --period
    )
end

phase.sh

#!/bin/bash
rm ~/.conkyrc/conky15/phase_lune.html
wget http://www.calendrier-lunaire.net/ -O ~/.conkyrc/conky15/phase_lune.html
cat ~/.conkyrc/conky-calendrier/phase_lune.html | sed -e :a -e 's/<[^>]*>//g;/</N;//ba' | grep "Nom de la phase" | awk '{print $6,$7}'
exit 0

02 May 2015 : update phase.sh

Last edited by chepioq (2015-05-02 14:46:18)

Offline

#5432 2013-05-26 06:39:39

Dobbie03
Resident Metaller
From: New Zealand
Registered: 2009-08-15
Posts: 1,591

Re: Conky v1.9 Thread

Please ignore me......I sorted my issue.....I removed the content of my post so you all can't see how silly I am. big_smile

Last edited by Dobbie03 (2013-05-26 08:02:49)

Offline

#5433 2013-05-26 12:16:28

Nili
#! Die Hard
From: 127.0.0.1
Registered: 2013-03-20
Posts: 811
Website

Re: Conky v1.9 Thread

Thank you Sector11,

I find it difficult to modify mine version, perhaps if i will tent to use your code may work.

In fact I wanted to make something with mine script, but I lack so hard to make and change the day color sad

Thanks for your intervention.


# Debian GNU/Linux 8:8.2 (netinst/stable)
# Packages Installed: 541
# Linux debian 3.16.0-4-686-pae #1 SMP Debian 3.16.7-ckt11-1+deb8u4 (2015-09-19) i686 GNU/Linux
# Startup finished in 2.850s (kernel) + 6.473s (userspace) = 9.324s

Offline

#5434 2013-05-27 14:12:30

Sector11
#!'er to BL'er
From: SR11 Cockpit
Registered: 2010-05-05
Posts: 15,667
Website

Re: Conky v1.9 Thread

Nili wrote:

Thank you Sector11,

I find it difficult to modify mine version, perhaps if i will tent to use your code may work.

In fact I wanted to make something with mine script, but I lack so hard to make and change the day color sad

Thanks for your intervention.

I hope it works for you.  If you have more problems, just ask for help again.

@ Dobbie03 - we all make oopsies on occasion.   cool


·  ↓   ↓   ↓   ↓   ↓   ↓  ·
BunsenLabs Forums now Open for Registration
·  ↑   ↑   ↑   ↑   ↑   ↑  · BL ModSquad

Offline

#5435 2013-05-27 14:23:09

easysid
#! CrunchBanger
From: India
Registered: 2013-01-25
Posts: 150

Re: Conky v1.9 Thread

Just something quick and dirty. big_smile
The alpha of the fill colour is linked to the battery_percent. So, as the battery drains, it fades to the background.
[The config below shows, (starting from top) cpu, ram, cpu temp, and fs_used (the circle )]

urBKrwi.png

Still a bit of work to do. Dunno where to place the text here tongue. Its cleaner this way, but having text output makes for better readings big_smile.  Also, I'd like to add a 'glow' effect to it. So it would look like radiating light. How do I do that?

Here's the code. Still needs a few things.

nuketest.lua

--[[ 
lua script for the nuke conky
Mon 27 May 2013 00:00:57 IST
written by easysid
]]--

require 'cairo'

function conky_main()
local settings_t = 
    {
    
         { 
            name = 'cpu',
            arg = 'cpu0',
            
            -- Following 4 settings remain the same. I need to refactor the code.
            xc = 200,  
            yc = 200,
            r1 = 40, --inner radius
            r2 = 140, -- outer radius
            
            pos = 1, -- pos can be 1,2,3,4 for top, right, left and centre.
            font_name = "monospace", -- not used
            font_size = 12, -- not used
            
            bg_color = {0xFFFF00, 0.9}, -- outline
            fg_color = {0xFFFF00, 0.8} -- fill. Note that alpha for this is not used, but you need it anyways.
        },
        
        { 
            name = 'memperc',
            arg = ' ',
            xc = 200,
            yc = 200,
            r1 = 40,
            r2 = 140,
            pos = 2,
            font_name = "monospace",
            font_size = 12,
            bg_color = {0xFFFF00, 0.9}, -- outline
            fg_color = {0xFFFF00, 0.8} -- fill
        },
        
        { 
            name = 'platform',
            arg = 'coretemp.0 temp 2',
            xc = 200,
            yc = 200,
            r1 = 40,
            r2 = 140,
            pos = 3,
            font_name = "monospace",
            font_size = 12,
            bg_color = {0xFFFF00, 0.9}, -- outline
            fg_color = {0xFFFF00, 0.2} -- fill
        },
            
        { 
            name = 'fs_used_perc',
            arg = '/',
            xc = 200,
            yc = 200,
            r1 = 40,
            r2 = 140,
            pos = 4,
            font_name = "monospace",
            font_size = 12,
            bg_color = {0xFFFF00, 0.9}, -- outline
            fg_color = {0xFFFF00, 0.8} -- fill
        },

    }--end settings_t

    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>3 then
        -- get the battery percent
        local alpha = tonumber(conky_parse('${battery_percent BAT0}'))
        -- map the battery percent to an alpha range.
        -- following maps battery [20,100] to alpha [0,0.8]
        alpha = (alpha - 20)/100
        
        for i in ipairs(settings_t) do
            settings_t[i].fg_color[2] = alpha --substitute the alpha of fg_color
            nuke_test(cr,settings_t[i])
        end --end for
        
    end --endif
end --end main()


function nuke_test(cr,t)
    
    local function angle(a)
        return a*math.pi/180
    end -- end angle
    
    cairo_set_source_rgba(cr, rgba_to_r_g_b_a(t.bg_color)) -- outline
    cairo_set_line_width(cr, 2)

    local a1, a2 = 0, 360
    local value = tonumber(conky_parse('${'..t.name..' '..t.arg..'}'))
    
    if value == nil then value = 0 end 
    
    -- special case for the centre circle
    if t.pos == 4 then 
        t.r1 = t.r1/2
        value = t.r1*value/100
        
        --OUTLINE
        cairo_arc(cr, t.xc, t.yc, t.r1, 0, angle(360));
        cairo_stroke(cr)
        
        --FILL
        cairo_set_source_rgba(cr, rgba_to_r_g_b_a(t.fg_color))
        cairo_set_line_width(cr,1)   
        cairo_arc(cr, t.xc, t.yc, value, 0, angle(360));
        cairo_fill(cr)

    else
        -- map the value to [r1,r2]
        value = t.r1+(t.r2-t.r1)*value/100
        
        -- determine the angles based on position. Refac needed
        if t.pos == 1 then a1, a2 = 240, 300 end
        if t.pos == 2 then a1, a2 = 0, 60 end
        if t.pos == 3 then a1, a2 = 120, 180 end
        
        --OUTLINE
        cairo_arc(cr, t.xc, t.yc, t.r2, angle(a1), angle(a2));
        cairo_arc_negative(cr, t.xc, t.yc, t.r1, angle(a2), angle(a1));
        cairo_close_path(cr)
        cairo_stroke(cr)
 
        --FILL
        cairo_set_source_rgba(cr, rgba_to_r_g_b_a(t.fg_color))
        cairo_set_line_width(cr,1)   
        cairo_arc(cr, t.xc, t.yc, value, angle(a1), angle(a2));
        cairo_arc_negative(cr, t.xc, t.yc, t.r1, angle(a2), angle(a1));
        cairo_fill(cr)

    end -- end if
end -- end nuke_test


function rgba_to_r_g_b_a(tcolor)
	local color,alpha=tcolor[1],tcolor[2]
	return ((color / 0x10000) % 0x100) / 255., 
		((color / 0x100) % 0x100) / 255., (color % 0x100) / 255., alpha
end --end rgba

EDIT: Added the code

Last edited by easysid (2013-05-28 14:06:21)

Offline

#5436 2013-05-27 17:53:08

Sector11
#!'er to BL'er
From: SR11 Cockpit
Registered: 2010-05-05
Posts: 15,667
Website

Re: Conky v1.9 Thread

easysid wrote:

Just something quick and dirty. big_smile
The alpha of the fill colour is linked to the battery_percent. So, as the battery drains, it fades to the background.
[The config below shows, (starting from top) cpu, ram, cpu temp, and fs_used (the circle )]

http://i.imgur.com/urBKrwi.png

Still a bit of work to do. Dunno where to place the text here tongue. Its cleaner this way, but having text output makes for better readings big_smile.  Also, I'd like to add a 'glow' effect to it. So it would look like radiating light. How do I do that?


OH YEA! Radio active waste conky  big_smile

And the code?

Why do you need text.  If you know what's what it's readable.  My Opinion!
First thing I'd do is rip out alpha colour from battery percent - No Battery - and hook it up to something like "upspeed" or cpu % or temp or fan speed.

KUDOS!


·  ↓   ↓   ↓   ↓   ↓   ↓  ·
BunsenLabs Forums now Open for Registration
·  ↑   ↑   ↑   ↑   ↑   ↑  · BL ModSquad

Offline

#5437 2013-05-27 18:31:46

dreadkopp
Member
Registered: 2011-10-13
Posts: 12

Re: Conky v1.9 Thread

is there a possibility to get the text of the latest mail?

since i have no static global ip, i got a script running, which sends every hour a mail with my current ip to xxxx@trash-mail.com... when i shotdown it sends a mail with the text "offline".

i need the ip to shh into my machine while i am at the university with my notebook.

since i don't want to open the browser and click to the mails, i want the text of the latest email shown in conky (either the ip or offline). a step more would be to write a script which ssh's to my machine without copy-paste of the ip.

hope u understand what's my desire wink

greetings

Offline

#5438 2013-05-28 00:26:43

jed
#! CrunchBanger
From: Detachment 7
Registered: 2012-08-28
Posts: 200
Website

Re: Conky v1.9 Thread

Haven't posted a scrot here in a while so here's the latest.  Back to simplicity...

screenshot-05272013-082439pm.png

Belated thanks to Sector11 for the help with discovering the correct use of my sensor outputs!


Proud user of VSDIO: Jedi!  You can download it from here...  I'm on  the web at NixNut.com!

Offline

#5439 2013-05-28 02:50:17

Sector11
#!'er to BL'er
From: SR11 Cockpit
Registered: 2010-05-05
Posts: 15,667
Website

Re: Conky v1.9 Thread

jed wrote:

Haven't posted a scrot here in a while so here's the latest.  Back to simplicity...

http://www.zimagez.com/miniature/screenshot-05272013-082439pm.png

Belated thanks to Sector11 for the help with discovering the correct use of my sensor outputs!

Oh you've thanked me many times over jed.  But still, was my pleasure.


·  ↓   ↓   ↓   ↓   ↓   ↓  ·
BunsenLabs Forums now Open for Registration
·  ↑   ↑   ↑   ↑   ↑   ↑  · BL ModSquad

Offline

#5440 2013-05-28 13:11:03

ragamatrix
#! Junkie
From: Earth
Registered: 2012-12-05
Posts: 286

Re: Conky v1.9 Thread

A simple horizontal with little rings and clock. Simple and useful.
horizonttle simple
If you like it I share it.
Tschüss

Offline

#5441 2013-05-28 13:53:01

easysid
#! CrunchBanger
From: India
Registered: 2013-01-25
Posts: 150

Re: Conky v1.9 Thread

Sector11 wrote:

OH YEA! Radio active waste conky  big_smile

And the code?

Why do you need text.  If you know what's what it's readable.  My Opinion!
First thing I'd do is rip out alpha colour from battery percent - No Battery - and hook it up to something like "upspeed" or cpu % or temp or fan speed.

KUDOS!

Thanks smile
I added the code in the original post. I hadn't added it earlier as I was trying to add text and stuff.
But the basic design is done. So there it is.
What you can also do, is instead of filling the sectors progressively, you can fill them completely, and link the alpha for each one separately to the variable being parsed. That way, you'd get a full symbol, but the sectors will glow differently. Just an idea.

ragamatrix wrote:

A simple horizontal with little rings and clock. Simple and useful.
horizonttle simple
If you like it I share it.
Tschüss

That looks very nice. smile

Last edited by easysid (2013-05-28 13:59:32)

Offline

#5442 2013-05-28 15:00:38

Sector11
#!'er to BL'er
From: SR11 Cockpit
Registered: 2010-05-05
Posts: 15,667
Website

Re: Conky v1.9 Thread

easysid wrote:
Sector11 wrote:

OH YEA! Radio active waste conky  big_smile
KUDOS!

Thanks :)Tschüss
I added the code in the original post. I hadn't added it earlier as I was trying to add text and stuff.
But the basic design is done. So there it is.
What you can also do, is instead of filling the sectors progressively, you can fill them completely, and link the alpha for each one separately to the variable being parsed. That way, you'd get a full symbol, but the sectors will glow differently. Just an idea.

Had to chuckle at the name - nuketest.lua!  Love it.
Thanks for the code ... something to play with on a rainy day.  Oh look, rain!  big_smile

easysid wrote:
ragamatrix wrote:

A simple horizontal with little rings and clock. Simple and useful.
horizonttle simple
If you like it I share it.
Tschüss

That looks very nice. smile

Yea, tempts us with a screenshot and then says - You want the code: BEG!   lol  lol B lol E lol G lol  lol
Well, OK, maybe not  big_smile


·  ↓   ↓   ↓   ↓   ↓   ↓  ·
BunsenLabs Forums now Open for Registration
·  ↑   ↑   ↑   ↑   ↑   ↑  · BL ModSquad

Offline

#5443 2013-05-28 15:30:29

ragamatrix
#! Junkie
From: Earth
Registered: 2012-12-05
Posts: 286

Re: Conky v1.9 Thread

Hi
I wanted to verified if there was no leaks of ram in the lua script... I suspect; so you can make tests.
I don't need to tempt you because I like sharing  O:) And I'm even there  wink
Here's the codes:
doublerings.lua:

-- 2011 changed by LaGaDesk


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=0x6948FF,
		-- "fg_alpha" is the alpha value of the indicator part of the ring.
		fg_alpha=0.75,
		-- "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=1120, y=35,
		-- "radius" is the radius of the ring.
		radius=23,
		-- "thickness" is the thickness of the ring, centred around the radius.
		thickness=2,
		-- "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 than start_angle.
		end_angle=360
	},
	{
		name='cpu',
		arg='cpu1',
		max=100,
		bg_colour=0xFFFFFF,
		bg_alpha=0.1,
		fg_colour=0x00EE00,
		fg_alpha=0.8,
		x=530, y=35,
		radius=20,
		thickness=2,
		start_angle=0,
		end_angle=360
	},
	{
		name='cpu',
		arg='cpu2',
		max=100,
		bg_colour=0xFFFFFF,
		bg_alpha=0.1,
		fg_colour=0x00EE00,
		fg_alpha=0.8,
		x=670, y=35,
		radius=20,
		thickness=2,
		start_angle=0,
		end_angle=360
	},
	{
		name='memperc',
		arg='',
		max=100,
		bg_colour=0xFFFFFF,
		bg_alpha=0.1,
		fg_colour=0xFFFF00,
		fg_alpha=0.8,
		x=600, y=35,
		radius=20,
		thickness=2,
		start_angle=0,
		end_angle=360
	},
	
	{
		name='fs_used_perc',
		arg='/',
		max=100,
		bg_colour=0xFFFFFF,
		bg_alpha=0.1,
		fg_colour=0x1E90FF,
		fg_alpha=0.8,
		x=230, y=35,
		radius=23,
		thickness=2,
		start_angle=0,
		end_angle=360
	},
	{
		name='fs_used_perc',
		arg='/home',
		max=100,
		bg_colour=0xFFFFFF,
		bg_alpha=0.1,
		fg_colour=0x1E90FF,
		fg_alpha=0.8,
		x=230, y=35,
		radius=18,
		thickness=2,
		start_angle=0,
		end_angle=360
	},
	
		
}

-- Use these settings to define the origin and extent of your clock.

clock_r=20

-- "clock_x" and "clock_y" are the coordinates of the centre of the clock, in pixels, from the top left of the Conky window.

clock_x=1120
clock_y=35

show_seconds=true

require 'cairo'
--------------------------------------------------------------------------------------------------------------------------
--                                                                 rgb_to_r_g_b
-- converts color in hexa to decimal
--
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_clock_hands(cr,xc,yc)
	local secs,mins,hours,secs_arc,mins_arc,hours_arc
	local xh,yh,xm,ym,xs,ys
	
	secs=os.date("%S")	
	mins=os.date("%M")
	hours=os.date("%I")
		
	secs_arc=(2*math.pi/60)*secs
	mins_arc=(2*math.pi/60)*mins+secs_arc/60
	hours_arc=(2*math.pi/12)*hours+mins_arc/12
		
	-- Draw hour hand
	
	xh=xc+0.7*clock_r*math.sin(hours_arc)
	yh=yc-0.7*clock_r*math.cos(hours_arc)
	cairo_move_to(cr,xc,yc)
	cairo_line_to(cr,xh,yh)
	
	cairo_set_line_cap(cr,CAIRO_LINE_CAP_ROUND)
	cairo_set_line_width(cr,5)
	cairo_set_source_rgba(cr,0.9,0.9,0.9,0.9)
	cairo_stroke(cr)
	
	-- Draw minute hand
	
	xm=xc+clock_r*math.sin(mins_arc)
	ym=yc-clock_r*math.cos(mins_arc)
	cairo_move_to(cr,xc,yc)
	cairo_line_to(cr,xm,ym)
	
	cairo_set_line_width(cr,3)
	cairo_stroke(cr)
	
	-- Draw seconds hand
	
	if show_seconds then
		xs=xc+clock_r*math.sin(secs_arc)
		ys=yc-clock_r*math.cos(secs_arc)
		cairo_move_to(cr,xc,yc)
		cairo_line_to(cr,xs,ys)
	
		cairo_set_line_width(cr,1)
		cairo_set_source_rgba(cr,0.9,0.2,0.1,0.8)
		cairo_stroke(cr)
                
	end
end

function conky_clock_rings()
	local function setup_rings(cr,pt)
		local str=''
		local value=0
		
		str=string.format('${%s %s}',pt['name'],pt['arg'])
		str=conky_parse(str)
		
		value=tonumber(str)
		pct=value/pt['max']
		
		draw_ring(cr,pct,pt)
	end
	
	-- Check that Conky has been running for at least 5s

	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 updates=conky_parse('${updates}')
	update_num=tonumber(updates)
	
	if update_num>5 then
		for i in pairs(settings_table) do
			setup_rings(cr,settings_table[i])
		end
	end
	
	draw_clock_hands(cr,clock_x,clock_y)
end

And the famous draw-bg.lua:

--[[Background originally by londonali1010 (2009)
    ability to set any size for background mrpeachy 2011
    ability to set variables for bg in conkyrc dk75

  the change is that if you set width and/or height to 0
  then it assumes the width and/or height of the conky window

so:

lua_load ~/Conky/LUA/draw_bg.lua
TEXT
${lua conky_draw_bg 20 0 0 0 0 0x000000 0.4}


${lua conky_draw_bg corner_radius x_position y_position width height color alpha}

covers the whole window and will change if you change the minimum_size setting

20             corner_radius
 0             x_position
 0             y_position
 0             width
 0             height
 0x000000      color
 0.4           alpha

]]

require 'cairo'
local    cs, cr = nil
function rgb_to_r_g_b(colour,alpha)
return ((colour / 0x10000) % 0x100) / 255., ((colour / 0x100) % 0x100) / 255., (colour % 0x100) / 255., alpha
end
function conky_draw_bg(r,x,y,w,h,color,alpha)
if conky_window == nil then return end
if cs == nil then cairo_surface_destroy(cs) end
if cr == nil then cairo_destroy(cr) 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)
w=w
h=h
if w=="0" then w=tonumber(conky_window.width) end
if h=="0" then h=tonumber(conky_window.height) end
cairo_set_source_rgba (cr,rgb_to_r_g_b(color,alpha))
--top left mid circle
local xtl=x+r
local ytl=y+r
--top right mid circle
local xtr=(x+r)+((w)-(2*r))
local ytr=y+r
--bottom right mid circle
local xbr=(x+r)+((w)-(2*r))
local ybr=(y+r)+((h)-(2*r))
--bottom right mid circle
local xbl=(x+r)
local ybl=(y+r)+((h)-(2*r))
-----------------------------
cairo_move_to (cr,xtl,ytl-r)
cairo_line_to (cr,xtr,ytr-r)
cairo_arc(cr,xtr,ytr,r,((2*math.pi/4)*3),((2*math.pi/4)*4))
cairo_line_to (cr,xbr+r,ybr)
cairo_arc(cr,xbr,ybr,r,((2*math.pi/4)*4),((2*math.pi/4)*1))
cairo_line_to (cr,xbl,ybl+r)
cairo_arc(cr,xbl,ybl,r,((2*math.pi/4)*1),((2*math.pi/4)*2))
cairo_line_to (cr,xtl-r,ytl)
cairo_arc(cr,xtl,ytl,r,((2*math.pi/4)*2),((2*math.pi/4)*3))
cairo_close_path(cr)
cairo_fill (cr)
------------------------------------------------------------
cairo_surface_destroy(cs)
cairo_destroy(cr)
return ""
end


The conky
:

##############################################
#  Settings
##############################################
background no
use_xft yes
xftfont font Droid Sans Mono:size=7
xftalpha 1
update_interval 1.0
total_run_times 0
own_window yes
own_window_transparent yes
#own_window_title ragamatrix horizonttle simple
own_window_type desktop
own_window_hints undecorated,below,sticky,skip_taskbar,skip_pager
double_buffer yes
minimum_size 1150 60
draw_shades no
draw_outline no
draw_borders no
draw_graph_borders no
default_color 1f1f1f
color1 DCDCDC#Gris#1E90FF(bleu)00FF00(vert)
color2 666666
color3 00FF00
color4 gold
color5 burlywood2
color6 DeepPink2
color7 fff00d
default_shade_color 282828
alignment tm
gap_x -45
gap_y -1
no_buffers yes
uppercase no
cpu_avg_samples 2
override_utf8_locale yes
###  LUA Settings  ###########################################################
lua_load ~/.conky/conky32/draw_bg.lua
# Lua Load  #
lua_load ~/.conky/conky32/doublerings.lua
lua_draw_hook_pre clock_rings



##############################################
#  Output#color#lua#8DEEEE${voffset -100}
##############################################
TEXT
${lua conky_draw_bg 28 5 5 1150 60 0x333333 1}
${voffset 5}${goto 20}${font :size=7}${color1}${execi 1000 cat /proc/cpuinfo | grep 'model name' | sed -e 's/model name.*: //'| uniq}${goto 20}${voffset 20}${font style:bold:size=8}${color1}Crunchbang $kernel
${voffset -30}${goto 220}${font style:bold:size=7}${color1}HD:
${goto 220}${color 1E90FF}${fs_used_perc /home}%
${voffset -30}${goto 275}${font :size=6}${color green2}${top name 1}${top cpu 1}%
${goto 275}${font :size=6}${color lightgray}${top name 2}${top cpu 2}%
${goto 275}${font :size=6}${color lightgray}${top name 3}${top cpu 3}%
${goto 275}${font :size=6}${color lightgray}${top name 4}${top cpu 4}%
${voffset -36}${goto 400}${font :size=6}${color ffff00}${top_mem name 1}${top_mem mem 1}%
${goto 400}${font :size=6}${color lightgray}${top_mem name 2}${top_mem mem 2}%
${goto 400}${font :size=6}${color lightgray}${top_mem name 3}${top_mem mem 3}%
${goto 400}${font :size=6}${color lightgray}${top_mem name 4}${top_mem mem 4}%
${goto 520}${voffset -26}${font :size=6}${color1}cpu1:
${goto 520}${color green2}${cpu}%
${goto 588}${voffset -17}${font :size=6}${color1}mem:
${goto 590}${color ffff00}${memperc}%
${goto 658}${voffset -18}${font :size=7}${color1}cpu2:
${goto 660}${font :size=6}${color green2} ${cpu cpu2}%
${goto 750}${voffset -20}${font style:bold:size=7}${color ffff00}mem: $mem${color1} / $memmax ${goto 910}${font :size=6}${color ffff00}Processus Actifs: $running_processes Lancés: ${threads}
${goto 860}${voffset 10}${font style:bold:size=10}${color lightgray}dl|ul${goto 710}${font :size=6}${color 00FFFF}${downspeedf eth0}Kb${goto 1010}${font :size=6}${color FF8C00}${upspeedf eth0}Kb${goto 1510}${goto 750}${voffset -13}${downspeedgraph eth0 20,90 ffff00 00F5FF}${goto 910}${upspeedgraph eth0 20,90 FF4500 FFD700}
#${goto 700}${goto 1280}${memgraph 30,120 8B0A50 CD2626}
${voffset -260}

enjoy !  wink

Last edited by ragamatrix (2013-05-28 15:33:35)

Offline

#5444 2013-05-28 17:28:12

Sector11
#!'er to BL'er
From: SR11 Cockpit
Registered: 2010-05-05
Posts: 15,667
Website

Re: Conky v1.9 Thread

ragamatrix wrote:

Hi
I wanted to verified if there was no leaks of ram in the lua script... I suspect; so you can make tests.
I don't need to tempt you because I like sharing  O:) And I'm even there  wink
Here's the codes:

enjoy !  wink

Thank you ... Danke.

I was just having fun with you.  You're cool, we know that.  wink


·  ↓   ↓   ↓   ↓   ↓   ↓  ·
BunsenLabs Forums now Open for Registration
·  ↑   ↑   ↑   ↑   ↑   ↑  · BL ModSquad

Offline

#5445 2013-05-28 21:00:44

ragamatrix
#! Junkie
From: Earth
Registered: 2012-12-05
Posts: 286

Re: Conky v1.9 Thread

No problémo !
I just have 2 problems with this one; a leak of ram and when you launch another conky this one disapears... I can't find how to fix it.
I've seen before that leak of ram was "heal" with tis kind of sentence in lua scripts:

tolua.takeownership(matrix1)

or

tolua.takeownership(te)

But I don't know where I can put it in the lua script...

Offline

#5446 2013-05-28 22:54:22

Sector11
#!'er to BL'er
From: SR11 Cockpit
Registered: 2010-05-05
Posts: 15,667
Website

Re: Conky v1.9 Thread

ragamatrix wrote:

No problémo !
I just have 2 problems with this one; a leak of ram and when you launch another conky this one disapears... I can't find how to fix it.
I've seen before that leak of ram was "heal" with tis kind of sentence in lua scripts:

tolua.takeownership(matrix1)

or

tolua.takeownership(te)

But I don't know where I can put it in the lua script...


Like this:  http://crunchbang.org/forums/viewtopic. … 09#p271809

Best way yo search the crunchbang forums (or any really) comes from John Raff:

cbs tolua.takeownership

cbs

#!/bin/bash
# search the Crunchbang forums
# by johnraff

USAGE='USAGE:
search words  - search the forum with several words, other google stuff like OR also OK.
"search phrase" - search for fixed phrase
-t topic word - search for topic in title, word anywhere
-t "topic phrase" word - search for "topic phrase" in title, word anywhere
-t topic -t subject - search for topic AND subject in title
-h or --help - this message
etc...'

unset q
while [[ $1 ]]
do
    case $1 in
        -t)
        shift
        if [[ $(echo $1 | wc -w) -eq 1 ]]
        then
            q="$q intitle:$1"
        else
            q="$q intitle:\"$1\""
        fi
        ;;

        -h|--help)
        echo "$USAGE"
        exit 0
        ;;

        *)
        if [[ $(echo $1 | wc -w) -eq 1 ]]
        then
            q="$q $1"
        else
            q="$q \"$1\""
        fi
        ;;
    esac
    shift
done

iceweasel "http://www.google.com/search?q=site:crunchbang.org/forums/ $q"

exit 0

·  ↓   ↓   ↓   ↓   ↓   ↓  ·
BunsenLabs Forums now Open for Registration
·  ↑   ↑   ↑   ↑   ↑   ↑  · BL ModSquad

Offline

#5447 2013-05-29 01:37:39

mrpeachy
20% cooler
From: The Everfree Forest
Registered: 2009-11-08
Posts: 3,460

Re: Conky v1.9 Thread

ragamatrix wrote:

No problémo !
I just have 2 problems with this one; a leak of ram and when you launch another conky this one disapears... I can't find how to fix it.
I've seen before that leak of ram was "heal" with tis kind of sentence in lua scripts:

tolua.takeownership(matrix1)

or

tolua.takeownership(te)

But I don't know where I can put it in the lua script...

for the disappearing problem launch the conky from a terminal and then watch the output when you launch the second conky

for the memory leak problem, that can be tricky to track down
unfortunately i write my scripts quite differently to your doublerings.lua script (whispers *i hate setting tables*) lol

Offline

#5448 2013-05-29 03:08:13

KrunchTime
#! Die Hard
From: not where I belong
Registered: 2012-03-02
Posts: 3,264

Re: Conky v1.9 Thread

jed wrote:

Haven't posted a scrot here in a while so here's the latest.  Back to simplicity...

http://www.zimagez.com/miniature/screenshot-05272013-082439pm.png

Belated thanks to Sector11 for the help with discovering the correct use of my sensor outputs!

Nice wallpaper!


Linux User #586672
Come and Die -- Kyle Idleman

Offline

#5449 2013-05-29 04:33:11

jed
#! CrunchBanger
From: Detachment 7
Registered: 2012-08-28
Posts: 200
Website

Re: Conky v1.9 Thread

Here's another version of simplicity.  Think it's my favorite so far.  The Conky was inspired by one I saw on the LinuxBBQ forum.  VastOne's gmb layout.

screenshot-05292013-123059am.png

Thanks Krunchtime!

Last edited by jed (2013-05-29 05:03:43)


Proud user of VSDIO: Jedi!  You can download it from here...  I'm on  the web at NixNut.com!

Offline

Help fund CrunchBang, donate to the project!

#5450 2013-05-29 07:27:14

ragamatrix
#! Junkie
From: Earth
Registered: 2012-12-05
Posts: 286

Re: Conky v1.9 Thread

mr peachy wrote:

for the disappearing problem launch the conky from a terminal and then watch the output when you launch the second conky

for the memory leak problem, that can be tricky to track down
unfortunately i write my scripts quite differently to your doublerings.lua script (whispers *i hate setting tables*) lol

I did but nothing appears in the terminal of the first conky launched... Mysterious conky  8)
I've got another ring lua may be you'll prefer  this one ?
It's making xorg ram and cpu goes up and I don't know why too. The script descibes that it was modified for leaks problems.
I just show you for an expert eye.
rings.lua:

--[[ RINGS with SECTORS widget
	v1.1 by wlourf (07 Jan. 2011)
	this widget draws a ring with differents effects 
	http://u-scripts.blogspot.com/2010/08/rings-sectors-widgets.html
	
To call the script in a conky, use, before TEXT
	lua_load /path/to/the/script/rings.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:
xc,yc		- coordinates of the center of the ring,
			  default = middle of the conky window
radius		- external radius of the ring, in pixels,
			  default = quarter of the width of the conky window
thickness	- thickness of the ring, in pixels, default = 10 pixels
start_angle	- starting angle of the ring, in degrees, value can be negative,
			  default = 0 degree
end_angle	- ending angle of the ring, in degrees,
			  value must be greater than start_angle, default = 360 degrees
sectors		- number of sectors in the ring, default = 10
gap_sectors - gap between two sectors, in pixels, default = 1 pixel
cap			- the way to close a sector, available values are
				"p" for parallel , default value 
				"r" for radial (follow the radius)
inverse_arc	- if set to true, arc will be anticlockwise, default=false
border_size	- size of the border, in pixels, default = 0 pixel i.e. no border
fill_sector	- if set to true, each sector will be completely filled,
			  default=false, this parameter is inoperate if sectors=1
background	- if set to false, background will not be drawn, default=true
foreground	- if set to false, foreground will not be drawn, default=true

Colours tables below are defined into braces :
{position in the gradient (0 to 1), colour in hexadecimal, alpha (0 to 1)}
example for a single colour table : 
{{0,0xFFAA00,1}} position parameter doesn't matter
example for a two-colours table : 
{{0,0xFFAA00,1},{1,0x00AA00,1}} or {{0.5,0xFFAA00,1},{1,0x00AA00,1}}
example for a three-colours table : 
{{0,0xFFAA00,1},{0.5,0xFF0000,1},{1,0x00AA00,1}}

bg_colour1	- colour table for background,
			  default = {{0,0x00ffff,0.1},{0.5,0x00FFFF,0.5},{1,0x00FFFF,0.1}}
fg_colour1	- colour table for foreground,
			  default = {{0,0x00FF00,0.1},{0.5,0x00FF00,1},{1,0x00FF00,0.1}}
bd_colour1	- colour table for border,
			  default = {{0,0xFFFF00,0.5},{0.5,0xFFFF00,1},{1,0xFFFF00,0.5}}			  

Seconds tables for radials gradients :
bg_colour2	- second colour table for background, default = no second colour
fg_colour2	- second colour table for foreground, default = no second colour
bd_colour2	- second colour table for border, default = no second colour

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 (08 Aug. 2010) original release
v1.1 (07 Jan. 2011) Add draw_me parameter and correct memory leaks, thanks to "Creamy Goodness"
                    text is parsed inside the function, not in the array of settings

--      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'

function conky_main_rings()
-- START PARAMETERS HERE
local rings_settings={
	--line1
   
	{
	name="cpu",
	arg="%S",
	max=100,
	xc=530,
	yc=45,
	thickness=4,
	radius=18,
	sectors=100,
 	gap_sectors=0,
	bg_colour1={{0,0xFFFFFF,0.1},{0.5,0xFFFFFF,0.4},{1,0xFFFFFF,0.1}},
	fg_colour1={{0,0x00FF00,0.1},{0.5,0x00FF00,1.0},{1,0x00FF00,0.1}},
	fg_colour2={{0,0xFF0000,0.1},{0.5,0xFF0000,1.0},{1,0xFF0000,0.1}},
	},

	{
	name="memperc",
	arg="%S",
	max=100,
	xc=600,
	yc=45,
	thickness=4,
	radius=18,
	sectors=100,
	gap_sectors=0,
	start_angle=0,
	end_angle=360,
	bg_colour1={{0,0xFFFFFF,0.1},{0.5,0xFFFFFF,0.6},{1,0xFFFFFF,0.1}},
	fg_colour1={{0,0xFFFF00,0.1},{0.5,0xFFFF00,1.0},{1,0xFFFF00,0.1}},
	fg_colour2={{0,0xFF0000,0.1},{0.5,0xFF0000,1.0},{1,0xFF0000,0.1}},
	},

	{
	name="cpu",
	arg="cpu0",
	max=100,
	xc=670,
	yc=45,
	thickness=4,
	radius=18,
	sectors=100,
 	gap_sectors=0,
	bg_colour1={{0,0xFFFFFF,0.1},{0.5,0xFFFFFF,0.4},{1,0xFFFFFF,0.1}},
	fg_colour1={{0,0x00FF00,0.1},{0.5,0x00FF00,1.0},{1,0x00FF00,0.1}},
	fg_colour2={{0,0xFF0000,0.1},{0.5,0xFF0000,1.0},{1,0xFF0000,0.1}},
	},
	
	
}
--END OF PARAMETERS HERE

--main function

	--if conky_window==nil then return 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 cr=cairo_create(cs)

	if tonumber(conky_parse('${updates}'))>3 then
		for i in pairs(rings_settings) do
			draw_ring(cr,rings_settings[i])
		end
	end

	cairo_destroy(cr)

end




function draw_ring(cr, t)

	local function rgba_to_r_g_b_a(tcolour)
		local colour,alpha=tcolour[2],tcolour[3]
		return ((colour / 0x10000) % 0x100) / 255., 
			((colour / 0x100) % 0x100) / 255., (colour % 0x100) / 255., alpha
	end
			
			
	local function calc_delta(tcol1,tcol2)
		--calculate deltas P R G B A to table_colour 1

		for x = 1, #tcol1 do
			tcol1[x].dA	= 0
			tcol1[x].dP = 0
	 		tcol1[x].dR = 0
			tcol1[x].dG = 0
			tcol1[x].dB = 0
			if tcol2~=nil and #tcol1 == #tcol2 then
				local r1,g1,b1,a1 = rgba_to_r_g_b_a(tcol1[x])
				local r2,g2,b2,a2 = rgba_to_r_g_b_a(tcol2[x])
				tcol1[x].dP = (tcol2[x][1]-tcol1[x][1])/t.sectors
		 		tcol1[x].dR = (r2-r1)/t.sectors
				tcol1[x].dG = (g2-g1)/t.sectors
				tcol1[x].dB = (b2-b1)/t.sectors
				tcol1[x].dA = (a2-a1)/t.sectors		
				
			end
		end
		
		return tcol1
	end

	--check values
	local function setup(t)
		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'")
			print ("for name=" .. t.name)
			print ("with arg=" .. t.arg)
			return
		end
		if t.name==nil then t.name="" end
		if t.arg==nil then t.arg="" 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.thickness ==nil then t.thickness = 10 end
		if t.radius ==nil then t.radius =conky_window.width/4 end
		if t.start_angle==nil then t.start_angle =0 end
		if t.end_angle==nil then t.end_angle=360 end
		if t.bg_colour1==nil then 
			t.bg_colour1={{0,0x00ffff,0.1},{0.5,0x00FFFF,0.5},{1,0x00FFFF,0.1}}
		end
		if t.fg_colour1==nil then
			t.fg_colour1={{0,0x00FF00,0.1},{0.5,0x00FF00,1},{1,0x00FF00,0.1}}
		end
		if t.bd_colour1==nil then
			t.bd_colour1={{0,0xFFFF00,0.5},{0.5,0xFFFF00,1},{1,0xFFFF00,0.5}}
		end
		if t.sectors==nil then t.sectors=10 end
		if t.gap_sectors==nil then t.gap_sectors=1 end 
		if t.fill_sector==nil then t.fill_sector=false end
		if t.sectors==1 then t.fill_sector=false end
		if t.border_size==nil then t.border_size=0 end
		if t.cap==nil then t.cap="p" end
		--some checks
		if t.thickness>t.radius then t.thickness=t.radius*0.1 end
		t.int_radius = t.radius-t.thickness

		--check colors tables 
		for i=1, #t.bg_colour1 do 
			if #t.bg_colour1[i]~=3 then t.bg_colour1[i]={1,0xFFFFFF,0.5} end
		end
		for i=1, #t.fg_colour1 do 
			if #t.fg_colour1[i]~=3 then t.fg_colour1[i]={1,0xFF0000,1} end
		end
		for i=1, #t.bd_colour1 do 
			if #t.bd_colour1[i]~=3 then t.bd_colour1[i]={1,0xFFFF00,1} end
		end
	
		if t.bg_colour2~=nil then
			for i=1, #t.bg_colour2 do 
				if #t.bg_colour2[i]~=3 then t.bg_colour2[i]={1,0xFFFFFF,0.5} end
			end
		end
		if t.fg_colour2~=nil then
			for i=1, #t.fg_colour2 do 
				if #t.fg_colour2[i]~=3 then t.fg_colour2[i]={1,0xFF0000,1} end
			end
		end
		if t.bd_colour2~=nil then
			for i=1, #t.bd_colour2 do 
				if #t.bd_colour2[i]~=3 then t.bd_colour2[i]={1,0xFFFF00,1} end
			end
		end 	
		
		if t.start_angle>=t.end_angle then
		 local tmp_angle=t.end_angle
		 t.end_angle= t.start_angle
		 t.start_angle = tmp_angle
		 -- print ("inversed angles")
			if t.end_angle-t.start_angle>360 and t.start_angle>0 then
				t.end_angle=360+t.start_angle
				print ("reduce angles")
			end
		
			if t.end_angle+t.start_angle>360 and t.start_angle<=0 then
				t.end_angle=360+t.start_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 radius")
			end
			if t.int_radius==t.radius then
				t.int_radius=0
				print ("int radius set to 0")
			end 
		end
		
		t.fg_colour1 = calc_delta(t.fg_colour1,t.fg_colour2)
		t.bg_colour1 = calc_delta(t.bg_colour1,t.bg_colour2)
		t.bd_colour1 = calc_delta(t.bd_colour1,t.bd_colour2)
	end
	
	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	
	--initialize table
	setup(t)
	
	--initialize cairo context
	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)

	--get value
	local value = 0
	if t.name ~="" then
		value = tonumber(conky_parse(string.format('${%s %s}', t.name, t.arg)))
	else
		value = tonumber(t.arg)
	end
	if value==nil then value =0 end

	--initialize sectors
	--angle of a sector :
	local angleA = ((t.end_angle-t.start_angle)/t.sectors)*math.pi/180
	--value of a sector : 
	local valueA = t.max/t.sectors
	--first angle of a sector : 
	local lastAngle = t.start_angle*math.pi/180


	local function draw_sector(type_arc,angle0,angle,valpc, idx)
	 
		--this function draws a portion of arc
	 	--type of arc, angle0 = strating angle, angle= angle of sector,
	 	--valpc = percentage inside the sector, idx = sctor number #
	 	local tcolor
		 if type_arc=="bg" then 		--background
			 if valpc==1 then return end
		 	tcolor=t.bg_colour1
		 elseif type_arc=="fg" then	--foreground
		 	if valpc==0 then return end
		 	tcolor=t.fg_colour1
		 elseif type_arc=="bd" then	--border
		 	tcolor=t.bd_colour1
		 end 

		--angles equivalents to gap_sector
		local ext_delta=math.atan(t.gap_sectors/(2*t.radius))
		local int_delta=math.atan(t.gap_sectors/(2*t.int_radius))

		--angles of arcs
		local ext_angle=(angle-ext_delta*2)*valpc
		local int_angle=(angle-int_delta*2)*valpc

		--define colours to use for this sector
		if #tcolor==1 then 
			--plain color
			local vR,vG,vB,vA = rgba_to_r_g_b_a(tcolor[1])
			cairo_set_source_rgba(cr,vR+tcolor[1].dR*idx,
									vG+tcolor[1].dG*idx,
									vB+tcolor[1].dB*idx,
									vA+tcolor[1].dA*idx	)
		else
			--radient color
			local pat=cairo_pattern_create_radial(0,0,t.int_radius,0,0,t.radius)
			for i=1, #tcolor do
				local vP,vR,vG,vB,vA = tcolor[i][1], rgba_to_r_g_b_a(tcolor[i])
				cairo_pattern_add_color_stop_rgba (pat, 
									vP+tcolor[i].dP*idx,
									vR+tcolor[i].dR*idx,
									vG+tcolor[i].dG*idx,
									vB+tcolor[i].dB*idx,
									vA+tcolor[i].dA*idx	)
			end
			cairo_set_source (cr, pat)
			cairo_pattern_destroy(pat)
		end

		--start drawing
		 cairo_save(cr)
		--x axis is parrallel to start of sector
		cairo_rotate(cr,angle0-math.pi/2)

		local ri,re = t.int_radius ,t.radius

		--point A 
		local angle_a
	
		if t.cap == "p" then 
			angle_a = int_delta
			if t.inverse_arc and type_arc ~="bg" then
				angle_a = angle-int_angle-int_delta
			end
			if not(t.inverse_arc) and type_arc =="bg" then
				angle_a = int_delta+int_angle
			end
		else --t.cap=="r"
			angle_a = ext_delta
			if t.inverse_arc and type_arc~="bg" then
				angle_a = angle-ext_angle-ext_delta
			end
			if not(t.inverse_arc) and type_arc=="bg" then
				angle_a = ext_delta+ext_angle
			end
		end
		local ax,ay = ri*math.cos(angle_a),ri*math.sin(angle_a)


		--point B
		local angle_b = ext_delta
		if t.cap == "p" then 
			if t.inverse_arc and type_arc ~="bg" then
				angle_b = angle-ext_angle-ext_delta
			end
			if not(t.inverse_arc) and type_arc=="bg" then
				angle_b = ext_delta+ext_angle
			end
		else
			if t.inverse_arc and type_arc ~="bg" then
				angle_b = angle-ext_angle-ext_delta
			end
			if not(t.inverse_arc) and type_arc=="bg" then
				angle_b = ext_delta+ext_angle
			end
		end
		local bx,by = re*math.cos(angle_b),re*math.sin(angle_b)

		-- EXTERNAL ARC B --> C
		local b0,b1
		if t.inverse_arc then
			if type_arc=="bg" then
				b0,b1= ext_delta, angle-ext_delta-ext_angle
			else
				b0,b1= angle-ext_angle-ext_delta, angle-ext_delta
			end
		else
			if type_arc=="bg" then
				b0,b1= ext_delta+ext_angle, angle-ext_delta
			else
				b0,b1= ext_delta, ext_angle+ext_delta
			end
		end
		
		---POINT D
		local angle_c, angle_d
		if t.cap == "p" then 
			angle_d = angle-int_delta
			if t.inverse_arc and type_arc=="bg" then
				angle_d = angle-int_delta-int_angle	
			end
			if not(t.inverse_arc) and type_arc~="bg" then
				angle_d=int_delta+int_angle
			end
		else
			angle_d = angle-ext_delta
			if t.inverse_arc and type_arc=="bg" then
				angle_d =angle-ext_delta-ext_angle
			end
			if not(t.inverse_arc) and type_arc~="bg" then
				angle_d = ext_angle+ext_delta
			end
		end
		local dx,dy = ri*math.cos(angle_d),ri*math.sin(angle_d)
		
		-- INTERNAL ARC D --> A
		local d0,d1
		if t.cap=="p" then	
			if t.inverse_arc then	
				if type_arc=="bg" then
					d0,d1= angle-int_delta-int_angle,int_delta
				else
					d0,d1= angle-int_delta, angle- int_angle-int_delta
				end
			else
				if type_arc=="bg" then
					d0,d1= angle-int_delta, int_delta+int_angle
				else
					d0,d1= int_delta+int_angle, int_delta
				end
			end
		else
			if t.inverse_arc then	
				if type_arc=="bg" then	
					d0,d1= angle-ext_delta-ext_angle,ext_delta
				else
					d0,d1= angle-ext_delta, angle- ext_angle-ext_delta
				end
			else
				if type_arc=="bg" then	
					d0,d1= angle-ext_delta,ext_delta+ext_angle
				else	
					d0,d1= ext_angle+ext_delta, ext_delta
				end
			end			
		end
			
		--draw sector
		cairo_move_to(cr,ax,ay)
		cairo_line_to(cr,bx,by)
		cairo_arc(cr,0,0,re,b0,b1)
		cairo_line_to(cr,dx,dy) 
		cairo_arc_negative(cr,0,0,ri,d0,d1)
		 cairo_close_path (cr);

		--stroke or fill sector
		 if type_arc=="bd" then
		 	cairo_set_line_width(cr,t.border_size)
		 	cairo_stroke(cr)
		 else
			 cairo_fill(cr)
		 end

		 cairo_restore(cr)

	 end
	--draw sectors
	local n0,n1,n2 = 1,t.sectors,1
	if t.inverse_arc then n0,n1,n2 = t.sectors,1,-1 end
	local index = 0
	for i = n0,n1,n2 do 
		index = index +1
		local valueZ=1
		local cstA, cstB = (i-1),i
		if t.inverse_arc then cstA,cstB = (t.sectors-i), (t.sectors-i+1) end
		
		if value>valueA *cstA and value<valueA*cstB then
			if not t.fill_sector then
				valueZ = (value-valueA*cstA)/valueA
			end
		else
			if value<valueA*cstB then valueZ=0 end
		end
		
		local start_angle= lastAngle+(i-1)*angleA
		if t.foreground ~= false then 
			draw_sector("fg",start_angle,angleA,valueZ, index)
		end
		if t.background ~= false then 
			draw_sector("bg",start_angle,angleA,valueZ, i)
		end
		if t.border_size>0 then draw_sector("bd",start_angle,angleA,1, i) end
	end

	cairo_restore(cr)
end


--[[END OF RING-SECTORS WIDGET]]

oops sorry there are settings tables  8.(  lol

Offline

Board footer

Powered by FluxBB

Copyright © 2012 CrunchBang Linux.
Proudly powered by Debian. Hosted by Linode.
Debian is a registered trademark of Software in the Public Interest, Inc.
Server: acrobat

Debian Logo