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 = {} function temperature:set_file(file) self._private.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 local temp = tempf:read() / 1000 tempf:close() widget:set_text(string.format(widget._private.format, temp)) else widget:set_text("err") end end -- return correct widget for os if osname == "Linux" then return function(file) local w = wibox.widget.textbox() gears.table.crush(w, temperature, true) 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) return w end end return wibox.widget.textbox("unsupported os")