moved watch to helper
This commit is contained in:
@@ -144,79 +144,47 @@ return function(widget, clock_mode)
|
|||||||
widget = wibox.container.background
|
widget = wibox.container.background
|
||||||
}
|
}
|
||||||
|
|
||||||
local total_prev = 0
|
awesome.connect_signal(
|
||||||
local idle_prev = 0
|
"update::cpu_usage",
|
||||||
|
function(usage)
|
||||||
watch(
|
cpu_usage_widget.container.cpu_layout.label.text = usage .. "%"
|
||||||
[[ 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")
|
|
||||||
end
|
end
|
||||||
)
|
)
|
||||||
|
|
||||||
watch(
|
awesome.connect_signal(
|
||||||
[[ bash -c "sensors | grep 'Package id 0:' | awk '{print $4}'" ]],
|
"update::cpu_temp",
|
||||||
3,
|
function(temp)
|
||||||
function(_, stdout)
|
|
||||||
|
|
||||||
local temp_icon
|
local temp_icon
|
||||||
local temp_color
|
local temp_color
|
||||||
|
if temp < 50 then
|
||||||
local temp_num = tonumber(stdout:match("%d+"))
|
|
||||||
if temp_num < 50 then
|
|
||||||
temp_color = color["Green200"]
|
temp_color = color["Green200"]
|
||||||
temp_icon = icon_dir .. "thermometer-low.svg"
|
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_color = color["Orange200"]
|
||||||
temp_icon = icon_dir .. "thermometer.svg"
|
temp_icon = icon_dir .. "thermometer.svg"
|
||||||
elseif temp_num >= 80 then
|
elseif temp >= 80 then
|
||||||
temp_color = color["Red200"]
|
temp_color = color["Red200"]
|
||||||
temp_icon = icon_dir .. "thermometer-high.svg"
|
temp_icon = icon_dir .. "thermometer-high.svg"
|
||||||
end
|
end
|
||||||
Hover_signal(cpu_temp, temp_color, Theme_config.cpu_temp.fg)
|
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.container.cpu_layout.icon_margin.icon_layout.icon:set_image(temp_icon)
|
||||||
cpu_temp:set_bg(temp_color)
|
cpu_temp:set_bg(temp_color)
|
||||||
cpu_temp.container.cpu_layout.label.text = math.floor(temp_num) .. "°C"
|
cpu_temp.container.cpu_layout.label.text = math.floor(temp) .. "°C"
|
||||||
awesome.emit_signal("update::cpu_temp_widget", temp_num, temp_icon)
|
awesome.emit_signal("update::cpu_temp_widget", temp, temp_icon)
|
||||||
end
|
end
|
||||||
)
|
)
|
||||||
|
|
||||||
watch(
|
awesome.connect_signal(
|
||||||
[[ bash -c "cat /proc/cpuinfo | grep "MHz" | awk '{print int($4)}'" ]],
|
"update::cpu_freq_average",
|
||||||
3,
|
function(average)
|
||||||
function(_, stdout)
|
cpu_clock.container.cpu_layout.label.text = average .. "Mhz"
|
||||||
local cpu_freq = {}
|
end
|
||||||
|
)
|
||||||
|
|
||||||
for value in stdout:gmatch("%d+") do
|
awesome.connect_signal(
|
||||||
table.insert(cpu_freq, value)
|
"update::cpu_freq_core",
|
||||||
end
|
function(freq)
|
||||||
|
cpu_clock.container.cpu_layout.label.text = freq .. "Mhz"
|
||||||
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
|
|
||||||
end
|
end
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|||||||
@@ -101,20 +101,17 @@ return function(widget)
|
|||||||
}
|
}
|
||||||
|
|
||||||
-- GPU Utilization
|
-- GPU Utilization
|
||||||
watch(
|
awesome.connect_signal(
|
||||||
[[ bash -c "nvidia-smi -q -d UTILIZATION | grep Gpu | awk '{print $3}'"]],
|
"update::gpu_usage",
|
||||||
3,
|
function(stdout)
|
||||||
function(_, stdout)
|
|
||||||
gpu_usage_widget.container.gpu_layout.label.text = stdout:gsub("\n", "") .. "%"
|
gpu_usage_widget.container.gpu_layout.label.text = stdout:gsub("\n", "") .. "%"
|
||||||
awesome.emit_signal("update::gpu_usage_widget", tonumber(stdout))
|
|
||||||
end
|
end
|
||||||
)
|
)
|
||||||
|
|
||||||
-- GPU Temperature
|
-- GPU Temperature
|
||||||
watch(
|
awesome.connect_signal(
|
||||||
[[ bash -c "nvidia-smi -q -d TEMPERATURE | grep 'GPU Current Temp' | awk '{print $5}'"]],
|
"update::gpu_temp",
|
||||||
3,
|
function(stdout)
|
||||||
function(_, stdout)
|
|
||||||
|
|
||||||
local temp_icon
|
local temp_icon
|
||||||
local temp_color
|
local temp_color
|
||||||
@@ -137,12 +134,9 @@ return function(widget)
|
|||||||
temp_color = color["Green200"]
|
temp_color = color["Green200"]
|
||||||
temp_icon = icon_dir .. "thermometer-low.svg"
|
temp_icon = icon_dir .. "thermometer-low.svg"
|
||||||
end
|
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.container.gpu_layout.icon_margin.icon_layout.icon:set_image(temp_icon)
|
||||||
gpu_temp_widget:set_bg(temp_color)
|
gpu_temp_widget:set_bg(temp_color)
|
||||||
gpu_temp_widget.container.gpu_layout.label.text = tostring(temp_num) .. "°C"
|
gpu_temp_widget.container.gpu_layout.label.text = tostring(temp_num) .. "°C"
|
||||||
awesome.emit_signal("update::gpu_temp_widget", temp_num, temp_icon)
|
|
||||||
|
|
||||||
end
|
end
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|||||||
@@ -57,18 +57,12 @@ return function()
|
|||||||
|
|
||||||
Hover_signal(ram_widget, Theme_config.ram_info.bg, Theme_config.ram_info.fg)
|
Hover_signal(ram_widget, Theme_config.ram_info.bg, Theme_config.ram_info.fg)
|
||||||
|
|
||||||
watch(
|
awesome.connect_signal(
|
||||||
[[ bash -c "cat /proc/meminfo| grep Mem | awk '{print $2}'" ]],
|
"update::ram",
|
||||||
3,
|
function(MemTotal, MemFree, MemAvailable)
|
||||||
function(_, stdout)
|
|
||||||
|
|
||||||
local MemTotal, MemFree, MemAvailable = stdout:match("(%d+)\n(%d+)\n(%d+)\n")
|
|
||||||
|
|
||||||
local ram_string = tostring(string.format("%.1f", ((MemTotal - MemAvailable) / 1024 / 1024)) ..
|
local ram_string = tostring(string.format("%.1f", ((MemTotal - MemAvailable) / 1024 / 1024)) ..
|
||||||
"/" .. string.format("%.1f", (MemTotal / 1024 / 1024)) .. "GB"):gsub(",", ".")
|
"/" .. string.format("%.1f", (MemTotal / 1024 / 1024)) .. "GB"):gsub(",", ".")
|
||||||
|
|
||||||
ram_widget.container.ram_layout.label.text = ram_string
|
ram_widget.container.ram_layout.label.text = ram_string
|
||||||
awesome.emit_signal("update::ram_widget", math.floor(((MemTotal - MemAvailable) / MemTotal * 100) + 0.5))
|
|
||||||
end
|
end
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user