Nos conky 2018

Bureaux,conky et autres personnalisations esthétiques.
Avatar du membre
zeb
Administrateur du site
Messages : 13398
Enregistré le : ven. 19 juin 2015 22:13
Localisation : Au pays du mistral

Nos conky 2018

Message par zeb » lun. 9 avr. 2018 08:43

Salut ;)
A l'image du sujet "nos bureaux.." ce sujet sera dédié aux conky (de cette année).
Dans un premier temps, l'image, suivi du code (en balise code bien sur :l )

Merci pour votre créativité 8-)
LMDE3 cinnamon 64-bit + Lm 17.3 MATE.
Proc: intel I5 4440, Cm: Gigabyte GA-B85M-D3H, Alim: Corsair CX Bronze 430 W, Ram: Crucial Ballistix Sport, 2 x 2 Go.
SSD: 2.5 sandisk ultra+ 64 Go pour /+home, DD: Seagate Barracuda 500 Go pour mes données persos, DD maxtor 160 Go pour la sauvegarde ciblée via luckybackup.
Impr: HP Envy 4502.

Avatar du membre
toryx
Messages : 165
Enregistré le : dim. 11 sept. 2016 21:57

Re: Nos conky 2018

Message par toryx » lun. 9 avr. 2018 21:06

bon ben je commence alors :D
Image

le lanceur qui regroupe tout les conky:

Code : Tout sélectionner

#!/bin/bash
killall conky
conky -p 1 -c ~/.conky/jimmy/conky_kernel &
conky -p 4 -c ~/.conky/jimmy/conky_cpu &
conky -p 4 -c ~/.conky/jimmy/conky_hdd &
conky -p 4 -c ~/.conky/jimmy/conky_network &
conky -p 8 -c ~/.conky/jimmy/conky_nvidiaDemo
exit
faudra adapter les conky suivant pour les modifs répertoires "$HOME/.conky/jimmy/"

le conky_kernel:

Code : Tout sélectionner

conky.config = {
-- ------------------------- Windows Settings
	own_window = true,
	own_window_type = 'normal',
	own_window_transparent = false,
	own_window_hints = 'undecorated,sticky,below,skip_taskbar,skip_pager',
	own_window_argb_visual = true,
	own_window_argb_value = 0,
    border_inner_margin = 0,
	border_outer_margin = 20,

	double_buffer = true,
	background = true,

-- ------------------------- Position
	alignment = 'bottom_left',

	minimum_width = 383,
	minimum_height = 165,
	maximum_width = 500,
	gap_x = 1500,
	gap_y = 600,

-- ------------------------- Font
	use_xft = true,
	xftalpha = 0.8,
	override_utf8_locale = true,

	draw_shades = true,
	default_shade_color = 'black',

	draw_borders = false,
	draw_outline = false,

	font = 'Monofur:bold:size=8',

-- ------------------------- Color
	default_color = 'DCDCDC',
	color0 = '1793d0',
	color1 = 'DDDDDD',
	color2 = 'AAAAAA',
	color3 = '888888',
    color4 = '637A70',

--------------------------- OTHER
    update_interval = 5,

	template0 = [[${GOTO 150}${color\1}${top_mem name \2}${alignr}${top_mem mem \2}%]],

	no_buffers = true,
	     
};

conky.text = [[
${color 6495ee}${font caviar dreams:size=8}${alignr 50}${nodename}
${color 6495ee}${font caviar dreams:size=8}${alignr 50}${exec cat /etc/issue.net}  $machine
${color 6495ee}${font caviar dreams:size=8}${alignr 50}Kernel: ${kernel}
]];
le conky_cpu:

Code : Tout sélectionner

conky.config = {
-- ------------------------- Windows Settings
	own_window = true,
	own_window_type = 'normal',
	own_window_transparent = false,
	own_window_hints = 'undecorated,sticky,below,skip_taskbar,skip_pager',
	own_window_argb_visual = true,
	own_window_argb_value = 0,
    border_inner_margin = 0,
	border_outer_margin = 20,

	double_buffer = true,
	background = true,

-- ------------------------- Position
	alignment = 'bottom_left',

	minimum_width = 383,
	minimum_height = 165,
	maximum_width = 500,
	gap_x = 1475,
	gap_y = 475,

-- ------------------------- Font
	use_xft = true,
	xftalpha = 0.8,
	override_utf8_locale = true,

	draw_shades = true,
	default_shade_color = 'black',

	draw_borders = false,
	draw_outline = false,

	font = 'Monofur:bold:size=8',

-- ------------------------- Color
	default_color = 'DCDCDC',
	color0 = '1793d0',
	color1 = 'DDDDDD',
	color2 = 'AAAAAA',
	color3 = '888888',
    color4 = '637A70',

--------------------------- OTHER
    update_interval = 5,

	template0 = [[${GOTO 150}${color\1}${top_mem name \2}${alignr}${top_mem mem \2}%]],

	no_buffers = true,
	lua_load = '~/.conky/jimmy/lua/bargraph.system.lua',
    lua_draw_hook_post = 'main_bars',
	      
};

conky.text = [[
${voffset 10}${GOTO 50}${color4}${hr 2}${color}
${GOTO 50}${font}${color 637A70}${alignr 200}CPU${color}
${font}${GOTO 60}Core1${alignr 185}${cpu cpu0}%${GOTO 310}${hwmon 1 temp 2}°C${alignr -4}${font}Freq: ${font Monofur:size=8}${freq_g} Ghz
${font}${GOTO 60}Core2${alignr 185}${cpu cpu1}%${GOTO 310}${hwmon 1 temp 3}°C${alignr -4}${font}Freq: ${font Monofur:size=8}${freq_g} Ghz
${font}${GOTO 60}Core3${alignr 185}${cpu cpu2}%${GOTO 310}${hwmon 1 temp 4}°C${alignr -4}${font}Freq: ${font Monofur:size=8}${freq_g} Ghz
${font}${GOTO 60}Core4${alignr 185}${cpu cpu3}%${GOTO 310}${hwmon 1 temp 5}°C${alignr -4}${font}Freq: ${font Monofur:size=8}${freq_g} Ghz
${image ~/.conky/jimmy/img/core_i7.png -p -1,10}
${voffset 5}${GOTO 50}${color4}${hr 2}${color}
${voffset 12}${GOTO 35}${font}${color 637A70}Total:${color DCDCDC} $memmax->${color 637A70}Usage:${GOTO 330}${color DCDCDC}${memperc}% | ${mem}
${alignr 190}${voffset 20}${font Monofur:size=8}${template0 0 1}
${GOTO 20}${template0 1 2}
${template0 2 3}
${template0 3 4}
${template0 4 5}
${image ~/.conky/jimmy/img/ddr3.png -p 50,155}
]];
les img: https://lut.im/uSA9hJONeU/QlCCg82JKYaKKsof.png https://lut.im/GcA38dxaQJ/351tkWuCnPzFObOw.png
le bargraph.system.lua:

Code : Tout sélectionner

