À la demande de Onyx67 je mets ici mon conkyrc
conky_plasma_draw_dark :
Code : Tout sélectionner
background yes
use_xft yes
xftfont Sans:regular:size=8
xftalpha 1
update_interval 1
total_run_times 0
# own_window_colour ffffff
own_window yes
own_window_transparent yes
own_window_type dock
own_window_hints undecorated,below,sticky,skip_taskbar
double_buffer yes
own_window_argb_visual yes
# own_window_argb_value 0
minimum_size 475 989
maximum_width 1920
draw_shades no
draw_outline no
draw_borders no
draw_graph_borders no
default_shade_color e0dfde
default_outline_color e0dfde
alignment tl
gap_x 25
gap_y 60
no_buffers yes
uppercase min
cpu_avg_samples 2
override_utf8_locale yes
text_buffer_size 4096
imlib_cache_size 0
default_color 000000
color1 5A5A5A # gris foncé
color2 1793D1 # bleu
color3 ed7f10 # orange
color4 BEBEBE # gris clair
color5 3DAEE6 # bleu clair
color6 00C000 # vert
color7 FF0000 # rouge
# -- Lua Load -- #
# SET THE PATH TO THE SCRIPT HERE
lua_load ~/.conky/draw_plasma_dark.lua
lua_draw_hook_pre main_box
TEXT
draw_plasma_dark.lua :
Code : Tout sélectionner
require 'cairo'
function conky_main_box()
if conky_window==nil then return end
---------------------- PARAMETERS BEGIN HERE
local boxes_settings={
{x=2, y=2,w=483,h=168,
corners={ {"circle",5},},
colour={ {0,0x2c2f3d,0.80} },
},
{x=112, y=25,w=354,h=2,
colour={ {0,0x377c9e,1} },
},
------------------------------
{x=2, y=183,w=483,h=100,
corners={ {"circle",5},},
colour={ {0,0x2c2f3d,0.80} },
},
{x=114, y=207,w=356,h=2,
colour={ {0,0x377c9e,1} },
},
{x=16, y=241,w=454,h=1,
colour={ {0,0x4C4C4C,1} },
},
{x=16, y=268,w=454,h=1,
colour={ {0,0x4C4C4C,1} },
},
------------------------------
{x=2, y=295,w=483,h=180,
corners={ {"circle",5},},
colour={ {0,0x2c2f3d,0.80} },
},
{x=136, y=317,w=334,h=2,
colour={ {0,0x377c9e,1} },
},
{x=16, y=351,w=454,h=1,
colour={ {0,0x4C4C4C,1} },
},
{x=16, y=378,w=454,h=1,
colour={ {0,0x4C4C4C,1} },
},
{x=16, y=405,w=454,h=1,
colour={ {0,0x4C4C4C,1} },
},
{x=16, y=432,w=454,h=1,
colour={ {0,0x4C4C4C,1} },
},
{x=16, y=459,w=454,h=1,
colour={ {0,0x4C4C4C,1} },
},
------------------------------
{x=2, y=487,w=483,h=148,
corners={ {"circle",5},},
colour={ {0,0x2c2f3d,0.80} },
},
{x=214, y=508,w=256,h=2,
colour={ {0,0x377c9e,1} },
},
{x=16, y=540,w=454,h=1,
colour={ {0,0x4C4C4C,1} },
},
------------------------------
{x=2, y=647,w=483,h=128,
corners={ {"circle",5},},
colour={ {0,0x2c2f3d,0.80} },
},
{x=98, y=671,w=372,h=2,
colour={ {0,0x377c9e,1} },
},
{x=16, y=705,w=454,h=1,
colour={ {0,0x4C4C4C,1} },
},
{x=16, y=732,w=454,h=1,
colour={ {0,0x4C4C4C,1} },
},
{x=16, y=759,w=454,h=1,
colour={ {0,0x4C4C4C,1} },
},
------------------------------
{x=2, y=787,w=483,h=212,
corners={ {"circle",5},},
colour={ {0,0x2c2f3d,0.80} },
},
{x=303, y=808,w=167,h=2,
colour={ {0,0x377c9e,1} },
},
}
---------------------------- PARAMETERS END HERE
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 tonumber(conky_parse("$updates"))<5 then return end
for i in pairs(boxes_settings) do
draw_box (cr,boxes_settings[i])
end
cairo_destroy(cr)
cairo_surface_destroy(cs)
end
function draw_box(cr,t)
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
local table_corners={"circle","curve","line"}
local t_operators={
clear = CAIRO_OPERATOR_CLEAR,
source = CAIRO_OPERATOR_SOURCE,
over = CAIRO_OPERATOR_OVER,
["in"] = CAIRO_OPERATOR_IN,
out = CAIRO_OPERATOR_OUT,
atop = CAIRO_OPERATOR_ATOP,
dest = CAIRO_OPERATOR_DEST,
dest_over = CAIRO_OPERATOR_DEST_OVER,
dest_in = CAIRO_OPERATOR_DEST_IN,
dest_out = CAIRO_OPERATOR_DEST_OUT,
dest_atop = CAIRO_OPERATOR_DEST_ATOP,
xor = CAIRO_OPERATOR_XOR,
add = CAIRO_OPERATOR_ADD,
saturate = CAIRO_OPERATOR_SATURATE,
}
function rgba_to_r_g_b_a(tc)
--tc={position,colour,alpha}
local colour = tc[2]
local alpha = tc[3]
return ((colour / 0x10000) % 0x100) / 255., ((colour / 0x100) % 0x100) / 255., (colour % 0x100) / 255., alpha
end
function table.copy(t)
local t2 = {}
for k,v in pairs(t) do
t2[k] = {v[1],v[2]}
end
return t2
end
function draw_corner(num,t)
local shape=t[1]
local radius=t[2]
local x,y = t[3],t[4]
if shape=="line" then
if num == 1 then cairo_line_to(cr,radius,0)
elseif num == 2 then cairo_line_to(cr,x,radius)
elseif num == 3 then cairo_line_to(cr,x-radius,y)
elseif num == 4 then cairo_line_to(cr,0,y-radius)
end
end
if shape=="circle" then
local PI = math.pi
if num == 1 then cairo_arc(cr,radius,radius,radius,-PI,-PI/2)
elseif num == 2 then cairo_arc(cr,x-radius,y+radius,radius,-PI/2,0)
elseif num == 3 then cairo_arc(cr,x-radius,y-radius,radius,0,PI/2)
elseif num == 4 then cairo_arc(cr,radius,y-radius,radius,PI/2,-PI)
end
end
if shape=="curve" then
if num == 1 then cairo_curve_to(cr,0,radius ,0,0 ,radius,0)
elseif num == 2 then cairo_curve_to(cr,x-radius,0, x,y, x,radius)
elseif num == 3 then cairo_curve_to(cr,x,y-radius, x,y, x-radius,y)
elseif num == 4 then cairo_curve_to(cr,radius,y, x,y, 0,y-radius)
end
end
end
--check values and set default values
if t.x == nil then t.x = 0 end
if t.y == nil then t.y = 0 end
if t.w == nil then t.w = conky_window.width end
if t.h == nil then t.h = conky_window.height end
if t.radius == nil then t.radius = 0 end
if t.border == nil then t.border = 0 end
if t.colour==nil then t.colour={{1,0xFFFFFF,0.5}} end
if t.linear_gradient ~= nil then
if #t.linear_gradient ~= 4 then
t.linear_gradient = {t.x,t.y,t.width,t.height}
end
end
if t.angle==nil then t.angle = 0 end
if t.skew_x == nil then t.skew_x=0 end
if t.skew_y == nil then t.skew_y=0 end
if t.scale_x==nil then t.scale_x=1 end
if t.scale_y==nil then t.scale_y=1 end
if t.rot_x == nil then t.rot_x=0 end
if t.rot_y == nil then t.rot_y=0 end
if t.operator == nil then t.operator = "over" end
if (t_operators[t.operator]) == nil then
print ("wrong operator :",t.operator)
t.operator = "over"
end
if t.radial_gradient ~= nil then
if #t.radial_gradient ~= 6 then
t.radial_gradient = {t.x,t.y,0, t.x,t.y, t.width}
end
end
for i=1, #t.colour do
if #t.colour[i]~=3 then
print ("error in color table")
t.colour[i]={1,0xFFFFFF,1}
end
end
if t.corners == nil then t.corners={ {"line",0} } end
local t_corners = {}
local t_corners = table.copy(t.corners)
--don't use t_corners=t.corners otherwise t.corners is altered
--complete the t_corners table if needed
for i=#t_corners+1,4 do
t_corners[i]=t_corners[#t_corners]
local flag=false
for j,v in pairs(table_corners) do flag=flag or (t_corners[i][1]==v) end
if not flag then print ("error in corners table :",t_corners[i][1]);t_corners[i][1]="curve" end
end
--this way :
-- t_corners[1][4]=x
-- t_corners[2][3]=y
--doesn't work
t_corners[1]={t_corners[1][1],t_corners[1][2],0,0}
t_corners[2]={t_corners[2][1],t_corners[2][2],t.w,0}
t_corners[3]={t_corners[3][1],t_corners[3][2],t.w,t.h}
t_corners[4]={t_corners[4][1],t_corners[4][2],0,t.h}
t.no_gradient = (t.linear_gradient == nil ) and (t.radial_gradient == nil )
cairo_save(cr)
cairo_translate(cr, t.x, t.y)
if t.rot_x~=0 or t.rot_y~=0 or t.angle~=0 then
cairo_translate(cr,t.rot_x,t.rot_y)
cairo_rotate(cr,t.angle*math.pi/180)
cairo_translate(cr,-t.rot_x,-t.rot_y)
end
if t.scale_x~=1 or t.scale_y~=1 or t.skew_x~=0 or t.skew_y~=0 then
local matrix0 = cairo_matrix_t:create()
tolua.takeownership(matrix0)
cairo_matrix_init (matrix0, t.scale_x,math.pi*t.skew_y/180 , math.pi*t.skew_x/180 ,t.scale_y,0,0)
cairo_transform(cr,matrix0)
end
local tc=t_corners
cairo_move_to(cr,tc[1][2],0)
cairo_line_to(cr,t.w-tc[2][2],0)
draw_corner(2,tc[2])
cairo_line_to(cr,t.w,t.h-tc[3][2])
draw_corner(3,tc[3])
cairo_line_to(cr,tc[4][2],t.h)
draw_corner(4,tc[4])
cairo_line_to(cr,0,tc[1][2])
draw_corner(1,tc[1])
if t.no_gradient then
cairo_set_source_rgba(cr,rgba_to_r_g_b_a(t.colour[1]))
else
if t.linear_gradient ~= nil then
pat = cairo_pattern_create_linear (t.linear_gradient[1],t.linear_gradient[2],t.linear_gradient[3],t.linear_gradient[4])
elseif t.radial_gradient ~= nil then
pat = cairo_pattern_create_radial (t.radial_gradient[1],t.radial_gradient[2],t.radial_gradient[3],
t.radial_gradient[4],t.radial_gradient[5],t.radial_gradient[6])
end
for i=1, #t.colour do
cairo_pattern_add_color_stop_rgba (pat, t.colour[i][1], rgba_to_r_g_b_a(t.colour[i]))
end
cairo_set_source (cr, pat)
cairo_pattern_destroy(pat)
end
cairo_set_operator(cr,t_operators[t.operator])
if t.border>0 then
cairo_close_path(cr)
if t.dash ~= nil then cairo_set_dash(cr, t.dash, 1, 0.0) end
cairo_set_line_width(cr,t.border)
cairo_stroke(cr)
else
cairo_fill(cr)
end
cairo_restore(cr)
end
conky_plasma_dark :
Code : Tout sélectionner
background yes
use_xft yes
xftfont Sans:regular:size=8
xftalpha 1
update_interval 1
total_run_times 0
# own_window_colour ffffff
own_window yes
own_window_transparent yes
own_window_type dock
own_window_hints undecorated,below,sticky,skip_taskbar
double_buffer yes
own_window_argb_visual yes
# own_window_argb_value 0
minimum_size 475 185
maximum_width 1920
draw_shades no
draw_outline no
draw_borders no
draw_graph_borders no
default_shade_color e0dfde
default_outline_color e0dfde
alignment tl
gap_x 25
gap_y 60
no_buffers yes
uppercase min
cpu_avg_samples 2
override_utf8_locale yes
default_bar_size 453 6
text_buffer_size 4096
imlib_cache_size 0
default_color EDEEEF
color1 909090 # gris foncé
color2 377c9e # 1793D1 # bleu
color3 ed7f10 # orange
color4 BEBEBE # gris clair
color5 377C9E # bleu clair
color6 428d3b # vert
color7 FF0000 # rouge
# -- Lua Load -- #
# SET THE PATH TO THE SCRIPT HERE
lua_load ~/.conky/graph_plasma_dark.lua
lua_draw_hook_pre main_graph
TEXT
########################################################################## SYSTÈME ######################################################################################
#
${font Sans :regular:size=14}${color1}${goto 20}${voffset 5}Système${font}${color2}
${font Sans :bold:size=8}${goto 18}${texeci 3000 users | cut -c1-7}@${nodename}${alignr 13}${uptime}${font}
${color}${goto 18}Version de KDE Plasma${goto 210}:${alignr 13}${texeci 3000 yaourt -Q plasma-desktop | cut -d " " -f 2} \
(${texeci 3000 yaourt -Q plasma-desktop | cut -d / -f 1})${font}
${goto 18}Version de QT${goto 210}:${alignr 13}${texeci 3000 yaourt -Q qt5-base | cut -d " " -f 2} \
(${texeci 3000 yaourt -Q qt5-base | cut -d / -f 1})${font}
${font Sans :bold:size=8}${color2}${goto 18}Version de noyau (démarré)${alignr 13}linux ${texeci 5 uname -r} (${texeci 5 head -n1 ~/.cache/kernel | cut -f 1 -d "/"})
${color}${goto 18}Autre noyau disponible${alignr 13}${texeci 5 tail -n1 ~/.cache/kernel | cut -f 2 -d "/"} (${texeci 5 tail -n1 ~/.cache/kernel | cut -f 1 -d "/"})
#Température GPU${goto 120}:${color3}${alignr}${acpitemp} °C
#
${font}${goto 18}MAJ(s) disponible(s)${font}${goto 210}:\
${font Sans :bold:size=8}${if_match ${texeci 30 cat ~/.cache/nb_majs}>0}\
${color3}${alignr 9}${texeci 600 cat ~/.cache/nb_majs}\
${else}${color6}${alignr 13}Système à jour${endif}
########################################################################## MÉMOIRE ######################################################################################
${font Sans :regular:size=14}${color1}${goto 20}${voffset 5}Mémoire${font}${color2}${color}
${font Sans :bold:size=8}${goto 18}RAM${font}${goto 65}:
${voffset -13}${alignc}${mem} / ${memmax}
${voffset -13}${alignr 13}${memperc} %
${color4}${voffset -6}${color}
${font Sans :bold:size=8}${goto 18}${voffset -6}SWAP${font}${goto 65}:
${voffset -13}${alignc}${swap} / ${swapmax}
${voffset -13}${alignr 13}${swapperc} %
${color4}${voffset -6}${color}
######################################################################## PROCESSEUR #####################################################################################
${font Sans :regular:size=14}${color1}${goto 20}${voffset 3}Processeur${font}${color2}${color}
${font Sans:bold:size=8}${color2}${goto 18}${texeci 3000 cat /proc/cpuinfo | grep 'model name' | head -n1 | sed -e 's/model name.*: //' | cut -c 1-25}\
${font}${goto 210}:${font Sans :bold:size=8}${alignr 13}${freq_g cpu} GHz${font}
${color4}${voffset -6}${color}
${if_existing /sys/class/hwmon/hwmon0/temp5_input}\
${font Sans:bold:size=8}${color}${goto 18}${voffset -6}Cpu1
${font}${voffset -13}${alignc}${hwmon 0 temp 2} °C
${voffset -13}${alignr 13}${cpu cpu1} %
${color4}${voffset -6}
${font Sans:bold:size=8}${color}${goto 18}${voffset -6}Cpu2
${font}${voffset -13}${alignc}${hwmon 0 temp 3} °C
${voffset -13}${alignr 13}${cpu cpu2} %
${color4}${voffset -6}
${font Sans:bold:size=8}${color}${goto 18}${voffset -6}Cpu3
${font}${voffset -13}${alignc}${hwmon 0 temp 4} °C
${voffset -13}${alignr 13}${cpu cpu3} %
${color4}${voffset -6}
${font Sans:bold:size=8}${color}${goto 18}${voffset -6}Cpu4
${font}${voffset -13}${alignc}${hwmon 0 temp 5} °C
${voffset -13}${alignr 13}${cpu cpu4} %
${color4}${voffset -6}${endif}
#
${voffset -13}\
${if_existing /sys/class/hwmon/hwmon1/temp5_input}\
${font Sans:bold:size=8}${color}${goto 18}${voffset -6}Cpu1
${font}${voffset -13}${alignc}${hwmon 1 temp 2} °C
${voffset -13}${alignr 13}${cpu cpu1} %
${color4}${voffset -6}
${font Sans:bold:size=8}${color}${goto 18}${voffset -6}Cpu2
${font}${voffset -13}${alignc}${hwmon 1 temp 3} °C
${voffset -13}${alignr 13}${cpu cpu2} %
${color4}${voffset -6}
${font Sans:bold:size=8}${color}${goto 18}${voffset -6}Cpu3
${font}${voffset -13}${alignc}${hwmon 1 temp 4} °C
${voffset -13}${alignr 13}${cpu cpu3} %
${color4}${voffset -6}
${font Sans:bold:size=8}${color}${goto 18}${voffset -6}Cpu4
${font}${voffset -13}${alignc}${hwmon 1 temp 5} °C
${voffset -13}${alignr 13}${cpu cpu4} %
${color4}${voffset -6}${endif}
#
${voffset -13}\
${if_existing /sys/class/hwmon/hwmon2/temp5_input}\
${font Sans:bold:size=8}${color}${goto 18}${voffset -6}Cpu1
${font}${voffset -13}${alignc}${hwmon 2 temp 2} °C
${voffset -13}${alignr 13}${cpu cpu1} %
${color4}${voffset -6}
${font Sans:bold:size=8}${color}${goto 18}${voffset -6}Cpu2
${font}${voffset -13}${alignc}${hwmon 2 temp 3} °C
${voffset -13}${alignr 13}${cpu cpu2} %
${color4}${voffset -6}
${font Sans:bold:size=8}${color}${goto 18}${voffset -6}Cpu3
${font}${voffset -13}${alignc}${hwmon 2 temp 4} °C
${voffset -13}${alignr 13}${cpu cpu3} %
${color4}${voffset -6}
${font Sans:bold:size=8}${color}${goto 18}${voffset -6}Cpu4
${font}${voffset -13}${alignc}${hwmon 2 temp 5} °C
${voffset -13}${alignr 13}${cpu cpu4} %
${color4}${voffset -6}${endif}
########################################################################## PROCESSUS EN COURS ############################################################################
${font Sans :regular:size=14}${color1}${goto 20}${voffset 3}Processus en cours${font}${color2}
${font Sans :bold:size=8}${color2}${goto 18}${voffset -2}Processus : ${processes}
${voffset -13}${alignc}en cours : ${running_processes}
${voffset -13}${alignr 13}(${loadavg 1 2 3})
${color4}${voffset -6}${color}
#
#${font Sans :italic:bold:size=8}${goto 18}${voffset -12}Process
#${voffset -13}${alignc}mem
#${voffset -13}${alignc -203}cpu
${font}${goto 18}${voffset -6}${top name 1}
${voffset -13}${alignc}${top mem 1} %
${voffset -13}${alignc -203}${top cpu 1} %
${goto 18}${voffset -6}${top name 2}
${voffset -13}${alignc}${top mem 2} %
${voffset -13}${alignc -203}${top cpu 2} %
${goto 18}${voffset -6}${top name 3}
${voffset -13}${alignc}${top mem 3} %
${voffset -13}${alignc -203}${top cpu 3} %
${goto 18}${voffset -6}${top name 4}
${voffset -13}${alignc}${top mem 4} %
${voffset -13}${alignc -203}${top cpu 4} %
########################################################################## RÉSEAU #######################################################################################
${font Sans :regular:size=14}${color1}${goto 20}${voffset 5}Réseau${font}${color2}
#wlp3s0
${font Sans :bold:size=8}${goto 18}enp4s0
${voffset -13}${alignc}${addr enp4s0}
${voffset -13}${alignr 13}${texeci 3000 wget -O - http://ip.tupeux.com | tail}
${font}${color4}${voffset -6}
${font Sans:bold:size=8}${color}${goto 18}${voffset -6}Réception
${font}${voffset -13}${alignc}${downspeedf enp4s0} kb/s
${voffset -13}${alignr 13}${totaldown enp4s0}
${color4}${voffset -6}
${font Sans:bold:size=8}${color}${goto 18}${voffset -6}Envoi
${font}${voffset -13}${alignc}${upspeedf enp4s0} kb/s
${voffset -13}${alignr 13}${totalup enp4s0}
${color4}${voffset -6}
##################################################################### OCCUPATION DES DISQUES DURS #######################################################################
${font Sans :regular:size=14}${color1}${goto 20}${voffset 3}Occupation des disques durs${font}${color2}
${color}${goto 18}/dev/sda3${goto 90}Windows 7\
${if_mounted /media/Windows}\
${alignc}${diskio_read /dev/sda3}/s
${voffset -13}${alignc -105}${fs_used /media/Windows} / 100GiB
${voffset -13}${alignr 13}${fs_used_perc /media/Windows} %
${color5}${goto 16}${fs_bar /media/Windows}${else}\
#
${color FF0000}${alignr 13}démonté
${color 4C4C4C}${goto 16}${cpubar cpu5}${endif}
#
${color}${goto 18}${voffset 1}/dev/sda4${goto 90}Document-NTFS\
${if_mounted /media/Documents-NTFS}\
${alignc}${diskio_read /dev/sda4}/ ${diskio_write /dev/sda4}
${voffset -13}${alignc -105}${fs_used /media/Documents-NTFS} / 100GiB
${voffset -13}${alignr 13}${fs_used_perc /media/Documents-NTFS} %
${color5}${goto 16}${fs_bar /media/Documents-NTFS}${else}\
#
${color FF0000}${alignr 13}démonté
${color 4C4C4C}${goto 16}${cpubar cpu5}${endif}
#
${font Sans :bold:size=8}${color2}${goto 18}${voffset 1}/dev/sda6${goto 90}(ArchLinux)\
${alignc}${diskio_read /dev/sda6}/ ${diskio_write /dev/sda6}
${voffset -13}${alignc -105}${fs_used /} / 40GiB
${voffset -13}${alignr 13}${fs_used_perc /} %
${font}${goto 16}${color6}${fs_bar /}
#
${color}${goto 18}${voffset 1}/dev/sda7${goto 90}Linux Mint\
${if_mounted /media/Debian}\
${alignc}${diskio_read /dev/sda7}/s
${voffset -13}${alignc -105}${fs_used /media/Debian} / 40GiB
${voffset -13}${alignr 13}${fs_used_perc /media/Debian} %
${color5}${goto 16}${fs_bar /media/Debian}${else}\
#
${color FF0000}${alignr 13}démonté
${color 4C4C4C}${goto 16}${cpubar cpu5}${endif}
#
${color}${goto 18}${voffset 1}/dev/sda8${goto 90}Calculate Linux\
${if_mounted /media/Calculate}\
${alignc}${diskio_read /dev/sda8}/s
${voffset -13}${alignc -105}${fs_used /media/Calculate} / 40GiB
${voffset -13}${alignr 13}${fs_used_perc /media/Calculate} %
${color5}${goto 16}${fs_bar /media/Calculate}${else}\
#
${color FF0000}${alignr 13}démonté
${color 4C4C4C}${goto 16}${cpubar cpu5}${endif}
#
${color}${goto 18}${voffset 1}/dev/sda9${goto 90}Document-EXT4\
${if_mounted /media/Documents-EXT4}\
${alignc}${diskio_read /dev/sda9}/ ${diskio_write /dev/sda9}
${voffset -13}${alignc -105}${fs_used /media/Documents-EXT4} / 600GiB
${voffset -13}${alignr 13}${fs_used_perc /media/Documents-EXT4} %
${color5}${goto 16}${fs_bar /media/Documents-EXT4}${else}\
#
${color FF0000}${alignr 13}démonté
${color 4C4C4C}${goto 16}${cpubar cpu5}${endif}
graph_plasma_dark.lua
Code : Tout sélectionner
require 'cairo'
function set_settings()
graph_settings={
{
name="memperc",
arg="",
max=100,
x=16,
y=241,
width=454,
height=24,
nb_values=200,
background=false,
foreground=true,
autoscale=false,
fg_colour = { {0,0x377c9e,1}}
},
{
name="swapperc",
arg="",
max=100,
x=16,
y=268,
width=454,
height=24,
nb_values=200,
background=false,
foreground=true,
autoscale=false,
fg_colour = { {0,0x377c9e,1}}
},
{
name="cpu",
arg="cpu1",
max=100,
x=16,
y=378,
width=454,
height=24,
nb_values=200,
background=false,
foreground=true,
autoscale=true,
fg_colour = { {0,0x377c9e,1}}
},
{
name="cpu",
arg="cpu2",
max=100,
x=16,
y=405,
width=454,
height=24,
nb_values=200,
background=false,
foreground=true,
autoscale=true,
fg_colour = { {0,0x377c9e,1}}
},
{
name="cpu",
arg="cpu3",
max=100,
x=16,
y=432,
width=454,
height=24,
nb_values=200,
background=false,
foreground=true,
autoscale=true,
fg_colour = { {0,0x377c9e,1}}
},
{
name="cpu",
arg="cpu4",
max=100,
x=16,
y=459,
width=454,
height=24,
nb_values=200,
background=false,
foreground=true,
autoscale=true,
fg_colour = { {0,0x377c9e,1}}
},
{
name="downspeedf",
arg="enp4s0",
max=2500,
x=16,
y=732,
autoscale=false,
width=454,
height=24,
nb_values=150,
fg_bd_size=1,
background=false,
fg_bd_colour = { {1,0x428d3b,1}},
foreground=false,
},
{
name="upspeedf",
arg="enp4s0",
max=500,
x=16,
y=759,
autoscale=false,
width=454,
height=24,
nb_values=150,
fg_bd_size=1,
background=false,
fg_bd_colour = { {1,0x428d3b,1}},
foreground=false,
},
}
end
function check_settings(t)
--tables are check only when conky start
if t.name==nil and t.arg==nil then
print ("No input values ... use parameters 'name'" ..
" with 'arg' or only parameter 'arg' ")
return 1
end
if t.max==nil then
print ("No maximum value defined, use 'max'")
print ("for name=" .. t.name .. " with arg=" .. t.arg)
return 1
end
if t.name==nil then t.name="" end
if t.arg==nil then t.arg="" end
return 0
end
function conky_main_graph()
if conky_window == nil then return end
local w=conky_window.width
local h=conky_window.height
local cs=cairo_xlib_surface_create(conky_window.display,
conky_window.drawable, conky_window.visual, w, h)
cr=cairo_create(cs)
updates=tonumber(conky_parse('${updates}'))
--start drawing after "updates_gap" updates
--prevent segmentation error for cpu
updates_gap=5
if updates==1 then
set_settings()
flagOK=0
for i in pairs(graph_settings) do
if graph_settings[i].width==nil then graph_settings[i].width=100 end
if graph_settings[i].nb_values==nil then
graph_settings[i].nb_values= graph_settings[i].width
end
--create an empty table to store values
graph_settings[i]["values"]={}
--beginning point
graph_settings[i].beg = graph_settings[i].nb_values
--graph_settings[i].beg = 0
for j =1, graph_settings[i].nb_values do
graph_settings[i].values[j]=0
end
graph_settings[i].flag_init=true
flagOK=flagOK + check_settings(graph_settings[i])
end
end
if flagOK>0 then
--abort script if error in one of the tables
print ("ERROR : Check the graph_setting table")
return
end
--drawing process
if updates > updates_gap then
for i in pairs(graph_settings) do
if graph_settings[i].draw_me==true then graph_settings[i].draw_me = nil end
if (graph_settings[i].draw_me==nil or conky_parse(tostring(graph_settings[i].draw_me)) == "1") then
local nb_values=graph_settings[i].nb_values
graph_settings[i].automax=0
for j =1, nb_values do
if graph_settings[i].values[j+1]==nil then
graph_settings[i].values[j+1]=0
end
graph_settings[i].values[j]=graph_settings[i].values[j+1]
if j==nb_values then
--store value
if graph_settings[i].name=="" then
value=graph_settings[i].arg
else
value=tonumber(conky_parse('${' ..
graph_settings[i].name .. " " ..
graph_settings[i].arg ..'}'))
end
graph_settings[i].values[nb_values]=value
end
graph_settings[i].automax=math.max(graph_settings[i].automax,
graph_settings[i].values[j])
--should stop weird glitches at beginning when no values reported yet for upspeed or diskio
if graph_settings[i].automax == 0 then graph_settings[i].automax = 1 end
end
draw_graph(graph_settings[i])
end
end
end
cairo_destroy(cr)
cairo_surface_destroy(cs)
updates=nil
updates_gap=nil
end
function draw_graph(t)
--drawing function
local function rgb_to_r_g_b(colour)
return ((colour[2] / 0x10000) % 0x100) / 255., ((colour[2] / 0x100) % 0x100) / 255., (colour[2] % 0x100) / 255., colour[3]
end
local function linear_orientation(o,w,h)
--set gradient for bg and bg border
local p
if o=="nn" then
p={w/2,h,w/2,0}
elseif o=="ne" then
p={w,h,0,0}
elseif o=="ww" then
p={0,h/2,w,h/2}
elseif o=="se" then
p={w,0,0,h}
elseif o=="ss" then
p={w/2,0,w/2,h}
elseif o=="ee" then
p={w,h/2,0,h/2}
elseif o=="sw" then
p={0,0,w,h}
elseif o=="nw" then
p={0,h,w,0}
end
return p
end
local function linear_orientation_inv(o,w,h)
--set gradient for fg and fg border
local p
if o=="ss" then
p={w/2,h,w/2,0}
elseif o=="sw" then
p={w,h,0,0}
elseif o=="ee" then
p={0,h/2,w,h/2}
elseif o=="nw" then
p={w,0,0,h}
elseif o=="nn" then
p={w/2,0,w/2,h}
elseif o=="ww" then
p={w,h/2,0,h/2}
elseif o=="ne" then
p={0,0,w,h}
elseif o=="se" then
p={0,h,w,0}
end
return p
end
--set default values
--cancel drawing if not needed
if t.draw_me~=nil and conky_parse(tostring(t.draw_me)) ~= "1" then
return
end
if t.height==nil then t.height=20 end
--checked in previous part : width and nb_values
if t.background==nil then t.background=true end
if t.bg_bd_size==nil then t.bg_bd_size=0 end
if t.x==nil then t.x=t.bg_bd_size end
if t.y==nil then t.y=conky_window.height -t.bg_bd_size end
if t.bg_colour==nil then t.bg_colour={{0,0x000000,.5},{1,0xFFFFFF,.5}} end
if t.bg_bd_colour==nil then t.bg_bd_colour={{1,0xFFFFFF,1}} end
if t.foreground==nil then t.foreground=true end
if t.fg_colour==nil then t.fg_colour={{0,0x00FFFF,1},{1,0x0000FF,1}} end
if t.fg_bd_size==nil then t.fg_bd_size=0 end
if t.fg_bd_colour==nil then t.fg_bd_colour={{1,0xFFFF00,1}} end
if t.autoscale==nil then t.autoscale=false end
if t.inverse==nil then t.inverse=false end
if t.angle==nil then t.angle=0 end
if t.bg_bd_orientation==nil then t.bg_bd_orientation="nn" end
if t.bg_orientation==nil then t.bg_orientation="nn" end
if t.fg_bd_orientation==nil then t.fg_bd_orientation="nn" end
if t.fg_orientation==nil then t.fg_orientation="nn" end
--check colours tables
for i=1, #t.fg_colour do
if #t.fg_colour[i]~=3 then
print ("error in fg_colour table")
t.fg_colour[i]={1,0x0000FF,1}
end
end
for i=1, #t.fg_bd_colour do
if #t.fg_bd_colour[i]~=3 then
print ("error in fg_bd_colour table")
t.fg_bd_colour[i]={1,0x00FF00,1}
end
end
for i=1, #t.bg_colour do
if #t.bg_colour[i]~=3 then
print ("error in background color table")
t.bg_colour[i]={1,0xFFFFFF,0.5}
end
end
for i=1, #t.bg_bd_colour do
if #t.bg_bd_colour[i]~=3 then
print ("error in background border color table")
t.bg_bd_colour[i]={1,0xFFFFFF,1}
end
end
--calculate skew parameters if needed
if t.flag_init then
if t.skew_x == nil then
t.skew_x=0
else
t.skew_x = math.pi*t.skew_x/180
end
if t.skew_y == nil then
t.skew_y=0
else
t.skew_y = math.pi*t.skew_y/180
end
t.flag_init=false
end
cairo_set_line_cap(cr,CAIRO_LINE_CAP_ROUND)
cairo_set_line_join(cr,CAIRO_LINE_JOIN_ROUND)
local matrix0 = cairo_matrix_t:create()
tolua.takeownership(matrix0)
cairo_save(cr)
cairo_matrix_init (matrix0, 1,t.skew_y,t.skew_x,1,0,0)
cairo_transform(cr,matrix0)
local ratio=t.width/t.nb_values
cairo_translate(cr,t.x,t.y)
cairo_rotate(cr,t.angle*math.pi/180)
cairo_scale(cr,1,-1)
--background
if t.background then
local pts=linear_orientation(t.bg_orientation,t.width,t.height)
local pat = cairo_pattern_create_linear (pts[1],pts[2],pts[3],pts[4])
for i=1, #t.bg_colour do
--print ("i",i,t.colour[i][1], rgb_to_r_g_b(t.colour[i]))
cairo_pattern_add_color_stop_rgba (pat, t.bg_colour[i][1], rgb_to_r_g_b(t.bg_colour[i]))
end
cairo_set_source (cr, pat)
cairo_rectangle(cr,0,0,t.width,t.height)
cairo_fill(cr)
cairo_pattern_destroy(pat)
end
--autoscale
cairo_save(cr)
if t.autoscale then
t.max= t.automax*1.1
end
local scale_x = t.width/(t.nb_values-1)
local scale_y = t.height/t.max
--define first point of the graph
if updates-updates_gap <t.nb_values then
t.beg = t.beg - 1
--next line prevent segmentation error when conky window is redraw
--quicly when another window "fly" over it
if t.beg<0 then t.beg=0 end
else
t.beg=0
end
if t.inverse then cairo_scale(cr,-1,1)
cairo_translate(cr,-t.width,0) end
--graph foreground
if t.foreground then
local pts_fg=linear_orientation_inv(t.fg_orientation,t.width,t.height)
local pat = cairo_pattern_create_linear (pts_fg[1],pts_fg[2],pts_fg[3],pts_fg[4])
for i=1,#t.fg_colour,1 do
cairo_pattern_add_color_stop_rgba (pat, 1-t.fg_colour[i][1], rgb_to_r_g_b(t.fg_colour[i]))
end
cairo_set_source (cr, pat)
cairo_move_to(cr,t.beg*scale_x,0)
cairo_line_to(cr,t.beg*scale_x,t.values[t.beg+1]*scale_y)
for i=t.beg, t.nb_values-1 do
cairo_line_to(cr,i*scale_x,t.values[i+1]*scale_y)
end
cairo_line_to(cr,(t.nb_values-1)*scale_x,0)
cairo_close_path(cr)
cairo_fill(cr)
cairo_pattern_destroy(pat)
end
--graph_border
if t.fg_bd_size>0 then
local pts=linear_orientation_inv(t.fg_bd_orientation,t.width,t.height)
local pat = cairo_pattern_create_linear (pts[1],pts[2],pts[3],pts[4])
for i=1,#t.fg_bd_colour,1 do
cairo_pattern_add_color_stop_rgba (pat, 1-t.fg_bd_colour[i][1], rgb_to_r_g_b(t.fg_bd_colour[i]))
end
cairo_set_source (cr, pat)
cairo_move_to(cr,t.beg*scale_x,t.values[t.beg+1]*scale_y)
for i=t.beg, t.nb_values-1 do
cairo_line_to(cr,i*scale_x,t.values[i+1]*scale_y)
end
cairo_set_line_width(cr,t.fg_bd_size)
cairo_stroke(cr)
cairo_pattern_destroy(pat)
end
cairo_restore(cr)
--background border
if t.bg_bd_size>0 then
local pts=linear_orientation(t.bg_bd_orientation,t.width,t.height)
local pat = cairo_pattern_create_linear (pts[1],pts[2],pts[3],pts[4])
for i=1, #t.bg_bd_colour do
--print ("i",i,t.colour[i][1], rgb_to_r_g_b(t.colour[i]))
cairo_pattern_add_color_stop_rgba (pat, t.bg_bd_colour[i][1], rgb_to_r_g_b(t.bg_bd_colour[i]))
end
cairo_set_source (cr, pat)
cairo_rectangle(cr,0,0,t.width,t.height)
cairo_set_line_width(cr,t.bg_bd_size)
cairo_stroke(cr)
cairo_pattern_destroy(pat)
end
cairo_restore(cr)
end
Note : j'utilise 2 fichiers lua, 1 pour les graphs, 1 pour les fenêtres, d'où l'usage de 2 conkys. Si je savais coder je joindrais ces 2 fichiers en un seul pour que ce soit plus propre
Et pour lancer le tout :
Code : Tout sélectionner
#!/bin/sh
if [ "$(pidof conky)" ]; then
killall conky
conky -c ~/.conky/conky_plasma_draw_dark
# conky -c ~/.conky/conky_plasma_rss_draw
sleep 4 &&
conky -c ~/.conky/conky_plasma_dark
conky -c ~/.conky/conky_memo_dark
# conky -c ~/.conky/conky_rss_plasma
exit
else
killall conky
conky -c ~/.conky/conky_plasma_draw_dark
# conky -c ~/.conky/conky_plasma_rss_draw
sleep 4 &&
conky -c ~/.conky/conky_plasma_dark
conky -c ~/.conky/conky_memo_dark
# conky -c ~/.conky/conky_rss_plasma
exit
fi