extensions from laptop
This commit is contained in:
@@ -11,6 +11,26 @@ local command = [[awk '
|
||||
local previous = {}
|
||||
local request_in_flight = false
|
||||
|
||||
local function colorForUsage(percent)
|
||||
if percent >= 85 then
|
||||
return "#ff453a" -- red
|
||||
end
|
||||
if percent >= 70 then
|
||||
return "#ff8800" -- orange
|
||||
end
|
||||
if percent >= 50 then
|
||||
return "#ffd60a" -- yellow
|
||||
end
|
||||
return "#ffffff" -- white
|
||||
end
|
||||
|
||||
local function renderStatus(text, color)
|
||||
barWidget.render(ui.row({ gap = 4, align = "center" }, {
|
||||
ui.glyph({ name = "cpu", size = 14, color = color }),
|
||||
ui.label({ text = text, color = color }),
|
||||
}))
|
||||
end
|
||||
|
||||
function update()
|
||||
noctalia.setUpdateInterval(2000)
|
||||
|
||||
@@ -23,7 +43,8 @@ function update()
|
||||
request_in_flight = false
|
||||
|
||||
if result.exitCode ~= 0 then
|
||||
barWidget.setText("CPU —")
|
||||
renderStatus("CPU —", "#fff1e6")
|
||||
barWidget.setTooltip("Unable to read CPU utilization")
|
||||
return
|
||||
end
|
||||
|
||||
@@ -47,12 +68,19 @@ function update()
|
||||
previous[name] = { total = total, idle = idle }
|
||||
end
|
||||
|
||||
barWidget.setGlyph("cpu")
|
||||
if sampled > 0 then
|
||||
barWidget.setText(string.format("%.0f%%", utilization))
|
||||
barWidget.setTooltip("Aggregate CPU utilization (100% per logical CPU)")
|
||||
-- Keep the aggregate display, but base its heat color on average
|
||||
-- utilization per logical CPU so multicore systems do not stay red.
|
||||
local per_cpu_utilization = utilization / sampled
|
||||
renderStatus(string.format("%.0f%%", utilization), colorForUsage(per_cpu_utilization))
|
||||
barWidget.setTooltip(
|
||||
string.format(
|
||||
"Aggregate CPU utilization (100%% per logical CPU) · %.0f%% average per CPU",
|
||||
per_cpu_utilization
|
||||
)
|
||||
)
|
||||
else
|
||||
barWidget.setText("—")
|
||||
renderStatus("—", "#fff1e6")
|
||||
barWidget.setTooltip("Sampling CPU utilization…")
|
||||
end
|
||||
end)
|
||||
|
||||
Reference in New Issue
Block a user