--[[ BARGRAPH WIDGET
	Author: Nooby4Ever v2.2
	Original author: wlourf (v1.0-2.1)
	this widget draws a bargraph with different effects 
	http://u-scripts.blogspot.com/2010/07/bargraph-widget.html
	
To call the script in a conky, use, before TEXT
	lua_load /path/to/the/script/NAME-OF-THE-SCRIPT.lua
	lua_draw_hook_pre main_bars
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:
====================
x,y			- coordinates of the starting point of the bar, default = middle of the conky window
cap			- end of cap line, ossibles values are r,b,s (for round, butt, square), default="b"
			  http://www.cairographics.org/samples/set_line_cap/
angle			- angle of rotation of the bar in degress, default = 0 (i.e. a vertical bar)
			  set to 90 for an horizontal bar
skew_x			- skew bar around x axis, default = 0
skew_y			- skew bar around y axis, default = 0
blocks  		- number of blocks to display for a bar (values >0) , default= 10
height			- height of a block, default=10 pixels
width			- width of a block, default=20 pixels
space			- space between 2 blocks, default=2 pixels
angle_bar		- this angle is used to draw a bar on a circular way (ok, this is no more a bar !) default=0
radius			- for cicular bars, internal radius, default=0
			  with radius, parameter width has no more effect.

Colours below are defined into braces {colour in hexadecimal, alpha}
fg_colour		- colour of a block ON, default= {0x00FF00,1}
bg_colour		- colour of a block OFF, default = {0x00FF00,0.5}
alarm			- threshold, values after this threshold will use alarm_colour colour , default=max
alarm_colour 		- colour of a block greater than alarm, default=fg_colour
smooth			- (true or false), create a gradient from fg_colour to bg_colour, default=false 
mid_colour		- colours to add to gradient, with this syntax {position into the gradient (0 to1), colour hexa, alpha}
			  for example, this table {{0.25,0xff0000,1},{0.5,0x00ff00,1},{0.75,0x0000ff,1}} will add
			  3 colurs to gradient created by fg_colour and alarm_colour, default=no mid_colour
led_effect		- add LED effects to each block, default=no led_effect
			  if smooth=true, led_effect is not used
			  possibles values : "r","a","e" for radial, parallelel, perdendicular to the bar (just try!)
			  led_effect has to be used with theses colours :
fg_led			- middle colour of a block ON, default = fg_colour
bg_led			- middle colour of a block OFF, default = bg_colour
alarm_led		- middle colour of a block > ALARM,  default = alarm_colour

==Note: reflection parameters, not avaimable for circular bars
reflection_alpha   	 - add a reflection effect (values from 0 to 1) default = 0 = no reflection
                     	 other values = starting opacity
reflection_scale    	- scale of the reflection (default = 1 = height of text)
reflection_length   	- length of reflection, define where the opacity will be set to zero
			calues from 0 to 1, default =1
reflection		- position of reflection, relative to a vertical bar, default="b"
			  possibles values are : "b","t","l","r" for bottom, top, left, right
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",

============================ EXTENTIONS =====================================================================
==Note: only works with block=1 and angle_bar=0 (circular bars)
handle_show		-(true or false) determins wherther or not the handle is shown
			all parameters of handle only matters if this is set true	
handle_size		- (number >0) determins the width of the handle
handle_color		- colour of the handle, default= {0x00FF00,1}
handle_length		- (number > width) determines the length of the handle
handle_flip		- (true or false) if length is set puts the handle out of the bar on the other side

==Note: not available for circular bars
=== note: txt_offsety and txt_offset are affected by txt_angle, every position is possible just play a bit with them
txt_show		- (true or false) determins wherther or not the text is shown 
			all parameters of txt only matters if this is set true.
txt_angle		- (in degree) rotates text, note the angle is not intuitive. (also see note above)
txt_color		- colour of the handle, default= {0x00FF00,1}
txt_size		- (number >0) size of the text
txt_offset		- (number) adds/substacts an extra offset to the x coordinate of the text (relative to the normal position of the text)
txt_offsety		- (number) adds/substacts an extra offset to the y coordinate of the text (relative to the normal position of the text)
txt_flip		- (true or false) puts the text on the other side of the bar if true
txt_font		- Sets the font of the txt (make sure it is put between "fontname"), default="ubuntu"
txt_add			- Adds aditional text behind the value (you might wan to include a space, example " Seconds"), 
			make sure the text is set between " ".
txt_alarm		- (true or false) if an alarm value is set the color of the text will change to the same color of the alarm
			if the value passes (or equals) the alarm value.

BUGS:
===========
- skew_x + skew_y doesnet work

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 Mar. 2010) added parameters radius & angle_bar to draw the bar in a circular way
v2.0 (12 Jul. 2010) rewrite script + add reflection effects and parameters are now set into tables
v2.1 (07 Jan. 2011) Add draw_me parameter and correct memory leaks, thanks to "Creamy Goodness"
V2.2 (XX XXXX 2013) [FORKED] Added txt and handle support

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

----------------START OF PARAMETERS ----------
function conky_main_bars()
	local bars_settings={
		{	--[ CPU 1 Bar Graph ]--
			name="cpu",
			arg="cpu0",
			max=100,
			alarm=80,
		        alarm_colour={0x104E8B,0.72},
		        bg_colour={0x1AAEB2,0.25},
		        fg_colour={0xDB671E,0.25},
		        mid_colour={{0.45,0xEF2307,0.70}},
			x=160,y=60,
                        cap="r",
                        blocks=36,
			space=2,
		        height=2,width=10,
			angle=90,
			smooth=true,
			draw_me=true
			},
		{	--[ CPU 2 Bar Graph ]--
			name="cpu",
			arg="cpu1",
			max=100,
			alarm=80,
		        alarm_colour={0x104E8B,0.72},
		        bg_colour={0x1AAEB2,0.25},
		        fg_colour={0xDB671E,0.25},
		        mid_colour={{0.45,0xEF2307,0.70}},
			x=160,y=73,
			blocks=36,
                        cap="r",
			space=2,
			height=2,width=10,
			angle=90,
			smooth=true,
			draw_me=true
			},
		{	--[ CPU 3 Bar Graph ]--
			name="cpu",
			arg="cpu2",
			max=100,
			alarm=80,
		        alarm_colour={0x104E8B,0.72},
		        bg_colour={0x1AAEB2,0.25},
		        fg_colour={0xDB671E,0.25},
		        mid_colour={{0.45,0xEF2307,0.70}},
			x=160,y=86,
			blocks=36,
                        cap="r",
			space=2,
			height=2,width=10,
			angle=90,
			smooth=true,
			draw_me=true
			},
		{	--[ CPU 4 Bar Graph ]--
			name="cpu",
			arg="cpu3",
			max=100,
			alarm=80,
		        alarm_colour={0x104E8B,0.72},
		        bg_colour={0x1AAEB2,0.25},
		        fg_colour={0xDB671E,0.25},
		        mid_colour={{0.45,0xEF2307,0.70}},
			x=160,y=99,
			blocks=36,
                        cap="r",
			space=2,
			height=2,width=10,
			angle=90,
			smooth=true,
			draw_me=true
			},
		{	--[ MEMORY Bar Graph ]--
			name="memperc",
			arg="",
			max=100,
			alarm=80,
		        alarm_colour={0xFF0000,0.72},
		        bg_colour={0x1AAEB2,0.25},
		        fg_colour={0xDB671E,0.25},
		        mid_colour={{0.45,0xEF2307,0.70}},
			x=185,y=153,
			blocks=35,
			space=2,
			height=2,width=10,
			angle=90,
			smooth=true,
			draw_me=true
			},
		
		 }	
-----------END OF PARAMETERS--------------

    
	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)    
	--prevent segmentation error when reading cpu state
    if tonumber(conky_parse('${updates}'))>3 then
        for i in pairs(bars_settings) do
        	
        	draw_multi_bar_graph(bars_settings[i])
        	
        end
    end
	cairo_destroy(cr)
	cairo_surface_destroy(cs)
	cr=nil

end

