diff options
Diffstat (limited to 'widgets/temperature.lua')
| -rw-r--r-- | widgets/temperature.lua | 24 |
1 files changed, 23 insertions, 1 deletions
diff --git a/widgets/temperature.lua b/widgets/temperature.lua index 867e7c4..cbefbd2 100644 --- a/widgets/temperature.lua +++ b/widgets/temperature.lua @@ -1,6 +1,8 @@ local wibox = require("wibox") local widgets_util = require("util.widgets") local gears = require("gears") +local cpuinfo = require("lib.cpuinfo") +local naughty = require("naughty") local temperature = {} @@ -9,6 +11,26 @@ function temperature:set_file(file) self._timer:emit_signal("timeout") end +function linux_auto_get_file() + -- determine hwmon name from cpu vendor + local vendor_hwmon_name = nil + if cpuinfo.vendor == "GenuineIntel" then + vendor_hwmon_name = "coretemp" + elseif cpuinfo.vendor == "AuthenticAMD" then + vendor_hwmon_name = "k10temp" + else + return nil + end + + -- find hwmon + local hwmons = io.popen([[awk '{ sub("/name$", "", FILENAME); print FILENAME, $0 }' /sys/class/hwmon/hwmon*/name]]) + for hwmon, hwmon_name in hwmons:read("*a"):gmatch("(.-)%s(.-)\n") do + if hwmon_name == vendor_hwmon_name then + return hwmon .. "/temp1_input" -- TODO dont hardcode temp1_input + end + end +end + function linux_update(widget) local tempf = io.open(widget._private.file) if tempf then @@ -25,7 +47,7 @@ if osname == "Linux" then return function(file) local w = wibox.widget.textbox() gears.table.crush(w, temperature, true) - w._private.file = file or "" + w._private.file = file or linux_auto_get_file() w._private.format = "%d°" widgets_util.add_timer(w, linux_update, 5) --return widgets.watchfn(linux.temperature, 5) |
