diff --git a/awesome/src/widgets/cpu_info.lua b/awesome/src/widgets/cpu_info.lua index d4be074..8519393 100644 --- a/awesome/src/widgets/cpu_info.lua +++ b/awesome/src/widgets/cpu_info.lua @@ -144,79 +144,47 @@ return function(widget, clock_mode) widget = wibox.container.background } - local total_prev = 0 - local idle_prev = 0 - - watch( - [[ cat "/proc/stat" | grep '^cpu ' ]], - 3, - function(_, stdout) - local user, nice, system, idle, iowait, irq, softirq, steal, guest, guest_nice = - stdout:match("(%d+)%s(%d+)%s(%d+)%s(%d+)%s(%d+)%s(%d+)%s(%d+)%s(%d+)%s(%d+)%s(%d+)%s") - - local total = user + nice + system + idle + iowait + irq + softirq + steal - - local diff_idle = idle - idle_prev - local diff_total = total - total_prev - local diff_usage = (1000 * (diff_total - diff_idle) / diff_total + 5) / 10 - - cpu_usage_widget.container.cpu_layout.label.text = tostring(math.floor(diff_usage)) .. "%" - awesome.emit_signal("update::cpu_usage_widget", math.floor(diff_usage + 0.5)) - - total_prev = total - idle_prev = idle - collectgarbage("collect") + awesome.connect_signal( + "update::cpu_usage", + function(usage) + cpu_usage_widget.container.cpu_layout.label.text = usage .. "%" end ) - watch( - [[ bash -c "sensors | grep 'Package id 0:' | awk '{print $4}'" ]], - 3, - function(_, stdout) - + awesome.connect_signal( + "update::cpu_temp", + function(temp) local temp_icon local temp_color - - local temp_num = tonumber(stdout:match("%d+")) - if temp_num < 50 then + if temp < 50 then temp_color = color["Green200"] temp_icon = icon_dir .. "thermometer-low.svg" - elseif temp_num >= 50 and temp_num < 80 then + elseif temp >= 50 and temp < 80 then temp_color = color["Orange200"] temp_icon = icon_dir .. "thermometer.svg" - elseif temp_num >= 80 then + elseif temp >= 80 then temp_color = color["Red200"] temp_icon = icon_dir .. "thermometer-high.svg" end Hover_signal(cpu_temp, temp_color, Theme_config.cpu_temp.fg) cpu_temp.container.cpu_layout.icon_margin.icon_layout.icon:set_image(temp_icon) cpu_temp:set_bg(temp_color) - cpu_temp.container.cpu_layout.label.text = math.floor(temp_num) .. "°C" - awesome.emit_signal("update::cpu_temp_widget", temp_num, temp_icon) + cpu_temp.container.cpu_layout.label.text = math.floor(temp) .. "°C" + awesome.emit_signal("update::cpu_temp_widget", temp, temp_icon) end ) - watch( - [[ bash -c "cat /proc/cpuinfo | grep "MHz" | awk '{print int($4)}'" ]], - 3, - function(_, stdout) - local cpu_freq = {} + awesome.connect_signal( + "update::cpu_freq_average", + function(average) + cpu_clock.container.cpu_layout.label.text = average .. "Mhz" + end + ) - for value in stdout:gmatch("%d+") do - table.insert(cpu_freq, value) - end - - local average = 0 - - if clock_mode == "average" then - for i = 1, #cpu_freq do - average = average + cpu_freq[i] - end - average = math.floor(average / #cpu_freq) - cpu_clock.container.cpu_layout.label.text = average .. "Mhz" - elseif clock_mode then - cpu_clock.container.cpu_layout.label.text = cpu_freq[clock_mode] .. "Mhz" - end + awesome.connect_signal( + "update::cpu_freq_core", + function(freq) + cpu_clock.container.cpu_layout.label.text = freq .. "Mhz" end ) diff --git a/awesome/src/widgets/gpu_info.lua b/awesome/src/widgets/gpu_info.lua index a81947e..5371d70 100644 --- a/awesome/src/widgets/gpu_info.lua +++ b/awesome/src/widgets/gpu_info.lua @@ -101,20 +101,17 @@ return function(widget) } -- GPU Utilization - watch( - [[ bash -c "nvidia-smi -q -d UTILIZATION | grep Gpu | awk '{print $3}'"]], - 3, - function(_, stdout) + awesome.connect_signal( + "update::gpu_usage", + function(stdout) gpu_usage_widget.container.gpu_layout.label.text = stdout:gsub("\n", "") .. "%" - awesome.emit_signal("update::gpu_usage_widget", tonumber(stdout)) end ) -- GPU Temperature - watch( - [[ bash -c "nvidia-smi -q -d TEMPERATURE | grep 'GPU Current Temp' | awk '{print $5}'"]], - 3, - function(_, stdout) + awesome.connect_signal( + "update::gpu_temp", + function(stdout) local temp_icon local temp_color @@ -137,12 +134,9 @@ return function(widget) temp_color = color["Green200"] temp_icon = icon_dir .. "thermometer-low.svg" end - Hover_signal(gpu_temp_widget, temp_color, Theme_config.gpu_temp.fg) gpu_temp_widget.container.gpu_layout.icon_margin.icon_layout.icon:set_image(temp_icon) gpu_temp_widget:set_bg(temp_color) gpu_temp_widget.container.gpu_layout.label.text = tostring(temp_num) .. "°C" - awesome.emit_signal("update::gpu_temp_widget", temp_num, temp_icon) - end ) diff --git a/awesome/src/widgets/ram_info.lua b/awesome/src/widgets/ram_info.lua index 4fe2657..0b163bb 100644 --- a/awesome/src/widgets/ram_info.lua +++ b/awesome/src/widgets/ram_info.lua @@ -57,18 +57,12 @@ return function() Hover_signal(ram_widget, Theme_config.ram_info.bg, Theme_config.ram_info.fg) - watch( - [[ bash -c "cat /proc/meminfo| grep Mem | awk '{print $2}'" ]], - 3, - function(_, stdout) - - local MemTotal, MemFree, MemAvailable = stdout:match("(%d+)\n(%d+)\n(%d+)\n") - + awesome.connect_signal( + "update::ram", + function(MemTotal, MemFree, MemAvailable) local ram_string = tostring(string.format("%.1f", ((MemTotal - MemAvailable) / 1024 / 1024)) .. "/" .. string.format("%.1f", (MemTotal / 1024 / 1024)) .. "GB"):gsub(",", ".") - ram_widget.container.ram_layout.label.text = ram_string - awesome.emit_signal("update::ram_widget", math.floor(((MemTotal - MemAvailable) / MemTotal * 100) + 0.5)) end )