function draw_multi_bar_graph(t)
	cairo_save(cr)
	--check values
	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	
	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'")
		return
	end
	if t.name==nil then t.name="" end
	if t.arg==nil then t.arg="" end

	--set default values	
	if t.x == nil		then t.x = conky_window.width/2 end
	if t.y == nil		then t.y = conky_window.height/2 end
	if t.blocks == nil	then t.blocks=10 end
	if t.height == nil	then t.height=10 end
	if t.angle == nil 	then t.angle=0 end
	t.angle = t.angle*math.pi/180
	--line cap style
	if t.cap==nil		then t.cap = "b" end
	local cap="b"
	for i,v in ipairs({"s","r","b"}) do 
		if v==t.cap then cap=v end
	end
	local delta=0
	if t.cap=="r" or t.cap=="s" then delta = t.height end
	if cap=="s" then 	cap = CAIRO_LINE_CAP_SQUARE
	elseif cap=="r" then
		cap = CAIRO_LINE_CAP_ROUND
	elseif cap=="b" then
		cap = CAIRO_LINE_CAP_BUTT
	end
	--end line cap style
	--if t.led_effect == nil	then t.led_effect="r" end
	if t.width == nil	then t.width=20 end
	if t.space == nil	then t.space=2 end
	if t.radius == nil	then t.radius=0 end
	if t.angle_bar == nil	then t.angle_bar=0 end
	t.angle_bar = t.angle_bar*math.pi/360 --halt angle
	
	--colours
	if t.bg_colour == nil 	then t.bg_colour = {0x00FF00,0.5} end
	if #t.bg_colour~=2 		then t.bg_colour = {0x00FF00,0.5} end
	if t.fg_colour == nil 	then t.fg_colour = {0x00FF00,1} end
	if #t.fg_colour~=2 		then t.fg_colour = {0x00FF00,1} end
	if t.alarm_colour == nil 	then t.alarm_colour = t.fg_colour end
	if #t.alarm_colour~=2 		then t.alarm_colour = t.fg_colour end

	if t.mid_colour ~= nil then	
		for i=1, #t.mid_colour do    
		    if #t.mid_colour[i]~=3 then 
		    	print ("error in mid_color table")
		    	t.mid_colour[i]={1,0xFFFFFF,1} 
		    end
		end
    	end
	
	if t.alarm==nil then t.alarm = t.max end --0.8*t.max end
	if t.smooth == nil then t.smooth = false end

	--handle
	if t.handle_show == nil		then t.handel_show=false end
	if t.handle_size == nil		then t.handle_size=t.width/2 end
	if t.handle_color == nil	then t.handle_color={0x00FF01,1} end
	if #t.handle_color ~= 2		then t.handle_color={0x00FF01,1} end
	if t.handle_length == nil or t.handle_length < t.width	then t.handle_length=t.width end
	if t.handle_flip == nil		then t.handle_flip=false end

	--txt
	if t.txt_show == nil		then t.txt_show=false end
	if t.txt_angle == nil		then t.txt_angle=0 end
	if t.txt_color == nil		then t.txt_color={0x00FF01,1} end
	if #t.txt_color ~= 2		then t.txt_color={0x00FF01,1} end
	if t.txt_size == nil		then t.txt_size=t.width end
	if t.txt_offset == nil		then t.txt_offset=0 end
	if t.txt_flip == nil		then t.txt_flip=false end
	if t.txt_font == nil		then t.txt_font="ubuntu" end
	if t.txt_add == nil		then t.txt_add="" end
	if (t.txt_alarm == nil) or (t.alarm == t.max)		then t.txt_alarm= false end
	if t.txt_offsety == nil		then t.txt_offsety=0 end
	if t.txt_weight == nil		then t.txt_weight=0 end
    
	if t.bg_led ~= nil and #t.bg_led~=2	then t.bg_led = t.bg_colour end
	if t.fg_led ~= nil and #t.fg_led~=2	then t.fg_led = t.fg_colour end
	if t.alarm_led~= nil and #t.alarm_led~=2 then t.alarm_led = t.fg_led end
	
	if t.led_effect~=nil then
		if t.bg_led == nil then t.bg_led = t.bg_colour end
		if t.fg_led == nil 	then t.fg_led = t.fg_colour end
		if t.alarm_led == nil  then t.alarm_led = t.fg_led end
	end

	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
	
	if t.reflection_alpha==nil then t.reflection_alpha=0 end
	if t.reflection_length==nil then t.reflection_length=1 end
	if t.reflection_scale==nil then t.reflection_scale=1 end
	
	--end of default values
	
	-- Function to return r g b color
 	local function rgb_to_r_g_b(col_a)
		return ((col_a[1] / 0x10000) % 0x100) / 255., ((col_a[1] / 0x100) % 0x100) / 255., (col_a[1] % 0x100) / 255., col_a[2]
	end
	
	
	--functions used to create patterns
	local function create_smooth_linear_gradient(x0,y0,x1,y1)
		local pat = cairo_pattern_create_linear (x0,y0,x1,y1)
		cairo_pattern_add_color_stop_rgba (pat, 0, rgb_to_r_g_b(t.fg_colour))
		cairo_pattern_add_color_stop_rgba (pat, 1, rgb_to_r_g_b(t.alarm_colour))
		if t.mid_colour ~=nil then
			for i=1, #t.mid_colour do
				cairo_pattern_add_color_stop_rgba (pat, t.mid_colour[i][1], rgb_to_r_g_b({t.mid_colour[i][2],t.mid_colour[i][3]}))
			end
		end
		return pat
	end

	local function create_smooth_radial_gradient(x0,y0,r0,x1,y1,r1)
		local pat =  cairo_pattern_create_radial (x0,y0,r0,x1,y1,r1)
		cairo_pattern_add_color_stop_rgba (pat, 0, rgb_to_r_g_b(t.fg_colour))
		cairo_pattern_add_color_stop_rgba (pat, 1, rgb_to_r_g_b(t.alarm_colour))
		if t.mid_colour ~=nil then
			for i=1, #t.mid_colour do
				cairo_pattern_add_color_stop_rgba (pat, t.mid_colour[i][1], rgb_to_r_g_b({t.mid_colour[i][2],t.mid_colour[i][3]}))
			end
		end
		return pat
	end
	
	local function create_led_linear_gradient(x0,y0,x1,y1,col_alp,col_led)
		local pat = cairo_pattern_create_linear (x0,y0,x1,y1) ---delta, 0,delta+ t.width,0)
		cairo_pattern_add_color_stop_rgba (pat, 0.0, rgb_to_r_g_b(col_alp))
		cairo_pattern_add_color_stop_rgba (pat, 0.5, rgb_to_r_g_b(col_led))
		cairo_pattern_add_color_stop_rgba (pat, 1.0, rgb_to_r_g_b(col_alp))
		return pat
	end

	local function create_led_radial_gradient(x0,y0,r0,x1,y1,r1,col_alp,col_led,mode)
		local pat = cairo_pattern_create_radial (x0,y0,r0,x1,y1,r1)
		if mode==3 then
			cairo_pattern_add_color_stop_rgba (pat, 0, rgb_to_r_g_b(col_alp))				
			cairo_pattern_add_color_stop_rgba (pat, 0.5, rgb_to_r_g_b(col_led))
			cairo_pattern_add_color_stop_rgba (pat, 1, rgb_to_r_g_b(col_alp))				
		else
			cairo_pattern_add_color_stop_rgba (pat, 0, rgb_to_r_g_b(col_led))
			cairo_pattern_add_color_stop_rgba (pat, 1, rgb_to_r_g_b(col_alp))				
		end
		return pat
	end

	--this fucntion is used for bars with a single block (blocks=1)
	local function draw_single_bar()
		local function create_pattern(col_alp,col_led,bg)
			local pat
			
			if not t.smooth then
				if t.led_effect=="e" then
					pat = create_led_linear_gradient (-delta, 0,delta+ t.width,0,col_alp,col_led)
				elseif t.led_effect=="a" then
					pat = create_led_linear_gradient (t.width/2, 0,t.width/2,-t.height,col_alp,col_led)
				elseif  t.led_effect=="r" then
					pat = create_led_radial_gradient (t.width/2, -t.height/2, 0, t.width/2,-t.height/2,t.height/1.5,col_alp,col_led,2)
				else
					pat = cairo_pattern_create_rgba  (rgb_to_r_g_b(col_alp))
				end
			else
				if bg then
					pat = cairo_pattern_create_rgba  (rgb_to_r_g_b(t.bg_colour))
				else
					pat = create_smooth_linear_gradient(t.width/2, 0, t.width/2,-t.height)
				end
			end
			return pat
		end
		
		local y1=-t.height*pct/100
		local y2,y3
		if pct>(100*t.alarm/t.max) then 
			y1 = -t.height*t.alarm/100
			y2 = -t.height*pct/100
			if t.smooth then y1=y2 end
		end
		
		if t.angle_bar==0 then
		
			--block for fg value
			local pat = create_pattern(t.fg_colour,t.fg_led,false)
			cairo_set_source(cr,pat)
			if (not t.handle_show) then
				cairo_rectangle(cr,0,0,t.width,y1)
			else
				if (y1 <= -t.handle_size) then
					cairo_rectangle(cr,0,0,t.width,y1+t.handle_size)
				end
			end
			cairo_fill(cr)
			cairo_pattern_destroy(pat)

			--block for handle
			if (t.handle_show) then
				local offsetx = 0
				if t.handle_flip then offsetx= t.handle_length-t.width end
				pat = cairo_pattern_create_rgba (rgb_to_r_g_b(t.handle_color))
				cairo_set_source(cr,pat)
				if (y1 >= -t.handle_size) then
					cairo_rectangle(cr,0-offsetx,0,t.handle_length,y1)
				else
					cairo_rectangle(cr,0-offsetx,y1+t.handle_size,t.handle_length,-t.handle_size)	
				end
				cairo_fill(cr)
				cairo_pattern_destroy(pat)
			end
			
			-- block for alarm value			
			if not t.smooth and y2 ~=nil then 
				pat = create_pattern(t.alarm_colour,t.alarm_led,false)
				cairo_set_source(cr,pat)
				cairo_rectangle(cr,0,y1,t.width,y2-y1)
				cairo_fill(cr)
				y3=y2
				cairo_pattern_destroy(pat)
			else
				y2,y3=y1,y1
			end

			-- block for bg value
			cairo_rectangle(cr,0,y2,t.width,-t.height-y3)
			pat = create_pattern(t.bg_colour,t.bg_led,true)
			cairo_set_source(cr,pat)
			cairo_pattern_destroy(pat)
			cairo_fill(cr)
		end		
	end  --end single bar
	
	--function used for bars with 2 or more blocks
	local function draw_multi_bar()
		for pt = 1,t.blocks do 
			--set block y
			local y1 = -(pt-1)*(t.height+t.space)
			local light_on=false
			
			--set colors
			local col_alp = t.bg_colour
			local col_led = t.bg_led
			if pct>=(100/t.blocks) or pct>0 then --ligth on or not the block
				if pct>=(pcb*(pt-1))  then 
					light_on = true
					if pct>=(100*t.alarm/t.max) and (pcb*pt)>(100*t.alarm/t.max) then 	-- Check whether the value is in the alarm range
						col_alp = t.alarm_colour 
						col_led = t.alarm_led 
					else
						-- Not in alarm range
						col_alp = t.fg_colour
						col_led = t.fg_led
					end
				end
			end

			--set colors
			--have to try to create gradients outside the loop ?
			local pat 
			
			if not t.smooth then
				if t.angle_bar==0 then
					if t.led_effect=="e" then
						pat = create_led_linear_gradient (-delta, 0,delta+ t.width,0,col_alp,col_led)
					elseif t.led_effect=="a" then
						pat = create_led_linear_gradient (t.width/2, -t.height/2+y1,t.width/2,0+t.height/2+y1,col_alp,col_led)					
					elseif  t.led_effect=="r" then
						pat = create_led_radial_gradient (t.width/2, y1, 0, t.width/2,y1,t.width/1.5,col_alp,col_led,2)	
					else
						pat = cairo_pattern_create_rgba  (rgb_to_r_g_b(col_alp))
					end
				else
					 if t.led_effect=="a"  then
						 pat = create_led_radial_gradient (0, 0, t.radius+(t.height+t.space)*(pt-1), 0, 0, t.radius+(t.height+t.space)*(pt), col_alp,col_led,3)	
					else
						pat = cairo_pattern_create_rgba  (rgb_to_r_g_b(col_alp))					
					end
					
				end
			else
				
				if light_on then
					if t.angle_bar==0 then
						pat = create_smooth_linear_gradient(t.width/2, t.height/2, t.width/2,-(t.blocks-0.5)*(t.height+t.space))
					else
						pat = create_smooth_radial_gradient(0, 0, (t.height+t.space),  0,0,(t.blocks+1)*(t.height+t.space),2)
					end
				else		
					pat = cairo_pattern_create_rgba  (rgb_to_r_g_b(t.bg_colour))
				end
			end
			cairo_set_source (cr, pat)
			cairo_pattern_destroy(pat)

			--draw a block
			if t.angle_bar==0 then
				cairo_move_to(cr,0,y1)
				cairo_line_to(cr,t.width,y1)
			else		
				cairo_arc( cr,0,0,
					t.radius+(t.height+t.space)*(pt)-t.height/2,
					 -t.angle_bar -math.pi/2 ,
					 t.angle_bar -math.pi/2)
			end
			cairo_stroke(cr)
		end	
	end
	
	
	
	--function used to retrieve the value to display and to set the cairo structure
	local function setup_bar_graph()
		if t.blocks ~=1 then t.y=t.y-t.height/2 end
		
		local value = 0
		if t.name ~="" then
			value = tonumber(conky_parse(string.format('${%s %s}', t.name, t.arg)))

			--$to_bytes doesn't work when value has a decimal point,
			--https://garage.maemo.org/plugins/ggit/browse.php/?p=monky;a=commitdiff;h=174c256c81a027a2ea406f5f37dc036fac0a524b;hp=d75e2db5ed3fc788fb8514121f67316ac3e5f29f
			--http://sourceforge.net/tracker/index.php?func=detail&aid=3000865&group_id=143975&atid=757310
			--conky bug?
			--value = (conky_parse(string.format('${%s %s}', t.name, t.arg)))
			--if string.match(value,"%w") then
			--	value = conky_parse(string.format('${to_bytes %s}',value))
			--end
		else
			value = tonumber(t.arg)
		end
	
		-- Value checks
		if value==nil then value =0 end
		if value > t.max then 
			print ("value retrieved from conky: " .. value .. " is bigger than max: " .. t.max .. ", value is set to max.")
			value=t.max
		end
		
		pct = 100*value/t.max
		pcb = 100/t.blocks
		
		cairo_set_line_width (cr, t.height)
		cairo_set_line_cap  (cr, cap)
		cairo_translate(cr,t.x,t.y)
		cairo_rotate(cr,t.angle)

		local matrix0 = cairo_matrix_t:create()
		tolua.takeownership(matrix0)
		cairo_matrix_init (matrix0, 1,t.skew_y,t.skew_x,1,0,0)
		cairo_transform(cr,matrix0)	
		
		--call the drawing function for blocks
		if t.blocks==1 and t.angle_bar==0 then
			draw_single_bar()
			if t.reflection=="t" or t.reflection=="b" then cairo_translate(cr,0,-t.height) end
		else
			draw_multi_bar()
		end

		--block for TXT
		-- -- Must be drawn after "bar" is assigned to matrix to avoid reflection of the text
		if (t.txt_show and t.angle_bar==0) then
			local ypos=0
			local barnr=0
			if (t.blocks == 1) then		--Determine the y position of the txt
				ypos = -t.height*pct/100 - t.txt_offsety
			else
				--Inefficient, feel free to replace with a formula (get block of the value)
				if (value <  (t.max/t.blocks)) then
					ypos= 0
				elseif (value > (t.max - (t.max/t.blocks))) then
					ypos= -(t.blocks-1)*(t.height+t.space)
				else
					for bar = 1,t.blocks do
						if not ((pct>=(100/t.blocks) or pct>0) and (pct>=(pcb*(bar-1)))) then --ligth on or not the block	
							barnr=bar					
							break
						end
					end
					ypos= -(barnr-2)*(t.height+t.space) - t.txt_offsety
				end
			end
			cairo_save(cr)	
			cairo_select_font_face(cr, t.txt_font, CAIRO_FONT_SLANT_NORMAL, t.txt_weight)
    			cairo_set_font_size(cr, t.txt_size)
			if (t.txt_alarm and value >= t.alarm) then
				cairo_set_source_rgba(cr, rgb_to_r_g_b(t.alarm_colour))
			else
				cairo_set_source_rgba(cr, rgb_to_r_g_b(t.txt_color))
			end
			if (t.txt_flip) then
				cairo_move_to (cr, -(t.width+t.txt_offset), ypos+10)
			else
				cairo_move_to (cr, t.width+t.txt_offset, ypos+10)
			end
			cairo_rotate(cr,t.txt_angle)
			cairo_show_text(cr, (pct/100*t.max) .. t.txt_add)
			cairo_restore(cr)
		end

		--dot for reminder (uncomment to debug, indicates 0,0)
		--[[		
		if t.blocks ~=1 then
			cairo_set_source_rgba(cr,1,0,0,1)
			cairo_arc(cr,0,t.height/2,3,0,2*math.pi)
			cairo_fill(cr)
		else
			cairo_set_source_rgba(cr,1,0,0,1)
			cairo_arc(cr,0,0,3,0,2*math.pi)
			cairo_fill(cr)
		end]]
		
		--call the drawing function for reflection and prepare the mask used		
		if t.reflection_alpha>0 and t.angle_bar==0 then
			local pat2
			local matrix1 = cairo_matrix_t:create()
			tolua.takeownership(matrix1)
			pts={-delta/2,(t.height+t.space)/2,t.width+delta,-(t.height+t.space)*(t.blocks)}
			if t.reflection=="t" then
				cairo_matrix_init (matrix1,1,0,0,-t.reflection_scale,0,-(t.height+t.space)*(t.blocks-0.5)*2*(t.reflection_scale+1)/2)
				pat2 = cairo_pattern_create_linear (t.width/2,-(t.height+t.space)*(t.blocks),t.width/2,(t.height+t.space)/2)
			elseif t.reflection=="r" then
				cairo_matrix_init (matrix1,-t.reflection_scale,0,0,1,delta+2*t.width,0)
				pat2 = cairo_pattern_create_linear (delta/2+t.width,0,-delta/2,0)
			elseif t.reflection=="l" then
				cairo_matrix_init (matrix1,-t.reflection_scale,0,0,1,-delta,0)
				pat2 = cairo_pattern_create_linear (-delta/2,0,delta/2+t.width,-0)
			else --bottom
				cairo_matrix_init (matrix1,1,0,0,-1*t.reflection_scale,0,(t.height+t.space)*(t.reflection_scale+1)/2)
				pat2 = cairo_pattern_create_linear (t.width/2,(t.height+t.space)/2,t.width/2,-(t.height+t.space)*(t.blocks))
			end

			cairo_transform(cr,matrix1)

			if t.blocks==1 then
				draw_single_bar()
				cairo_translate(cr,0,-t.height/2) 
			else
				draw_multi_bar()
			end
						
			cairo_set_line_width(cr,0.01)
			cairo_pattern_add_color_stop_rgba (pat2, 0,0,0,0,1-t.reflection_alpha)
			cairo_pattern_add_color_stop_rgba (pat2, t.reflection_length,0,0,0,1)
			cairo_rectangle(cr,pts[1],pts[2],pts[3],pts[4])

			cairo_clip_preserve(cr)
			cairo_set_operator(cr,CAIRO_OPERATOR_CLEAR)
			cairo_stroke(cr)
			cairo_mask(cr,pat2)
			cairo_pattern_destroy(pat2)
			cairo_set_operator(cr,CAIRO_OPERATOR_OVER)
			
		end --reflection

		pct,pcb=nil
	end --setup_bar_graph()
	
	--start here !
	setup_bar_graph()
	cairo_restore(cr)
