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

readme updated
[etc/awesome.git] / widgets / temp.lua
1
2 --[[
3                                                   
4      Licensed under GNU General Public License v2 
5       * (c) 2013, Luke Bonham                     
6                                                   
7 --]]
8
9 local markup       = require("lain.util.markup")
10
11 local beautiful    = require("beautiful")
12 local wibox        = require("wibox")
13
14 local io           = io
15 local tonumber     = tonumber
16
17 local setmetatable = setmetatable
18
19 -- coretemp
20 -- lain.widgets.temp
21 local temp = {}
22
23 function worker(args)
24     local args = args or {}
25     local refresh_timeout = args.refresh_timeout or 5
26     local header = args.header or " Temp "
27     local header_color = args.header_color or beautiful.fg_normal or "#FFFFFF"
28     local color = args.color or beautiful.fg_focus or header_color
29     local footer = args.footer or "C "
30
31     local mytemp = wibox.widget.textbox()
32
33     local mytempupdate = function()
34         local f = io.open("/sys/class/thermal/thermal_zone0/temp")
35         local ret = f:read("*all")
36         f:close()
37
38         ret = tonumber(ret) / 1000
39
40         mytemp:set_markup(markup(header_color, header) ..
41                           markup(color, ret .. footer))
42     end
43
44     local mytemptimer = timer({ timeout = refresh_timeout })
45     mytemptimer:connect_signal("timeout", mytempupdate)
46     mytemptimer:start()
47     mytemptimer:emit_signal("timeout")
48
49     return mytemp
50 end
51
52 return setmetatable(temp, { __call = function(_, ...) return worker(...) end })