Escitorio Abril [conky-4]



Esta es mi última instancia de conky, y supongo debería ser la más compleja, pues posee un script lua, aunque realmente no lo es; así que vamos a tema, primero el clock_rings.lua

settings_table = {
   {
      -- Edit this table to customise your rings.
      -- You can create more rings simply by adding more elements to settings_table.
      -- "name" is the type of stat to display; you can choose from 'cpu', 'memperc', 'fs_used_perc', 'battery_used_perc'.
      name='time',
      -- "arg" is the argument to the stat type, e.g. if in Conky you would write ${cpu cpu0}, 'cpu0' would be the argument. If you would not use an argument in the Conky variable, use ''.
      arg='%I.%M',
      -- "max" is the maximum value of the ring. If the Conky variable outputs a percentage, use 100.
      max=12,
      -- "bg_colour" is the colour of the base ring.
      bg_colour=0xffffff,
      -- "bg_alpha" is the alpha value of the base ring.
      bg_alpha=0.1,
      -- "fg_colour" is the colour of the indicator part of the ring.
      fg_colour=0xffffff,
      -- "fg_alpha" is the alpha value of the indicator part of the ring.
      fg_alpha=0.2,
      -- "x" and "y" are the x and y coordinates of the centre of the ring, relative to the top left corner of the Conky window.
      x=165, y=170,
      -- "radius" is the radius of the ring.
      radius=50,
      -- "thickness" is the thickness of the ring, centred around the radius.
      thickness=5,
      -- "start_angle" is the starting angle of the ring, in degrees, clockwise from top. Value can be either positive or negative.
      start_angle=0,
      -- "end_angle" is the ending angle of the ring, in degrees, clockwise from top. Value can be either positive or negative, but must be larger (e.g. more clockwise) than start_angle.
      end_angle=360
   },
   {
      name='time',
      arg='%M.%S',
      max=60,
      bg_colour=0xffffff,
      bg_alpha=0.1,
      fg_colour=0xffffff,
      fg_alpha=0.4,
      x=165, y=170,
      radius=56,
      thickness=5,
      start_angle=0,
      end_angle=360
   },
   {
      name='time',
      arg='%S',
      max=60,
      bg_colour=0xffffff,
      bg_alpha=0.1,
      fg_colour=0xffffff,
      fg_alpha=0.6,
      x=165, y=170,
      radius=62,
      thickness=5,
      start_angle=0,
      end_angle=360
   },
   {
      name='cpu',
      arg='cpu0',
      max=100,
      bg_colour=0xffffff,
      bg_alpha=0,
      fg_colour=0xffffff,
      fg_alpha=0.4,
      x=165, y=170,
      radius=70,
      thickness=5,
      start_angle=60,
      end_angle=120
   },
   {
      name='cpu',
      arg='cpu1',
      max=100,
      bg_colour=0xffffff,
      bg_alpha=0,
      fg_colour=0xffffff,
      fg_alpha=0.4,
      x=165, y=170,
      radius=76,
      thickness=5,
      start_angle=60,
      end_angle=120
   },
   {
      name='cpu',
      arg='cpu2',
      max=100,
      bg_colour=0xffffff,
      bg_alpha=0,
      fg_colour=0xffffff,
      fg_alpha=0.4,
      x=165, y=170,
      radius=82,
      thickness=5,
      start_angle=60,
      end_angle=120
   },
   {
      name='cpu',
      arg='cpu3',
      max=100,
      bg_colour=0xffffff,
      bg_alpha=0.2,
      fg_colour=0xffffff,
      fg_alpha=0.4,
      x=165, y=170,
      radius=88,
      thickness=5,
      start_angle=60,
      end_angle=120
   },
   {
      name='Top',
      arg='mem 1',
      max=100,
      bg_colour=0xffffff,
      bg_alpha=0.1,
      fg_colour=0xffffff,
      fg_alpha=0.6,
      x=165, y=170,
      radius=72,
      thickness=11,
      start_angle=122,
      end_angle=210
   },
   {
      name='memperc',
      arg='',
      max=100,
      bg_colour=0xffffff,
      bg_alpha=0.1,
      fg_colour=0xffffff,
      fg_alpha=0.8,
      x=165, y=170,
      radius=83.5,
      thickness=10,
      start_angle=122,
      end_angle=210
   },
   {
      name='time',
      arg='%d',
      max=31,
      bg_colour=0xffffff,
      bg_alpha=0.1,
      fg_colour=0xffffff,
      fg_alpha=0.8,
      x=165, y=170,
      radius=70,
      thickness=5,
      start_angle=212,
      end_angle=360
   },
   {
      name='time',
      arg='%m',
      max=12,
      bg_colour=0xffffff,
      bg_alpha=0.1,
      fg_colour=0xffffff,
      fg_alpha=0.8,
      x=165, y=170,
      radius=76,
      thickness=5,
      start_angle=212,
      end_angle=360
   },
   {
      name='fs_used_perc',
      arg='/',
      max=150,
      bg_colour=0xffffff,
      bg_alpha=0.4,
      fg_colour=0xffffff,
      fg_alpha=0.6,
      x=165, y=170,
      radius=108.5,
      thickness=3,
      start_angle=-120,
      end_angle=240
   },
   {
      name='fs_used_perc',
      arg='/home',
      max=100,
      bg_colour=0xffffff,
      bg_alpha=0.2,
      fg_colour=0xffffff,
      fg_alpha=0.3,
      x=165, y=170,
      radius=135,
      thickness=50,
      start_angle=-120,
      end_angle=120
   },
}