end
le conky_hdd:

Code : Tout sélectionner

conky.config = {
-- ------------------------- Windows Settings
	own_window = true,
	own_window_type = 'normal',
	own_window_transparent = false,
	own_window_hints = 'undecorated,sticky,below,skip_taskbar,skip_pager',
	own_window_argb_visual = true,
	own_window_argb_value = 0,

	double_buffer = true,
	background = true,

-- ------------------------- Position
	alignment = 'bottom_left',

	maximum_width = 383,
    minimum_width = 400,
	maximum_height = 10,
	gap_x = 1500,
	gap_y = 260,

-- ------------------------- Font
	use_xft = true,
	xftalpha = 0.8,
	override_utf8_locale = true,

	draw_shades = true,
	default_shade_color = 'black',

	draw_borders = false,
	draw_outline = false,

	font = 'Monofur:bold:size=8',

-- ------------------------- Color
	default_color = 'DCDCDC',
    color0 = '637A70',

--------------------------- OTHER
	update_interval = 1,
    lua_load = '~/.conky/jimmy/lua/bargraph.hdd.lua',
    lua_draw_hook_post = 'main_bars',
};

conky.text = [[
${voffset 35}${GOTO 50}${color0}${hr 2}${color}
${GOTO 110}${color 637A70}${font}HDD:${GOTO 110}${color}${font}${GOTO 170}Temp: ${font Monofur:size=8}${hwmon 1 temp 1}°C${GOTO 230} 
${GOTO 60}${font Monofur:size=8}${voffset 35}${font}System: ${alignr 5}${font Monofur:size=8}utilisé ${fs_used /} ${fs_used_perc /}%
${GOTO 70}${font Monofur:size=8}${voffset 3}${font}Home: ${alignr 5}${font Monofur:size=8}utilisé ${fs_used /home} ${fs_used_perc /home}%
${voffset 70}

${image ~/.conky/jimmy/img/Hard_disc.png -p 50,50}
]];
les img: https://lut.im/5QytGfaeou/NdgMH4N7DCZreocd.png
le bargraph.hdd.lua:

Code : Tout sélectionner

--[[ BARGRAPH WIDGET
	Author: Nooby4Ever v2.2
	Original author: wlourf (v1.0-2.1)
	this widget draws a bargraph with different effects 
	http://u-scripts.blogspot.com/2010/07/bargraph-widget.html
	
To call the script in a conky, use, before TEXT
	lua_load /path/to/the/script/NAME-OF-THE-SCRIPT.lua
	lua_draw_hook_pre main_bars
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:
====================
x,y			- coordinates of the starting point of the bar, default = middle of the conky window
cap			- end of cap line, ossibles values are r,b,s (for round, butt, square), default="b"
			  http://www.cairographics.org/samples/set_line_cap/
angle			- angle of rotation of the bar in degress, default = 0 (i.e. a vertical bar)
			  set to 90 for an horizontal bar
skew_x			- skew bar around x axis, default = 0
skew_y			- skew bar around y axis, default = 0
blocks  		- number of blocks to display for a bar (values >0) , default= 10
height			- height of a block, default=10 pixels
width			- width of a block, default=20 pixels
space			- space between 2 blocks, default=2 pixels
angle_bar		- this angle is used to draw a bar on a circular way (ok, this is no more a bar !) default=0
radius			- for cicular bars, internal radius, default=0
			  with radius, parameter width has no more effect.

Colours below are defined into braces {colour in hexadecimal, alpha}
fg_colour		- colour of a block ON, default= {0x00FF00,1}
bg_colour		- colour of a block OFF, default = {0x00FF00,0.5}
alarm			- threshold, values after this threshold will use alarm_colour colour , default=max
alarm_colour 		- colour of a block greater than alarm, default=fg_colour
smooth			- (true or false), create a gradient from fg_colour to bg_colour, default=false 
mid_colour		- colours to add to gradient, with this syntax {position into the gradient (0 to1), colour hexa, alpha}
			  for example, this table {{0.25,0xff0000,1},{0.5,0x00ff00,1},{0.75,0x0000ff,1}} will add
			  3 colurs to gradient created by fg_colour and alarm_colour, default=no mid_colour
led_effect		- add LED effects to each block, default=no led_effect
			  if smooth=true, led_effect is not used
			  possibles values : "r","a","e" for radial, parallelel, perdendicular to the bar (just try!)
			  led_effect has to be used with theses colours :
fg_led			- middle colour of a block ON, default = fg_colour
bg_led			- middle colour of a block OFF, default = bg_colour
alarm_led		- middle colour of a block > ALARM,  default = alarm_colour

==Note: reflection parameters, not avaimable for circular bars
reflection_alpha   	 - add a reflection effect (values from 0 to 1) default = 0 = no reflection
                     	 other values = starting opacity
reflection_scale    	- scale of the reflection (default = 1 = height of text)
reflection_length   	- length of reflection, define where the opacity will be set to zero
			calues from 0 to 1, default =1
reflection		- position of reflection, relative to a vertical bar, default="b"
			  possibles values are : "b","t","l","r" for bottom, top, left, right
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",

============================ EXTENTIONS =====================================================================
==Note: only works with block=1 and angle_bar=0 (circular bars)
handle_show		-(true or false) determins wherther or not the handle is shown
			all parameters of handle only matters if this is set true	
handle_size		- (number >0) determins the width of the handle
handle_color		- colour of the handle, default= {0x00FF00,1}
handle_length		- (number > width) determines the length of the handle
handle_flip		- (true or false) if length is set puts the handle out of the bar on the other side

==Note: not available for circular bars
=== note: txt_offsety and txt_offset are affected by txt_angle, every position is possible just play a bit with them
txt_show		- (true or false) determins wherther or not the text is shown 
			all parameters of txt only matters if this is set true.
txt_angle		- (in degree) rotates text, note the angle is not intuitive. (also see note above)
txt_color		- colour of the handle, default= {0x00FF00,1}
txt_size		- (number >0) size of the text
txt_offset		- (number) adds/substacts an extra offset to the x coordinate of the text (relative to the normal position of the text)
txt_offsety		- (number) adds/substacts an extra offset to the y coordinate of the text (relative to the normal position of the text)
txt_flip		- (true or false) puts the text on the other side of the bar if true
txt_font		- Sets the font of the txt (make sure it is put between "fontname"), default="ubuntu"
txt_add			- Adds aditional text behind the value (you might wan to include a space, example " Seconds"), 
			make sure the text is set between " ".
txt_alarm		- (true or false) if an alarm value is set the color of the text will change to the same color of the alarm
			if the value passes (or equals) the alarm value.

BUGS:
===========
- skew_x + skew_y doesnet work

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 Mar. 2010) added parameters radius & angle_bar to draw the bar in a circular way
v2.0 (12 Jul. 2010) rewrite script + add reflection effects and parameters are now set into tables
v2.1 (07 Jan. 2011) Add draw_me parameter and correct memory leaks, thanks to "Creamy Goodness"
V2.2 (XX XXXX 2013) [FORKED] Added txt and handle support

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

----------------START OF PARAMETERS ----------
function conky_main_bars()
	local bars_settings={
		{	--[ Hdd sys ]--
			name="fs_used_perc",
			arg="",
			max=100,
			alarm=80,
		        alarm_colour={0x104E8B,0.72},
		        bg_colour={0x1AAEB2,0.25},
		        fg_colour={0xDB671E,0.25},
		        mid_colour={{0.45,0xEF2307,0.70}},
			x=120,y=105,
                        cap="r",
                        blocks=36,
			space=2,
		        height=2,width=10,
			angle=90,
			smooth=true,
			draw_me=true
			},
		{	--[ hdd home ]--
			name="fs_used_perc",
			arg="/home",
			max=100,
			alarm=80,
		        alarm_colour={0x104E8B,0.72},
		        bg_colour={0x1AAEB2,0.25},
		        fg_colour={0xDB671E,0.25},
		        mid_colour={{0.45,0xEF2307,0.70}},
			x=120,y=118,
			blocks=36,
                        cap="r",
			space=2,
			height=2,width=10,
			angle=90,
			smooth=true,
			draw_me=true
			},
				
		 }	
-----------END OF PARAMETERS--------------

    
	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)    
	--prevent segmentation error when reading cpu state
    if tonumber(conky_parse('${updates}'))>3 then
        for i in pairs(bars_settings) do
        	
        	draw_multi_bar_graph(bars_settings[i])
        	
        end
    end
	cairo_destroy(cr)
	cairo_surface_destroy(cs)
	cr=nil

