]> git.madduck.net Git - etc/awesome.git/blob - widgets/base.lua

madduck's git repository

Every one of the projects in this repository is available at the canonical URL git://git.madduck.net/madduck/pub/<projectpath> — see each project's metadata for the exact URL.

All patches and comments are welcome. Please squash your changes to logical commits before using git-format-patch and git-send-email to patches@git.madduck.net. If you'd read over the Git project's submission guidelines and adhered to them, I'd be especially grateful.

SSH access, as well as push access can be individually arranged.

If you use my repositories frequently, consider adding the following snippet to ~/.gitconfig and using the third clone URL listed for each project:

[url "git://git.madduck.net/madduck/"]
  insteadOf = madduck:

merge and resolve conflicts from #134; #114
[etc/awesome.git] / widgets / base.lua
1
2 --[[
3                                                   
4      Licensed under GNU General Public License v2 
5       * (c) 2014, Luke Bonham                     
6                                                   
7 --]]
8
9 local helpers      = require("lain.helpers")
10 local wibox        = require("wibox")
11
12 local setmetatable = setmetatable
13
14 -- Basic template for custom widgets
15 -- lain.widgets.base
16
17 local function worker(args)
18     local base     = {}
19     local args     = args or {}
20     local timeout  = args.timeout or 1
21     local cmd      = args.cmd or ""
22     local settings = args.settings or function() end
23
24     base.widget = wibox.widget.textbox('')
25     helpers.set_map(cmd, '')
26
27     function base.update()
28         output = helpers.read_pipe(cmd)
29
30         if helpers.get_map(cmd) ~= output then
31             widget = base.widget
32             settings()
33             helpers.set_map(cmd, output)
34         end
35     end
36
37     helpers.newtimer(cmd, timeout, base.update)
38
39     return setmetatable(base, { __index = base.widget })
40 end
41
42 return setmetatable({}, { __call = function(_, ...) return worker(...) end })