You are not logged in.

#1 2017-02-26 11:51:18

alogim
Member
Registered: 2015-08-25
Posts: 43

[SOLVED] [Conky + Cairo] Strange lines appear

I am currenlty configuring Conky to show five rings representing the current usage of each CPU's core. Inside each ring, I want to show the usage percentage, however I keep getting the following strange result.

Without percentage:
Rings without percentage

With percentage:
Rings with percentage

The code is as following:

--this is a lua script for use in conky
require 'cairo'

function conky_main()
  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)
  
  --SETTINGS
  local cpu_ring_center_x = 30
  local cpu_ring_center_y = 20
  local cpu_ring_radius = 20
  local cpu_ring_width = 5
  local max_value = 100
	
  local core_number = get_core_number()
	
  for i=0,core_number do
    local cpu_usage_perc = conky_parse("${cpu cpu" .. i .. "}")
    cpu_ring_center_y = cpu_ring_center_y + 50
    draw_cpu_ring(cpu_ring_width, cpu_usage_perc, max_value, cpu_ring_center_x, 
      cpu_ring_center_y, cpu_ring_radius)			
      draw_cpu_ring_text(cpu_usage_perc, cpu_ring_center_x, cpu_ring_center_y)	
  end
	
  cairo_destroy(cr)
  cairo_surface_destroy(cs)
  cr = nil
end

function draw_cpu_ring_text(cpu_usage_perc, cpu_ring_center_x, cpu_ring_center_y)
  local xpos = cpu_ring_center_x - 13
  local ypos = cpu_ring_center_y + 5
  local text = cpu_usage_perc .. "%"
  cairo_move_to(cr, xpos, ypos)
  cairo_show_text(cr, text)
end

function get_core_number()
  local handle = io.popen("cat /proc/cpuinfo | grep processor | wc -l")
  local core_number = tonumber(handle:read("*a"))
  handle:close()
  return core_number
end

function compute_colours(percentage)
  if tonumber(percentage) <= 50 then
    red = percentage * 5.12 
    green = 255
  else
    red = 255
    green = (100 - percentage) * 5.12
  end
	
  red = red / 255
  green = green / 255
  blue = 0
  return red, green, blue
end

function draw_cpu_ring(cpu_ring_width, cpu_usage_perc, max_value, 
  cpu_ring_center_x, cpu_ring_center_y, cpu_ring_radius)
  cairo_set_line_width(cr, cpu_ring_width)
  end_angle = cpu_usage_perc * (360 / max_value)

  r, g, b = compute_colours(cpu_usage_perc)
  cairo_set_source_rgba(cr, r, g, b, 1)
  cairo_arc(cr, 
    cpu_ring_center_x, 
    cpu_ring_center_y,
    cpu_ring_radius,
    (-90) * (math.pi / 180),
    (end_angle - 90) * (math.pi / 180))
  cairo_stroke(cr)
end

Last edited by alogim (2017-03-08 11:15:08)

Offline

#2 2017-02-26 16:56:03

jean_no
Member
Registered: 2007-09-18
Posts: 48

Re: [SOLVED] [Conky + Cairo] Strange lines appear

Hi
Shows the used version of conky:

conky -v

The version of the extra repository is not compiled with the support of lua and cairo.

On AUR, there are conky-lua-nv: https://aur.archlinux.org/packages/conky-lua-nv/
A+

Offline

#3 2017-02-26 19:37:37

alogim
Member
Registered: 2015-08-25
Posts: 43

Re: [SOLVED] [Conky + Cairo] Strange lines appear

The output of the above command is as follows:

conky 1.10.6_pre compiled Tue  7 Feb 12:07:34 CET 2017 for Linux 4.9.7-1-ARCH x86_64

Compiled in features:

System config file: /etc/conky/conky.conf
Package library path: /usr/lib/conky


 General:
  * math
  * hddtemp
  * portmon
  * IPv6
  * Curl
  * RSS
  * iconv
  * Weather (METAR)
  * Weather (XOAP)
  * wireless
  * support for IBM/Lenovo notebooks
  * nvidia
  * builtin default configuration
  * old configuration syntax
  * Imlib2
  * apcupsd
  * iostats
  * ncurses
  * Internationalization support

 Lua bindings:
  * Cairo
  * Imlib2
  * RSVG
 X11:
  * Xdamage extension
  * Xinerama extension (virtual display)
  * Xshape extension (click through)
  * XDBE (double buffer extension)
  * Xft
  * ARGB visual
  * Own window

 Music detection:
  * MPD
  * MOC

 Default values:
  * Netdevice: eth0
  * Local configfile: $HOME/.conkyrc
  * Localedir: /usr/share/locale
  * Maximum netdevices: 64
  * Maximum text size: 16384
  * Size text buffer: 256

So, any idea?

Last edited by alogim (2017-02-28 13:32:02)

Offline

#4 2017-03-01 09:59:41

alogim
Member
Registered: 2015-08-25
Posts: 43

Re: [SOLVED] [Conky + Cairo] Strange lines appear

By the way, I am using XFCE and conky-cairo from the AUR.
So, any possible fixes for this problem?

Offline

#5 2017-03-08 11:14:30

alogim
Member
Registered: 2015-08-25
Posts: 43

Re: [SOLVED] [Conky + Cairo] Strange lines appear

Solved by adding

cairo_stroke(cr)

right after

cairo_show_text(cr, text)

Offline

Board footer

Powered by FluxBB