end

function draw_multi_bar_graph(t)
	cairo_save(cr)
	--check values
	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	
	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'")
		return
	end
	if t.name==nil then t.name="" end
	if t.arg==nil then t.arg="" end

	--set default values	
	if t.x == nil		then t.x = conky_window.width/2 end
	if t.y == nil		then t.y = conky_window.height/2 end
	if t.blocks == nil	then t.blocks=10 end
	if t.height == nil	then t.height=10 end
	if t.angle == nil 	then t.angle=0 end
	t.angle = t.angle*math.pi/180
	--line cap style
	if t.cap==nil		then t.cap = "b" end
	local cap="b"
	for i,v in ipairs({"s","r","b"}) do 
		if v==t.cap then cap=v end
	end
	local delta=0
	if t.cap=="r" or t.cap=="s" then delta = t.height end
	if cap=="s" then 	cap = CAIRO_LINE_CAP_SQUARE
	elseif cap=="r" then
		cap = CAIRO_LINE_CAP_ROUND
	elseif cap=="b" then
		cap = CAIRO_LINE_CAP_BUTT
	end
	--end line cap style
	--if t.led_effect == nil	then t.led_effect="r" end
	if t.width == nil	then t.width=20 end
	if t.space == nil	then t.space=2 end
	if t.radius == nil	then t.radius=0 end
	if t.angle_bar == nil	then t.angle_bar=0 end
	t.angle_bar = t.angle_bar*math.pi/360 --halt angle
	
	--colours
	if t.bg_colour == nil 	then t.bg_colour = {0x00FF00,0.5} end
	if #t.bg_colour~=2 		then t.bg_colour = {0x00FF00,0.5} end
	if t.fg_colour == nil 	then t.fg_colour = {0x00FF00,1} end
	if #t.fg_colour~=2 		then t.fg_colour = {0x00FF00,1} end
	if t.alarm_colour == nil 	then t.alarm_colour = t.fg_colour end
	if #t.alarm_colour~=2 		then t.alarm_colour = t.fg_colour end

	if t.mid_colour ~= nil then	
		for i=1, #t.mid_colour do    
		    if #t.mid_colour[i]~=3 then 
		    	print ("error in mid_color table")
		    	t.mid_colour[i]={1,0xFFFFFF,1} 
		    end
		end
    	end
	
	if t.alarm==nil then t.alarm = t.max end --0.8*t.max end
	if t.smooth == nil then t.smooth = false end

	--handle
	if t.handle_show == nil		then t.handel_show=false end
	if t.handle_size == nil		then t.handle_size=t.width/2 end
	if t.handle_color == nil	then t.handle_color={0x00FF01,1} end
	if #t.handle_color ~= 2		then t.handle_color={0x00FF01,1} end
	if t.handle_length == nil or t.handle_length < t.width	then t.handle_length=t.width end
	if t.handle_flip == nil		then t.handle_flip=false end

	--txt
	if t.txt_show == nil		then t.txt_show=false end
	if t.txt_angle == nil		then t.txt_angle=0 end
	if t.txt_color == nil		then t.txt_color={0x00FF01,1} end
	if #t.txt_color ~= 2		then t.txt_color={0x00FF01,1} end
	if t.txt_size == nil		then t.txt_size=t.width end
	if t.txt_offset == nil		then t.txt_offset=0 end
	if t.txt_flip == nil		then t.txt_flip=false end
	if t.txt_font == nil		then t.txt_font="ubuntu" end
	if t.txt_add == nil		then t.txt_add="" end
	if (t.txt_alarm == nil) or (t.alarm == t.max)		then t.txt_alarm= false end
	if t.txt_offsety == nil		then t.txt_offsety=0 end
	if t.txt_weight == nil		then t.txt_weight=0 end
    
	if t.bg_led ~= nil and #t.bg_led~=2	then t.bg_led = t.bg_colour end
	if t.fg_led ~= nil and #t.fg_led~=2	then t.fg_led = t.fg_colour end
	if t.alarm_led~= nil and #t.alarm_led~=2 then t.alarm_led = t.fg_led end
	
	if t.led_effect~=nil then
		if t.bg_led == nil then t.bg_led = t.bg_colour end
		if t.fg_led == nil 	then t.fg_led = t.fg_colour end
		if t.alarm_led == nil  then t.alarm_led = t.fg_led end
	end

	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
	
	if t.reflection_alpha==nil then t.reflection_alpha=0 end
	if t.reflection_length==nil then t.reflection_length=1 end
	if t.reflection_scale==nil then t.reflection_scale=1 end
	
	--end of default values
	
	-- Function to return r g b color
 	local function rgb_to_r_g_b(col_a)
		return ((col_a[1] / 0x10000) % 0x100) / 255., ((col_a[1] / 0x100) % 0x100) / 255., (col_a[1] % 0x100) / 255., col_a[2]
	end
	
	
	--functions used to create patterns
	local function create_smooth_linear_gradient(x0,y0,x1,y1)
		local pat = cairo_pattern_create_linear (x0,y0,x1,y1)
		cairo_pattern_add_color_stop_rgba (pat, 0, rgb_to_r_g_b(t.fg_colour))
		cairo_pattern_add_color_stop_rgba (pat, 1, rgb_to_r_g_b(t.alarm_colour))
		if t.mid_colour ~=nil then
			for i=1, #t.mid_colour do
				cairo_pattern_add_color_stop_rgba (pat, t.mid_colour[i][1], rgb_to_r_g_b({t.mid_colour[i][2],t.mid_colour[i][3]}))
			end
		end
		return pat
	end

	local function create_smooth_radial_gradient(x0,y0,r0,x1,y1,r1)
		local pat =  cairo_pattern_create_radial (x0,y0,r0,x1,y1,r1)
		cairo_pattern_add_color_stop_rgba (pat, 0, rgb_to_r_g_b(t.fg_colour))
		cairo_pattern_add_color_stop_rgba (pat, 1, rgb_to_r_g_b(t.alarm_colour))
		if t.mid_colour ~=nil then
			for i=1, #t.mid_colour do
				cairo_pattern_add_color_stop_rgba (pat, t.mid_colour[i][1], rgb_to_r_g_b({t.mid_colour[i][2],t.mid_colour[i][3]}))
			end
		end
		return pat
	end
	
	local function create_led_linear_gradient(x0,y0,x1,y1,col_alp,col_led)
		local pat = cairo_pattern_create_linear (x0,y0,x1,y1) ---delta, 0,delta+ t.width,0)
		cairo_pattern_add_color_stop_rgba (pat, 0.0, rgb_to_r_g_b(col_alp))
		cairo_pattern_add_color_stop_rgba (pat, 0.5, rgb_to_r_g_b(col_led))
		cairo_pattern_add_color_stop_rgba (pat, 1.0, rgb_to_r_g_b(col_alp))
		return pat
	end

	local function create_led_radial_gradient(x0,y0,r0,x1,y1,r1,col_alp,col_led,mode)
		local pat = cairo_pattern_create_radial (x0,y0,r0,x1,y1,r1)
		if mode==3 then
			cairo_pattern_add_color_stop_rgba (pat, 0, rgb_to_r_g_b(col_alp))				
			cairo_pattern_add_color_stop_rgba (pat, 0.5, rgb_to_r_g_b(col_led))
			cairo_pattern_add_color_stop_rgba (pat, 1, rgb_to_r_g_b(col_alp))				
		else
			cairo_pattern_add_color_stop_rgba (pat, 0, rgb_to_r_g_b(col_led))
			cairo_pattern_add_color_stop_rgba (pat, 1, rgb_to_r_g_b(col_alp))				
		end
		return pat
	end

	--this fucntion is used for bars with a single block (blocks=1)
	local function draw_single_bar()
		local function create_pattern(col_alp,col_led,bg)
			local pat
			
			if not t.smooth then
				if t.led_effect=="e" then
					pat = create_led_linear_gradient (-delta, 0,delta+ t.width,0,col_alp,col_led)
				elseif t.led_effect=="a" then
					pat = create_led_linear_gradient (t.width/2, 0,t.width/2,-t.height,col_alp,col_led)
				elseif  t.led_effect=="r" then
					pat = create_led_radial_gradient (t.width/2, -t.height/2, 0, t.width/2,-t.height/2,t.height/1.5,col_alp,col_led,2)
				else
					pat = cairo_pattern_create_rgba  (rgb_to_r_g_b(col_alp))
				end
			else
				if bg then
					pat = cairo_pattern_create_rgba  (rgb_to_r_g_b(t.bg_colour))
				else
					pat = create_smooth_linear_gradient(t.width/2, 0, t.width/2,-t.height)
				end
			end
			return pat
		end
		
		local y1=-t.height*pct/100
		local y2,y3
		if pct>(100*t.alarm/t.max) then 
			y1 = -t.height*t.alarm/100
			y2 = -t.height*pct/100
			if t.smooth then y1=y2 end
		end
		
		if t.angle_bar==0 then
		
			--block for fg value
			local pat = create_pattern(t.fg_colour,t.fg_led,false)
			cairo_set_source(cr,pat)
			if (not t.handle_show) then
				cairo_rectangle(cr,0,0,t.width,y1)
			else
				if (y1 <= -t.handle_size) then
					cairo_rectangle(cr,0,0,t.width,y1+t.handle_size)
				end
			end
			cairo_fill(cr)
			cairo_pattern_destroy(pat)

			--block for handle
			if (t.handle_show) then
				local offsetx = 0
				if t.handle_flip then offsetx= t.handle_length-t.width end
				pat = cairo_pattern_create_rgba (rgb_to_r_g_b(t.handle_color))
				cairo_set_source(cr,pat)
				if (y1 >= -t.handle_size) then
					cairo_rectangle(cr,0-offsetx,0,t.handle_length,y1)
				else
					cairo_rectangle(cr,0-offsetx,y1+t.handle_size,t.handle_length,-t.handle_size)	
				end
				cairo_fill(cr)
				cairo_pattern_destroy(pat)
			end
			
			-- block for alarm value			
			if not t.smooth and y2 ~=nil then 
				pat = create_pattern(t.alarm_colour,t.alarm_led,false)
				cairo_set_source(cr,pat)
				cairo_rectangle(cr,0,y1,t.width,y2-y1)
				cairo_fill(cr)
				y3=y2
				cairo_pattern_destroy(pat)
			else
				y2,y3=y1,y1
			end

			-- block for bg value
			cairo_rectangle(cr,0,y2,t.width,-t.height-y3)
			pat = create_pattern(t.bg_colour,t.bg_led,true)
			cairo_set_source(cr,pat)
			cairo_pattern_destroy(pat)
			cairo_fill(cr)
		end		
	end  --end single bar
	
	--function used for bars with 2 or more blocks
	local function draw_multi_bar()
		for pt = 1,t.blocks do 
			--set block y
			local y1 = -(pt-1)*(t.height+t.space)
			local light_on=false
			
			--set colors
			local col_alp = t.bg_colour
			local col_led = t.bg_led
			if pct>=(100/t.blocks) or pct>0 then --ligth on or not the block
				if pct>=(pcb*(pt-1))  then 
					light_on = true
					if pct>=(100*t.alarm/t.max) and (pcb*pt)>(100*t.alarm/t.max) then 	-- Check whether the value is in the alarm range
						col_alp = t.alarm_colour 
						col_led = t.alarm_led 
					else
						-- Not in alarm range
						col_alp = t.fg_colour
						col_led = t.fg_led
					end
				end
			end

			--set colors
			--have to try to create gradients outside the loop ?
			local pat 
			
			if not t.smooth then
				if t.angle_bar==0 then
					if t.led_effect=="e" then
						pat = create_led_linear_gradient (-delta, 0,delta+ t.width,0,col_alp,col_led)
					elseif t.led_effect=="a" then
						pat = create_led_linear_gradient (t.width/2, -t.height/2+y1,t.width/2,0+t.height/2+y1,col_alp,col_led)					
					elseif  t.led_effect=="r" then
						pat = create_led_radial_gradient (t.width/2, y1, 0, t.width/2,y1,t.width/1.5,col_alp,col_led,2)	
					else
						pat = cairo_pattern_create_rgba  (rgb_to_r_g_b(col_alp))
					end
				else
					 if t.led_effect=="a"  then
						 pat = create_led_radial_gradient (0, 0, t.radius+(t.height+t.space)*(pt-1), 0, 0, t.radius+(t.height+t.space)*(pt), col_alp,col_led,3)	
					else
						pat = cairo_pattern_create_rgba  (rgb_to_r_g_b(col_alp))					
					end
					
				end
			else
				
				if light_on then
					if t.angle_bar==0 then
						pat = create_smooth_linear_gradient(t.width/2, t.height/2, t.width/2,-(t.blocks-0.5)*(t.height+t.space))
					else
						pat = create_smooth_radial_gradient(0, 0, (t.height+t.space),  0,0,(t.blocks+1)*(t.height+t.space),2)
					end
				else		
					pat = cairo_pattern_create_rgba  (rgb_to_r_g_b(t.bg_colour))
				end
			end
			cairo_set_source (cr, pat)
			cairo_pattern_destroy(pat)

			--draw a block
			if t.angle_bar==0 then
				cairo_move_to(cr,0,y1)
				cairo_line_to(cr,t.width,y1)
			else		
				cairo_arc( cr,0,0,
					t.radius+(t.height+t.space)*(pt)-t.height/2,
					 -t.angle_bar -math.pi/2 ,
					 t.angle_bar -math.pi/2)
			end
			cairo_stroke(cr)
		end	
	end
	
	
	
	--function used to retrieve the value to display and to set the cairo structure
	local function setup_bar_graph()
		if t.blocks ~=1 then t.y=t.y-t.height/2 end
		
		local value = 0
		if t.name ~="" then
			value = tonumber(conky_parse(string.format('${%s %s}', t.name, t.arg)))

			--$to_bytes doesn't work when value has a decimal point,
			--https://garage.maemo.org/plugins/ggit/browse.php/?p=monky;a=commitdiff;h=174c256c81a027a2ea406f5f37dc036fac0a524b;hp=d75e2db5ed3fc788fb8514121f67316ac3e5f29f
			--http://sourceforge.net/tracker/index.php?func=detail&aid=3000865&group_id=143975&atid=757310
			--conky bug?
			--value = (conky_parse(string.format('${%s %s}', t.name, t.arg)))
			--if string.match(value,"%w") then
			--	value = conky_parse(string.format('${to_bytes %s}',value))
			--end
		else
			value = tonumber(t.arg)
		end
	
		-- Value checks
		if value==nil then value =0 end
		if value > t.max then 
			print ("value retrieved from conky: " .. value .. " is bigger than max: " .. t.max .. ", value is set to max.")
			value=t.max
		end
		
		pct = 100*value/t.max
		pcb = 100/t.blocks
		
		cairo_set_line_width (cr, t.height)
		cairo_set_line_cap  (cr, cap)
		cairo_translate(cr,t.x,t.y)
		cairo_rotate(cr,t.angle)

		local matrix0 = cairo_matrix_t:create()
		tolua.takeownership(matrix0)
		cairo_matrix_init (matrix0, 1,t.skew_y,t.skew_x,1,0,0)
		cairo_transform(cr,matrix0)	
		
		--call the drawing function for blocks
		if t.blocks==1 and t.angle_bar==0 then
			draw_single_bar()
			if t.reflection=="t" or t.reflection=="b" then cairo_translate(cr,0,-t.height) end
		else
			draw_multi_bar()
		end

		--block for TXT
		-- -- Must be drawn after "bar" is assigned to matrix to avoid reflection of the text
		if (t.txt_show and t.angle_bar==0) then
			local ypos=0
			local barnr=0
			if (t.blocks == 1) then		--Determine the y position of the txt
				ypos = -t.height*pct/100 - t.txt_offsety
			else
				--Inefficient, feel free to replace with a formula (get block of the value)
				if (value <  (t.max/t.blocks)) then
					ypos= 0
				elseif (value > (t.max - (t.max/t.blocks))) then
					ypos= -(t.blocks-1)*(t.height+t.space)
				else
					for bar = 1,t.blocks do
						if not ((pct>=(100/t.blocks) or pct>0) and (pct>=(pcb*(bar-1)))) then --ligth on or not the block	
							barnr=bar					
							break
						end
					end
					ypos= -(barnr-2)*(t.height+t.space) - t.txt_offsety
				end
			end
			cairo_save(cr)	
			cairo_select_font_face(cr, t.txt_font, CAIRO_FONT_SLANT_NORMAL, t.txt_weight)
    			cairo_set_font_size(cr, t.txt_size)
			if (t.txt_alarm and value >= t.alarm) then
				cairo_set_source_rgba(cr, rgb_to_r_g_b(t.alarm_colour))
			else
				cairo_set_source_rgba(cr, rgb_to_r_g_b(t.txt_color))
			end
			if (t.txt_flip) then
				cairo_move_to (cr, -(t.width+t.txt_offset), ypos+10)
			else
				cairo_move_to (cr, t.width+t.txt_offset, ypos+10)
			end
			cairo_rotate(cr,t.txt_angle)
			cairo_show_text(cr, (pct/100*t.max) .. t.txt_add)
			cairo_restore(cr)
		end

		--dot for reminder (uncomment to debug, indicates 0,0)
		--[[		
		if t.blocks ~=1 then
			cairo_set_source_rgba(cr,1,0,0,1)
			cairo_arc(cr,0,t.height/2,3,0,2*math.pi)
			cairo_fill(cr)
		else
			cairo_set_source_rgba(cr,1,0,0,1)
			cairo_arc(cr,0,0,3,0,2*math.pi)
			cairo_fill(cr)
		end]]
		
		--call the drawing function for reflection and prepare the mask used		
		if t.reflection_alpha>0 and t.angle_bar==0 then
			local pat2
			local matrix1 = cairo_matrix_t:create()
			tolua.takeownership(matrix1)
			pts={-delta/2,(t.height+t.space)/2,t.width+delta,-(t.height+t.space)*(t.blocks)}
			if t.reflection=="t" then
				cairo_matrix_init (matrix1,1,0,0,-t.reflection_scale,0,-(t.height+t.space)*(t.blocks-0.5)*2*(t.reflection_scale+1)/2)
				pat2 = cairo_pattern_create_linear (t.width/2,-(t.height+t.space)*(t.blocks),t.width/2,(t.height+t.space)/2)
			elseif t.reflection=="r" then
				cairo_matrix_init (matrix1,-t.reflection_scale,0,0,1,delta+2*t.width,0)
				pat2 = cairo_pattern_create_linear (delta/2+t.width,0,-delta/2,0)
			elseif t.reflection=="l" then
				cairo_matrix_init (matrix1,-t.reflection_scale,0,0,1,-delta,0)
				pat2 = cairo_pattern_create_linear (-delta/2,0,delta/2+t.width,-0)
			else --bottom
				cairo_matrix_init (matrix1,1,0,0,-1*t.reflection_scale,0,(t.height+t.space)*(t.reflection_scale+1)/2)
				pat2 = cairo_pattern_create_linear (t.width/2,(t.height+t.space)/2,t.width/2,-(t.height+t.space)*(t.blocks))
			end

			cairo_transform(cr,matrix1)

			if t.blocks==1 then
				draw_single_bar()
				cairo_translate(cr,0,-t.height/2) 
			else
				draw_multi_bar()
			end
						
			cairo_set_line_width(cr,0.01)
			cairo_pattern_add_color_stop_rgba (pat2, 0,0,0,0,1-t.reflection_alpha)
			cairo_pattern_add_color_stop_rgba (pat2, t.reflection_length,0,0,0,1)
			cairo_rectangle(cr,pts[1],pts[2],pts[3],pts[4])

			cairo_clip_preserve(cr)
			cairo_set_operator(cr,CAIRO_OPERATOR_CLEAR)
			cairo_stroke(cr)
			cairo_mask(cr,pat2)
			cairo_pattern_destroy(pat2)
			cairo_set_operator(cr,CAIRO_OPERATOR_OVER)
			
		end --reflection

		pct,pcb=nil
	end --setup_bar_graph()
	
	--start here !
	setup_bar_graph()
	cairo_restore(cr)
