]> git.madduck.net Git - etc/awesome.git/blob - widgets/contrib/brightness.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:

wiki: new commit
[etc/awesome.git] / widgets / contrib / brightness.lua
1
2 --[[
3                                                    
4      Licensed under GNU General Public License v2  
5       * (c) 2013, yawnt <yawn.localhost@gmail.com> 
6                                                    
7 --]]
8
9 local newtimer        = require("lain.helpers").newtimer
10
11 local wibox           = require("wibox")
12 local io              = { popen  = io.popen }
13 local string          = { match  = string.match }
14
15 local setmetatable    = setmetatable
16
17 -- Brightness level
18 -- lain.widgets.contrib.brightness
19 local brightness = {}
20
21 local function worker(args)
22     local args      = args or {}
23     local backlight = args.backlight or "acpi_video0"
24     local timeout   = args.timeout or 5
25     local settings  = args.settings or function() end
26
27     brightness.widget = wibox.widget.textbox('')
28
29     function brightness.update()
30         local f = assert(io.popen('cat /sys/class/backlight/' .. backlight .. "/brightness"))
31         brightness_now = f:read("*a")
32         f:close()
33
34         widget = brightness.widget
35         settings()
36     end
37
38     newtimer("brightness", timeout, brightness.update)
39
40     return setmetatable(brightness, { __index = brightness.widget })
41 end
42
43 return setmetatable(brightness, { __call = function(_, ...) return worker(...) end })