From cbb61c6e177ed92e0e2439f3b3770a22e7084cde Mon Sep 17 00:00:00 2001 From: Julien Danjou Date: Tue, 9 Dec 2008 16:50:06 +0100 Subject: [PATCH] telak: import Signed-off-by: Julien Danjou --- lib/telak.lua.in | 77 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 77 insertions(+) create mode 100644 lib/telak.lua.in diff --git a/lib/telak.lua.in b/lib/telak.lua.in new file mode 100644 index 00000000..58798e75 --- /dev/null +++ b/lib/telak.lua.in @@ -0,0 +1,77 @@ +---------------------------------------------------------------------------- +-- @author Julien Danjou <julien@danjou.info> +-- @copyright 2008 Julien Danjou +-- @release @AWESOME_VERSION@ +---------------------------------------------------------------------------- + +-- Grab environment +local os = os +local otable = otable +local setmetatable = setmetatable +local util = require("awful.util") +local hooks = require("awful.hooks") +local capi = +{ + wibox = wibox, + widget = widget, + image = image +} + +--- Root window image display library +module("telak") + +command = "wget -q -O " + +local data = otable() + +-- Update a telak wibox. +-- @param w The wibox to update. +local function update(w) + local tmp = os.tmpname() + os.execute(command .. tmp .. " '" .. data[w].image .. "'") + 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. +local function new(_, args) + if not args or not args.image then return end + + -- Create wibox + local w = capi.wibox({ position = "floating" }) + data[w] = { image = args.image } + local wimg = capi.widget({ type = "imagebox" }) + w.widgets = wimg + + data[w].cb = function () update(w) end + hooks.timer.register(args.timer or 3, data[w].cb) + + update(w) + + return w +end + +--- Delete a telak wibox. +-- @param w The wibox. +function delete(w) + if data[w] then + hooks.timer.unregister(data[w].cb) + data[w] = nil + end +end + +setmetatable(_M, { __call = new }) + +-- vim: filetype=lua:expandtab:shiftwidth=4:tabstop=8:softtabstop=4:encoding=utf-8:textwidth=80 -- 2.11.4.GIT