feat(noctalia): add modular Hyprland profiles
This commit is contained in:
@@ -0,0 +1,59 @@
|
||||
-- Sum each logical CPU's interval utilization. Unlike the built-in average,
|
||||
-- this follows Unix tools by allowing the value to exceed 100%.
|
||||
local command = [[awk '
|
||||
/^cpu[0-9]+ / {
|
||||
total = 0
|
||||
for (i = 2; i <= NF; i++) total += $i
|
||||
idle = $5 + $6
|
||||
printf "%s %.0f %.0f\n", $1, total, idle
|
||||
}' /proc/stat]]
|
||||
|
||||
local previous = {}
|
||||
local request_in_flight = false
|
||||
|
||||
function update()
|
||||
noctalia.setUpdateInterval(2000)
|
||||
|
||||
if request_in_flight then
|
||||
return
|
||||
end
|
||||
|
||||
request_in_flight = true
|
||||
noctalia.runAsync(command, function(result)
|
||||
request_in_flight = false
|
||||
|
||||
if result.exitCode ~= 0 then
|
||||
barWidget.setText("CPU —")
|
||||
return
|
||||
end
|
||||
|
||||
local utilization = 0
|
||||
local sampled = 0
|
||||
for line in string.gmatch(result.stdout, "[^\r\n]+") do
|
||||
local name, total, idle = string.match(line, "^(cpu%d+) (%d+) (%d+)$")
|
||||
total = tonumber(total)
|
||||
idle = tonumber(idle)
|
||||
local prior = previous[name]
|
||||
|
||||
if prior ~= nil then
|
||||
local total_delta = total - prior.total
|
||||
local idle_delta = idle - prior.idle
|
||||
if total_delta > 0 then
|
||||
utilization = utilization + (100 * (total_delta - idle_delta) / total_delta)
|
||||
sampled = sampled + 1
|
||||
end
|
||||
end
|
||||
|
||||
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)")
|
||||
else
|
||||
barWidget.setText("—")
|
||||
barWidget.setTooltip("Sampling CPU utilization…")
|
||||
end
|
||||
end)
|
||||
end
|
||||
@@ -0,0 +1,43 @@
|
||||
-- Read the tiny kernel meminfo pseudo-file every five seconds. This avoids a
|
||||
-- resident helper process and reuses Noctalia's lightweight widget lifecycle.
|
||||
local command = [[awk '
|
||||
$1 == "MemTotal:" { total = $2 }
|
||||
$1 == "MemAvailable:" { available = $2 }
|
||||
$1 == "SwapTotal:" { swap_total = $2 }
|
||||
$1 == "SwapFree:" { swap_free = $2 }
|
||||
END {
|
||||
if (!total || !available) exit 1
|
||||
used = total - available
|
||||
if (swap_total > 0) {
|
||||
swap_used = (swap_total - swap_free) * 100 / swap_total
|
||||
printf "RAM %.1f/%.1f GiB S %.0f%%\n", used / 1048576, total / 1048576, swap_used
|
||||
} else {
|
||||
printf "RAM %.1f/%.1f GiB S —\n", used / 1048576, total / 1048576
|
||||
}
|
||||
}' /proc/meminfo]]
|
||||
|
||||
local request_in_flight = false
|
||||
|
||||
function update()
|
||||
noctalia.setUpdateInterval(5000)
|
||||
|
||||
if request_in_flight then
|
||||
return
|
||||
end
|
||||
|
||||
request_in_flight = true
|
||||
noctalia.runAsync(command, function(result)
|
||||
request_in_flight = false
|
||||
|
||||
if result.exitCode ~= 0 then
|
||||
barWidget.setText("RAM —")
|
||||
barWidget.setTooltip("Unable to read /proc/meminfo")
|
||||
return
|
||||
end
|
||||
|
||||
local text = string.gsub(result.stdout, "%s+$", "")
|
||||
barWidget.setGlyph("memory")
|
||||
barWidget.setText(text)
|
||||
barWidget.setTooltip("RAM used / total · S = swap used")
|
||||
end)
|
||||
end
|
||||
@@ -0,0 +1,14 @@
|
||||
id = "alex/system-status"
|
||||
name = "System Status"
|
||||
version = "1.0.0"
|
||||
plugin_api = 3
|
||||
author = "alex"
|
||||
description = "Low-overhead memory and swap indicator for the bar."
|
||||
|
||||
[[widget]]
|
||||
id = "cpu"
|
||||
entry = "cpu.luau"
|
||||
|
||||
[[widget]]
|
||||
id = "memory"
|
||||
entry = "memory.luau"
|
||||
Reference in New Issue
Block a user