require 'cairo'

function rgb_to_r_g_b(colour,alpha)
   return ((colour / 0x10000) % 0x100) / 255., ((colour / 0x100) % 0x100) / 255., (colour % 0x100) / 255., alpha
end

function draw_ring(cr,t,pt)
   local w,h=conky_window.width,conky_window.height

   local xc,yc,ring_r,ring_w,sa,ea=pt['x'],pt['y'],pt['radius'],pt['thickness'],pt['start_angle'],pt['end_angle']
   local bgc, bga, fgc, fga=pt['bg_colour'], pt['bg_alpha'], pt['fg_colour'], pt['fg_alpha']

   local angle_0=sa*(2*math.pi/360)-math.pi/2
   local angle_f=ea*(2*math.pi/360)-math.pi/2
   local t_arc=t*(angle_f-angle_0)

   -- Draw background ring

   cairo_arc(cr,xc,yc,ring_r,angle_0,angle_f)
   cairo_set_source_rgba(cr,rgb_to_r_g_b(bgc,bga))
   cairo_set_line_width(cr,ring_w)
   cairo_stroke(cr)

   -- Draw indicator ring

   cairo_arc(cr,xc,yc,ring_r,angle_0,angle_0+t_arc)
   cairo_set_source_rgba(cr,rgb_to_r_g_b(fgc,fga))
   cairo_stroke(cr)
end

function conky_ring_stats()
   local function setup_rings(cr,pt)
      local str=''
      local value=0

      str=string.format('${%s %s}',pt['name'],pt['arg'])
      str=conky_parse(str)

      value=tonumber(str)
      if value == nil then value = 0 end
      pct=value/pt['max']

      draw_ring(cr,pct,pt)
   end

   if conky_window==nil then return end
   local cs=cairo_xlib_surface_create(conky_window.display,conky_window.drawable,conky_window.visual, conky_window.width,conky_window.height)

   local cr=cairo_create(cs)

   local updates=conky_parse('${updates}')
   update_num=tonumber(updates)

   if update_num>5 then
      for i in pairs(settings_table) do
         setup_rings(cr,settings_table[i])
      end
   end
end 


deje los comentarios por defecto porque son magnificas ayudas para poder modificar nuestro script lua, notarán que arg es un argumento de conky, o sea que cualquier dato "contable" podemos pasarlo a un ring, por ejemplo el estado de la batería si nuestro equipo es un laptop.

añadido a esto, encontré este blog donde hacen una buena explicación de cada aspecto de este script

también cabe anotar que el script original es de la user londonali1010 que lo publicó bajo la licencia creative commons A-NC-SA.

una vez dicho todo lo anterior, procedo a mostrar el .conkyrc_rings:

# -- Conky settings -- #
#background yes
update_interval 1
cpu_avg_samples 2
net_avg_samples 2
override_utf8_locale yes
double_buffer yes
no_buffers yes
text_buffer_size 2048
imlib_cache_size 0
# -- Window specifications -- #
own_window yes
own_window_type override
own_window_transparent yes
#own_window_hints undecorate,sticky,skip_taskbar,skip_pager,below
border_inner_margin 0
border_outer_margin 0
minimum_size 480 280
maximum_width 1000
alignment mm
gap_x -400
gap_y 150
# -- Graphics settings -- #
draw_shades no
draw_outline no
draw_borders no
draw_graph_borders no
# -- Text settings -- #
use_xft yes
xftfont Ænigma Scrawl 4 BRK:size=20
xftalpha 0.8
uppercase no
default_color FFFFFF
# -- Lua Load -- #
lua_load /home/cesar/.Conkyrc/rings.lua
lua_draw_hook_pre ring_stats
TEXT
${goto 117}${voffset 137}${font Obloquy Solid BRK:size=15}${time %I:%M}
${goto 180}${voffset -15}${hr 3}
${goto 117}${voffset -10}${font Daniel - regular:size=12}${time %A %d}

ok acá encontramos los cargadores de los scripts de lua, como notarán, van antes del texto en conky y se hace el llamado indicando la ubicación del mismo en el path: lua_load /path/to/script.lua

como vemos, el script un aspecto distinto al texto de conky y también a las imágenes que podemos agregar con ${image} de tal modo que podemos incluso si lo deseamos agregar imágenes de fondo para complementar nuestros conkys, como notarán yo no aplico ninguna imagen en este conky, sin embargo, si es posible.

volviendo al tema, lo siguiente que también es importante de hacer notar en el script es que damos un tamaño mínimo al conky, caso contrario los rings se mostrarían cortados, la ventana no los detecta por si mismos, y si notan, el ancho del mínimo es más amplio que el anillo, el hecho es simple, en el texto creo una línea horizontal, con la sentencia ${hr 3} línea que llena de lado a lado el conky, con ${goto} la movemos para que no corte al completo el mismo, sino desde un punto, sin embargo para "estética" es preferible que la misma llegue o toque un borde de la pantalla, así pues el ancho del conky está hecho para llegar al borde de la pantalla.



también implemento la hora del sistema en formato de 12 horas con %I y muestro los minutos con %M luego agregamos %A para mostrar el día y %d para la fecha, sin embargo en cada una de las líneas (hora, minutos) (día, fecha) uso un goto pequeño, eso es debido a que realicé un cambio con respecto a la primera imagen, pues ahora estos datos, se muestran en el centro de los rings, que a mi punto, se ve más bonito.

con esto, terminaría la parte de los conkys, solo faltarían detalles finales, una última publicación final, no muy importante.

Comentarios

Publicar un comentario

Entradas populares