end
le conky_network:

Code : Tout sélectionner

conky.config = {
-- ------------------------- Windows Settings
	own_window = true,
	own_window_type = 'normal',
	own_window_transparent = false,
	own_window_hints = 'undecorated,sticky,below,skip_taskbar,skip_pager',
	own_window_argb_visual = true,
	own_window_argb_value = 0,

	double_buffer = true,
	--background = true,

-- ------------------------- Position
	alignment = 'bottom_left',

	minimum_width = 383,
	minimum_height = 165,
	maximum_width = 313,
	gap_x = 1500,
	gap_y = 200,

-- ------------------------- Font
	use_xft = true,
	xftalpha = 0.8,
	override_utf8_locale = true,

	draw_shades = true,
	default_shade_color = 'black',

	draw_borders = false,
	draw_outline = false,

	font = 'Monofur:bold:size=8',

-- ------------------------- Color
	default_color = 'DCDCDC',
    color0 = '637A70',


-- ------------------------- OTHER
	update_interval = 1,

	lua_load = '~/.conky/jimmy/lua/net_graph.lua',
	lua_draw_hook_pre = 'main_graph',

};

conky.text = [[
${voffset 40}${GOTO 50}${color0}${hr 2}${color}
${if_existing /proc/net/route enp3s0}${voffset 10}${GOTO 110}${color 637A70}${font}Network ${stippled_hr 1}${color}
${GOTO 110}${font}Local ip: ${addr enp3s0}
${GOTO 110}${font}IP Publique : ${execi 1800 /home/toryx/ip.sh
${voffset 85}${GOTO 110}${color 1793d0}${font}Recieve: ${font Monofur:size=8}${downspeed enp3s0}${GOTO 260}${color FEE83D}${font}Send: ${font Monofur:size=8}${upspeed enp3s0}
${image ~/.conky/jimmy/img/netw.png -p 35,60}
${else}${if_existing /proc/net/route enp3s0}${voffset 25}${GOTO 50}${font}Network
${GOTO 50}${font}No connection
${image ~/.conky/jimmy/img/network.png -p 0,15}${endif}${endif}
]];
les img: https://lut.im/QaTpfGMFL3/SLTNXuH1rmpZAoMJ.png
le net_graph.lua:

Code : Tout sélectionner

require 'cairo'

function set_settings()
	graph_settings={

        {--Upload Bar
        name="upspeedf",
        arg="enp3s0",
        max=100,
        autoscale=true,
        x=120,        y=125,
        width=190,
        height=32,
        nb_values=500,
        background =false,
        fg_colour={ {0,0xF0191E,1}, {1,0xE8F019,1}},
        fg_orientation="ww"
        },

        {--Download Bar
        name="downspeedf",
        arg="enp3s0",
        max=100,
        autoscale=true,
        x=310,        y=130,
        width=190,
        height=32,
        nb_values=500,
	inverse=true,
        background =false,
        fg_colour={ {0,0x41AA2C,1}, {1,0x0F5E85,1}},
        fg_orientation="ww",
	angle=180
        },
                                                                                       
       }
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
    flagOK=0
    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
 		    if conky_parse("${if_existing /proc/net/route enp3s0}1${else}0${endif}") then 
				graph_settings[i].arg = "enp3s0"
				draw_graph(graph_settings[i])
		    elseif conky_parse("${if_existing /proc/net/route wlp2s0}1${else}0${endif}") then 
				graph_settings[i].arg = "wlp2s0"
				draw_graph(graph_settings[i])
    		    else 
				graph_settings[i].draw_me=nil
				draw_graph(graph_settings[i]) end
		    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
le conky_nvidiaDemo:

Code : Tout sélectionner

conky.config = {
-- ------------------------- Windows Settings
	own_window = true,
	own_window_type = 'normal',
	own_window_transparent = false,
	own_window_hints = 'undecorated,sticky,below,skip_taskbar,skip_pager',
	own_window_argb_visual = true,
	own_window_argb_value = 0,

	double_buffer = true,
	--background = true,


-- ------------------------- Position
	alignment = 'bottom_left',

	minimum_width = 300,
	minimum_height = 10,

	gap_x = 1600,
	gap_y = 20,

-- ------------------------- Font
	draw_shades = false,
	draw_outline = false,
	draw_borders = false,

	use_spacer = 'right',

	use_xft = true,
	override_utf8_locale = true,

	font = 'Ubuntu:size=9',

-- ------------------------- Other
	update_interval = 5,

	color0 = '637A70',
    lua_load = '~/.conky/lua/image.lua',

};


conky.text = [[
${lua fDrawImage $HOME/.conky/jimmy/img/nvidia.png 100 150 100 70}
${voffset 110}${color0}${hr 2}${color}
${GOTO 5}${color 637A70}GPU Performance ${stippled_hr 1}${color}

Memory${alignr}${exec nvidia-settings -q [gpu:0]/UsedDedicatedGPUMemory -t} / ${exec nvidia-settings -q [gpu:0]/TotalDedicatedGPUMemory -t} MiB 
Temp:${alignr}${exec nvidia-settings -q [thermalsensor:0]/ThermalSensorReading -t} °C 
Fan speed:${alignr}${exec nvidia-settings -q [fan:0]/GPUCurrentFanSpeed -t}% - ${exec nvidia-settings -q [fan:0]/GPUCurrentFanSpeedRPM -t} RPM
Fan speed target:${alignr}${exec nvidia-settings -q [fan:0]/GPUTargetFanSpeed -t}% 

${GOTO 5}${color0}Software ${stippled_hr 1}${color} 

Driver Version:${alignr}${exec nvidia-settings -q 0/NvidiaDriverVersion -t} 

${color0}${hr 2}${color} 
]];
les img: https://lut.im/VOeQk9Phuk/CiGBeUNeg9D75DyJ.png
Modifié en dernier par toryx le mar. 10 avr. 2018 19:18, modifié 1 fois.

Avatar du membre
ultimatum
Messages : 1090
Enregistré le : mar. 25 oct. 2016 07:52

Re: Nos conky 2018

Message par ultimatum » mar. 10 avr. 2018 07:59

merci pour ton conky
pourais tu juste me filer les liens des images aussi hihi
merci d'avance
Image

Avatar du membre
arghlub
modérateur
Messages : 4833
Enregistré le : dim. 21 mai 2017 08:19
Localisation : Provence

Re: Nos conky 2018

Message par arghlub » mar. 10 avr. 2018 08:10

Salut ultimatum ;)
ultimatum a écrit :pourais tu juste me filer les liens des images aussi hihi
Pour récupérer les images, fais un clic droit dessus et «enregistrer l'image sous» :
Image
Portable • Lenovo G50-80 “boosté RAM+SSD” | CPU Intel I3-4005U | RAM 8Go | tripleBoot avec “/data” commune : LMint 18.3 Sylvia | MX Linux 18 | LMint 19.1 Tessa | XFCE (pour les 3)
Tour (custom)CM MSI Z270 M3 | CPU Intel I7-7700K | CG Nvidia GTX 1080 | RAM 16Go DDR4 3000MHz | tripleBoot : Debian 9 | MX Linux 18 | LMint 19.1 Tessa | XFCE
────────────────────────────────────
... pour une informatique libre ! -membre de l'April

