Skip to content

Instantly share code, notes, and snippets.

@Strae
Created June 8, 2017 08:57
Show Gist options
  • Save Strae/f6d812a671c1054153b6fcad011ca2d7 to your computer and use it in GitHub Desktop.
Save Strae/f6d812a671c1054153b6fcad011ca2d7 to your computer and use it in GitHub Desktop.
Conky simple vertical bars
alignment top_left
background no
border_width 0
default_color white
default_outline_color white
double_buffer yes
draw_borders no
draw_outline no
draw_shades yes
use_xft yes
xftfont Open Sans Regular:size=8
gap_x 1870
gap_y 0
minimum_size 25 1050
net_avg_samples 2
no_buffers yes
out_to_console no
out_to_stderr no
extra_newline no
own_window yes
own_window_class Conky
own_window_type desktop
own_window_hints undecorated,below,sticky,skip_taskbar,skip_pager
own_window_transparent no
own_window_argb_visual yes
own_window_argb_value 0
stippled_borders 0
update_interval 0.3
uppercase no
use_spacer none
show_graph_scale no
show_graph_range no
lua_load /home/dp/Documenti/Scripts/conky_bars.lua
lua_draw_hook_pre conky_bar_stats
TEXT
--[[
conky vertical bar graph
by iggykoopa mods by arpinux(2009)
most of the credit goes to londonali1010, I stole big chunks from her ring graphs
]]
require 'cairo'
-- Uso andylangton.co.uk/tools/colour-converter per convertire un colore hex nei valori decimali
settings_table = {
{
name = 'fs_free_perc',
arg = '/',
max = 100,
width = 3,
height = 769,
x = 22,
y = 0,
fillRed = 0.48,
fillGreen = 0.48,
fillBlue = 0.48,
alpha = 1
},
{
name = 'memperc',
arg = '',
max = 100,
width = 3,
height = 769,
x = 18,
y = 0,
fillRed = 1,
fillGreen = 0.2,
fillBlue = 0.0,
alpha = 1
},
{
name = 'cpu',
arg = 'cpu0',
max = 100,
width = 3,
height = 769,
x = 12,
y = 0,
fillRed = 1,
fillGreen = 0.80,
fillBlue = 0.07,
alpha = 1
},
{
name = 'cpu',
arg = 'cpu1',
max = 100,
width = 3,
height = 769,
x = 8,
y = 0,
fillRed = 0.75,
fillGreen = 0.24,
fillBlue = 1,
alpha = 1
},
{
name = 'cpu',
arg = 'cpu2',
max = 100,
width = 3,
height = 769,
x = 4,
y = 0,
fillRed = 0.29,
fillGreen = 0.62,
fillBlue = 0.97,
alpha = 1
},
{
name = 'cpu',
arg = 'cpu3',
max = 100,
width = 3,
height = 769,
x = 0,
y = 0,
fillRed = 0.27,
fillGreen = 0.55,
fillBlue = 0,
alpha = 1
}
}
function draw_bar(pct, pt)
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)
alpha = pt['alpha']
if pct<1 then
pct = 1
alpha = 0.2
end
cairo_set_source_rgba(cr, pt['fillRed'], pt['fillGreen'], pt['fillBlue'], alpha)
cairo_set_line_width (cr, pt['width'])
-- Original code
--cairo_move_to (cr, (pt['width'] / 2) + pt['x'], pt['height'] + pt['y'] - 1)
--cairo_line_to (cr, (pt['width'] / 2) + pt['x'], pt['height'] - (pt['height'] * pct) + pt['y'] - 1)
-- Barre orizzontali
--cairo_move_to (cr, pt['x'], pt['y']+25)
--cairo_line_to (cr, pt['x'] - (pt['x'] * (pct / 100)), pt['y']+25)
-- Barre verticali
cairo_move_to (cr, (pt['width'] / 2) + pt['x']+5, pt['y'])
cairo_line_to (cr, (pt['width'] / 2) + pt['x']+5, (pt['height'] * (pct / 100)))
cairo_stroke (cr)
cairo_destroy(cr)
cr = nil
end
function conky_bar_stats()
local function setup_bars(pt)
local str=''
local value=0
str=string.format('${%s %s}',pt['name'],pt['arg'])
str=conky_parse(str)
value=tonumber(str)
--value=50 -- Test
--pct=value/pt['max'] -- Il calcolo lo faccio in draw_bar
pct=value
draw_bar(pct,pt)
end
if conky_window == nil then return end
local updates=conky_parse('${updates}')
update_num=tonumber(updates)
if update_num>5 then
for i in pairs(settings_table) do
setup_bars(settings_table[i])
end
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment