The second (system) clock was created by @Olgmen, a developer from St.Petersburg. He always impressed me with how he simplified guru configurations (mrpeachy; wlourf etc.).
Interestingly, the original 1.9 configuration works in MX17.
Code: Select all
--[[
При сборке скрипта использованы данные из следующих скриптов
Conky Widgets by londonali1010 (2009) - часы и кольца
Shadowed clock by wlourf (10 jan. 2010) - стрелки часов с тенью
BARGRAPH WIDGET v1.3 by wlourf (03 march 2010)
Собрал все это Борис Кринкель <olgmen> krinkel@rambler.ru
Для этого серипта требуется CONKY версии 1.7.2
Для вызова этого скрипта в Conky вставьте следующие строки до TEXT (при условии, что скрипт сохранен в ~/scripts/conky_widgets.lua):
lua_load ~/scripts/olgmen7_1.lua
lua_draw_hook_pre widgets
]]
require 'cairo'
--[[ AIR CLOCK WIDGET ]]
--[[ Виджет выводит изображение часов.
Часть настроек находится в виджете
]]
function clock(cr, x, y, s, bgc, bga, fgc, fga)
-- функция перекодировки цвета
function rgb_to_r_g_b(colour,alpha)
return ((colour / 0x10000) % 0x100) / 255., ((colour / 0x100) % 0x100) / 255., (colour % 0x100) / 255., alpha
end
-- назначаем толщину выводимых линий
local s_th = 2
-- рисуем циферблат
local radius = s/2
local m_x,m_y = x + s/2, y + s/2
-- вывод часовых делений
local i = 0
local winkel = math.rad(30)
for i=0,11,1 do
cairo_set_line_width(cr,s_th*1.5)
cairo_move_to(cr, m_x-math.sin(winkel*i)*(radius), m_y-math.cos(winkel*i)*(radius))
cairo_line_to(cr, m_x-math.sin(winkel*i)*(radius*0.8), m_y-math.cos(winkel*i)*(radius*0.8))
cairo_fill_preserve(cr)
cairo_set_source_rgba(cr,rgb_to_r_g_b(fgc,fga))
cairo_stroke(cr)
end
-- вывод минутных делений
local i = 0
local winkel = math.rad(6)
for i=0,59,1 do
cairo_set_line_width(cr,1)
cairo_move_to(cr, m_x-math.sin(winkel*i)*radius, m_y-math.cos(winkel*i)*radius)
cairo_line_to(cr, m_x-math.sin(winkel*i)*(radius*0.9), m_y-math.cos(winkel*i)*(radius*0.9))
cairo_stroke(cr)
end
-- часовые стрелки с тенью, взято из Shadowed clock by wlourf (10 jan. 2010)
function draw_hand(a_trame,arc,arc0,arc1,lg,r,border,rgb)
xx = xc + clock_r*math.sin(arc)*lg
yy = yc - clock_r*math.cos(arc)*lg
x0 = xc + r*math.sin(arc0)
y0 = yc - r*math.cos(arc0)
x1 = xc + r*math.sin(arc1)
y1 = yc - r*math.cos(arc1)
if border ~= nil then
cairo_set_line_width(cr,1)
cairo_set_source_rgba(cr,border[1],border[2],border[3],0.5)
cairo_move_to (cr, x0, y0)
cairo_curve_to (cr, x0, y0, xx, yy, x1, y1)
cairo_arc(cr,xc,yc,r,arc1-math.pi/2,arc0-math.pi/2)
cairo_stroke(cr)
end
-- рисуем тень
cairo_move_to (cr, x0, y0)
cairo_curve_to (cr, x0, y0, xx+shadow_xoffset, yy+shadow_yoffset, x1, y1)
cairo_arc(cr,xc,yc,r,arc1-math.pi/2,arc0-math.pi/2)
pat = cairo_pattern_create_radial (xc, yc, 0, xc, yc, clock_r)
cairo_pattern_add_color_stop_rgba (pat, 0, 0, 0, 0, shadow_opacity)
cairo_pattern_add_color_stop_rgba (pat, 1, 0, 0, 0, 0)
cairo_set_source (cr, pat)
cairo_fill (cr)
-- рисуем стрелки
cairo_move_to (cr, x0, y0)
cairo_curve_to (cr, x0, y0, xx, yy, x1, y1)
cairo_arc(cr,xc,yc,r,arc1-math.pi/2,arc0-math.pi/2)
pat = cairo_pattern_create_radial (xc, yc, clock_r/10, xc, yc, clock_r*lg)
cairo_pattern_add_color_stop_rgba (pat,0, rgb[1], rgb[2], rgb[3], 1)
cairo_pattern_add_color_stop_rgba (pat, 1, 0, 0, 0, 1)
cairo_set_source (cr, pat)
cairo_fill (cr)
cairo_pattern_destroy (pat)
end
-- Здесь вводятся основные данные
-- радиус часов в пикселях, задаем половину диаметра часов
clock_r=s/2
-- координаты центра часов
xc = x+s/2
yc = y+s/2
-- координаты источника света относительно центра часов, 0 - источник света над центром
-- может быть положительным, источник света выше центра, или отрицательным
shadow_xoffset=70
shadow_yoffset=70
-- прозрачность тени, значения от 0 до 1
shadow_opacity=0.5
-- Выводить секундную стрелку, Да - true, Нет - false.
-- При выводе секундной стрелки update_interval в .conkyrc должен быть менее 1 сек.
show_seconds=true
-- Выводить ось стрелок в центре часов, Да - true, Нет - false.
show_dot = true
-- размеры стрелок, первая цифра ширина, вторая - длина
rh,lgh=3,1.2 -- часовая стрелка
rm,lgm=2,1.75 -- минутная стрелка
rs,lgs=1,1.9 -- секундная стрелка
-- забираем данные из ОС
local hours=os.date("%I")
local mins=os.date("%M")
local secs=os.date("%S")
-- расчет угла движения стрелок
gamma = math.pi/2-math.atan(rs/(clock_r*lgs))
secs_arc=(2*math.pi/60)*secs
secs_arc0=secs_arc-gamma
secs_arc1=secs_arc+gamma
gamma = math.pi/2-math.atan(rm/(clock_r*lgm))
mins_arc=(2*math.pi/60)*mins + secs_arc/60
mins_arc0=mins_arc-gamma
mins_arc1=mins_arc+gamma
gamma = math.pi/2-math.atan(rh/(clock_r*lgh))
hours_arc=(2*math.pi/12)*hours+mins_arc/12
hours_arc0=hours_arc-gamma
hours_arc1=hours_arc+gamma
-- вывод стрелок
draw_hand(alpha_trame,hours_arc,hours_arc0,hours_arc1,lgh,rh,{0,0,0},{1,1,1})
draw_hand(alpha_trame,mins_arc,mins_arc0,mins_arc1,lgm,rm,{0,0,0},{.9,.9,.9})
if show_seconds then
draw_hand(alpha_trame,secs_arc,secs_arc0,secs_arc1,lgs,rs,{0,0,0},{.8,.8,.8})
end
-- рисуем ось стрелок
if show_dot then
lg_shadow_center=3
radius=math.min(rh,rm,rs)*0.75
if radius<1 then radius=1 end
ang = math.atan(shadow_yoffset/shadow_xoffset)
-- тень от оси
gamma = -math.atan(1/lg_shadow_center)
ang0=ang-gamma
ang1=ang+gamma
end
end
--[[ END AIR CLOCK WIDGET ]]
-- ---------------------------------------------------------------------------
--[[ BARGRAPH WIDGET
v1.3 by wlourf (03 march 2010)
This widget draw a simple bar like (old) equalizers on hi-fi systems.
http://u-scripts.blogspot.com/
The arguments are :
- "name" is the type of stat to display; you can choose from 'cpu', 'memperc', 'fs_used_perc', 'battery_used_perc'...
or you can set it to "" if you want to display a numeric value with arg=numeric_value
- "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 ''.
- "max" is the maximum value of the bar. If the Conky variable outputs a percentage, use 100.
- "nb_blocks" is the umber of block to draw
- "cap" id the cap of a block, possibles values are CAIRO_LINE_CAP_ROUND , CAIRO_LINE_CAP_SQUARE or CAIRO_LINE_CAP_BUTT
see http://www.cairographics.org/samples/set_line_cap/
- "xb" and "yb" are the coordinates of the bottom left point of the bar, or the center of the circle if radius>0
- "w" and "h" are the width and the height of a block (without caps), w has no effect for "circle" bar
- "space" is the space betwwen two blocks, can be null or negative
- "bgc" and "bga" are background colors and alpha when the block is not LIGHT OFF
- "fgc" and "fga" are foreground colors and alpha when the block is not LIGHT ON
- "alc" and "ala" are foreground colors and alpha when the block is not LIGHT ON and ALARM ON
- "alarm" is the value where blocks LIGHT ON are in a different color (values from 0 to 100)
- "led_effect" true or false : to show a block with a led effect
- "led_alpha" alpha of the center of the led (values from 0 to 1)
- "smooth" true or false : colors in the bar has a smooth effect
- "mid_color",mid_alpha" : colors of the center of the bar (mid_color can to be set to nil)
- "rotation" : angle of rotation of the bar (values are 0 to 360 degrees). 0 = vertical bar, 90 = horizontal bar
- "radius" : draw the bar on a circle (it's no more a circle, radius = 0 to keep bars)
- "angle_bar" : if radius>0 angle_bar is the angle of the bar
v1.0 (10 Feb. 2010) original release
v1.1 (13 Feb. 2010) numeric values can be passed instead conky stats with parameters name="", arg = numeric_value
v1.2 (28 Feb. 2010) just renamed the widget to bargraph
v1.3 (03 March 2010) added parameters radius & angle_bar to draw the bar in a circular way
]]
function equalizer(cr, name, arg, max, nb_blocks, cap, xb, yb, w, h, space, bgc, bga, fgc, fga,alc,ala,alarm,led_effect,led_alpha,smooth,mid_color,mid_alpha,rotation, radius, angle_bar)
local function rgb_to_r_g_b(colour, alpha)
return ((colour / 0x10000) % 0x100) / 255., ((colour / 0x100) % 0x100) / 255., (colour % 0x100) / 255., alpha
end
local function setup_equalizer()
local value = 0
if name ~="" then
local str = conky_parse(string.format('${%s %s}', name, arg))
value = tonumber(str)
else
value = arg
end
if value==nil then value =0 end
--if value <= 25 then max = 50
--elseif value <= 50 then max = 100 end
local pct = 100*value/max
local pcb = 100/nb_blocks
cairo_set_line_width (cr, h)
cairo_set_line_cap (cr, cap)
local angle_rot= rotation*math.pi/180
local alpha_bar = (angle_bar*math.pi/180)/2
for pt = 1,nb_blocks do
local light_on=false
--set colors
local col,alpha = bgc,bga
if pct>=(100/nb_blocks/2) then --start after an half bloc
if pct>=(pcb*(pt-1)) then
light_on=true
col,alpha = fgc,fga
if pct>=alarm and (pcb*pt)>alarm then col,alpha = alc,ala end
end
end
--vertical points
local x1=xb
local y1=yb-pt*(h+space)
local radius0 = yb-y1
local x2=xb+radius0*math.sin(angle_rot)
local y2=yb-radius0*math.cos(angle_rot)
--line on angle_rot
local a1=(y2-yb)/(x2-xb)
local b1=y2-a1*x2
--line perpendicular to angle_rot
local a2=-1/a1
local b2=y2-a2*x2
--dots on perpendicular
local xx0,xx1,yy0,yy1=0,0,0,0
if rotation == 90 or rotation == 270 then
xx0,xx1=x2,x2
yy0=yb
yy1=yb+w
else
xx0,xx1=x2,x2+w*math.cos(angle_rot)
yy0=xx0*a2+b2
yy1=xx1*a2+b2
end
local xc,yc
--perpendicular segment
if alpha_bar == 0 then
cairo_move_to (cr, xx0 ,yy0)
cairo_line_to (cr, xx1 ,yy1)
xc,yc=(xx0+xx1)/2,(yy0+yy1)/2
else
cairo_arc( cr,
xb,
yb,
radius+(h+space)*(pt)-h/2,
( -alpha_bar -math.pi/2+angle_rot) ,
( alpha_bar -math.pi/2+angle_rot)
)
xc=xb+ (radius+(h+space)*(pt))*math.sin(angle_rot)
yc=yb- (radius+(h+space)*(pt))*math.cos(angle_rot)
end
--colors
if light_on and led_effect then
local pat = cairo_pattern_create_radial (xc, yc, 0, xc,yc,w/1.5)
cairo_pattern_add_color_stop_rgba (pat, 0, rgb_to_r_g_b(col,led_alpha))
cairo_pattern_add_color_stop_rgba (pat, 1, rgb_to_r_g_b(col,alpha))
cairo_set_source (cr, pat)
cairo_pattern_destroy(pat)
else
cairo_set_source_rgba(cr, rgb_to_r_g_b(col,alpha))
end
if light_on and smooth then
local radius = (nb_blocks+1)*(h+space)
if pt==1 then
xc0,yc0=xc,yc --remember the center of first block
end
cairo_move_to(cr,xc0,yc0)
local pat = cairo_pattern_create_radial (xc0, yc0, 0, xc0,yc0,radius)
cairo_pattern_add_color_stop_rgba (pat, 0, rgb_to_r_g_b(fgc,fga))
cairo_pattern_add_color_stop_rgba (pat, 1, rgb_to_r_g_b(alc,ala))
if mid_color ~=nil then
cairo_pattern_add_color_stop_rgba (pat, 0.5,rgb_to_r_g_b(mid_color,mid_alpha))
end
cairo_set_source (cr, pat)
cairo_pattern_destroy(pat)
end
cairo_stroke (cr);
end
end
--prevent segmentatioon error
local updates=tonumber(conky_parse('${updates}'))
if updates> 3 then
setup_equalizer()
end
end
-- ------------------------------------------------------------------------------------
--[[ TEXT WIDGET ]]
function addzero100(num)
if tonumber(num) == nil then return end --tonumber(num) == 0 end
if tonumber(num) < 10 then
return "00" .. num
elseif tonumber(num) <100 then
return "0" .. num
else
return num
end
end
function string:split(delimiter)
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 circlewriting(cr, text, font, fsize, radi, horiz, verti, tred, tgreen, tblue, talpha, start, finish, var1)
local inum=string.len(text)
range=finish
deg=(finish-start)/(inum-1)
degrads=1*(math.pi/180)
local textcut=string.gsub(text, ".", "%1@@@")
texttable=string.split(textcut, "@@@")
for i = 1,inum do
ival=i
interval=(degrads*(start+(deg*(i-1))))+var1
interval2=degrads*(start+(deg*(i-1)))
txs=0+radi*(math.sin(interval))
tys=0-radi*(math.cos(interval))
cairo_select_font_face (cr, font, CAIRO_FONT_SLANT_NORMAL, CAIRO_FONT_WEIGHT_NORMAL);
cairo_set_font_size (cr, fsize);
cairo_set_source_rgba (cr, tred, tgreen, tblue, talpha);
cairo_move_to (cr, txs+horiz, tys+verti);
cairo_rotate (cr, interval2)
cairo_show_text (cr, (texttable[i]))
cairo_rotate (cr, -interval2)
end
end
function circlewritingdown(cr, text, font, fsize, radi, horiz, verti, tred, tgreen, tblue, talpha, start, finish, var1)
local inum=string.len(text)
deg=(start-finish)/(inum-1)
degrads=1*(math.pi/180)
local textcut=string.gsub(text, ".", "%1@@@")
texttable=string.split(textcut, "@@@")
for i = 1,inum do
ival=i
interval=(degrads*(start-(deg*(i-1))))+var1
interval2=degrads*(start-(deg*(i-1)))
txs=0+radi*(math.sin(interval))
tys=0-radi*(math.cos(interval))
cairo_select_font_face (cr, font, CAIRO_FONT_SLANT_NORMAL, CAIRO_FONT_WEIGHT_NORMAL);
cairo_set_font_size (cr, fsize);
cairo_set_source_rgba (cr, tred, tgreen, tblue, talpha);
cairo_move_to (cr, txs+horiz, tys+verti);
cairo_rotate (cr, interval2+(180*math.pi/180))
cairo_show_text (cr, (texttable[i]))
cairo_rotate (cr, -interval2-(180*math.pi/180))
end
end
function conky_draw_text()
local updates=conky_parse('${updates}')
update_num=tonumber(updates)
--circlewriting variable
cpu=tonumber(conky_parse('${cpu cpu0}'))
if cpu == nil then cpu = 0 end
--text must be in quotes
text=("CPU 1 " .. (addzero100(cpu)) .. "%")
--font name must be in quotes
font="PT Sans"
fontsize=12
radius=70
positionx=140
positiony=160
colorred=1
colorgreen=0.7
colorblue=0
coloralpha=1
--to set start and finish values for circlewriting, if the text will cross 0 degrees then you must calculate for 360+finish degrees
--eg if you want to go from 270 to 90, then you will input 270 to 450. Finish has to be greater than start.
start=290
finish=340
letterposition=0
circlewriting(cr, text, font, fontsize, radius, positionx, positiony, colorred, colorgreen, colorblue, coloralpha, start, finish, letterposition)
--circlewritingdown variables
cpu=tonumber(conky_parse('${cpu cpu2}'))
if cpu == nil then cpu = 0 end
--text must be in quotes
text=("CPU 2 " .. (addzero100(cpu)) .. "%")
--font name must be in quotes
font="PT Sans"
fontsize=12
radius=70
positionx=140
positiony=160
colorred=1
colorgreen=0.7
colorblue=0
coloralpha=1
--to set start and finish values for circlewritingdown, if the text will cross 0 degrees then you must calculate for 0-finish degrees
--eg if you want to go from 90 to 270, then you will input 90 to -90. Start has to be greater than finish
start=10
finish=60
letterposition=0
circlewriting(cr, text, font, fontsize, radius, positionx, positiony, colorred, colorgreen, colorblue, coloralpha, start, finish, letterposition)
--circlewritingdown variable
down=tonumber(conky_parse('${downspeedf eth0}'))
--text must be in quotes
text=("DOWN " .. down .. "")
--font name must be in quotes
font="PT Sans"
fontsize=12
radius=77
positionx=140
positiony=160
colorred=1
colorgreen=0.7
colorblue=0
coloralpha=1
--to set start and finish values for circlewritingdown, if the text will cross 0 degrees then you must calculate for 0-finish degrees
--eg if you want to go from 90 to 270, then you will input 90 to -90. Start has to be greater than finish
start=250
finish=190
letterposition=0.06
circlewritingdown(cr, text, font, fontsize, radius, positionx, positiony, colorred, colorgreen, colorblue, coloralpha, start, finish, letterposition)
--circlewriting variables
up=tonumber(conky_parse('${upspeedf eth0}'))
--text must be in quotes
text=("UP " .. up .. "")
--font name must be in quotes
font="PT Sans"
fontsize=12
radius=77
positionx=140
positiony=160
colorred=1
colorgreen=0.7
colorblue=0
coloralpha=1
--to set start and finish values for circlewriting, if the text will cross 0 degrees then you must calculate for 360+finish degrees
--eg if you want to go from 270 to 90, then you will input 270 to 450. Finish has to be greater than start.
start=150
finish=120
letterposition=0
circlewritingdown(cr, text, font, fontsize, radius, positionx, positiony, colorred, colorgreen, colorblue, coloralpha, start, finish, letterposition)
-- end
end
--[[ END TEXT WIDGET ]]
-- -------------------------------------------------------------------------------------
function conky_widgets()
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)
-- -------------------------------------------------------------------------------------
--function equalizer(name, arg, max, nb_blocks, cap, xb, yb, w, h, space, bgc, bga, fgc, fga, alc, ala, alarm, led_effect, led_alpha, smooth, mid_color, mid_alpha, rotation, radius, angle_bar)
cr = cairo_create(cs)
if var == nil then var = 0 end
var = var + 1
angle = var
equalizer(cr, 'cpu', 'cpu0', 100, 50, CAIRO_LINE_CAP_SQUARE, 140, 160, 100, 1, 1, 0x00cc66, 0.2, 0x66ff00, 1, 0x00ccff, 1, 80, true, 1, true, 0xff0000, 1.0, 40, 10, 75)
equalizer(cr, 'cpu', 'cpu1', 100, 50, CAIRO_LINE_CAP_SQUARE, 140, 160, 100, 1, 1, 0x00cc66, 0.2, 0x66ff00, 1, 0x00ccff, 1, 80, true, 1, true, 0xff0000, 1.0, 320, 10, 75)
equalizer(cr, 'memperc', '', 100, 50, CAIRO_LINE_CAP_BUTT, 140, 160, 100, 1, 1, 0x00cc66, 0.2, 0x66ff00, 1, 0x00ccff, 1, 80, true, 1, true, 0xff0000, 1.0, 270, 10, 20)
equalizer(cr, 'fs_used_perc', '/', 100, 50, CAIRO_LINE_CAP_SQUARE, 140, 160, 100, 1, 1, 0x00cc66, 0.2, 0x66ff00, 1, 0x00ccff, 1, 80, true, 1, true, 0xff0000, 1.0, 90, 10, 20)
equalizer(cr, 'downspeedf', 'eth0', 1000, 50, CAIRO_LINE_CAP_SQUARE, 140, 160, 100, 1, 1, 0x00cc66, 0.2, 0x66ff00, 1, 0x66ff00, 1, 80, true, 1, true, 0xff0000, 1.0, 220, 10, 75)
equalizer(cr, 'upspeedf', 'eth0', 100, 50, CAIRO_LINE_CAP_SQUARE, 140, 160, 100, 1, 1, 0x00cc66, 0.2, 0x66ff00, 1, 0x66ff00, 1, 80, true, 1, true, 0xff0000, 1.0, 140, 10, 75)
cairo_destroy(cr)
--[[ Вывод часов ]]
cr = cairo_create(cs)
clock(cr, 30, 50, 220, 0xffffff, 1, 0xFFF8DC, 1)
cairo_destroy(cr)
--[[ Вывод текста по кругу, настройке в скрипте ]]
cr = cairo_create(cs)
conky_draw_text()
cairo_destroy(cr)
end