Lua API
Conky features a Lua programming API and also ships with Lua bindings for some useful libraries. Note that the bindings require tolua++.
To use Lua with Conky, first make sure you have a version of
Conky with Lua support enabled (conky -v will report this).
Conky defines certain global functions and variables that can be
accessed from Lua code running inside Conky. Scripts must first be loaded
using the lua_load configuration option. You can then call Lua functions
through Conky's $lua, $lua_read, and Lua hooks.
Be careful when creating threaded objects through the Lua API. You could end up with a large number of threads running if a thread is created with each iteration.
Note: to accommodate certain features in the Cairo library's API, Conky will export a few additional functions for the creation of certain structures. These are documented below.
cairo_place_image(file, cr, x, y, width, height, alpha)Renders an image onto a cairo_t, using imlib2. In some cases using a cairo_t and exact coordinates is more useful.
| Argument | Description |
|---|---|
| file | Path to the image to render. |
| cr | The cairo_t to render to. |
| x,y | Position to render the image. |
| width, height | The width and height to draw the image |
| alpha | The transparency of the image 1.0 is solid 0.0 is fully translucent. |
require('cairo_imlib2_helper') in your lua file.
conky_surface()Returns the current cairo_surface_t for the active display output,
or nil if no graphical surface is available. This is the preferred,
backend-agnostic way to obtain a drawing surface for use with Cairo.
The returned surface is only valid for the current draw cycle. Do not
cache it across frames; call conky_surface() each time your draw
hook is invoked.
Example usage:
require('cairo')
function conky_draw()
local surface = conky_surface()
if not surface then return end
local cr = cairo_create(surface)
-- draw ...
cairo_destroy(cr)
end
conky_windowThis table contains read-only information about Conky's window. The following table describes the values contained:
| Key | Value |
|---|---|
| drawable | Deprecated. Window's drawable (Xlib Drawable). Use conky_surface() instead. |
| visual | Deprecated. Window's visual (Xlib Visual). Use conky_surface() instead. |
| display | Deprecated. Window's display (Xlib Display). Use conky_surface() instead. |
| width | Window width in layout points (pt; logical). |
| height | Window height in layout points (pt; logical). |
| pixel_size.x | Window width in device pixels (px; physical). |
| pixel_size.y | Window height in device pixels (px; physical). |
| scale | Scaling factor of the buffer (dpi; pixel_size / size). |
| border_inner_margin | Window's inner border margin (in pixels). |
| border_outer_margin | Window's outer border margin (in pixels). |
| border_width | Window's border width (in pixels). |
| text_start_x | The x component of the starting coordinate of text drawing. |
| text_start_y | The y component of the starting coordinate of text drawing. |
| text_width | The width of the text drawing region. |
| text_height | The height of the text drawing region. |
NOTE: This table is only defined when a GUI output is
active. The drawable, visual, and display fields are
X11-specific and deprecated.
ret_scale_x,ret_scale_y:cairo_draw_image(file, cs, x, y, scale_x, scale_y)Renders an image onto a cairo_surface_t, using imlib2. Returns the amount the image was scaled by
| Argument | Description |
|---|---|
| file | Path to the image to render. |
| cs | The cairo_surface_t to render to. |
| x,y | Position to render the image. |
| scale_x, scale_y | The amount to scale the image, 1.0 provides no scaling, 2.0 for twice the size and |
| 0.5 for half size etc. Default value: No Scaling (1.0,1.0) |
require('cairo_imlib2_helper') in your lua file.
cairo_text_hp_show(cr, x, y, text, font, font_size, alignment, language, script, direction)Renders text to a cairo_t using HarfBuzz and FreeType. This provides
significantly better text rendering than Cairo's built-in functions.
| Argument | Description |
|---|---|
| cr | The cairo_t to render to. |
| x,y | Position to render the text. |
| text | The text to render. |
| font | The name of the font to be used, Fontconfig is used to search for the font. |
| font_size | The font size. |
| alignment | One of CAIRO_TEXT_ALIGN_LEFT, CAIRO_TEXT_ALIGN_RIGHT, CAIRO_TEXT_ALIGN_CENTER.Default value: CAIRO_TEXT_ALIGN_LEFT |
| language | A string containing a BCP 47 language tag. Default value: en |
| script | A string containing a ISO 15924 script tag. Default value: auto-detect from text |
| direction | A string representing text direction eg LTR, RTL or TTBDefault value: auto-detect from text otherwise LTR |
width,height:cairo_text_hp_text_size(text, font, font_size, language, script, direction)Used to calculate how many pixels will be required to render a string with
cairo_text_hp_show returns a pair of int's with width and height.
| Argument | Description |
|---|---|
| cr | The cairo_t to render to. |
| text | The text to render. |
| font | The name of the font to be used, Fontconfig is used to search for the font. |
| font_size | The font size. |
| language | A string containing a BCP 47 language tag. Default value: en |
| script | A string containing a ISO 15924 script tag. Default value: auto-detect from text |
| direction | A string representing text direction eg LTR, RTL or TTBDefault value: auto-detect from text otherwise LTR |