Codice: Seleziona tutto
settings_table = {
{
name='cpu',
arg='cpu1',
max=100,
bg_colour=0x000000,
bg_alpha=0.1,
fg_colour=0xA1A1A1,
fg_alpha=0.8,
x=160, y=215,
radius=80,
thickness=7,
start_angle=21,
end_angle=238
},
{
name='cpu',
arg='cpu0',
max=100,
bg_colour=0x000000,
bg_alpha=0.1,
fg_colour=0xA1A1A1,
fg_alpha=0.8,
x=160, y=215,
radius=95,
thickness=7,
start_angle=21,
end_angle=260
},
{
name='memperc',
arg='',
max=100,
bg_colour=0x000000,
bg_alpha=0.1,
fg_colour=0x818181,
fg_alpha=0.8,
x=160, y=215,
radius=110,
thickness=7,
start_angle=21,
end_angle=280
},
{
name='fs_used_perc',
arg='/',
max=100,
bg_colour=0x000000,
bg_alpha=0.1,
fg_colour=0x5E5E5E,
fg_alpha=0.8,
x=160, y=215,
radius=125,
thickness=7,
start_angle=21,
end_angle=300
},
{
name='fs_used_perc',
arg='/home',
max=100,
bg_colour=0x000000,
bg_alpha=0.1,
fg_colour=0x4A4A4A,
fg_alpha=0.8,
x=160, y=215,
radius=140,
thickness=7,
start_angle=21,
end_angle=320
},
{
name='battery_percent',
arg='BAT0',
max=100,
bg_colour=0x000000,
bg_alpha=0.1,
fg_colour=0x252525,
fg_alpha=0.8,
x=162, y=215,
radius=155,
thickness=7,
start_angle=20,
end_angle=340
},
}
require 'cairo'
function rgb_to_r_g_b(colour,alpha)
return ((colour / 0x10000) % 0x100) / 255., ((colour / 0x100) % 0x100) / 255., (colour % 0x100) / 255., alpha
end
function draw_ring(cr,t,pt)
local w,h=conky_window.width,conky_window.height
local xc,yc,ring_r,ring_w,sa,ea=pt['x'],pt['y'],pt['radius'],pt['thickness'],pt['start_angle'],pt['end_angle']
local bgc, bga, fgc, fga=pt['bg_colour'], pt['bg_alpha'], pt['fg_colour'], pt['fg_alpha']
local angle_0=sa*(2*math.pi/360)-math.pi/2
local angle_f=ea*(2*math.pi/360)-math.pi/2
local t_arc=t*(angle_f-angle_0)
-- Draw background ring
cairo_arc(cr,xc,yc,ring_r,angle_0,angle_f)
cairo_set_source_rgba(cr,rgb_to_r_g_b(bgc,bga))
cairo_set_line_width(cr,ring_w)
cairo_stroke(cr)
-- Draw indicator ring
cairo_arc(cr,xc,yc,ring_r,angle_0,angle_0+t_arc)
cairo_set_source_rgba(cr,rgb_to_r_g_b(fgc,fga))
cairo_stroke(cr)
end
function conky_ring_stats()
local function setup_rings(cr,pt)
local str=''
local value=0
local str=string.format('${%s %s}',pt['name'],pt['arg'])
local str=conky_parse(str)
local value=tonumber(str)
local pct=value/pt['max']
draw_ring(cr,pct,pt)
end
if conky_window==nil then return end
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=conky_parse('${updates}')
local update_num=tonumber(updates)
if update_num>5 then
for i in pairs(settings_table) do
setup_rings(cr,settings_table[i])
end
end
cairo_surface_destroy(cs)
cairo_destroy(cr)
end
function conky_draw_clock()
if conky_window==nil then return end
local w=conky_window.width
local h=conky_window.height
cs=cairo_xlib_surface_create(conky_window.display, conky_window.drawable, conky_window.visual, w, h)
cr=cairo_create(cs)
-- Settings
-- What radius should the clock face (not including border) be, in pixels?
--local clock_r=50
-- x and y coordinates, relative to the top left corner of Conky, in pixels
local xc=340
local yc=407
-- Extent of the shadow, in pixels
local shadow_width=5
-- x and y offsets of the drop shadow, relative to the centre of the clock face, in pixels. Can be positive (downward) or negative (upward)
local shadow_xoffset=0
local shadow_yoffset=2
-- Do you want to show the second hand? Use this if you use a Conky update_interval > 1s. Can be true or false.
local show_seconds=true
-- Grab time
local hours=os.date("%I")
local mins=os.date("%M")
local secs=os.date("%S")
local secs_arc=(2*math.pi/60)*secs
local mins_arc=(2*math.pi/60)*mins
local hours_arc=(2*math.pi/12)*hours+mins_arc/12
-- Drop shadow
ds_pat=cairo_pattern_create_radial(xc+shadow_xoffset,yc+shadow_yoffset,clock_r*1.25,xc+shadow_xoffset,yc+shadow_yoffset,clock_r*1.25+shadow_width)
cairo_pattern_add_color_stop_rgba(ds_pat,0,0,0,0,0.2)
cairo_pattern_add_color_stop_rgba(ds_pat,1,0,0,0,0)
cairo_move_to(cr,0,0)
cairo_line_to(cr,w,0)
cairo_line_to(cr,w,h)
cairo_line_to(cr,0,h)
cairo_new_sub_path(cr)
cairo_arc(cr,xc,yc,clock_r*1.25,0,2*math.pi)
cairo_set_source(cr,ds_pat)
cairo_set_fill_rule(cr,CAIRO_FILL_RULE_EVEN_ODD)
cairo_fill(cr)
-- Glassy border
cairo_arc(cr,xc,yc,clock_r*1.25,0,2*math.pi)
cairo_set_source_rgba(cr,0.5,0.5,0.5,0.2)
cairo_set_line_width(cr,1)
cairo_stroke(cr)
border_pat=cairo_pattern_create_linear(xc,yc-clock_r*1.25,xc,yc+clock_r*1.25)
cairo_pattern_add_color_stop_rgba(border_pat,0,1,1,1,0.7)
cairo_pattern_add_color_stop_rgba(border_pat,0.3,1,1,1,0)
cairo_pattern_add_color_stop_rgba(border_pat,0.5,1,1,1,0)
cairo_pattern_add_color_stop_rgba(border_pat,0.7,1,1,1,0)
cairo_pattern_add_color_stop_rgba(border_pat,1,1,1,1,0.7)
cairo_set_source(cr,border_pat)
cairo_arc(cr,xc,yc,clock_r*1.125,0,2*math.pi)
cairo_close_path(cr)
cairo_set_line_width(cr,clock_r*0.15)
cairo_stroke(cr)
-- Set clock face
cairo_arc(cr,xc,yc,clock_r,0,2*math.pi)
cairo_close_path(cr)
face_pat=cairo_pattern_create_radial(xc,yc-clock_r*0.75,0,xc,yc,clock_r)
cairo_pattern_add_color_stop_rgba(face_pat,0,0,0,0,0)
cairo_pattern_add_color_stop_rgba(face_pat,0,0,0,0,0)
cairo_pattern_add_color_stop_rgba(face_pat,0,0,0,0,0)
cairo_set_source(cr,face_pat)
cairo_fill_preserve(cr)
cairo_set_source_rgba(cr,0.7,0.7,0.7,0.2)
cairo_set_line_width(cr, 1)
cairo_stroke (cr)
-- Draw hour hand
local xh=xc+0.7*clock_r*math.sin(hours_arc)
local 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.6,0.6,0.6,1)
cairo_stroke(cr)
-- Draw minute hand
local xm=xc+0.9*clock_r*math.sin(mins_arc)
local ym=yc-0.9*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
local xs=xc+0.9*clock_r*math.sin(secs_arc)
local ys=yc-0.9*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_stroke(cr)
end
cairo_pattern_destroy(ds_pat)
cairo_pattern_destroy(border_pat)
cairo_pattern_destroy(face_pat)
cairo_surface_destroy(cs)
cairo_destroy(cr)
end
function conky_main()
conky_ring_stats()
conky_draw_clock()
end