Avatar du membre
ultimatum
Messages : 1090
Enregistré le : mar. 25 oct. 2016 07:52

Re: Nos conky 2018

Message par ultimatum » mar. 10 avr. 2018 12:23

rho il étais tôt j'ai même pas essayer ....désolé mais ton tuto en aidera d'autre hihi
Image

Avatar du membre
débitant
modérateur
Messages : 8884
Enregistré le : mar. 14 juil. 2015 18:22
Localisation : Lorraine France

Re: Nos conky 2018

Message par débitant » mar. 10 avr. 2018 13:36

j'en profite pour rappeler qu'il ne faut pas prendre le lien d'une image pour la poster directement sur un autre forum
toujours enregistrer l'image dans son pc et passer par un hébergeur pour poster le lien que cet hébergeur vous donnera en retour, après si on ne veut pas garder l'image dans son pc, on l'efface c'est tout ;)
Petite lecture de rappel

jbalibeux
Messages : 6
Enregistré le : lun. 9 avr. 2018 01:27

Re: Nos conky 2018

Message par jbalibeux » mar. 10 avr. 2018 20:52

bonjour alors moi je vous propose un conky "old school" (prévu pour fond d’écran sombre mais modifiable évidement)
sans lua et donc facilement modifiable pour un débutant (que je suis!)
c'est inspirer de plusieurs sources que j'ai re-assemblé et remanier à ma sauce.

