telak: import
[awesome.git] / lib / telak.lua.in
blob58798e754e44dc537e0dd5d41d693a595d7d445c
1 ----------------------------------------------------------------------------
2 -- @author Julien Danjou <julien@danjou.info>
3 -- @copyright 2008 Julien Danjou
4 -- @release @AWESOME_VERSION@
5 ----------------------------------------------------------------------------
7 -- Grab environment
8 local os = os
9 local otable = otable
10 local setmetatable = setmetatable
11 local util = require("awful.util")
12 local hooks = require("awful.hooks")
13 local capi =
15 wibox = wibox,
16 widget = widget,
17 image = image
20 --- Root window image display library
21 module("telak")
23 command = "wget -q -O "
25 local data = otable()
27 -- Update a telak wibox.
28 -- @param w The wibox to update.
29 local function update(w)
30 local tmp = os.tmpname()
31 os.execute(command .. tmp .. " '" .. data[w].image .. "'")
32 local img = capi.image(tmp)
33 if img then
34 w:geometry({ width = img.width, height = img.height })
35 w.widgets.image = img
36 else
37 w.visible = false
38 end
39 os.remove(tmp)
40 end
42 --- Create a new telak wibox. This will be automagically update to show a
43 -- local or remote image.
44 -- @param args A table with arguments: image is the local or remote image.
45 -- Timer can be specified to set the time in seconds between two update.
46 -- Default is 300 seconds.
47 -- @return The wibox. You need to attach it to a screen and to set its
48 -- coordinates as you want.
49 local function new(_, args)
50 if not args or not args.image then return end
52 -- Create wibox
53 local w = capi.wibox({ position = "floating" })
54 data[w] = { image = args.image }
55 local wimg = capi.widget({ type = "imagebox" })
56 w.widgets = wimg
58 data[w].cb = function () update(w) end
59 hooks.timer.register(args.timer or 3, data[w].cb)
61 update(w)
63 return w
64 end
66 --- Delete a telak wibox.
67 -- @param w The wibox.
68 function delete(w)
69 if data[w] then
70 hooks.timer.unregister(data[w].cb)
71 data[w] = nil
72 end
73 end
75 setmetatable(_M, { __call = new })
77 -- vim: filetype=lua:expandtab:shiftwidth=4:tabstop=8:softtabstop=4:encoding=utf-8:textwidth=80