2008-12-09 16:50:06 +01:00
|
|
|
----------------------------------------------------------------------------
|
|
|
|
-- @author Julien Danjou <julien@danjou.info>
|
|
|
|
-- @copyright 2008 Julien Danjou
|
|
|
|
-- @release @AWESOME_VERSION@
|
|
|
|
----------------------------------------------------------------------------
|
|
|
|
|
|
|
|
-- Grab environment
|
|
|
|
local os = os
|
2008-12-14 11:26:34 +01:00
|
|
|
local io = io
|
|
|
|
local http = require("socket.http")
|
|
|
|
local ltn12 = require("ltn12")
|
2008-12-09 16:50:06 +01:00
|
|
|
local setmetatable = setmetatable
|
|
|
|
local util = require("awful.util")
|
|
|
|
local capi =
|
|
|
|
{
|
2009-06-30 13:56:08 +02:00
|
|
|
timer = timer,
|
2008-12-09 16:50:06 +01:00
|
|
|
wibox = wibox,
|
|
|
|
widget = widget,
|
|
|
|
image = image
|
|
|
|
}
|
|
|
|
|
2009-08-28 17:02:16 +02:00
|
|
|
--- Display a remote image on your root window, and update it once in a while.
|
2008-12-09 16:50:06 +01:00
|
|
|
module("telak")
|
|
|
|
|
2009-04-11 14:11:13 +02:00
|
|
|
local data = setmetatable({}, { __mode = 'k' })
|
2008-12-09 16:50:06 +01:00
|
|
|
|
|
|
|
-- Update a telak wibox.
|
|
|
|
-- @param w The wibox to update.
|
|
|
|
local function update(w)
|
|
|
|
local tmp = os.tmpname()
|
2008-12-14 11:26:34 +01:00
|
|
|
http.request{url = data[w].image, sink = ltn12.sink.file(io.open(tmp, "w"))}
|
2008-12-09 16:50:06 +01:00
|
|
|
local img = capi.image(tmp)
|
|
|
|
if img then
|
|
|
|
w:geometry({ width = img.width, height = img.height })
|
|
|
|
w.widgets.image = img
|
|
|
|
else
|
|
|
|
w.visible = false
|
|
|
|
end
|
|
|
|
os.remove(tmp)
|
|
|
|
end
|
|
|
|
|
|
|
|
--- Create a new telak wibox. This will be automagically update to show a
|
|
|
|
-- local or remote image.
|
|
|
|
-- @param args A table with arguments: image is the local or remote image.
|
|
|
|
-- Timer can be specified to set the time in seconds between two update.
|
|
|
|
-- Default is 300 seconds.
|
|
|
|
-- @return The wibox. You need to attach it to a screen and to set its
|
|
|
|
-- coordinates as you want.
|
2009-08-28 17:02:16 +02:00
|
|
|
local function new(args)
|
2008-12-09 16:50:06 +01:00
|
|
|
if not args or not args.image then return end
|
|
|
|
|
|
|
|
-- Create wibox
|
2009-05-05 17:32:53 +02:00
|
|
|
local w = capi.wibox{}
|
2008-12-09 16:50:06 +01:00
|
|
|
data[w] = { image = args.image }
|
|
|
|
local wimg = capi.widget({ type = "imagebox" })
|
|
|
|
w.widgets = wimg
|
|
|
|
|
2009-06-30 13:56:08 +02:00
|
|
|
data[w].timer = capi.timer { timeout = args.timer or 300 }
|
|
|
|
data[w].timer:add_signal("timeout", function update(w) end)
|
|
|
|
data[w].timer:start()
|
2008-12-09 16:50:06 +01:00
|
|
|
|
|
|
|
update(w)
|
|
|
|
|
|
|
|
return w
|
|
|
|
end
|
|
|
|
|
|
|
|
--- Delete a telak wibox.
|
|
|
|
-- @param w The wibox.
|
|
|
|
function delete(w)
|
|
|
|
if data[w] then
|
2009-06-30 13:56:08 +02:00
|
|
|
data[w].timer:stop()
|
2008-12-09 16:50:06 +01:00
|
|
|
data[w] = nil
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2009-08-28 17:02:16 +02:00
|
|
|
setmetatable(_M, { __call = function(_, ...) return new(...) end })
|
2008-12-09 16:50:06 +01:00
|
|
|
|
|
|
|
-- vim: filetype=lua:expandtab:shiftwidth=4:tabstop=8:softtabstop=4:encoding=utf-8:textwidth=80
|