]> git.madduck.net Git - etc/awesome.git/blob - widgets/abase.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 pull request #286 from aajjbb/fix-alsa-channel
[etc/awesome.git] / widgets / abase.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 local setmetatable = setmetatable
12
13 -- Basic template for custom widgets (asynchronous version)
14 -- lain.widgets.abase
15
16 local function worker(args)
17     local abase     = helpers.make_widget_textbox()
18     local args      = args or {}
19     local timeout   = args.timeout or 5
20     local nostart   = args.nostart or false
21     local stoppable = args.stoppable or false
22     local cmd       = args.cmd or ""
23     local settings  = args.settings or function() end
24
25     function abase.update()
26         helpers.async(cmd, function(f)
27             output = f
28             if output ~= abase.prev then
29                 widget = abase.widget
30                 settings()
31                 abase.prev = output
32             end
33         end)
34     end
35
36     abase.timer = helpers.newtimer(cmd, timeout, abase.update, nostart, stoppable)
37
38     return setmetatable(abase, { __index = abase.widget })
39 end
40
41 return setmetatable({}, { __call = function(_, ...) return worker(...) end })