You are not logged in.
I am using Conky and Cairo to draw some nice things on my desktop. I would like to try to center some text. I was trying to follow this tutorial, however when porting that code into Lua code, the line
cairo_text_extents(cr, utf8, extents)causes conky to stop without showing any error. I think the problem is that the data type cairo_text_extents_t is not recognized by lua. Is there any solution to this?
My ported code is as following:
local extents
local utf8 = "cairo"
local x, y
cairo_select_font_face(cr, "Ubuntu", CAIRO_FONT_SLANT_NORMAL, CAIRO_FONT_WEIGHT_NORMAL)
cairo_set_font_size(cr, 13)
cairo_text_extents(cr, utf8, extents)
x = 128.0 - (extents.width / 2 + extents.x_bearing)
y = 128.0 - (extents.height / 2 + extents.y_bearing)
cairo_move_to (cr, x, y)
cairo_show_text (cr, utf8)
cairo_set_source_rgba (cr, 1, 0.2, 0.2, 0.6)
cairo_set_line_width (cr, 6.0)
cairo_arc (cr, x, y, 10.0, 0, 2 * math.pi)
cairo_fill (cr)
cairo_move_to (cr, 128.0, 0)
cairo_rel_line_to (cr, 0, 256)
cairo_move_to (cr, 0, 128.0)
cairo_rel_line_to (cr, 256, 0)
cairo_stroke (cr)Conky package is conky-cairo from the AUR and the version is the following:
conky -v
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: 256Last edited by alogim (2017-03-08 13:11:19)
Offline
Solved by using the following:
local extents=cairo_text_extents_t:create()
tolua.takeownership(extents)
local utf8 = "cairo"
local x, y
cairo_select_font_face(cr, "Ubuntu", CAIRO_FONT_SLANT_NORMAL, CAIRO_FONT_WEIGHT_NORMAL)
cairo_set_font_size(cr, 52)
cairo_text_extents(cr, utf8, extents)
x = 128.0 - (extents.width / 2 + extents.x_bearing)
y = 128.0 - (extents.height / 2 + extents.y_bearing)
cairo_move_to (cr, x, y)
cairo_show_text (cr, utf8)Offline