Image
(euh.. il vous faudra peut être enlever quelques cœur j'ai du matériel un peu particulier..)

sinon voila le code dans la bonne vieille ancienne syntaxe mais qui fonctionne encore tres bien avec mon conky 1.10.6

Code : Tout sélectionner

background yes
double_buffer yes

border_width 1
cpu_avg_samples 2
default_color white
default_outline_color white
default_shade_color white
draw_borders no
draw_graph_borders yes
draw_outline no

draw_shades no  
alignment top_right
gap_x 20
gap_y 40
net_avg_samples 2
no_buffers yes
out_to_console no
out_to_stderr no
extra_newline no

own_window yes
own_window_type normal
own_window_transparent yes
own_window_colour 000000
own_window_argb_visual no
own_window_argb_value 0
own_window_hints undecorated,below,sticky,skip_taskbar,skip_pager

minimum_size 200 200
stippled_borders 0
update_interval 1.0
uppercase no
use_spacer none

show_graph_scale no
show_graph_range no

use_xft yes
xftalpha 0.1
xftfont Droid Sans:size=8

color0 lightgrey
color1 blue
color2 orange
color3 grey
color4 slate grey


TEXT
${font weight:bold}LinuxMint 18.3 '${color2}Sylvia${color}'${font}

${color4}UpTime:${color}${alignr}$uptime
${color4}Kern:${color}${alignr}$kernel
${color4}Load:${color}${alignr}$loadavg
${color4}Processes:${color}${alignr}$processes
${color4}Running:${color}${alignr}$running_processes 

${color4}Highest CPU:
${color #ddaa00}${offset 14}${top name 1} ${goto 150} ${top_mem cpu 1}
${color lightgrey}${offset 14}${top name 2} ${goto 150} ${top cpu 2}
${color lightgrey}${offset 14}${top name 3} ${goto 150} ${top cpu 3}
${color lightgrey}${offset 14}${top name 4} ${goto 150} ${top cpu 4}

${color4}Highest MEM:${color}
${color #ddaa00}${offset 14}${top_mem name 1} ${goto 150} ${top_mem mem 1}
${color lightgrey}${offset 14}${top_mem name 2} ${goto 150} ${top_mem mem 2}
${color lightgrey}${offset 14}${top_mem name 3} ${goto 150} ${top_mem mem 3}
${color lightgrey}${offset 14}${top_mem name 4} ${goto 150} ${top_mem mem 4}

${color4}MEM:${color}${alignr}$memperc%        $mem/$memmax
${offset 14}${color3}${memgraph 50,168}
${color4}Utilisation Disques:  ${color }
${offset 14}SWAP ${alignr}$swapperc% $swap/$swapmax    
${offset 14}${swapbar 3,100}
${offset 14}/${alignr}${fs_free /}/${fs_size /}    
${offset 14}${fs_bar 3,100 /}

${color4}NET:${color}${offset 14}(enp1s0f1)${alignr}${addr enp1s0f1}
${offset 14}Up:${upspeed enp1s0f1}k/s
${offset 14}${upspeedgraph enp1s0f1 20,168 000000 ffffff}
${offset 14}Down: ${downspeed enp1s0f1}k/s
${offset 14}${downspeedgraph enp1s0f1 20,168 000000 ffffff}

${color4}CPU:${color}    ${cpu cpu0}%${alignr}${hwmon 0 temp 1}°C
${offset 12}${color3}${cpugraph 50,168}
${goto 90}${color2}CPU 1 ${color0}
${color4}Coeur 1 : ${color0} ${cpu cpu0}%  ${goto 90}${color3}${cpubar cpu1 }
${color4}Coeur 2 : ${color0} ${cpu cpu0}%  ${goto 90}${color3}${cpubar cpu2 }
${color4}Coeur 3 : ${color0} ${cpu cpu0}%  ${goto 90}${color3}${cpubar cpu3 }
${color4}Coeur 4 : ${color0} ${cpu cpu0}%  ${goto 90}${color3}${cpubar cpu4 }
${color4}Coeur 5 : ${color0} ${cpu cpu0}%  ${goto 90}${color3}${cpubar cpu5 }
${color4}Coeur 6 : ${color0} ${cpu cpu0}%  ${goto 90}${color3}${cpubar cpu6 }
${color4}Coeur 7 : ${color0} ${cpu cpu0}%  ${goto 90}${color3}${cpubar cpu7 }
${color4}Coeur 8 : ${color0} ${cpu cpu0}%  ${goto 90}${color3}${cpubar cpu8 }
${goto 90}${color2}CPU 2 ${color0}
${color4}Coeur 9 : ${color0} ${cpu cpu0}%  ${goto 90}${color3}${cpubar cpu9 }
${color4}Coeur 10: ${color0} ${cpu cpu0}%  ${goto 90}${color3}${cpubar cpu10 }
${color4}Coeur 11: ${color0} ${cpu cpu0}%  ${goto 90}${color3}${cpubar cpu11 }
${color4}Coeur 12: ${color0} ${cpu cpu0}%  ${goto 90}${color3}${cpubar cpu12 }
${color4}Coeur 13: ${color0} ${cpu cpu0}%  ${goto 90}${color3}${cpubar cpu13 }
${color4}Coeur 14: ${color0} ${cpu cpu0}%  ${goto 90}${color3}${cpubar cpu14 }
${color4}Coeur 15: ${color0} ${cpu cpu0}%  ${goto 90}${color3}${cpubar cpu15 }
${color4}Coeur 16: ${color0} ${cpu cpu0}%  ${goto 90}${color3}${cpubar cpu16 }

${font weight:bold}${color4}Nvidia Geforce GTX 760${color} ${font}
${offset 14}GPU Temp ${alignr}${nvidia temp} °C    
${offset 14}Fan Speed ${alignr}${execi 5 nvidia-settings -q [fan:0]/GPUCurrentFanSpeed -t} %    
${offset 14}GPU Clock ${alignr}${nvidia gpufreq} MHz    
${offset 14}Mem Clock ${alignr}${nvidia memfreq} MHz    
${offset 14}Mem Used ${alignr}${execi 5 nvidia-settings -q [gpu:0]/UsedDedicatedGPUMemory -t} / ${exec nvidia-settings -q [gpu:0]/TotalDedicatedGPUMemory -t} MiB 

Avatar du membre
arghlub
modérateur
Messages : 4833
Enregistré le : dim. 21 mai 2017 08:19
Localisation : Provence

Re: Nos conky 2018

Message par arghlub » mar. 10 avr. 2018 21:04

Merci toryx et jbalibeux pour vos contributions 8-)

NOTE IMPORTANTE : je rappelle aux futurs intervenants qui feraient des captures d'écran de leur conky de ne pas oublier de masquer d'éventuelles infos personnelles (comme l'a fait toryx dans son post avec son adresse IP). ;)
Portable • Lenovo G50-80 “boosté RAM+SSD” | CPU Intel I3-4005U | RAM 8Go | tripleBoot avec “/data” commune : LMint 18.3 Sylvia | MX Linux 18 | LMint 19.1 Tessa | XFCE (pour les 3)
Tour (custom)CM MSI Z270 M3 | CPU Intel I7-7700K | CG Nvidia GTX 1080 | RAM 16Go DDR4 3000MHz | tripleBoot : Debian 9 | MX Linux 18 | LMint 19.1 Tessa | XFCE
────────────────────────────────────
... pour une informatique libre ! -membre de l'April

Avatar du membre
david37
modérateur
Messages : 2769
Enregistré le : lun. 22 août 2016 05:06

Re: Nos conky 2018

Message par david37 » mer. 11 avr. 2018 21:19

ultimatum a écrit :merci pour ton conky
pourais tu juste me filer les liens des images aussi hihi
merci d'avance

dis donc tu veux pas qu'il te l'installe chez toi aussi ? :lol: :lol: :lol:
PC1: Hp pavilion g6 / 1.36 GHz AMD E2-1800 APU with Radeon(tm) HD Graphics / 500 GB hard drive / 4G RAM /
LM 18.3 Mate x64
PC2: Hp-Pavilion Slimline / 2.5 GHz AMD RV710 / 4GB RAM / 500 GB hard drive / LM 18.3 Mate x64 & LM 18.3 Cinnamon x64
PC3: Lenovo ThinkPad R61i / 1.87 GHz Intel T2390 / NVIDIA G86M / 2GB RAM / 100 GB Hard Drive / LMDE2-Mate x64
PC4: Dell-Latitude E7240 / 2GHz i5-4310U / Intel Haswell-ULT HD 4400 / 8GB RAM / 256 GB Hard Drive / LM19 xfce x64

Avatar du membre
ultimatum
Messages : 1090
Enregistré le : mar. 25 oct. 2016 07:52

Re: Nos conky 2018

Message par ultimatum » jeu. 12 avr. 2018 06:16

david37 a écrit :
tu veux pas qu'il te l'installe chez toi aussi ?
j'y avais pas penser mais c'est pas c...
voila mon teamwiever ID 12345678 et pass AZERTY au cas ou .... :B :oops: :arrow: :arrow: :arrow:
Image

Répondre