]> git.madduck.net Git - etc/awesome.git/blob - .config/awesome/lain/widget/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:

Flameshot shortcut
[etc/awesome.git] / .config / awesome / lain / widget / temp.lua
1 --[[
2
3      Licensed under GNU General Public License v2
4       * (c) 2013, Luca CPZ
5
6 --]]
7
8 local helpers  = require("lain.helpers")
9 local wibox    = require("wibox")
10 local tonumber = tonumber
11
12 -- {thermal,core} temperature info
13 -- lain.widget.temp
14
15 local function factory(args)
16     local temp     = { widget = wibox.widget.textbox() }
17     local args     = args or {}
18     local timeout  = args.timeout or 30
19     local tempfile = args.tempfile or "/sys/devices/virtual/thermal/thermal_zone0/temp"
20     local settings = args.settings or function() end
21
22     function temp.update()
23         helpers.async({"find", "/sys/devices", "-type", "f", "-name", "*temp*"}, function(f)
24             temp_now = {}
25             local temp_fl, temp_value
26             for t in f:gmatch("[^\n]+") do
27                 temp_fl = helpers.first_line(t)
28                 if temp_fl then
29                     temp_value = tonumber(temp_fl)
30                     temp_now[t] = temp_value and temp_value/1e3 or temp_fl
31                 end
32             end
33             coretemp_now = temp_now[tempfile] or "N/A"
34             widget = temp.widget
35             settings()
36         end)
37     end
38
39     helpers.newtimer("thermal", timeout, temp.update)
40
41     return temp
42 end
43
44 return factory