forked from awesomeWM/awesome
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtelak.lua.in
More file actions
77 lines (65 loc) · 2.09 KB
/
Copy pathtelak.lua.in
File metadata and controls
77 lines (65 loc) · 2.09 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
----------------------------------------------------------------------------
-- @author Julien Danjou <julien@danjou.info>
-- @copyright 2008 Julien Danjou
-- @release @AWESOME_VERSION@
----------------------------------------------------------------------------
-- Grab environment
local os = os
local io = io
local http = require("socket.http")
local ltn12 = require("ltn12")
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")
local data = setmetatable({}, { __mode = 'k' })
-- Update a telak wibox.
-- @param w The wibox to update.
local function update(w)
local tmp = os.tmpname()
http.request{url = data[w].image, sink = ltn12.sink.file(io.open(tmp, "w"))}
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 300, 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