Created
January 4, 2012 11:23
-
-
Save slok/1559638 to your computer and use it in GitHub Desktop.
Conkyrc file for conky and lua for slackware
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
--[[ | |
Clock Rings by Linux Mint (2011) reEdited by despot77 | |
This script draws percentage meters as rings, and also draws clock hands if you want! It is fully customisable; all options are described in the script. This script is based off a combination of my clock.lua script and my rings.lua script. | |
IMPORTANT: if you are using the 'cpu' function, it will cause a segmentation fault if it tries to draw a ring straight away. The if statement on line 145 uses a delay to make sure that this doesn't happen. It calculates the length of the delay by the number of updates since Conky started. Generally, a value of 5s is long enough, so if you update Conky every 1s, use update_num>5 in that if statement (the default). If you only update Conky every 2s, you should change it to update_num>3; conversely if you update Conky every 0.5s, you should use update_num>10. ALSO, if you change your Conky, is it best to use "killall conky; conky" to update it, otherwise the update_num will not be reset and you will get an error. | |
To call this script in Conky, use the following (assuming that you save this script to ~/scripts/rings.lua): | |
lua_load ~/scripts/clock_rings.lua | |
lua_draw_hook_pre clock_rings | |
Changelog: | |
+ v1.0 -- Original release (30.09.2009) | |
v1.1p -- Jpope edit londonali1010 (05.10.2009) | |
*v 2011mint -- reEdit despot77 (18.02.2011) | |
]] | |
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=0x0066FF, | |
-- "fg_alpha" is the alpha value of the indicator part of the ring. | |
fg_alpha=0.2, | |
-- "x" and "y" are the x and y coordinates of the centre of the ring, relative to the top left corner of the Conky window. | |
x=100, y=150, | |
-- "radius" is the radius of the ring. | |
radius=50, | |
-- "thickness" is the thickness of the ring, centred around the radius. | |
thickness=5, | |
-- "start_angle" is the starting angle of the ring, in degrees, clockwise from top. Value can be either positive or negative. | |
start_angle=0, | |
-- "end_angle" is the ending angle of the ring, in degrees, clockwise from top. Value can be either positive or negative, but must be larger than start_angle. | |
end_angle=360 | |
}, | |
{ | |
name='time', | |
arg='%M.%S', | |
max=60, | |
bg_colour=0xffffff, | |
bg_alpha=0.1, | |
fg_colour=0x0066FF, | |
fg_alpha=0.4, | |
x=100, y=150, | |
radius=56, | |
thickness=5, | |
start_angle=0, | |
end_angle=360 | |
}, | |
{ | |
name='time', | |
arg='%S', | |
max=60, | |
bg_colour=0xffffff, | |
bg_alpha=0.1, | |
fg_colour=0x0066FF, | |
fg_alpha=0.6, | |
x=100, y=150, | |
radius=62, | |
thickness=5, | |
start_angle=0, | |
end_angle=360 | |
}, | |
{ | |
name='time', | |
arg='%d', | |
max=31, | |
bg_colour=0xffffff, | |
bg_alpha=0.1, | |
fg_colour=0x0066FF, | |
fg_alpha=0.8, | |
x=100, y=150, | |
radius=70, | |
thickness=5, | |
start_angle=-90, | |
end_angle=90 | |
}, | |
{ | |
name='time', | |
arg='%m', | |
max=12, | |
bg_colour=0xffffff, | |
bg_alpha=0.1, | |
fg_colour=0x0066FF, | |
fg_alpha=1, | |
x=100, y=150, | |
radius=76, | |
thickness=5, | |
start_angle=-90, | |
end_angle=90 | |
}, | |
{ | |
name='battery_percent', | |
arg='BAT0', | |
max=100, | |
bg_colour=0xffffff, | |
bg_alpha=0.2, | |
fg_colour=0x0066FF, | |
fg_alpha=0.8, | |
x=50, y=300, | |
radius=25, | |
thickness=4, | |
start_angle=-90, | |
end_angle=180 | |
}, | |
{ | |
name='cpu', | |
arg='cpu0', | |
max=100, | |
bg_colour=0xffffff, | |
bg_alpha=0.2, | |
fg_colour=0x0066FF, | |
fg_alpha=0.8, | |
x=140, y=300, | |
radius=50, | |
thickness=9, | |
start_angle=-90, | |
end_angle=180 | |
}, | |
{ | |
name='cpu', | |
arg='cpu1', | |
max=100, | |
bg_colour=0xffffff, | |
bg_alpha=0.2, | |
fg_colour=0x0066FF, | |
fg_alpha=0.8, | |
x=140, y=300, | |
radius=40, | |
thickness=9, | |
start_angle=-90, | |
end_angle=180 | |
}, | |
{ | |
name='cpu', | |
arg='cpu2', | |
max=100, | |
bg_colour=0xffffff, | |
bg_alpha=0.2, | |
fg_colour=0x0066FF, | |
fg_alpha=0.8, | |
x=140, y=300, | |
radius=30, | |
thickness=9, | |
start_angle=-90, | |
end_angle=180 | |
}, | |
{ | |
name='cpu', | |
arg='cpu3', | |
max=100, | |
bg_colour=0xffffff, | |
bg_alpha=0.2, | |
fg_colour=0x0066FF, | |
fg_alpha=0.8, | |
x=140, y=300, | |
radius=20, | |
thickness=9, | |
start_angle=-90, | |
end_angle=180 | |
}, | |
{ | |
name='memperc', | |
arg='', | |
max=100, | |
bg_colour=0xffffff, | |
bg_alpha=0.2, | |
fg_colour=0x0066FF, | |
fg_alpha=0.8, | |
x=75, y=350, | |
radius=25, | |
thickness=5, | |
start_angle=-90, | |
end_angle=180 | |
}, | |
{ | |
name='fs_used_perc', | |
arg='/', | |
max=100, | |
bg_colour=0xffffff, | |
bg_alpha=0.2, | |
fg_colour=0x0066FF, | |
fg_alpha=0.8, | |
x=100, y=400, | |
radius=25, | |
thickness=5, | |
start_angle=-90, | |
end_angle=180 | |
}, | |
{ | |
name='fs_used_perc', | |
arg='/home', | |
max=100, | |
bg_colour=0xffffff, | |
bg_alpha=0.2, | |
fg_colour=0x0066FF, | |
fg_alpha=0.8, | |
x=125, y=450, | |
radius=25, | |
thickness=5, | |
start_angle=-90, | |
end_angle=180 | |
}, | |
{ | |
name='downspeedf', | |
arg='wlan0', | |
max=100, | |
bg_colour=0xffffff, | |
bg_alpha=0.2, | |
fg_colour=0x0066FF, | |
fg_alpha=0.8, | |
x=150, y=500, | |
radius=25, | |
thickness=4, | |
start_angle=-90, | |
end_angle=180 | |
}, | |
{ | |
name='upspeedf', | |
arg='wlan0', | |
max=100, | |
bg_colour=0xffffff, | |
bg_alpha=0.2, | |
fg_colour=0xff3300, | |
fg_alpha=0.8, | |
x=150, y=500, | |
radius=20, | |
thickness=4, | |
start_angle=-90, | |
end_angle=180 | |
}, | |
} | |
-- Use these settings to define the origin and extent of your clock. | |
clock_r=65 | |
-- "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=100 | |
clock_y=150 | |
show_seconds=true | |
require 'cairo' | |
function rgb_to_r_g_b(colour,alpha) | |
return ((colour / 0x10000) % 0x100) / 255., ((colour / 0x100) % 0x100) / 255., (colour % 0x100) / 255., alpha | |
end | |
function draw_ring(cr,t,pt) | |
local w,h=conky_window.width,conky_window.height | |
local xc,yc,ring_r,ring_w,sa,ea=pt['x'],pt['y'],pt['radius'],pt['thickness'],pt['start_angle'],pt['end_angle'] | |
local bgc, bga, fgc, fga=pt['bg_colour'], pt['bg_alpha'], pt['fg_colour'], pt['fg_alpha'] | |
local angle_0=sa*(2*math.pi/360)-math.pi/2 | |
local angle_f=ea*(2*math.pi/360)-math.pi/2 | |
local t_arc=t*(angle_f-angle_0) | |
-- Draw background ring | |
cairo_arc(cr,xc,yc,ring_r,angle_0,angle_f) | |
cairo_set_source_rgba(cr,rgb_to_r_g_b(bgc,bga)) | |
cairo_set_line_width(cr,ring_w) | |
cairo_stroke(cr) | |
-- Draw indicator ring | |
cairo_arc(cr,xc,yc,ring_r,angle_0,angle_0+t_arc) | |
cairo_set_source_rgba(cr,rgb_to_r_g_b(fgc,fga)) | |
cairo_stroke(cr) | |
end | |
function draw_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,1.0,1.0,1.0,1.0) | |
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_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) | |
if value == nil then | |
value=0 | |
end | |
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 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# Conky settings # | |
background no | |
update_interval 1 | |
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 | |
temperature_unit fahrenheit | |
# Window specifications # | |
own_window yes | |
own_window_type override | |
own_window_transparent yes | |
own_window_hints undecorate,sticky,skip_taskbar,skip_pager,below | |
border_inner_margin 0 | |
border_outer_margin 0 | |
minimum_size 200 250 | |
maximum_width 200 | |
alignment tr | |
gap_x 35 | |
gap_y 55 | |
# Graphics settings # | |
draw_shades no | |
draw_outline no | |
draw_borders no | |
draw_graph_borders no | |
# Text settings # | |
use_xft yes | |
xftfont caviar dreams:size=8 | |
xftalpha 0.5 | |
uppercase no | |
temperature_unit celsius | |
default_color FFFFFF | |
# Lua Load # | |
lua_load ~/.conky/.lua/scripts/clock_rings.lua | |
lua_draw_hook_pre clock_rings | |
TEXT | |
${voffset 8}${color 0066FF}${font caviar dreams:size=16}${time %A}${font}${voffset -8}${alignr 50}${color FFFFFF}${font caviar dreams:size=38}${time %e}${font} | |
${color FFFFFF}${voffset -30}${color FFFFFF}${font caviar dreams:size=18}${time %b}${font}${voffset -3} ${color FFFFFF}${font caviar dreams:si | |
ze=20}${time %Y}${font}${color 0066FF}${hr} | |
${voffset 140}${font caviar dreams:size=10}${alignr}BILBO${font} | |
${font caviar dreams:size=12}${color FFFFFF}${alignr}${weather http://weather.noaa.gov/pub/data/observations/metar/stations/ LEBB temperature temperature 30} °C${font} | |
${image ~/.conky/slackware-logo.png -p 52,101 -s 95x95} | |
${color FFFFFF}${goto 25}${voffset 35}${offset -18}${battery_percent BAT0}% ${color 0066FF}${goto 25} ${offset 58}0 ${color 0066FF}${goto 25} ${offset 69}1 ${color 0066FF}${goto 25} ${offset 79}2 ${color 0066FF}${goto 25} ${offset 88}3 | |
${color 0066FF}${goto 25}${offset -18}Battery ${color 0066FF}${goto 25}${offset 75}CPU${font} | |
${color FFFFFF}${goto 50}${voffset 23}${memperc}% | |
${color 0066FF}${goto 50}RAM | |
${color FFFFFF}${goto 75}${voffset 23}${fs_used_perc /}% | |
${color 0066FF}${goto 75}/ | |
${color FFFFFF}${goto 100}${voffset 23}${fs_used_perc /home}% | |
${color 0066FF}${goto 85}/home | |
${color FFFFFF}${goto 115}${voffset 25}${downspeed wlan0} | |
${color FFFFFF}${goto 115}${upspeed wlan0} | |
${color 0066FF}${goto 115}Wlan | |
${color FFFFFF}${font caviar dreams:size=8}Uptime: ${uptime_short} | |
${color FFFFFF}${font caviar dreams:size=8}Processes: ${processes} | |
${color FFFFFF}${font caviar dreams:size=8}Running: ${running_processes} | |
${color 0066FF}${font caviar dreams:size=8}${alignr}${nodename} | |
${color 0066FF}${font caviar dreams:size=8}${alignr}${pre_exec cat /etc/issue.net} $machine | |
${color 0066FF}${font caviar dreams:size=8}${alignr}Kernel: ${kernel} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
--============================================================================== | |
-- conky_HUD.lua | |
-- | |
-- author : SLK | |
-- version : v2011011601 | |
-- license : Distributed under the terms of GNU GPL version 2 or later | |
-- | |
--============================================================================== | |
require 'cairo' | |
-------------------------------------------------------------------------------- | |
-- gauge DATA | |
gauge = { | |
{ | |
name='cpu', arg='cpu0', max_value=100, | |
x=180, y=120, | |
graph_radius=50, | |
graph_thickness=5, | |
graph_start_angle=0, | |
graph_unit_angle=0.9, graph_unit_thickness=0.9, | |
graph_bg_colour=0x00FFBB, graph_bg_alpha=0.3, | |
graph_fg_colour=0x00FFBB, graph_fg_alpha=0.0, | |
hand_fg_colour=0x00FFBB, hand_fg_alpha=1.0, | |
txt_radius=40, | |
txt_weight=1, txt_size=10.0, | |
txt_fg_colour=0x00FFBB, txt_fg_alpha=0.8, | |
graduation_radius=30, | |
graduation_thickness=0, graduation_mark_thickness=1, | |
graduation_unit_angle=27, | |
graduation_fg_colour=0x00FFBB, graduation_fg_alpha=0.3, | |
caption='', | |
caption_weight=1, caption_size=8.0, | |
caption_fg_colour=0xFFFFFF, caption_fg_alpha=0.3, | |
}, | |
{ | |
name='cpu', arg='cpu1', max_value=100, | |
x=180, y=120, | |
graph_radius=60, | |
graph_thickness=5, | |
graph_start_angle=0, | |
graph_unit_angle=0.9, graph_unit_thickness=0.9, | |
graph_bg_colour=0x00FFBB, graph_bg_alpha=0.3, | |
graph_fg_colour=0x00FFBB, graph_fg_alpha=0.0, | |
hand_fg_colour=0x00FFBB, hand_fg_alpha=1.0, | |
txt_radius=70, | |
txt_weight=1, txt_size=10.0, | |
txt_fg_colour=0x00FFBB, txt_fg_alpha=0.8, | |
graduation_radius=55, | |
graduation_thickness=5, graduation_mark_thickness=2, | |
graduation_unit_angle=27, | |
graduation_fg_colour=0x00FFBB, graduation_fg_alpha=0.3, | |
caption='', | |
caption_weight=1, caption_size=8.0, | |
caption_fg_colour=0xFFFFFF, caption_fg_alpha=0.3, | |
}, | |
{ | |
name='memperc', arg='', max_value=100, | |
x=40, y=85, | |
graph_radius=34, | |
graph_thickness=5, | |
graph_start_angle=180, | |
graph_unit_angle=2, graph_unit_thickness=2, | |
graph_bg_colour=0x00FFBB, graph_bg_alpha=0.3, | |
graph_fg_colour=0x00FFBB, graph_fg_alpha=0.0, | |
hand_fg_colour=0x00FFBB, hand_fg_alpha=1.0, | |
txt_radius=20, | |
txt_weight=1, txt_size=10.0, | |
txt_fg_colour=0x00FFBB, txt_fg_alpha=0.8, | |
graduation_radius=24, | |
graduation_thickness=6, graduation_mark_thickness=2, | |
graduation_unit_angle=10, | |
graduation_fg_colour=0x00FFBB, graduation_fg_alpha=0.3, | |
caption='', | |
caption_weight=1, caption_size=10.0, | |
caption_fg_colour=0xFFFFFF, caption_fg_alpha=0.5, | |
}, | |
{ | |
name='fs_used_perc', arg='/', max_value=100, | |
x=120, y=70, | |
graph_radius=40, | |
graph_thickness=4, | |
graph_start_angle=210, | |
graph_unit_angle=2, graph_unit_thickness=2, | |
graph_bg_colour=0x00FFBB, graph_bg_alpha=0.3, | |
graph_fg_colour=0x00FFBB, graph_fg_alpha=0.0, | |
hand_fg_colour=0x00FFBB, hand_fg_alpha=1.0, | |
txt_radius=32, | |
txt_weight=1, txt_size=10.0, | |
txt_fg_colour=0x00FFBB, txt_fg_alpha=0.8, | |
graduation_radius=46, | |
graduation_thickness=0, graduation_mark_thickness=2, | |
graduation_unit_angle=20, | |
graduation_fg_colour=0x00FFBB, graduation_fg_alpha=0.3, | |
caption='', | |
caption_weight=1, caption_size=8.0, | |
caption_fg_colour=0xFFFFFF, caption_fg_alpha=0.5, | |
}, | |
{ | |
name='fs_used_perc', arg='/home/', max_value=100, | |
x=120, y=70, | |
graph_radius=50, | |
graph_thickness=8, | |
graph_start_angle=210, | |
graph_unit_angle=2, graph_unit_thickness=2, | |
graph_bg_colour=0x00FFBB, graph_bg_alpha=0.3, | |
graph_fg_colour=0x00FFBB, graph_fg_alpha=0.0, | |
hand_fg_colour=0x00FFBB, hand_fg_alpha=1.0, | |
txt_radius=60, | |
txt_weight=1, txt_size=10.0, | |
txt_fg_colour=0x00FFBB, txt_fg_alpha=0.8, | |
graduation_radius=58, | |
graduation_thickness=4, graduation_mark_thickness=2, | |
graduation_unit_angle=20, | |
graduation_fg_colour=0x00FFBB, graduation_fg_alpha=0.3, | |
caption='', | |
caption_weight=1, caption_size=8.0, | |
caption_fg_colour=0xFFFFFF, caption_fg_alpha=0.5, | |
}, | |
} | |
------------------------------------------------------------------------------- | |
-- 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 | |
------------------------------------------------------------------------------- | |
-- angle_to_position | |
-- convert degree to rad and rotate (0 degree is top/north) | |
-- | |
function angle_to_position(start_angle, current_angle) | |
local pos = current_angle + start_angle | |
return ( ( pos * (2 * math.pi / 360) ) - (math.pi / 2) ) | |
end | |
------------------------------------------------------------------------------- | |
-- draw_gauge_ring | |
-- displays gauges | |
-- | |
function draw_gauge_ring(display, data, value) | |
local max_value = data['max_value'] | |
local x, y = data['x'], data['y'] | |
local graph_radius = data['graph_radius'] | |
local graph_thickness, graph_unit_thickness = data['graph_thickness'], data['graph_unit_thickness'] | |
local graph_start_angle = data['graph_start_angle'] | |
local graph_unit_angle = data['graph_unit_angle'] | |
local graph_bg_colour, graph_bg_alpha = data['graph_bg_colour'], data['graph_bg_alpha'] | |
local graph_fg_colour, graph_fg_alpha = data['graph_fg_colour'], data['graph_fg_alpha'] | |
local hand_fg_colour, hand_fg_alpha = data['hand_fg_colour'], data['hand_fg_alpha'] | |
local graph_end_angle = (max_value * graph_unit_angle) % 360 | |
-- background ring | |
cairo_arc(display, x, y, graph_radius, angle_to_position(graph_start_angle, 0), angle_to_position(graph_start_angle, graph_end_angle)) | |
cairo_set_source_rgba(display, rgb_to_r_g_b(graph_bg_colour, graph_bg_alpha)) | |
cairo_set_line_width(display, graph_thickness) | |
cairo_stroke(display) | |
-- arc of value | |
local val = value % (max_value + 1) | |
local start_arc = 0 | |
local stop_arc = 0 | |
local i = 1 | |
while i <= val do | |
start_arc = (graph_unit_angle * i) - graph_unit_thickness | |
stop_arc = (graph_unit_angle * i) | |
cairo_arc(display, x, y, graph_radius, angle_to_position(graph_start_angle, start_arc), angle_to_position(graph_start_angle, stop_arc)) | |
cairo_set_source_rgba(display, rgb_to_r_g_b(graph_fg_colour, graph_fg_alpha)) | |
cairo_stroke(display) | |
i = i + 1 | |
end | |
local angle = start_arc | |
-- hand | |
start_arc = (graph_unit_angle * val) - (graph_unit_thickness * 2) | |
stop_arc = (graph_unit_angle * val) | |
cairo_arc(display, x, y, graph_radius, angle_to_position(graph_start_angle, start_arc), angle_to_position(graph_start_angle, stop_arc)) | |
cairo_set_source_rgba(display, rgb_to_r_g_b(hand_fg_colour, hand_fg_alpha)) | |
cairo_stroke(display) | |
-- graduations marks | |
local graduation_radius = data['graduation_radius'] | |
local graduation_thickness, graduation_mark_thickness = data['graduation_thickness'], data['graduation_mark_thickness'] | |
local graduation_unit_angle = data['graduation_unit_angle'] | |
local graduation_fg_colour, graduation_fg_alpha = data['graduation_fg_colour'], data['graduation_fg_alpha'] | |
if graduation_radius > 0 and graduation_thickness > 0 and graduation_unit_angle > 0 then | |
local nb_graduation = graph_end_angle / graduation_unit_angle | |
local i = 0 | |
while i < nb_graduation do | |
cairo_set_line_width(display, graduation_thickness) | |
start_arc = (graduation_unit_angle * i) - (graduation_mark_thickness / 2) | |
stop_arc = (graduation_unit_angle * i) + (graduation_mark_thickness / 2) | |
cairo_arc(display, x, y, graduation_radius, angle_to_position(graph_start_angle, start_arc), angle_to_position(graph_start_angle, stop_arc)) | |
cairo_set_source_rgba(display,rgb_to_r_g_b(graduation_fg_colour,graduation_fg_alpha)) | |
cairo_stroke(display) | |
cairo_set_line_width(display, graph_thickness) | |
i = i + 1 | |
end | |
end | |
-- text | |
local txt_radius = data['txt_radius'] | |
local txt_weight, txt_size = data['txt_weight'], data['txt_size'] | |
local txt_fg_colour, txt_fg_alpha = data['txt_fg_colour'], data['txt_fg_alpha'] | |
local movex = txt_radius * math.cos(angle_to_position(graph_start_angle, angle)) | |
local movey = txt_radius * math.sin(angle_to_position(graph_start_angle, angle)) | |
cairo_select_font_face (display, "ubuntu", CAIRO_FONT_SLANT_NORMAL, txt_weight) | |
cairo_set_font_size (display, txt_size) | |
cairo_set_source_rgba (display, rgb_to_r_g_b(txt_fg_colour, txt_fg_alpha)) | |
cairo_move_to (display, x + movex - (txt_size / 2), y + movey + 3) | |
cairo_show_text (display, value) | |
cairo_stroke (display) | |
-- caption | |
local caption = data['caption'] | |
local caption_weight, caption_size = data['caption_weight'], data['caption_size'] | |
local caption_fg_colour, caption_fg_alpha = data['caption_fg_colour'], data['caption_fg_alpha'] | |
local tox = graph_radius * (math.cos((graph_start_angle * 2 * math.pi / 360)-(math.pi/2))) | |
local toy = graph_radius * (math.sin((graph_start_angle * 2 * math.pi / 360)-(math.pi/2))) | |
cairo_select_font_face (display, "ubuntu", CAIRO_FONT_SLANT_NORMAL, caption_weight); | |
cairo_set_font_size (display, caption_size) | |
cairo_set_source_rgba (display, rgb_to_r_g_b(caption_fg_colour, caption_fg_alpha)) | |
cairo_move_to (display, x + tox + 5, y + toy + 1) | |
-- bad hack but not enough time ! | |
if graph_start_angle < 105 then | |
cairo_move_to (display, x + tox - 30, y + toy + 1) | |
end | |
cairo_show_text (display, caption) | |
cairo_stroke (display) | |
end | |
------------------------------------------------------------------------------- | |
-- go_gauge_rings | |
-- loads data and displays gauges | |
-- | |
function go_gauge_rings(display) | |
local function load_gauge_rings(display, data) | |
local str, value = '', 0 | |
str = string.format('${%s %s}',data['name'], data['arg']) | |
str = conky_parse(str) | |
value = tonumber(str) | |
draw_gauge_ring(display, data, value) | |
end | |
for i in pairs(gauge) do | |
load_gauge_rings(display, gauge[i]) | |
end | |
end | |
------------------------------------------------------------------------------- | |
-- MAIN | |
function conky_main() | |
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 display = cairo_create(cs) | |
local updates = conky_parse('${updates}') | |
update_num = tonumber(updates) | |
if update_num > 5 then | |
go_gauge_rings(display) | |
end | |
end | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment