From 6da394b5d9f9d3a520e7babd640b3c23b913436c Mon Sep 17 00:00:00 2001 From: Tim Keller Date: Mon, 14 Sep 2026 15:38:08 -0500 Subject: automatically get correct hwmon temp zone on linux via cpu vendor. cpuinfo lib. remove manual temp files --- hosts/T430.lua | 3 --- hosts/T495.lua | 3 --- hosts/libreX60.lua | 1 - lib/cpuinfo.lua | 25 +++++++++++++++++++++++++ widgets/temperature.lua | 24 +++++++++++++++++++++++- 5 files changed, 48 insertions(+), 8 deletions(-) delete mode 100644 hosts/T430.lua delete mode 100644 hosts/T495.lua create mode 100644 lib/cpuinfo.lua diff --git a/hosts/T430.lua b/hosts/T430.lua deleted file mode 100644 index c268fca..0000000 --- a/hosts/T430.lua +++ /dev/null @@ -1,3 +0,0 @@ -local bar_widgets = require("bar") - -bar_widgets.temp.file = "/sys/class/hwmon/hwmon0/temp1_input" diff --git a/hosts/T495.lua b/hosts/T495.lua deleted file mode 100644 index 0615b5c..0000000 --- a/hosts/T495.lua +++ /dev/null @@ -1,3 +0,0 @@ -local bar_widgets = require("bar") - -bar_widgets.temp.file = "/sys/class/hwmon/hwmon2/temp1_input" diff --git a/hosts/libreX60.lua b/hosts/libreX60.lua index af69c6a..3beb841 100644 --- a/hosts/libreX60.lua +++ b/hosts/libreX60.lua @@ -8,4 +8,3 @@ beautiful.font_sans = beautiful.font_mono local bar_widgets = require("bar") bar_widgets.textclock.format = "%a, %b %-e, %-H:%M" -bar_widgets.temp.file = "/sys/class/thermal/thermal_zone0/temp" diff --git a/lib/cpuinfo.lua b/lib/cpuinfo.lua new file mode 100644 index 0000000..f713249 --- /dev/null +++ b/lib/cpuinfo.lua @@ -0,0 +1,25 @@ +local naughty = require("naughty") +local cpuinfo = {} + +function linux_setup() + local cpuinfof = io.open("/proc/cpuinfo") + local cpuinfoc = cpuinfof:read("*a") + cpuinfof:close() + + + local a = {} + for k, v in cpuinfoc:gmatch("(.-)%s+:%s*(.-)\n") do + a[k] = v + end + + cpuinfo.model = a["model name"] + cpuinfo.vendor = a["vendor_id"] + --cpuinfo.processors = tonumber(a["processors"]) + 1 + cpuinfo.cache = a["cache size"] -- nil if missing +end + +if osname == "Linux" then + linux_setup() +end + +return cpuinfo 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) -- cgit v1.2.3