--[[ Another Clock by kit_oz
Simple clock, written using cairo
To use this script in Conky
1. load scripts:
lua_load ~/.conky/just_another_clock/cairo_clock.lua
2. call function as you like:
${lua cairo_clock theme}
or
lua_draw_hook_pre cairo_clock theme
3. ?????
4. PROFIT
Options are:
Theme - name of the folder with the theme. Mandatory parameter
Width - width of clock in pixels. The default 200px
X and Y positions. By default center of conky window
2011.12.11 First release!
2011.12.13 Redesign back to original idea
]]
require 'cairo'
home = os.getenv ('HOME')
function conky_cairo_clock(theme,w,x,y)
theme = string.gsub(theme, "~", home)
theme = string.gsub(theme, "$HOME", home)
if conky_window==nil then return ' ' end
local w = w or 200
local x = x or conky_window.width / 2
local y = y or conky_window.height / 2
local cs = cairo_xlib_surface_create(conky_window.display, conky_window.drawable, conky_window.visual, conky_window.width, conky_window.height)
local function fDrawImage(path,x,y,w,h,arc)
local img = cairo_image_surface_create_from_png(path)
local w_img, h_img = cairo_image_surface_get_width (img), cairo_image_surface_get_height (img)
local cr = cairo_create (cs)
cairo_translate (cr, x, y)
if arc then
cairo_rotate (cr, arc)
end
cairo_scale (cr, w/w_img, h/h_img)
cairo_set_source_surface (cr, img, -w_img/2, -h_img/2)
cairo_paint (cr)
cairo_destroy(cr)
cairo_surface_destroy (img)
end
local arc_s = (2 * math.pi / 60) * os.date("%S")
local arc_m = (2 * math.pi / 60) * os.date("%M") + arc_s / 60
local arc_h = (2 * math.pi / 12) * os.date("%I") + arc_m / 12
fDrawImage(theme..'/base.png',x,y,w,w)
fDrawImage(theme..'/h.png',x,y,w,w,arc_h)
fDrawImage(theme..'/m.png',x,y,w,w,arc_m)
fDrawImage(theme..'/s.png',x,y,w,w,arc_s)
cairo_surface_destroy(cs)
return ' '
end