diff options
| author | Tim Keller <tjkeller.xyz> | 2024-11-03 16:09:10 -0600 | 
|---|---|---|
| committer | Tim Keller <tjkeller.xyz> | 2024-11-03 16:09:10 -0600 | 
| commit | fea2bd24e83c90c311f4e77ccf46f1464a6f5afb (patch) | |
| tree | 2edc2072ae629d8082fdb653a052df23b1c49f2e | |
| parent | 9a11cd62ac1ca5659a36fb3111d3bf7dead9d85b (diff) | |
| download | awesome-fea2bd24e83c90c311f4e77ccf46f1464a6f5afb.tar.xz awesome-fea2bd24e83c90c311f4e77ccf46f1464a6f5afb.zip | |
update temp widget to be fancier and other small stuff
| -rw-r--r-- | bar.lua | 14 | ||||
| -rw-r--r-- | hosts/T430.lua | 3 | ||||
| -rw-r--r-- | hosts/libreX60.lua | 3 | ||||
| -rw-r--r-- | util/widgets.lua | 14 | ||||
| -rw-r--r-- | widgets/temperature.lua | 26 | 
5 files changed, 41 insertions, 19 deletions
| @@ -17,6 +17,7 @@ local spacing = 8  local separator = { widget = wibox.widget.separator, opacity = 0 }  local widgets = { +	temperature_file = nil;  	spacing = spacing, -- constant  	layoutlist = wibox.widget {  		layout = wibox.layout.fixed.horizontal, @@ -47,15 +48,14 @@ local widgets = {  		},  		separator,  	} end, -	textclock = wibox.widget.textclock("%A, %B %e, %-I:%M %p"), -	cpu = wibox.widget { +	textclock = wibox.widget.textclock("%A, %B %-e, %-I:%M %p"), +	cpu = {  		layout = wibox.layout.fixed.horizontal,  		wibox.widget.textbox "CPU: ",  		widget_cpu_usage,  		wibox.widget.textbox "% ", -		widget_temperature "/sys/class/hwmon/hwmon2/temp1_input", -- FIXME -		wibox.widget.textbox "°",  	}, +	temp = widget_temperature(),  	ram = {  		layout = wibox.layout.fixed.horizontal,  		wibox.widget.textbox "RAM: ", @@ -101,7 +101,11 @@ function widgets.right_widgets(s) return wibox.widget {  	{  		layout = wibox.layout.fixed.horizontal,  		spacing = spacing, -		widgets.cpu, +		{ +			layout = wibox.layout.fixed.horizontal, +			widgets.cpu, +			widgets.temp, +		},  		widgets.ram,  		widgets.vol,  		widgets.bat, diff --git a/hosts/T430.lua b/hosts/T430.lua new file mode 100644 index 0000000..c268fca --- /dev/null +++ b/hosts/T430.lua @@ -0,0 +1,3 @@ +local bar_widgets = require("bar") + +bar_widgets.temp.file = "/sys/class/hwmon/hwmon0/temp1_input" diff --git a/hosts/libreX60.lua b/hosts/libreX60.lua index 3ce5619..294c1a1 100644 --- a/hosts/libreX60.lua +++ b/hosts/libreX60.lua @@ -1,4 +1,5 @@  local wibox = require("wibox")  local bar_widgets = require("bar") -bar_widgets.textclock.format = "%a, %b %e, %-H:%M" +bar_widgets.textclock.format = "%a, %b %-e, %-H:%M" +bar_widgets.temp.file = "/sys/class/hwmon/hwmon2/temp1_input" diff --git a/util/widgets.lua b/util/widgets.lua index 301f25b..eae351d 100644 --- a/util/widgets.lua +++ b/util/widgets.lua @@ -3,17 +3,21 @@ local gears = require("gears")  local widgets = {} -function widgets.watchfn(callback, timeout, base_widget) -	local widget = (base_widget or wibox.widget.textbox)() -	gears.timer({ +function widgets.add_timer(w, callback, timeout) +	w._timer = gears.timer({  		timeout = timeout or 5,  		call_now = true,  		autostart = true,  		callback = function() -			callback(widget) +			callback(w)  		end  	}) -	return widget +	return w +end + +function widgets.watchfn(callback, timeout, base_widget) +	local widget = (base_widget or wibox.widget.textbox)() +	return widgets.add_timer(widget, callback, timeout)  end  return widgets diff --git a/widgets/temperature.lua b/widgets/temperature.lua index a30e1ed..867e7c4 100644 --- a/widgets/temperature.lua +++ b/widgets/temperature.lua @@ -1,15 +1,20 @@  local wibox = require("wibox") -local widgets = require("util.widgets") +local widgets_util = require("util.widgets") +local gears = require("gears") +local temperature = {} -local linux = { file = nil } -function linux.temperature(widget) -	-- read meminfo -	local tempf = io.open(linux.file) +function temperature:set_file(file) +	self._private.file = file +	self._timer:emit_signal("timeout") +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(math.floor(temp)) +		widget:set_text(string.format(widget._private.format, temp))  	else  		widget:set_text("err")  	end @@ -18,8 +23,13 @@ end  -- return correct widget for os  if osname == "Linux" then  	return function(file) -		linux.file = file -		return widgets.watchfn(linux.temperature, 5) +		local w = wibox.widget.textbox() +		gears.table.crush(w, temperature, true) +		w._private.file = file or "" +		w._private.format = "%d°" +		widgets_util.add_timer(w, linux_update, 5) +		--return widgets.watchfn(linux.temperature, 5) +		return w  	end  end | 
