RediWM is a Wayland compositor written in Zig (OpenGL ES) that includes everything in one process
system monitor update
oxydizerb9f10bed4de7
diff --git a/assets/icons/cpu.svg b/assets/icons/cpu.svgnew file mode 100644index 0000000..a4238d9--- /dev/null+++ b/assets/icons/cpu.svg@@ -0,0 +1,5 @@+<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 24 24" fill="none" stroke="black" stroke-width="1.7" stroke-linecap="round" stroke-linejoin="round">+ <rect x="5" y="5" width="14" height="14" rx="2"/>+ <rect x="8" y="8" width="8" height="8" rx="1"/>+ <path d="M8 2v3m4-3v3m4-3v3M8 19v3m4-3v3m4-3v3M2 8h3m-3 4h3m-3 4h3m14-8h3m-3 4h3m-3 4h3"/>+</svg>diff --git a/assets/icons/ram.svg b/assets/icons/ram.svgnew file mode 100644index 0000000..b8feefc--- /dev/null+++ b/assets/icons/ram.svg@@ -0,0 +1,6 @@+<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 24 24" fill="none" stroke="black" stroke-width="1.7" stroke-linecap="round" stroke-linejoin="round">+ <rect x="2" y="5" width="20" height="13" rx="2"/>+ <path d="M6 18v3m4-3v3m4-3v3m4-3v3"/>+ <rect x="5" y="8" width="5" height="7" rx=".6"/>+ <rect x="14" y="8" width="5" height="7" rx=".6"/>+</svg>diff --git a/build/support.zig b/build/support.zigindex a41883f..b8ba4dc 100644--- a/build/support.zig+++ b/build/support.zig@@ -152,7 +152,7 @@ pub fn addShellUi(b: *std.Build, module: *std.Build.Module) void {pub fn addShellIcons(b: *std.Build, module: *std.Build.Module) void {module.addAnonymousImport("redi-logo", .{ .root_source_file = b.path("assets/redi-logo.svg") });module.addAnonymousImport("rediwm-settings-icon", .{ .root_source_file = b.path("assets/icons/rediwm-settings.png") });- inline for (.{ "git-branch", "home", "folder", "terminal", "settings", "keyboard", "edit", "mouse", "touchpad", "trackball", "display", "music", "headphones", "wifi", "ethernet", "globe", "bluetooth", "battery", "notification-bell", "speaker", "speaker-xmark", "power-button", "clock", "lock", "logout", "restart", "eye", "eye-off", "refresh", "cut", "copy", "paste", "trash-outline", "trash", "view-grid", "view-list", "sort", "filter", "zoom-in", "zoom-out", "rotate", "crop", "undo", "save", "fit", "print", "open", "usb-stick", "drive", "eject", "users", "squares", "divide" }) |name| {+ inline for (.{ "git-branch", "home", "folder", "terminal", "settings", "keyboard", "edit", "mouse", "touchpad", "trackball", "display", "music", "headphones", "wifi", "ethernet", "globe", "bluetooth", "battery", "notification-bell", "speaker", "speaker-xmark", "power-button", "clock", "cpu", "ram", "lock", "logout", "restart", "eye", "eye-off", "refresh", "cut", "copy", "paste", "trash-outline", "trash", "view-grid", "view-list", "sort", "filter", "zoom-in", "zoom-out", "rotate", "crop", "undo", "save", "fit", "print", "open", "usb-stick", "drive", "eject", "users", "squares", "divide" }) |name| {module.addAnonymousImport("shell-icon-" ++ name, .{ .root_source_file = b.path("assets/icons/" ++ name ++ ".svg") });}}diff --git a/docs/system-monitor.md b/docs/system-monitor.mdindex aaabac6..d81f599 100644--- a/docs/system-monitor.md+++ b/docs/system-monitor.md@@ -4,13 +4,26 @@ Open **System Monitor** from the launcher, with **Ctrl+Alt+Del**, or byrunning `rediwm-monitor`. The shortcut restores and focuses an existingwindow, including one on another workspace.-CPU and RAM summaries have 60-second graphs. System RAM usage is+CPU and RAM summary cards show large current percentages and shaded 60-second+graphs. CPU includes its reported frequency and logical CPU count; RAM includes+used/total capacity and a usage bar. Graph axes show CPU percentages and memory+capacity. The cards use a compact layout in narrow windows. System RAM usage is`MemTotal - MemAvailable`; process memory is resident memory. A processusing one CPU core reads 100%, so multithreaded processes can exceed 100%.New processes and the first sample after resuming show an em dash untilthere is a second CPU measurement. Unavailable data also shows an em dash.Nonlocal account names fall back to their numeric UID.+The bottom bar groups CPU, RAM, swap, network, uptime and CPU temperature+beside the process actions. It wraps the readouts and actions at smaller+window sizes. CPU shows online logical CPUs and CPU 0's reported frequency;+RAM and swap show used/total capacity and a percentage. Network arrows show+total upload/download rates across non-loopback interfaces (virtual interfaces+can count the same traffic again). The first sample after resume or an interface+change shows a dash. Temperature is the hottest supported CPU sensor, never a+disk or GPU reading. Missing metrics show a dash; FreeBSD currently provides+CPU count, frequency and uptime, with network and temperature unavailable.+The list starts with your processes, sorted by CPU usage. Click a column tosort; click again to reverse. **My processes / All processes** changes theownership filter. Search matches names, PIDs and users. Selection follows@@ -23,6 +36,12 @@ confirmation has been open. Signals use a validated pidfd. Other users'processes can be viewed where `/proc` permits but cannot be managed here.The monitor never requests elevated privileges.+The process table has alternating rows, column dividers, process glyphs and+colored state indicators. CPU bars fill at one core (100%); resident-memory+bars are relative to the largest process in the snapshot, including processes+outside the current filter. Exact values stay visible, and bars hide when the+window is too narrow to fit them.+Process rows use Files' rounded hover and selection cards. The hover fades inand glides between rows; selection fades use the accent outline. Both followthe theme and animation settings and stop requesting frames when settled.diff --git a/po/de.po b/po/de.poindex 2500db3..b0d6244 100644--- a/po/de.po+++ b/po/de.po@@ -16,9 +16,9 @@ msgstr """X-RediWM-Locale: de_DE.UTF-8\n""X-RediWM-Reviewed: no\n"-#: src/system_monitor/app.zig-msgid " · /proc unavailable"-msgstr " · /proc nicht verfügbar"+#: src/system_monitor/app_footer.zig+msgid " · Process data unavailable"+msgstr " · Prozessdaten nicht verfügbar"#: src/control_center/sections/printers.zigmsgid " · Default"@@ -7410,11 +7410,11 @@ msgid_plural "{n} completed sheets reported by CUPS"msgstr[0] "{n} fertiggestelltes Blatt von CUPS gemeldet"msgstr[1] "{n} fertiggestellte Blätter von CUPS gemeldet"-#: src/system_monitor/app.zig-msgid "{n} process · Swap {swap}{status}"-msgid_plural "{n} processes · Swap {swap}{status}"-msgstr[0] "{n} Prozess · Auslagerung {swap}{status}"-msgstr[1] "{n} Prozesse · Auslagerung {swap}{status}"+#: src/system_monitor/app_footer.zig+msgid "{n} process{status}"+msgid_plural "{n} processes{status}"+msgstr[0] "{n} Prozess{status}"+msgstr[1] "{n} Prozesse{status}"#: src/control_center/sections/services.zigmsgid "{n} service, {enabled} enabled"diff --git a/po/es.po b/po/es.poindex 5edf62e..9912bb6 100644--- a/po/es.po+++ b/po/es.po@@ -13,9 +13,9 @@ msgstr """X-RediWM-Locale: es_ES.UTF-8\n""X-RediWM-Reviewed: no\n"-#: src/system_monitor/app.zig-msgid " · /proc unavailable"-msgstr " · /proc no disponible"+#: src/system_monitor/app_footer.zig+msgid " · Process data unavailable"+msgstr " · Datos de procesos no disponibles"#: src/control_center/sections/printers.zigmsgid " · Default"@@ -7407,11 +7407,11 @@ msgid_plural "{n} completed sheets reported by CUPS"msgstr[0] "CUPS notificó {n} hoja completada"msgstr[1] "CUPS notificó {n} hojas completadas"-#: src/system_monitor/app.zig-msgid "{n} process · Swap {swap}{status}"-msgid_plural "{n} processes · Swap {swap}{status}"-msgstr[0] "{n} proceso · Intercambio {swap}{status}"-msgstr[1] "{n} procesos · Intercambio {swap}{status}"+#: src/system_monitor/app_footer.zig+msgid "{n} process{status}"+msgid_plural "{n} processes{status}"+msgstr[0] "{n} proceso{status}"+msgstr[1] "{n} procesos{status}"#: src/control_center/sections/services.zigmsgid "{n} service, {enabled} enabled"diff --git a/po/fr.po b/po/fr.poindex c93b4f9..b4417ad 100644--- a/po/fr.po+++ b/po/fr.po@@ -16,9 +16,9 @@ msgstr """X-RediWM-Locale: fr_FR.UTF-8\n""X-RediWM-Reviewed: no\n"-#: src/system_monitor/app.zig-msgid " · /proc unavailable"-msgstr " · /proc indisponible"+#: src/system_monitor/app_footer.zig+msgid " · Process data unavailable"+msgstr " · Données des processus indisponibles"#: src/control_center/sections/printers.zigmsgid " · Default"@@ -7410,11 +7410,11 @@ msgid_plural "{n} completed sheets reported by CUPS"msgstr[0] "{n} feuille terminée signalée par CUPS"msgstr[1] "{n} feuilles terminées signalées par CUPS"-#: src/system_monitor/app.zig-msgid "{n} process · Swap {swap}{status}"-msgid_plural "{n} processes · Swap {swap}{status}"-msgstr[0] "{n} processus · Échange {swap}{status}"-msgstr[1] "{n} processus · Échange {swap}{status}"+#: src/system_monitor/app_footer.zig+msgid "{n} process{status}"+msgid_plural "{n} processes{status}"+msgstr[0] "{n} processus{status}"+msgstr[1] "{n} processus{status}"#: src/control_center/sections/services.zigmsgid "{n} service, {enabled} enabled"diff --git a/po/lint-files b/po/lint-filesindex afd9c51..16362c9 100644--- a/po/lint-files+++ b/po/lint-files@@ -137,6 +137,9 @@ src/start_menu/panel.zigsrc/start_menu/scan.zigsrc/start_menu/search.zigsrc/system_monitor/app.zig+src/system_monitor/app_footer.zig+src/system_monitor/app_summary.zig+src/system_monitor/app_table.zigsrc/system_monitor/client.zigsrc/system_monitor_main.zigsrc/taskbar/battery.zigdiff --git a/po/pt_BR.po b/po/pt_BR.poindex bc2713c..7f78a31 100644--- a/po/pt_BR.po+++ b/po/pt_BR.po@@ -13,9 +13,9 @@ msgstr """X-RediWM-Locale: pt_BR.UTF-8\n""X-RediWM-Reviewed: no\n"-#: src/system_monitor/app.zig-msgid " · /proc unavailable"-msgstr " · /proc indisponível"+#: src/system_monitor/app_footer.zig+msgid " · Process data unavailable"+msgstr " · Dados de processos indisponíveis"#: src/control_center/sections/printers.zigmsgid " · Default"@@ -7407,11 +7407,11 @@ msgid_plural "{n} completed sheets reported by CUPS"msgstr[0] "O CUPS informou {n} folha concluída"msgstr[1] "O CUPS informou {n} folhas concluídas"-#: src/system_monitor/app.zig-msgid "{n} process · Swap {swap}{status}"-msgid_plural "{n} processes · Swap {swap}{status}"-msgstr[0] "{n} processo · Swap {swap}{status}"-msgstr[1] "{n} processos · Swap {swap}{status}"+#: src/system_monitor/app_footer.zig+msgid "{n} process{status}"+msgid_plural "{n} processes{status}"+msgstr[0] "{n} processo{status}"+msgstr[1] "{n} processos{status}"#: src/control_center/sections/services.zigmsgid "{n} service, {enabled} enabled"diff --git a/po/rediwm.pot b/po/rediwm.potindex e6f171a..965718e 100644--- a/po/rediwm.pot+++ b/po/rediwm.pot@@ -3,23 +3,23 @@ msgid ""msgstr """Content-Type: text/plain; charset=UTF-8\n"-#: src/system_monitor/app.zig-msgid " · /proc unavailable"-msgstr ""-#: src/control_center/sections/printers.zigmsgid " · Default"msgstr ""-#: src/system_monitor/app.zig+#: src/system_monitor/app_footer.zigmsgid " · List limited"msgstr ""-#: src/system_monitor/app.zig+#: src/system_monitor/app_footer.zigmsgid " · Paused"msgstr ""-#: src/system_monitor/app.zig+#: src/system_monitor/app_footer.zig+msgid " · Process data unavailable"+msgstr ""++#: src/system_monitor/app_footer.zigmsgid " · Some processes unavailable"msgstr ""@@ -107,7 +107,7 @@ msgstr ""msgid "5 seconds"msgstr ""-#: src/system_monitor/app.zig+#: src/system_monitor/app_summary.zigmsgid "60 seconds"msgstr ""@@ -803,11 +803,15 @@ msgstr ""msgid "CENTER"msgstr ""+#: src/system_monitor/app_footer.zig+msgid "CPU"+msgstr ""+#: src/system_monitor/app.zigmsgid "CPU %"msgstr ""-#: src/system_monitor/app.zig+#: src/system_monitor/app_footer.zigmsgid "CPU: 100% = one core · Memory: resident · Ctrl+F search · Delete end · Shift+Delete force quit"msgstr ""@@ -1343,7 +1347,7 @@ msgstr ""msgid "Closing ends this shell and its running jobs."msgstr ""-#: src/system_monitor/app.zig+#: src/system_monitor/app_footer.zigmsgid "Collecting processes…"msgstr ""@@ -2263,7 +2267,7 @@ msgstr ""msgid "Discovering printers; authorization may be required…"msgstr ""-#: src/system_monitor/app.zig+#: src/system_monitor/app_table.zigmsgid "Disk wait"msgstr ""@@ -2691,7 +2695,7 @@ msgstr ""msgid "Existing windows outside a smaller canvas stay reachable."msgstr ""-#: src/system_monitor/app.zig+#: src/system_monitor/app_table.zigmsgid "Exited"msgstr ""@@ -3219,7 +3223,7 @@ msgstr ""msgid "Icon theme"msgstr ""-#: src/system_monitor/app.zig+#: src/system_monitor/app_table.zigmsgid "Idle"msgstr ""@@ -3955,6 +3959,10 @@ msgstr ""msgid "My processes"msgstr ""+#: src/system_monitor/app_footer.zig+msgid "NET"+msgstr ""+#: src/files/app_layout.zigmsgid "Name"msgstr ""@@ -4123,6 +4131,10 @@ msgstr ""msgid "No audio device available"msgstr ""+#: src/files/app_audio_playlist.zig+msgid "No audio files"+msgstr ""+#: src/files/app_paint.zigmsgid "No changed files"msgstr ""@@ -4171,7 +4183,7 @@ msgstr ""msgid "No matching items"msgstr ""-#: src/system_monitor/app.zig+#: src/system_monitor/app_table.zigmsgid "No matching processes"msgstr ""@@ -4743,6 +4755,10 @@ msgstr ""msgid "Play"msgstr ""+#: src/files/app_audio_bar.zig+msgid "Playlist"+msgstr ""+#: src/images/app_edit.zigmsgid "Please wait for the file operation to finish."msgstr ""@@ -5027,11 +5043,11 @@ msgstr ""msgid "Problem"msgstr ""-#: src/system_monitor/app.zig+#: src/system_monitor/app_table.zigmsgid "Process data unavailable"msgstr ""-#: src/system_monitor/app.zig+#: src/system_monitor/app_footer.zigmsgid "Processes"msgstr ""@@ -5131,6 +5147,10 @@ msgstr ""msgid "Quit"msgstr ""+#: src/system_monitor/app_footer.zig+msgid "RAM"+msgstr ""+#: src/control_center/sections/display.zigmsgid "REDIWM_SCALE sets scaling; restart to apply Xwayland changes."msgstr ""@@ -5517,7 +5537,7 @@ msgstr ""msgid "Round"msgstr ""-#: src/system_monitor/app.zig+#: src/system_monitor/app_table.zigmsgid "Running"msgstr ""@@ -5529,6 +5549,10 @@ msgstr ""msgid "SOUND"msgstr ""+#: src/system_monitor/app_footer.zig+msgid "SWAP"+msgstr ""+#: src/control_center/sections/appearance_rows.zigmsgid "Same as theme"msgstr ""@@ -6029,7 +6053,7 @@ msgstr ""msgid "Sleep and battery"msgstr ""-#: src/system_monitor/app.zig+#: src/system_monitor/app_table.zigmsgid "Sleeping"msgstr ""@@ -6333,6 +6357,10 @@ msgstr ""msgid "Systemd is unavailable."msgstr ""+#: src/system_monitor/app_footer.zig+msgid "TEMP"+msgstr ""+#: src/control_center/sections/shortcuts.zigmsgid "Take shortcuts back from a virtual machine or remote desktop."msgstr ""@@ -7021,6 +7049,10 @@ msgstr ""msgid "UI font"msgstr ""+#: src/system_monitor/app_footer.zig+msgid "UPTIME"+msgstr ""+#: src/printing/ladder.zigmsgid "USB presence or queue-to-device identity could not be established."msgstr ""@@ -7517,7 +7549,7 @@ msgstr ""msgid "Your unsaved changes will be lost if you discard them."msgstr ""-#: src/system_monitor/app.zig+#: src/system_monitor/app_table.zigmsgid "Zombie"msgstr ""@@ -8205,6 +8237,10 @@ msgid_plural "{count}{more} items"msgstr[0] ""msgstr[1] ""+#: src/system_monitor/app_footer.zig+msgid "{hours}h {minutes}m"+msgstr ""+#: src/taskbar/battery.zigmsgid "{hours}h {minutes}min"msgstr ""@@ -8285,6 +8321,12 @@ msgstr ""msgid "{name}: level unavailable"msgstr ""+#: src/system_monitor/app_footer.zig+msgid "{n} CPU"+msgid_plural "{n} CPUs"+msgstr[0] ""+msgstr[1] ""+#: src/control_center/sections/printers_details.zigmsgid "{n} completed sheet reported by CUPS"msgid_plural "{n} completed sheets reported by CUPS"@@ -8297,9 +8339,9 @@ msgid_plural "{n} minutes"msgstr[0] ""msgstr[1] ""-#: src/system_monitor/app.zig-msgid "{n} process · Swap {swap}{status}"-msgid_plural "{n} processes · Swap {swap}{status}"+#: src/system_monitor/app_footer.zig+msgid "{n} process{status}"+msgid_plural "{n} processes{status}"msgstr[0] ""msgstr[1] ""diff --git a/po/ru.po b/po/ru.poindex 9fe71db..0f57c16 100644--- a/po/ru.po+++ b/po/ru.po@@ -16,9 +16,9 @@ msgstr """X-RediWM-Locale: ru_RU.UTF-8\n""X-RediWM-Reviewed: no\n"-#: src/system_monitor/app.zig-msgid " · /proc unavailable"-msgstr " · /proc недоступен"+#: src/system_monitor/app_footer.zig+msgid " · Process data unavailable"+msgstr " · Данные процессов недоступны"#: src/control_center/sections/printers.zigmsgid " · Default"@@ -7421,12 +7421,12 @@ msgstr[0] "CUPS сообщает о {n} напечатанном листе"msgstr[1] "CUPS сообщает о {n} напечатанных листах"msgstr[2] "CUPS сообщает о {n} напечатанных листах"-#: src/system_monitor/app.zig-msgid "{n} process · Swap {swap}{status}"-msgid_plural "{n} processes · Swap {swap}{status}"-msgstr[0] "{n} процесс · Подкачка {swap}{status}"-msgstr[1] "{n} процесса · Подкачка {swap}{status}"-msgstr[2] "{n} процессов · Подкачка {swap}{status}"+#: src/system_monitor/app_footer.zig+msgid "{n} process{status}"+msgid_plural "{n} processes{status}"+msgstr[0] "{n} процесс{status}"+msgstr[1] "{n} процесса{status}"+msgstr[2] "{n} процессов{status}"#: src/control_center/sections/services.zigmsgid "{n} service, {enabled} enabled"diff --git a/src/system_monitor/AGENTS.md b/src/system_monitor/AGENTS.mdindex cc22ae4..6e7d85c 100644--- a/src/system_monitor/AGENTS.md+++ b/src/system_monitor/AGENTS.md@@ -9,7 +9,9 @@(`kern.proc` sysctls; a `Process` holds the `kinfo_proc` taken at open, CPU isin microseconds). Never read`/proc` outside a backend; a new OS needs `Process`, `List`, `cpuTotals`,- `memoryTotals` and `ticksPerSecond`. The Linux parsers are pure and tested+ `memoryTotals`, `systemStats` and `ticksPerSecond`. Optional footer telemetry+ lives in `proc_linux_system.zig`; rates reset with the worker generation.+ The Linux parsers are pure and testedeverywhere through `proc_linux.zig`.* A snapshot owns its arena. The worker publishes under its mutex through aneventfd; the UI takes ownership. A generation change cancels enumeration anddiff --git a/src/system_monitor/app.zig b/src/system_monitor/app.zigindex 89d5c1e..4c4066c 100644--- a/src/system_monitor/app.zig+++ b/src/system_monitor/app.zig@@ -13,9 +13,12 @@ const proc = @import("proc.zig");const actions = @import("actions.zig");const scrollbar = ui.widgets.scrollbar;const a = std.heap.c_allocator;-const row_h: f64 = 32;+pub const row_h: f64 = 32;+const table = @import("app_table.zig");+const footer_view = @import("app_footer.zig");+const summary = @import("app_summary.zig");const titles = [_]i18n.Message{ i18n.msg("Name"), i18n.msg("PID"), i18n.msg("User"), i18n.msg("CPU %"), i18n.msg("Memory (resident)"), i18n.msg("State") };-const proportions = [_]f32{ 0.28, 0.10, 0.15, 0.12, 0.21, 0.14 };+const proportions = [_]f32{ 0.25, 0.10, 0.11, 0.18, 0.20, 0.16 };const Pending = enum { none, end, confirm, cancel, force };const Confirmation = struct { identity: proc.Identity, name: [256]u8 = undefined, len: usize };const Selection = struct { identity: proc.Identity, fade: ui.hover_glide.Fade = .{} };@@ -116,12 +119,15 @@ pub const App = struct {header.* = self.button(title.get(), 10 + i, 0);header.width = .{ .percent = width };header.kind.button.variant = .ghost;+ header.kind.button.alignment = .left;}self.footer = .{.{ .kind = .container, .width = .{ .flex = 1 } },self.button(tr("End process"), 2, 124),self.button(tr("Force quit…"), 3, 124),};+ self.footer[1].kind.button.destructive = true;+ for (self.footer[1..]) |*control| control.height = .{ .fixed = 38 };self.sections = .{.{ .kind = .container, .height = .{ .fixed = 150 } },.{ .kind = .container, .height = .{ .fixed = 50 }, .padding = .{ .left = 16, .right = 16, .top = 4 }, .gap = 8, .children = &self.toolbar },@@ -141,8 +147,10 @@ pub const App = struct {fn layout(self: *App) void {if (!self.initialized) return;self.sections[2].padding.right = scrollbar.gutter(theme.global.scrollbar_width) + 16;+ self.sections[4].height = .{ .fixed = footer_view.height(self) };ui.measure.measure(&self.root, @floatFromInt(self.w), @floatFromInt(self.h));ui.arrange.arrange(&self.root, 0, 0, @floatFromInt(self.w), @floatFromInt(self.h));+ self.layoutFooter();const box = self.dialogBox();ui.measure.measure(&self.modal, 252, 34);ui.arrange.arrange(&self.modal, box.x + box.w - 276, box.y + box.h - 50, 252, 34);@@ -150,7 +158,7 @@ pub const App = struct {}pub fn resize(self: *App, width: i32, height: i32) void {self.w = @max(640, width);- self.h = @max(400, height);+ self.h = @max(480, height);self.layout();self.dirty = true;}@@ -171,7 +179,7 @@ pub const App = struct {},2 => self.pending = .end,3 => self.pending = .confirm,- 10...15 => self.model.setSort(@enumFromInt(id - 10)),+ 10...15 => self.model.setSort(@fromBackingInt(@intCast(id - 10))),20 => self.pending = .cancel,21 => self.pending = .force,else => {},@@ -373,8 +381,8 @@ pub const App = struct {if (self.confirmation != null or self.ctrl or self.alt) return false;return sym == c.XKB_KEY_Up or sym == c.XKB_KEY_Down or sym == c.XKB_KEY_Page_Up or sym == c.XKB_KEY_Page_Down or sym == c.XKB_KEY_BackSpace or (self.dispatcher.focused == &self.toolbar[0] and text.len > 0);}- fn listBox(self: *const App) Rect {- return .{ .x = 16, .y = 236, .w = @floatFromInt(self.w - 32), .h = @floatFromInt(@max(0, self.h - 310)) };+ pub fn listBox(self: *const App) Rect {+ return .{ .x = 16, .y = 236, .w = @floatFromInt(self.w - 32), .h = @max(0, @as(f32, @floatFromInt(self.h)) - 264 - footer_view.height(self)) };}fn processAt(self: *const App) ?usize {if (self.confirmation != null or self.suspended or self.bar_drag.active) return null;@@ -384,14 +392,14 @@ pub const App = struct {const index: usize = @intFromFloat(@floor((self.py - list.y + self.model.scroll) / row_h));return if (index < self.model.rows.items.len) index else null;}- fn rowBox(self: *const App, row: f32) cairo.ItemBox {+ pub fn rowBox(self: *const App, row: f32) cairo.ItemBox {const list = self.listBox();return .{ .x = list.x + 1, .y = list.y + @as(f64, row) * row_h - self.model.scroll + 1, .w = list.w - scrollbar.gutter(theme.global.scrollbar_width) - 2, .h = row_h - 2 };}fn clampScroll(self: *App) void {self.model.scroll = std.math.clamp(self.model.scroll, 0, @max(0, @as(f64, @floatFromInt(self.model.rows.items.len)) * row_h - self.listBox().h));}- fn barGeometry(self: *const App) ?scrollbar.Geometry {+ pub fn barGeometry(self: *const App) ?scrollbar.Geometry {const list = self.listBox();const gutter = scrollbar.gutter(theme.global.scrollbar_width);return scrollbar.Geometry.compute(.vertical, .{ .x = list.x + list.w - gutter, .y = list.y, .w = gutter, .h = list.h }, list.h, @as(f32, @floatFromInt(self.model.rows.items.len)) * @as(f32, @floatCast(row_h)), @floatCast(self.model.scroll));@@ -459,11 +467,12 @@ pub const App = struct {cairo.setSource(cr, theme.global.app_bg);c.cairo_paint(cr);self.paintSummary(cr);- self.paintRows(cr);+ self.paintTable(cr);+ self.paintFooter(cr);self.toolbar[1].kind.button.label = if (self.model.mine) tr("My processes") else tr("All processes");self.toolbar[2].kind.button.label = if (self.paused) tr("Resume updates") else tr("Pause updates");for (&self.headers, titles, 0..) |*header, title, i| {- header.kind.button.label = std.fmt.bufPrint(&self.header_labels[i], "{s}{s}", .{ title.get(), if (@intFromEnum(self.model.sort) == i) if (self.model.descending) " ↓" else " ↑" else "" }) catch title.get();+ header.kind.button.label = std.fmt.bufPrint(&self.header_labels[i], "{s}{s}", .{ title.get(), if (@backingInt(self.model.sort) == i) if (self.model.descending) " ↓" else " ↑" else "" }) catch title.get();}for (self.footer[1..]) |*control| {if (!self.manageable()) control.kind.button.state = .disabled else if (control.kind.button.state == .disabled) control.kind.button.state = .idle;@@ -475,90 +484,14 @@ pub const App = struct {ui.paint.paint(&self.root, &layer.renderer);layer.finish();}- const foot = self.sections[4];- var status_buf: [256]u8 = undefined;- const status = if (self.notice.len > 0) self.notice else blk: {- const snap = self.model.snapshot orelse break :blk tr("Collecting processes…");- var swap_buf: [80]u8 = undefined;- const swap = if (snap.memory) |mem| if (mem.swap_total != null and mem.swap_free != null) bytesPair(&swap_buf, mem.swap_total.? -| mem.swap_free.?, mem.swap_total.?) else tr("Unavailable") else tr("Unavailable");- break :blk i18n.fmt(&status_buf, i18n.trn("{n} process · Swap {swap}{status}", "{n} processes · Swap {swap}{status}", self.model.rows.items.len), .{ .n = self.model.rows.items.len, .swap = swap, .status = if (self.paused) tr(" · Paused") else if (snap.failed) tr(" · /proc unavailable") else if (snap.truncated) tr(" · List limited") else if (snap.unavailable > 0) tr(" · Some processes unavailable") else "" }) catch tr("Processes");- };- textBox(cr, status, .{ .x = 16, .y = foot.computed_y + 8, .w = @max(0, foot.computed_width - 308), .h = 28 }, cairo.statusSize(), false, theme.global.window_fg);- textBox(cr, tr("CPU: 100% = one core · Memory: resident · Ctrl+F search · Delete end · Shift+Delete force quit"), .{ .x = 16, .y = @floatFromInt(self.h - 26), .w = @floatFromInt(self.w - 32), .h = 24 }, cairo.statusSize(), false, theme.global.window_fg);+ self.paintFooterStatus(cr);if (self.confirmation) |confirmation| self.paintConfirmation(cr, confirmation);}- fn paintSummary(self: *App, cr: *c.cairo_t) void {- const gap: f32 = 16;- const width = (@as(f32, @floatFromInt(self.w)) - gap * 3) / 2;- const snap = self.model.snapshot;- for (0..2) |index| {- const box: Rect = .{ .x = gap + @as(f32, @floatFromInt(index)) * (width + gap), .y = 14, .w = width, .h = 122 };- var buf: [128]u8 = undefined;- const label = if (index == 0) if (snap != null and snap.?.cpu_percent != null) std.fmt.bufPrint(&buf, "CPU {d:.1}%", .{snap.?.cpu_percent.?}) catch "CPU" else "CPU —" else if (snap != null and snap.?.memory != null) blk: {- var pair_buf: [80]u8 = undefined;- const mem = snap.?.memory.?;- break :blk std.fmt.bufPrint(&buf, "RAM {s}", .{bytesPair(&pair_buf, mem.used(), mem.total)}) catch "RAM";- } else "RAM —";- textBox(cr, label, .{ .x = box.x, .y = box.y, .w = box.w, .h = 30 }, cairo.headingSize(), true, theme.global.window_fg);- textBox(cr, tr("60 seconds"), .{ .x = box.x, .y = box.y + 30, .w = box.w, .h = 20 }, cairo.statusSize(), false, theme.global.window_fg);- const graph: Rect = .{ .x = box.x, .y = box.y + 56, .w = box.w, .h = 64 };- cairo.setSource(cr, theme.global.app_divider);- c.cairo_set_line_width(cr, 1);- for (0..3) |line| {- const y = graph.y + graph.h * @as(f32, @floatFromInt(line)) / 2;- c.cairo_move_to(cr, graph.x, y);- c.cairo_line_to(cr, graph.x + graph.w, y);- }- c.cairo_stroke(cr);- if (snap == null) continue;- cairo.setSource(cr, theme.shellPalette().accent);- c.cairo_set_line_width(cr, 2);- var last: ?u64 = null;- for (self.history.points[0..self.history.count]) |point| {- const value = if (index == 0) point.cpu else point.memory;- const age = snap.?.at_ns -| point.at_ns;- if (value == null or age >= 60_000_000_000) {- last = null;- continue;- }- const x = graph.x + graph.w * (1 - @as(f64, @floatFromInt(age)) / 60_000_000_000);- const y = graph.y + graph.h * (1 - std.math.clamp(value.?, 0, 100) / 100);- if (last == null or point.at_ns -| last.? > 2_000_000_000) c.cairo_move_to(cr, x, y) else c.cairo_line_to(cr, x, y);- last = point.at_ns;- }- c.cairo_stroke(cr);- }- }- fn paintRows(self: *App, cr: *c.cairo_t) void {- const list = self.listBox();- const snap = self.model.snapshot orelse return;- c.cairo_save(cr);- defer c.cairo_restore(cr);- c.cairo_rectangle(cr, list.x, list.y, list.w, list.h);- c.cairo_clip(cr);- const first: usize = @intFromFloat(@floor(self.model.scroll / row_h));- const last = @min(self.model.rows.items.len, first + @as(usize, @intFromFloat(@ceil(list.h / row_h))) + 1);- const hover = self.row_hover.frame;- if (hover.alpha > 0) cairo.drawItemHighlight(cr, self.rowBox(hover.row), false, hover.alpha, hover.alpha);- for (first..last) |i| {- const row = snap.processes[self.model.rows.items[i]];- const y: f32 = @floatCast(list.y + @as(f64, @floatFromInt(i)) * row_h - self.model.scroll);- for (self.selections.items) |selection| if (selection.identity.eql(row.identity)) {- cairo.drawItemHighlight(cr, self.rowBox(@floatFromInt(i)), true, selection.fade.alpha, selection.fade.alpha);- break;- };- var pid_buf: [32]u8 = undefined;- var cpu_buf: [32]u8 = undefined;- var mem_buf: [32]u8 = undefined;- const pid = std.fmt.bufPrint(&pid_buf, "{d}", .{row.identity.pid}) catch "—";- const cpu = if (row.cpu_percent) |v| std.fmt.bufPrint(&cpu_buf, "{d:.1}%", .{v}) catch "—" else "—";- const memory = if (row.resident_bytes) |v| bytesLabel(&mem_buf, v) else "—";- const values = [_][]const u8{ row.name, pid, row.user, cpu, memory, stateName(row.state) };- for (values, self.headers) |value, header| textBox(cr, value, .{ .x = header.computed_x + 8, .y = y, .w = @max(0, header.computed_width - 16), .h = row_h }, cairo.textSize(), false, theme.global.window_fg);- }- if (self.model.rows.items.len == 0) textBox(cr, if (snap.failed) tr("Process data unavailable") else tr("No matching processes"), .{ .x = list.x + 8, .y = list.y + 12, .w = list.w - 16, .h = 32 }, cairo.textSize(), false, theme.global.window_fg);- if (self.barGeometry()) |g| cairo.drawScrollbar(cr, scrollbar.look(g, self.bar, theme.global.scrollbar_width, theme.global));- }+ pub const paintSummary = summary.paint;+ pub const paintTable = table.paint;+ pub const paintFooter = footer_view.paint;+ pub const layoutFooter = footer_view.layout;+ pub const paintFooterStatus = footer_view.paintStatus;fn dialogBox(self: *const App) Rect {return .{ .x = (@as(f32, @floatFromInt(self.w)) - 520) / 2, .y = (@as(f32, @floatFromInt(self.h)) - 232) / 2, .w = 520, .h = 232 };}@@ -583,7 +516,7 @@ pub const App = struct {}};-fn textBox(cr: *c.cairo_t, text: []const u8, box: Rect, size: f32, bold: bool, color: [4]f32) void {+pub fn textBox(cr: *c.cairo_t, text: []const u8, box: Rect, size: f32, bold: bool, color: [4]f32) void {if (box.w <= 0 or box.h <= 0) return;c.cairo_save(cr);defer c.cairo_restore(cr);@@ -593,28 +526,15 @@ fn textBox(cr: *c.cairo_t, text: []const u8, box: Rect, size: f32, bold: bool, cconst metrics = cairo.fontMetrics(cr, size);cairo.drawText(cr, text, box.x, box.y + (box.h - metrics.ascent - metrics.descent) / 2 + metrics.ascent, size, bold);}-fn bytesLabel(buf: []u8, value: u64) []const u8 {+pub fn bytesLabel(buf: []u8, value: u64) []const u8 {const units = [_][]const u8{ "B", "KiB", "MiB", "GiB", "TiB" };var n: f64 = @floatFromInt(value);var unit: usize = 0;while (n >= 1024 and unit + 1 < units.len) : (unit += 1) n /= 1024;return std.fmt.bufPrint(buf, "{d:.1} {s}", .{ n, units[unit] }) catch "—";}-fn bytesPair(buf: []u8, used: u64, total: u64) []const u8 {+pub fn bytesPair(buf: []u8, used: u64, total: u64) []const u8 {var left: [32]u8 = undefined;var right: [32]u8 = undefined;return std.fmt.bufPrint(buf, "{s} / {s}", .{ bytesLabel(&left, used), bytesLabel(&right, total) }) catch "—";}--fn stateName(state: u8) []const u8 {- return switch (state) {- 'R' => tr("Running"),- 'S' => tr("Sleeping"),- 'D' => tr("Disk wait"),- 'T', 't' => tr("Stopped"),- 'Z' => tr("Zombie"),- 'I' => tr("Idle"),- 'X', 'x' => tr("Exited"),- else => tr("Unknown"),- };-}diff --git a/src/system_monitor/app_footer.zig b/src/system_monitor/app_footer.zignew file mode 100644index 0000000..577292b--- /dev/null+++ b/src/system_monitor/app_footer.zig@@ -0,0 +1,178 @@+//! Responsive system readouts; process actions remain persistent shared widgets.+const std = @import("std");+const i18n = @import("i18n");+const tr = i18n.tr;+const ui = @import("ui");+const cairo = ui.cairo;+const theme = ui.theme;+const c = @import("../files/c.zig").api;+const app = @import("app.zig");+const App = app.App;+const Rect = cairo.Rect;+const proc = @import("proc.zig");++fn wide(self: *const App) bool {+ return self.w >= 1200;+}+fn columns(self: *const App) usize {+ return if (self.w < 900) 3 else 6;+}+fn metricHeight(self: *const App) f32 {+ return if (wide(self)) 82 else if (columns(self) == 3) 62 else 70;+}+pub fn height(self: *const App) f32 {+ return metricHeight(self) * @as(f32, @floatFromInt(6 / columns(self))) + (if (wide(self)) @as(f32, 16) else 62);+}+fn frame(self: *const App) Rect {+ return .{ .x = 16, .y = self.sections[4].computed_y + 8, .w = @floatFromInt(self.w - 32), .h = height(self) - 16 };+}+pub fn layout(self: *App) void {+ const box = frame(self);+ const y = if (wide(self)) box.y + (box.h - 38) / 2 else box.y + box.h - 44;+ const width: f32 = if (wide(self)) 140 else 124;+ for (self.footer[1..], 0..) |*control, index| {+ const x = box.x + box.w - 12 - (width + 10) * @as(f32, @floatFromInt(2 - index)) + 10;+ ui.measure.measure(control, width, 38);+ ui.arrange.arrange(control, x, y, width, 38);+ }+}++pub fn paint(self: *App, cr: *c.cairo_t) void {+ const box = frame(self);+ if (cairo.Layer.begin(cr, box)) |value| {+ var layer = value;+ layer.renderer.fillRect(0.5, 0.5, box.w - 1, box.h - 1, .{+ .color = theme.global.app_bar,+ .radius = theme.global.radius_md,+ .border_width = 1,+ .border_color = theme.global.app_divider,+ });+ layer.finish();+ }+ const count = columns(self);+ const available = box.w - (if (wide(self)) @as(f32, 316) else 0);+ const cell_w = available / @as(f32, @floatFromInt(count));+ for (0..6) |index| {+ const cell: Rect = .{+ .x = box.x + @as(f32, @floatFromInt(index % count)) * cell_w,+ .y = box.y + @as(f32, @floatFromInt(index / count)) * metricHeight(self),+ .w = cell_w,+ .h = metricHeight(self),+ };+ if (index % count > 0) rule(cr, cell.x, cell.y + 14, 1, cell.h - 28);+ paintMetric(self, cr, index, cell);+ }+ if (wide(self)) {+ rule(cr, box.x + available, box.y + 14, 1, box.h - 28);+ } else {+ rule(cr, box.x + 12, box.y + box.h - 48, box.w - 24, 1);+ if (count == 3) rule(cr, box.x + 12, box.y + metricHeight(self), box.w - 24, 1);+ }+}++fn paintMetric(self: *App, cr: *c.cairo_t, index: usize, cell: Rect) void {+ const snap = self.model.snapshot;+ const system: proc.System = if (snap) |s| s.system else .{};+ const labels = [_][]const u8{ tr("CPU"), tr("RAM"), tr("SWAP"), tr("NET"), tr("UPTIME"), tr("TEMP") };+ const colors = [_][4]f32{+ theme.global.danger, theme.global.danger, theme.global.app_git_added,+ theme.global.terminal_cyan orelse .{ 0.2, 0.78, 0.9, 1 }, theme.global.window_fg, theme.global.terminal_yellow orelse .{ 0.96, 0.75, 0.35, 1 },+ };+ var content: Rect = .{ .x = cell.x + 14, .y = cell.y + (cell.h - 48) / 2, .w = cell.w - 28, .h = 20 };+ if ((cell.w >= 190 and index == 0) or (cell.w >= 140 and index == 4)) {+ if (cairo.Layer.begin(cr, .{ .x = content.x, .y = cell.y + (cell.h - 26) / 2, .w = 26, .h = 26 })) |value| {+ var layer = value;+ layer.renderer.drawIcon(0, 0, 26, 26, .{ .id = if (index == 0) .power_performance else .clock, .color = colors[index] });+ layer.finish();+ }+ content.x += 36;+ content.w -= 36;+ }+ var title_box = content;+ if (index == 1 or index == 2) title_box.w = @max(0, title_box.w - 54);+ app.textBox(cr, labels[index], title_box, cairo.statusSize(), true, if (index == 0) colors[index] else theme.global.window_fg);+ var buf: [128]u8 = undefined;+ content.y += 22;+ content.h = 26;+ switch (index) {+ 0 => {+ var count_buf: [48]u8 = undefined;+ const cpus = if (system.logical_cpus) |n| i18n.fmt(&count_buf, i18n.trn("{n} CPU", "{n} CPUs", n), .{ .n = n }) catch "—" else "—";+ const value = if (system.frequency_ghz) |ghz| std.fmt.bufPrint(&buf, "{s} {d:.1} GHz", .{ cpus, ghz }) catch "—" else cpus;+ app.textBox(cr, value, content, cairo.textSize(), false, theme.global.window_fg);+ },+ 1, 2 => {+ const mem = if (snap) |s| s.memory else null;+ const total: ?u64 = if (mem) |m| if (index == 1) m.total else m.swap_total else null;+ const used: ?u64 = if (mem) |m| if (index == 1) m.used() else if (m.swap_total != null and m.swap_free != null) m.swap_total.? -| m.swap_free.? else null else null;+ memory(cr, content, used, total, colors[index]);+ },+ 3 => {+ const rate = if (snap) |s| s.network_rate else null;+ content.y -= 4;+ content.h = 18;+ app.textBox(cr, rateLabel(&buf, "↑", if (rate) |r| r.sent else null), content, cairo.statusSize(), false, colors[index]);+ content.y += 17;+ app.textBox(cr, rateLabel(&buf, "↓", if (rate) |r| r.received else null), content, cairo.statusSize(), false, theme.global.window_fg);+ },+ 4 => {+ const value = if (system.uptime_seconds) |seconds| i18n.fmt(&buf, tr("{hours}h {minutes}m"), .{ .hours = seconds / 3600, .minutes = seconds / 60 % 60 }) catch "—" else "—";+ app.textBox(cr, value, content, cairo.textSize(), false, theme.global.window_fg);+ },+ 5 => {+ const value = if (system.temperature_c) |temp| std.fmt.bufPrint(&buf, "{d:.0}°C", .{temp}) catch "—" else "—";+ app.textBox(cr, value, content, cairo.textSize(), false, colors[index]);+ },+ else => unreachable,+ }+}++fn memory(cr: *c.cairo_t, content: Rect, used: ?u64, total: ?u64, color: [4]f32) void {+ if (used == null or total == null) return app.textBox(cr, "—", content, cairo.textSize(), false, theme.global.window_fg);+ const units = [_][]const u8{ "B", "KiB", "MiB", "GiB", "TiB" };+ var unit: usize = 0;+ var divisor: f64 = 1;+ while (@as(f64, @floatFromInt(total.?)) / divisor >= 1024 and unit + 1 < units.len) : (unit += 1) divisor *= 1024;+ var buf: [64]u8 = undefined;+ const value = std.fmt.bufPrint(&buf, "{d:.1}", .{@as(f64, @floatFromInt(used.?)) / divisor}) catch "—";+ app.textBox(cr, value, content, cairo.textSize(), false, color);+ var tail = content;+ const advance: f32 = @floatCast(cairo.measureText(cr, value, cairo.textSize(), false));+ tail.x += advance;+ tail.w = @max(0, tail.w - advance);+ const suffix = std.fmt.bufPrint(&buf, " / {d:.1} {s}", .{ @as(f64, @floatFromInt(total.?)) / divisor, units[unit] }) catch "—";+ app.textBox(cr, suffix, tail, cairo.textSize(), false, theme.global.window_fg);+ const percentage = if (total.? == 0) 0 else @as(f64, @floatFromInt(used.?)) * 100 / @as(f64, @floatFromInt(total.?));+ const percent = std.fmt.bufPrint(&buf, "{d:.1}%", .{percentage}) catch "—";+ const width: f32 = @floatCast(cairo.measureText(cr, percent, cairo.statusSize(), false));+ // Put the percentage beside the title so both values fit at normal widths.+ app.textBox(cr, percent, .{ .x = content.x + content.w - width, .y = content.y - 22, .w = width + 1, .h = 20 }, cairo.statusSize(), false, theme.global.window_fg);+}++fn rateLabel(buf: []u8, arrow: []const u8, rate: ?f64) []const u8 {+ const value = rate orelse return std.fmt.bufPrint(buf, "{s} —", .{arrow}) catch "—";+ var size_buf: [32]u8 = undefined;+ const bytes: u64 = @intFromFloat(@min(@as(f64, @floatFromInt(std.math.maxInt(u64) - 4096)), @max(0, value)));+ return std.fmt.bufPrint(buf, "{s} {s}/s", .{ arrow, app.bytesLabel(&size_buf, bytes) }) catch "—";+}++pub fn paintStatus(self: *App, cr: *c.cairo_t) void {+ const box = frame(self);+ var buf: [256]u8 = undefined;+ const status = if (self.notice.len > 0) self.notice else blk: {+ const snap = self.model.snapshot orelse break :blk tr("Collecting processes…");+ break :blk i18n.fmt(&buf, i18n.trn("{n} process{status}", "{n} processes{status}", self.model.rows.items.len), .{+ .n = self.model.rows.items.len,+ .status = if (self.paused) tr(" · Paused") else if (snap.failed) tr(" · Process data unavailable") else if (snap.truncated) tr(" · List limited") else if (snap.unavailable > 0) tr(" · Some processes unavailable") else "",+ }) catch tr("Processes");+ };+ const status_box: Rect = if (wide(self)) .{ .x = 16, .y = @floatFromInt(self.h - 26), .w = @floatFromInt(self.w - 32), .h = 24 } else .{ .x = box.x + 14, .y = box.y + box.h - 44, .w = @max(0, self.footer[1].computed_x - box.x - 28), .h = 38 };+ app.textBox(cr, status, status_box, cairo.statusSize(), false, theme.global.window_fg);+ if (!wide(self)) app.textBox(cr, tr("CPU: 100% = one core · Memory: resident · Ctrl+F search · Delete end · Shift+Delete force quit"), .{ .x = 16, .y = @floatFromInt(self.h - 26), .w = @floatFromInt(self.w - 32), .h = 24 }, cairo.statusSize(), false, theme.global.window_fg);+}++fn rule(cr: *c.cairo_t, x: f32, y: f32, w: f32, h: f32) void {+ cairo.setSource(cr, theme.global.app_divider);+ c.cairo_rectangle(cr, x, y, w, h);+ c.cairo_fill(cr);+}diff --git a/src/system_monitor/app_summary.zig b/src/system_monitor/app_summary.zignew file mode 100644index 0000000..3c352a8--- /dev/null+++ b/src/system_monitor/app_summary.zig@@ -0,0 +1,203 @@+//! CPU and RAM cards: current values beside a bounded, gap-aware history.+const std = @import("std");+const i18n = @import("i18n");+const tr = i18n.tr;+const ui = @import("ui");+const cairo = ui.cairo;+const theme = ui.theme;+const c = @import("../files/c.zig").api;+const app = @import("app.zig");+const App = app.App;+const Rect = cairo.Rect;+const Position = struct { x: f64, y: f64 };++pub fn paint(self: *App, cr: *c.cairo_t) void {+ const width = (@as(f32, @floatFromInt(self.w)) - 48) / 2;+ for (0..2) |index| paintCard(self, cr, index, .{+ .x = 16 + @as(f32, @floatFromInt(index)) * (width + 16),+ .y = 14,+ .w = width,+ .h = 122,+ });+}++fn paintCard(self: *App, cr: *c.cairo_t, index: usize, box: Rect) void {+ const compact = box.w < 420;+ const info_width = std.math.clamp(box.w * 0.38, 200, 260);+ const accent = theme.shellPalette().accent;+ const snap = self.model.snapshot;+ const mem = if (snap) |s| s.memory else null;+ const percent: ?f64 = if (index == 0)+ (if (snap) |s| s.cpu_percent else null)+ else if (mem) |m|+ (if (m.total > 0) @as(f64, @floatFromInt(m.used())) * 100 / @as(f64, @floatFromInt(m.total)) else null)+ else+ null;+ if (cairo.Layer.begin(cr, box)) |value| {+ var layer = value;+ layer.renderer.fillRect(0.5, 0.5, box.w - 1, box.h - 1, .{+ .color = theme.global.app_bar,+ .radius = theme.global.radius_md,+ .border_width = 1,+ .border_color = theme.global.app_divider,+ });+ const badge: f32 = if (compact) 28 else 36;+ var tint = accent;+ tint[3] *= 0.14;+ layer.renderer.fillRect(12, 12, badge, badge, .{ .color = tint, .radius = theme.global.radius });+ layer.renderer.drawIcon(17, 17, badge - 10, badge - 10, .{ .id = if (index == 0) .cpu else .ram, .color = accent });+ layer.finish();+ }+ const text_x = box.x + (if (compact) @as(f32, 48) else 62);+ const text_w = if (compact) box.w - 166 else info_width - 76;+ label(cr, if (index == 0) tr("CPU") else tr("RAM"), .{ .x = text_x, .y = box.y + 10, .w = text_w, .h = 24 }, cairo.headingSize() * 1.25, true);+ var buf: [128]u8 = undefined;+ const percent_text = if (percent) |p| std.fmt.bufPrint(&buf, "{d:.1}%", .{p}) catch "—" else "—";+ const number_box: Rect = if (compact)+ .{ .x = box.x + box.w - 118, .y = box.y + 8, .w = 106, .h = 36 }+ else+ .{ .x = text_x, .y = box.y + (if (index == 0) @as(f32, 36) else 58), .w = text_w, .h = 40 };+ label(cr, percent_text, number_box, cairo.headingSize() * (if (compact) @as(f32, 2.2) else 2.6), true);+ const details: Rect = if (compact)+ .{ .x = box.x + 12, .y = box.y + 43, .w = box.w - 24, .h = 22 }+ else+ .{ .x = text_x, .y = box.y + (if (index == 0) @as(f32, 84) else 34), .w = text_w, .h = 24 };+ if (index == 0) {+ var count_buf: [48]u8 = undefined;+ const system = if (snap) |s| s.system else @import("proc.zig").System{};+ const count = if (system.logical_cpus) |n| i18n.fmt(&count_buf, i18n.trn("{n} CPU", "{n} CPUs", n), .{ .n = n }) catch "—" else "—";+ const text = if (system.frequency_ghz) |ghz| std.fmt.bufPrint(&buf, "{d:.1} GHz · {s}", .{ ghz, count }) catch "—" else count;+ label(cr, text, details, cairo.textSize(), false);+ } else {+ const text = if (mem) |m| app.bytesPair(&buf, m.used(), m.total) else "—";+ label(cr, text, details, cairo.textSize(), false);+ const meter: Rect = if (compact)+ .{ .x = box.x + 12, .y = box.y + 66, .w = box.w - 24, .h = 4 }+ else+ .{ .x = text_x, .y = box.y + 101, .w = text_w, .h = 8 };+ paintMeter(cr, meter, percent);+ }+ const axis_w = axisWidth(cr, index, if (mem) |m| m.total else null);+ const graph: Rect = if (compact)+ .{ .x = box.x + 12, .y = box.y + 78, .w = box.w - 32 - axis_w, .h = 32 }+ else+ .{ .x = box.x + info_width, .y = box.y + 18, .w = box.w - info_width - axis_w - 20, .h = 84 };+ paintGrid(cr, graph, index, if (mem) |m| m.total else null, compact);+ paintHistory(self, cr, index, graph);+ if (!compact) label(cr, tr("60 seconds"), .{ .x = graph.x, .y = box.y + 104, .w = graph.w, .h = 16 }, cairo.statusSize(), false);+}++fn label(cr: *c.cairo_t, text: []const u8, box: Rect, size: f32, bold: bool) void {+ app.textBox(cr, text, box, size, bold, theme.global.window_fg);+}++fn paintMeter(cr: *c.cairo_t, box: Rect, percent: ?f64) void {+ if (cairo.Layer.begin(cr, box)) |value| {+ var layer = value;+ layer.renderer.fillRect(0, 0, box.w, box.h, .{ .color = theme.global.app_divider, .radius = box.h / 2 });+ if (percent) |p| {+ const width = box.w * @as(f32, @floatCast(std.math.clamp(p / 100, 0, 1)));+ if (width > 0) layer.renderer.fillRect(0, 0, width, box.h, .{ .color = theme.shellPalette().accent, .radius = @min(width, box.h) / 2 });+ }+ layer.finish();+ }+}++fn axisLabel(buf: []u8, index: usize, total: ?u64, quarter: usize) []const u8 {+ if (index == 0) return std.fmt.bufPrint(buf, "{d}%", .{quarter * 25}) catch "—";+ const bytes = total orelse return "—";+ if (quarter == 0) return "0 B";+ // Divide before multiplying so very large capacities cannot overflow.+ return app.bytesLabel(buf, bytes / 4 * quarter + bytes % 4 * quarter / 4);+}++fn axisWidth(cr: *c.cairo_t, index: usize, total: ?u64) f32 {+ var width: f32 = 0;+ var buf: [32]u8 = undefined;+ for (0..5) |quarter| width = @max(width, @as(f32, @floatCast(cairo.measureText(cr, axisLabel(&buf, index, total, quarter), cairo.statusSize(), false))));+ return width;+}++fn paintGrid(cr: *c.cairo_t, graph: Rect, index: usize, total: ?u64, compact: bool) void {+ c.cairo_save(cr);+ defer c.cairo_restore(cr);+ c.cairo_set_line_width(cr, 1);+ cairo.setSource(cr, theme.global.app_divider);+ for (0..5) |line| {+ const x = graph.x + graph.w * @as(f32, @floatFromInt(line)) / 4;+ c.cairo_move_to(cr, x, graph.y);+ c.cairo_line_to(cr, x, graph.y + graph.h);+ if (!compact or line % 2 == 0) {+ const y = graph.y + graph.h * @as(f32, @floatFromInt(line)) / 4;+ c.cairo_move_to(cr, graph.x, y);+ c.cairo_line_to(cr, graph.x + graph.w, y);+ }+ }+ c.cairo_stroke(cr);+ var buf: [32]u8 = undefined;+ for (0..5) |line| {+ if (compact and line % 2 != 0) continue;+ const y = graph.y + graph.h * @as(f32, @floatFromInt(line)) / 4;+ label(cr, axisLabel(&buf, index, total, 4 - line), .{ .x = graph.x + graph.w + 8, .y = y - 8, .w = 80, .h = 16 }, cairo.statusSize(), false);+ }+}++fn paintHistory(self: *const App, cr: *c.cairo_t, index: usize, graph: Rect) void {+ const snap = self.model.snapshot orelse return;+ var points: [60]Position = undefined;+ var count: usize = 0;+ var last: ?u64 = null;+ c.cairo_save(cr);+ defer c.cairo_restore(cr);+ c.cairo_rectangle(cr, graph.x, graph.y - 1, graph.w, graph.h + 2);+ c.cairo_clip(cr);+ for (self.history.points[0..self.history.count]) |point| {+ const value = if (index == 0) point.cpu else point.memory;+ const age = snap.at_ns -| point.at_ns;+ if (value == null or age >= 60_000_000_000 or (last != null and point.at_ns -| last.? > 2_000_000_000)) {+ paintSegment(cr, points[0..count], graph.y + graph.h);+ count = 0;+ last = null;+ }+ if (value == null or age >= 60_000_000_000) continue;+ points[count] = .{+ .x = graph.x + graph.w * (1 - @as(f64, @floatFromInt(age)) / 60_000_000_000),+ .y = graph.y + graph.h * (1 - std.math.clamp(value.?, 0, 100) / 100),+ };+ count += 1;+ last = point.at_ns;+ }+ paintSegment(cr, points[0..count], graph.y + graph.h);+}++fn paintSegment(cr: *c.cairo_t, points: []const Position, bottom: f64) void {+ if (points.len == 0) return;+ const accent = theme.shellPalette().accent;+ if (points.len == 1) {+ cairo.setSource(cr, accent);+ c.cairo_arc(cr, points[0].x, points[0].y, 1.5, 0, 2 * std.math.pi);+ c.cairo_fill(cr);+ return;+ }+ var top = bottom;+ c.cairo_move_to(cr, points[0].x, bottom);+ for (points) |point| {+ c.cairo_line_to(cr, point.x, point.y);+ top = @min(top, point.y);+ }+ c.cairo_line_to(cr, points[points.len - 1].x, bottom);+ c.cairo_close_path(cr);+ const gradient = c.cairo_pattern_create_linear(0, top, 0, @max(top + 1, bottom));+ defer c.cairo_pattern_destroy(gradient);+ c.cairo_pattern_add_color_stop_rgba(gradient, 0, accent[0], accent[1], accent[2], accent[3] * 0.28);+ c.cairo_pattern_add_color_stop_rgba(gradient, 1, accent[0], accent[1], accent[2], accent[3] * 0.025);+ c.cairo_set_source(cr, gradient);+ c.cairo_fill(cr);+ c.cairo_move_to(cr, points[0].x, points[0].y);+ for (points[1..]) |point| c.cairo_line_to(cr, point.x, point.y);+ cairo.setSource(cr, accent);+ c.cairo_set_line_width(cr, 2);+ c.cairo_set_line_cap(cr, c.CAIRO_LINE_CAP_ROUND);+ c.cairo_set_line_join(cr, c.CAIRO_LINE_JOIN_ROUND);+ c.cairo_stroke(cr);+}diff --git a/src/system_monitor/app_table.zig b/src/system_monitor/app_table.zignew file mode 100644index 0000000..31f1b74--- /dev/null+++ b/src/system_monitor/app_table.zig@@ -0,0 +1,194 @@+//! Process table presentation. Geometry is shared with the sortable widgets,+//! row picking and scrollbar; sampling and process identity stay in the model.+const std = @import("std");+const tr = @import("i18n").tr;+const ui = @import("ui");+const cairo = ui.cairo;+const theme = ui.theme;+const c = @import("../files/c.zig").api;+const app = @import("app.zig");+const App = app.App;+const Rect = cairo.Rect;+const row_h: f32 = @floatCast(app.row_h);+const scrollbar = ui.widgets.scrollbar;+const pad = 13;++pub fn paint(self: *App, cr: *c.cairo_t) void {+ const list = self.listBox();+ const top = self.sections[2].computed_y;+ const frame: Rect = .{ .x = list.x, .y = top, .w = list.w, .h = list.y + list.h - top };+ c.cairo_save(cr);+ defer c.cairo_restore(cr);+ roundPath(cr, frame, theme.global.radius_md);+ c.cairo_clip(cr);+ fill(cr, .{ .x = frame.x, .y = top, .w = frame.w, .h = list.y - top }, theme.global.app_bar);+ paintRows(self, cr);+ cairo.setSource(cr, theme.global.app_divider);+ c.cairo_set_line_width(cr, 1);+ c.cairo_move_to(cr, frame.x, list.y - 0.5);+ c.cairo_line_to(cr, frame.x + frame.w, list.y - 0.5);+ c.cairo_stroke(cr);+ roundPath(cr, .{ .x = frame.x + 0.5, .y = frame.y + 0.5, .w = frame.w - 1, .h = frame.h - 1 }, theme.global.radius_md);+ c.cairo_stroke(cr);+}++fn paintRows(self: *App, cr: *c.cairo_t) void {+ const list = self.listBox();+ const content_w = list.w - scrollbar.gutter(theme.global.scrollbar_width);+ const count = self.model.rows.items.len;+ const first: usize = @intFromFloat(@floor(self.model.scroll / row_h));+ const last = @min(count, first + @as(usize, @intFromFloat(@ceil(list.h / row_h))) + 1);+ c.cairo_save(cr);+ c.cairo_rectangle(cr, list.x, list.y, list.w, list.h);+ c.cairo_clip(cr);+ for (first..last) |i| {+ const y: f32 = @floatCast(list.y + @as(f64, @floatFromInt(i)) * row_h - self.model.scroll);+ if (i % 2 == 1) fill(cr, .{ .x = list.x, .y = y, .w = content_w, .h = row_h }, theme.global.app_item);+ var rule = theme.global.app_divider;+ rule[3] *= 0.4;+ fill(cr, .{ .x = list.x, .y = y + row_h - 1, .w = content_w, .h = 1 }, rule);+ }+ c.cairo_restore(cr);+ // Column rules continue through the header and body, beneath row feedback.+ var rule = theme.global.app_divider;+ rule[3] *= 0.65;+ for (self.headers[1..]) |header| fill(cr, .{+ .x = header.computed_x - 0.5,+ .y = self.sections[2].computed_y,+ .w = 1,+ .h = list.y + list.h - self.sections[2].computed_y,+ }, rule);+ c.cairo_save(cr);+ defer c.cairo_restore(cr);+ c.cairo_rectangle(cr, list.x, list.y, list.w, list.h);+ c.cairo_clip(cr);+ const snap = self.model.snapshot orelse {+ app.textBox(cr, tr("Collecting processes…"), .{ .x = list.x + pad, .y = list.y + 12, .w = content_w - 2 * pad, .h = row_h }, cairo.textSize(), false, theme.global.window_fg);+ return;+ };+ // One scale for every resident-memory bar, independent of filtering or+ // scrolling. CPU fills at one core; numeric values can exceed 100%.+ var memory_max: u64 = 1;+ for (snap.processes) |row| memory_max = @max(memory_max, row.resident_bytes orelse 0);+ const hover = self.row_hover.frame;+ if (hover.alpha > 0) cairo.drawItemHighlight(cr, self.rowBox(hover.row), false, hover.alpha, hover.alpha);+ for (first..last) |i| {+ const row = snap.processes[self.model.rows.items[i]];+ const y: f32 = @floatCast(list.y + @as(f64, @floatFromInt(i)) * row_h - self.model.scroll);+ for (self.selections.items) |selection| if (selection.identity.eql(row.identity)) {+ cairo.drawItemHighlight(cr, self.rowBox(@floatFromInt(i)), true, selection.fade.alpha, selection.fade.alpha);+ break;+ };+ var pid_buf: [32]u8 = undefined;+ var cpu_buf: [32]u8 = undefined;+ var mem_buf: [32]u8 = undefined;+ const pid = std.fmt.bufPrint(&pid_buf, "{d}", .{row.identity.pid}) catch "—";+ const cpu = if (row.cpu_percent) |v| std.fmt.bufPrint(&cpu_buf, "{d:.1}%", .{v}) catch "—" else "—";+ const memory = if (row.resident_bytes) |v| app.bytesLabel(&mem_buf, v) else "—";+ var name_box = cell(self, 0, y);+ const icon_box: Rect = .{ .x = name_box.x, .y = y + 6, .w = 20, .h = 20 };+ if (cairo.Layer.begin(cr, icon_box)) |value| {+ var layer = value;+ layer.renderer.drawIcon(0, 0, 20, 20, .{ .id = processIcon(row.name), .color = theme.global.app_icon });+ layer.finish();+ }+ name_box.x += 30;+ name_box.w = @max(0, name_box.w - 30);+ label(cr, row.name, name_box);+ label(cr, pid, cell(self, 1, y));+ label(cr, row.user, cell(self, 2, y));+ usage(cr, cpu, cell(self, 3, y), if (row.cpu_percent) |v| v / 100 else null, "999.9%");+ usage(cr, memory, cell(self, 4, y), if (row.resident_bytes) |v| @as(f64, @floatFromInt(v)) / @as(f64, @floatFromInt(memory_max)) else null, "999.9 MiB");+ var state_box = cell(self, 5, y);+ cairo.setSource(cr, stateColor(row.state));+ c.cairo_arc(cr, state_box.x + 4, y + row_h / 2, 3.5, 0, 2 * std.math.pi);+ c.cairo_fill(cr);+ state_box.x += 16;+ state_box.w = @max(0, state_box.w - 16);+ label(cr, stateName(row.state), state_box);+ }+ if (count == 0) label(cr, if (snap.failed) tr("Process data unavailable") else tr("No matching processes"), .{ .x = list.x + pad, .y = list.y + 12, .w = content_w - 2 * pad, .h = row_h });+ if (self.barGeometry()) |g| cairo.drawScrollbar(cr, scrollbar.look(g, self.bar, theme.global.scrollbar_width, theme.global));+}++fn cell(self: *const App, column: usize, y: f32) Rect {+ const header = self.headers[column];+ return .{ .x = header.computed_x + pad, .y = y, .w = @max(0, header.computed_width - 2 * pad), .h = row_h };+}++fn label(cr: *c.cairo_t, value: []const u8, box: Rect) void {+ app.textBox(cr, value, box, cairo.textSize(), false, theme.global.window_fg);+}++fn usage(cr: *c.cairo_t, value: []const u8, box: Rect, fraction: ?f64, sample: []const u8) void {+ const text_w: f32 = @floatCast(@max(cairo.measureText(cr, sample, cairo.textSize(), false), cairo.measureText(cr, value, cairo.textSize(), false)));+ const bar_w = box.w - text_w - 12;+ if (bar_w < 28) return label(cr, value, box);+ label(cr, value, .{ .x = box.x, .y = box.y, .w = text_w, .h = box.h });+ if (fraction == null) return;+ const track: Rect = .{ .x = box.x + text_w + 12, .y = box.y + (box.h - 6) / 2, .w = bar_w, .h = 6 };+ roundPath(cr, track, 3);+ cairo.setSource(cr, theme.global.app_divider);+ c.cairo_fill(cr);+ const amount: f32 = @floatCast(std.math.clamp(fraction.?, 0, 1));+ if (amount <= 0) return;+ var bar = track;+ bar.w = @min(track.w, @max(3, track.w * amount));+ roundPath(cr, bar, @min(3, bar.w / 2));+ cairo.setSource(cr, theme.shellPalette().accent);+ c.cairo_fill(cr);+}++fn processIcon(name: []const u8) ui.layout.IconId {+ const known = .{+ .{ "rediwm-monitor", .power_performance }, .{ "rediwm-session", .display },+ .{ "rediwm-files", .folder }, .{ "rediwm-editor", .edit },+ .{ "rediwm", .settings }, .{ "systemd", .settings },+ .{ "kitty", .terminal }, .{ "foot", .terminal },+ .{ "bash", .terminal }, .{ "zsh", .terminal },+ .{ "zig", .terminal }, .{ "codex", .terminal },+ .{ "firefox", .browser }, .{ "chromium", .browser },+ .{ "(sd-pam)", .lock }, .{ "dbus-broker", .drive },+ };+ inline for (known) |entry| if (std.mem.eql(u8, name, entry[0])) return entry[1];+ return .generic;+}++fn stateColor(state: u8) [4]f32 {+ return switch (state) {+ 'R' => theme.global.app_git_added,+ 'S', 'I' => theme.global.terminal_blue orelse .{ 0.38, 0.72, 0.96, 1 },+ 'D', 'T', 't' => theme.global.terminal_yellow orelse .{ 0.96, 0.75, 0.35, 1 },+ 'Z', 'X', 'x' => theme.global.danger,+ else => theme.global.app_icon,+ };+}++fn fill(cr: *c.cairo_t, box: Rect, color: [4]f32) void {+ cairo.setSource(cr, color);+ c.cairo_rectangle(cr, box.x, box.y, box.w, box.h);+ c.cairo_fill(cr);+}++fn roundPath(cr: *c.cairo_t, box: Rect, radius: f32) void {+ const r = @min(radius, @min(box.w, box.h) / 2);+ c.cairo_new_sub_path(cr);+ c.cairo_arc(cr, box.x + box.w - r, box.y + r, r, -std.math.pi / 2.0, 0);+ c.cairo_arc(cr, box.x + box.w - r, box.y + box.h - r, r, 0, std.math.pi / 2.0);+ c.cairo_arc(cr, box.x + r, box.y + box.h - r, r, std.math.pi / 2.0, std.math.pi);+ c.cairo_arc(cr, box.x + r, box.y + r, r, std.math.pi, 3 * std.math.pi / 2.0);+ c.cairo_close_path(cr);+}++fn stateName(state: u8) []const u8 {+ return switch (state) {+ 'R' => tr("Running"),+ 'S' => tr("Sleeping"),+ 'D' => tr("Disk wait"),+ 'T', 't' => tr("Stopped"),+ 'Z' => tr("Zombie"),+ 'I' => tr("Idle"),+ 'X', 'x' => tr("Exited"),+ else => tr("Unknown"),+ };+}diff --git a/src/system_monitor/client.zig b/src/system_monitor/client.zigindex 26af4ab..5361f9f 100644--- a/src/system_monitor/client.zig+++ b/src/system_monitor/client.zig@@ -339,7 +339,7 @@ pub const Client = struct {if (self.outputs.items.len > 0) {const output = self.outputs.items[0];if (output.logical_width > 0) width = std.math.clamp(output.logical_width - 160, 640, 1080);- if (output.logical_height > 0) height = std.math.clamp(output.logical_height - 200, 400, 640);+ if (output.logical_height > 0) height = std.math.clamp(output.logical_height - 200, 480, 640);}self.app.resize(width, height);}@@ -348,7 +348,7 @@ pub const Client = struct {suspended = true;};self.app.setSuspended(suspended);- self.xdg_toplevel.setMinSize(640, 400 + tbh);+ self.xdg_toplevel.setMinSize(640, 480 + tbh);self.app.dirty = true;},.close => {@@ -820,7 +820,7 @@ pub fn run(init: std.process.Init) !void {// Real min size is set from xdgToplevelEvent once the decoration mode// (and thus titlebar height) is known; this is just a safe pre-configure// default sized for the worst case (self-decorated).- self.xdg_toplevel.setMinSize(640, 400 + CSD_TITLEBAR_H);+ self.xdg_toplevel.setMinSize(640, 480 + CSD_TITLEBAR_H);// Prefer server-side decorations; the compositor may still tell us via// decorationEvent to self-decorate (e.g. it has no SSD implementation),diff --git a/src/system_monitor/collector.zig b/src/system_monitor/collector.zigindex d625cf0..9a05baa 100644--- a/src/system_monitor/collector.zig+++ b/src/system_monitor/collector.zig@@ -23,6 +23,8 @@ pub const Snapshot = struct {cpu: ?proc.Cpu,cpu_percent: ?f64 = null,memory: ?proc.Memory,+ system: proc.System = .{},+ network_rate: ?proc.NetworkRate = null,unavailable: usize = 0,truncated: bool = false,failed: bool = false,@@ -40,6 +42,7 @@ pub fn sample(cancelled: *const std.atomic.Value(u64), generation: u64) !*Snapshvar buf: [65536]u8 = undefined;snapshot.cpu = proc.cpuTotals(&buf);snapshot.memory = proc.memoryTotals(&buf);+ snapshot.system = proc.systemStats(&buf);var list = proc.List.open() orelse {snapshot.failed = true;return snapshot;@@ -165,6 +168,7 @@ pub const Worker = struct {defer previous.deinit(a);var last_at: u64 = 0;var last_cpu: ?proc.Cpu = null;+ var last_network: ?proc.Network = null;var observed: u64 = std.math.maxInt(u64);var deadline: u64 = 0;const hz = proc.ticksPerSecond();@@ -175,6 +179,7 @@ pub const Worker = struct {previous.clearRetainingCapacity();last_at = 0;last_cpu = null;+ last_network = null;deadline = 0;}if (self.active.load(.acquire) and proc.nowNs() >= deadline) {@@ -189,6 +194,9 @@ pub const Worker = struct {if (last_cpu) |before| if (snap.cpu) |after| {snap.cpu_percent = proc.cpuPercent(before, after);};+ if (last_network) |before| if (snap.system.network) |after| {+ snap.network_rate = proc.networkRate(before, after, snap.at_ns -| last_at);+ };for (snap.processes) |*row| {if (previous.get(row.identity.pid)) |before| {row.cpu_percent = proc.processPercent(.{ .name = "", .state = 0, .cpu = before.cpu, .start = before.start, .rss = 0 }, .{ .name = "", .state = 0, .cpu = row.cpu_ticks, .start = row.identity.start, .rss = 0 }, hz, snap.at_ns -| last_at);@@ -198,6 +206,7 @@ pub const Worker = struct {for (snap.processes) |row| previous.put(a, row.identity.pid, .{ .start = row.identity.start, .cpu = row.cpu_ticks }) catch {};last_at = snap.at_ns;last_cpu = snap.cpu;+ last_network = snap.system.network;deadline = snap.at_ns + 1_000_000_000;self.mutex.lockUncancelable(self.io);if (self.generation.load(.acquire) == generation and self.active.load(.acquire)) {diff --git a/src/system_monitor/proc.zig b/src/system_monitor/proc.zigindex 6b488d6..bac8025 100644--- a/src/system_monitor/proc.zig+++ b/src/system_monitor/proc.zig@@ -7,7 +7,7 @@//! * `Process`: `open(pid)`, `close`, `stat(buf)`, `uids(buf)`, `exePath(buf)`.//! One open `Process` describes one task, so its three reads agree.//! * `List`: `open()`, `next()` (a pid), `close()`.-//! * `cpuTotals(buf)`, `memoryTotals(buf)`, `ticksPerSecond()`.+//! * `cpuTotals(buf)`, `memoryTotals(buf)`, `systemStats(buf)`, `ticksPerSecond()`.//!//! No compositor, Wayland or UI dependencies.const builtin = @import("builtin");@@ -25,6 +25,10 @@ pub const Stat = common.Stat;pub const Uids = common.Uids;pub const Cpu = common.Cpu;pub const Memory = common.Memory;+pub const System = common.System;+pub const Network = common.Network;+pub const NetworkRate = common.NetworkRate;+pub const networkRate = common.networkRate;pub const owned = common.owned;pub const protectedName = common.protectedName;pub const cpuPercent = common.cpuPercent;@@ -37,6 +41,7 @@ pub const Process = backend.Process;pub const List = backend.List;pub const cpuTotals = backend.cpuTotals;pub const memoryTotals = backend.memoryTotals;+pub const systemStats = backend.systemStats;pub const ticksPerSecond = backend.ticksPerSecond;/// One process's stat, or null if it is gone or unreadable. `name` points into `buf`.diff --git a/src/system_monitor/proc_common.zig b/src/system_monitor/proc_common.zigindex 64bc023..8a60f74 100644--- a/src/system_monitor/proc_common.zig+++ b/src/system_monitor/proc_common.zig@@ -36,6 +36,27 @@ pub fn protectedName(name: []const u8) bool {}pub const Cpu = struct { total: u64, idle: u64 };+pub const System = struct {+ logical_cpus: ?u32 = null,+ frequency_ghz: ?f64 = null,+ uptime_seconds: ?u64 = null,+ temperature_c: ?f64 = null,+ network: ?Network = null,+};+pub const Network = struct { received: u64 = 0, sent: u64 = 0, interfaces: u64 = 0 };+pub const NetworkRate = struct { received: f64, sent: f64 };++/// Interface changes and reset counters need a fresh baseline, as does resume.+pub fn networkRate(before: Network, after: Network, elapsed_ns: u64) ?NetworkRate {+ if (elapsed_ns == 0 or before.interfaces != after.interfaces or+ after.received < before.received or after.sent < before.sent) return null;+ const seconds = @as(f64, @floatFromInt(elapsed_ns)) / 1_000_000_000;+ return .{+ .received = @as(f64, @floatFromInt(after.received - before.received)) / seconds,+ .sent = @as(f64, @floatFromInt(after.sent - before.sent)) / seconds,+ };+}+pub fn cpuPercent(before: Cpu, after: Cpu) ?f64 {if (after.total <= before.total or after.idle < before.idle) return null;const total = after.total - before.total;diff --git a/src/system_monitor/proc_freebsd.zig b/src/system_monitor/proc_freebsd.zigindex e3bdc8b..99e54c7 100644--- a/src/system_monitor/proc_freebsd.zig+++ b/src/system_monitor/proc_freebsd.zig@@ -180,3 +180,17 @@ pub fn memoryTotals(_: []u8) ?common.Memory {pub fn ticksPerSecond() u64 {return 1_000_000;}++pub fn systemStats(_: []u8) common.System {+ var result: common.System = .{};+ if (sysctlValue(c_uint, "hw.ncpu")) |count| if (count > 0) {+ result.logical_cpus = count;+ };+ if (sysctlValue(c_int, "dev.cpu.0.freq")) |mhz| if (mhz > 0) {+ result.frequency_ghz = @as(f64, @floatFromInt(mhz)) / 1000;+ };+ var uptime: c.struct_timespec = undefined;+ if (c.clock_gettime(c.CLOCK_UPTIME, &uptime) == 0 and uptime.tv_sec >= 0)+ result.uptime_seconds = @intCast(uptime.tv_sec);+ return result;+}diff --git a/src/system_monitor/proc_linux.zig b/src/system_monitor/proc_linux.zigindex 1664453..1eedaa5 100644--- a/src/system_monitor/proc_linux.zig+++ b/src/system_monitor/proc_linux.zig@@ -10,6 +10,7 @@ const Uids = common.Uids;const Cpu = common.Cpu;const Memory = common.Memory;const readAt = common.readAt;+pub const systemStats = @import("proc_linux_system.zig").sample;/// comm may contain spaces, newlines and closing parentheses. Field 3 starts/// after the LAST closing parenthesis; fields 4/14/15/22/24 are PPID/CPU/start/RSS.diff --git a/src/system_monitor/proc_linux_system.zig b/src/system_monitor/proc_linux_system.zignew file mode 100644index 0000000..b045e88--- /dev/null+++ b/src/system_monitor/proc_linux_system.zig@@ -0,0 +1,103 @@+//! Optional footer telemetry, sampled only by the monitor's active worker.+const std = @import("std");+const common = @import("proc_common.zig");+const c = common.c;++pub fn sample(buf: []u8) common.System {+ var result: common.System = .{};+ const cpus = c.sysconf(c._SC_NPROCESSORS_ONLN);+ if (cpus > 0) result.logical_cpus = @intCast(cpus);+ if (number("/sys/devices/system/cpu/cpu0/cpufreq/scaling_cur_freq", buf)) |khz| {+ if (khz > 0) result.frequency_ghz = khz / 1_000_000;+ }+ if (common.readAt(c.AT_FDCWD, "/proc/uptime", buf)) |bytes| {+ var fields = std.mem.tokenizeAny(u8, bytes, " \t\n");+ if (fields.next()) |value| {+ const seconds = std.fmt.parseFloat(f64, value) catch -1;+ if (std.math.isFinite(seconds) and seconds >= 0 and seconds < 1e15)+ result.uptime_seconds = @intFromFloat(seconds);+ }+ } else |_| {}+ if (common.readAt(c.AT_FDCWD, "/proc/net/dev", buf)) |bytes| {+ result.network = parseNetwork(bytes);+ } else |_| {}+ result.temperature_c = temperature(buf);+ return result;+}++pub fn parseNetwork(bytes: []const u8) ?common.Network {+ var lines = std.mem.splitScalar(u8, bytes, '\n');+ if (std.mem.indexOf(u8, lines.next() orelse return null, "Inter-") == null) return null;+ if (std.mem.indexOf(u8, lines.next() orelse return null, "bytes") == null) return null;+ var result: common.Network = .{};+ while (lines.next()) |line| {+ if (std.mem.trim(u8, line, " \t").len == 0) continue;+ const colon = std.mem.lastIndexOfScalar(u8, line, ':') orelse return null;+ const name = std.mem.trim(u8, line[0..colon], " \t");+ if (std.mem.eql(u8, name, "lo")) continue;+ if (name.len == 0) return null;+ var fields = std.mem.tokenizeAny(u8, line[colon + 1 ..], " \t");+ for (0..16) |index| {+ const value = std.fmt.parseInt(u64, fields.next() orelse return null, 10) catch return null;+ if (index == 0) result.received = std.math.add(u64, result.received, value) catch return null;+ if (index == 8) result.sent = std.math.add(u64, result.sent, value) catch return null;+ }+ // Independent of enumeration order, but changes on add/remove/rename.+ result.interfaces +%= std.hash.Wyhash.hash(0, name);+ }+ return result;+}++fn number(path: [*:0]const u8, buf: []u8) ?f64 {+ const bytes = common.readAt(c.AT_FDCWD, path, buf) catch return null;+ const value = std.fmt.parseFloat(f64, std.mem.trim(u8, bytes, " \t\n")) catch return null;+ return if (std.math.isFinite(value)) value else null;+}++/// Only CPU sensors: do not silently substitute a disk, GPU or ACPI sensor.+fn temperature(buf: []u8) ?f64 {+ var hottest: ?f64 = null;+ const dir = c.opendir("/sys/class/hwmon") orelse return thermalTemperature(buf);+ defer _ = c.closedir(dir);+ while (c.readdir(dir)) |entry| {+ const name = std.mem.sliceTo(entry.*.d_name[0..], 0);+ if (!std.mem.startsWith(u8, name, "hwmon")) continue;+ var path_buf: [512]u8 = undefined;+ const driver_path = std.fmt.bufPrintSentinel(&path_buf, "/sys/class/hwmon/{s}/name", .{name}, 0) catch continue;+ const driver = std.mem.trim(u8, common.readAt(c.AT_FDCWD, driver_path, buf) catch continue, " \n");+ if (!std.mem.eql(u8, driver, "coretemp") and !std.mem.eql(u8, driver, "k10temp") and !std.mem.eql(u8, driver, "zenpower")) continue;+ const path = std.fmt.bufPrintSentinel(&path_buf, "/sys/class/hwmon/{s}", .{name}, 0) catch continue;+ const sensors = c.opendir(path) orelse continue;+ defer _ = c.closedir(sensors);+ while (c.readdir(sensors)) |sensor| {+ const file = std.mem.sliceTo(sensor.*.d_name[0..], 0);+ if (!std.mem.startsWith(u8, file, "temp") or !std.mem.endsWith(u8, file, "_input")) continue;+ const input = std.fmt.bufPrintSentinel(&path_buf, "/sys/class/hwmon/{s}/{s}", .{ name, file }, 0) catch continue;+ keepTemperature(&hottest, number(input, buf));+ }+ }+ return hottest orelse thermalTemperature(buf);+}++fn thermalTemperature(buf: []u8) ?f64 {+ var hottest: ?f64 = null;+ const dir = c.opendir("/sys/class/thermal") orelse return null;+ defer _ = c.closedir(dir);+ while (c.readdir(dir)) |entry| {+ const name = std.mem.sliceTo(entry.*.d_name[0..], 0);+ if (!std.mem.startsWith(u8, name, "thermal_zone")) continue;+ var path_buf: [512]u8 = undefined;+ const type_path = std.fmt.bufPrintSentinel(&path_buf, "/sys/class/thermal/{s}/type", .{name}, 0) catch continue;+ const kind = std.mem.trim(u8, common.readAt(c.AT_FDCWD, type_path, buf) catch continue, " \n");+ if (!std.mem.eql(u8, kind, "x86_pkg_temp") and !std.mem.eql(u8, kind, "cpu-thermal") and !std.mem.startsWith(u8, kind, "cpu_thermal")) continue;+ const input = std.fmt.bufPrintSentinel(&path_buf, "/sys/class/thermal/{s}/temp", .{name}, 0) catch continue;+ keepTemperature(&hottest, number(input, buf));+ }+ return hottest;+}++fn keepTemperature(hottest: *?f64, millidegrees: ?f64) void {+ const value = (millidegrees orelse return) / 1000;+ if (value < -50 or value > 200) return;+ hottest.* = @max(hottest.* orelse value, value);+}diff --git a/src/system_monitor/proc_system_tests.zig b/src/system_monitor/proc_system_tests.zignew file mode 100644index 0000000..154a765--- /dev/null+++ b/src/system_monitor/proc_system_tests.zig@@ -0,0 +1,27 @@+const std = @import("std");+const proc = @import("proc.zig");+const linux = @import("proc_linux_system.zig");+const header = "Inter-| Receive | Transmit\n face |bytes packets errs drop fifo frame compressed multicast|bytes packets errs drop fifo colls carrier compressed\n";+const ethernet = "eth0: 1000 1 0 0 0 0 0 0 2000 2 0 0 0 0 0 0\n";+const wifi = "wlan0: 500 1 0 0 0 0 0 0 300 2 0 0 0 0 0 0\n";++test "network totals exclude loopback and compare interface sets independent of order" {+ const before = linux.parseNetwork(header ++ ethernet ++ wifi ++ "lo: 9999 0 0 0 0 0 0 0 9999 0 0 0 0 0 0 0\n").?;+ const reordered = linux.parseNetwork(header ++ wifi ++ ethernet).?;+ try std.testing.expectEqual(@as(u64, 1500), before.received);+ try std.testing.expectEqual(@as(u64, 2300), before.sent);+ try std.testing.expectEqual(before, reordered);+ const unchanged = proc.networkRate(before, reordered, 1_000_000_000).?;+ try std.testing.expectEqual(@as(f64, 0), unchanged.received);+ var after = before;+ after.received += 3000;+ after.sent += 1000;+ const rate = proc.networkRate(before, after, 2_000_000_000).?;+ try std.testing.expectEqual(@as(f64, 1500), rate.received);+ try std.testing.expectEqual(@as(f64, 500), rate.sent);+ try std.testing.expect(proc.networkRate(after, before, 1_000_000_000) == null);+ try std.testing.expect(proc.networkRate(before, after, 0) == null);+ try std.testing.expect(proc.networkRate(linux.parseNetwork(header ++ ethernet).?, after, 1_000_000_000) == null);+ try std.testing.expect(linux.parseNetwork(header ++ "eth0: 1 2 3\n") == null);+ try std.testing.expect(linux.parseNetwork("unavailable") == null);+}diff --git a/src/system_monitor_tests.zig b/src/system_monitor_tests.zigindex c3750bc..d8529ba 100644--- a/src/system_monitor_tests.zig+++ b/src/system_monitor_tests.zig@@ -6,6 +6,10 @@ const model = @import("system_monitor/model.zig");const collector = @import("system_monitor/collector.zig");const actions = @import("system_monitor/actions.zig");+test {+ _ = @import("system_monitor/proc_system_tests.zig");+}+test "monitor backend lists and describes this process and the machine" {const pid = proc.c.getpid();var list = proc.List.open().?;@@ -171,6 +175,7 @@ test "monitor worker pause cancels publication and resume starts a fresh CPU inttry std.testing.expect(proc.c.poll(&fd, 1, 3000) > 0);const first = worker.take().?;try std.testing.expect(first.cpu_percent == null);+ try std.testing.expect(first.network_rate == null);first.deinit();worker.setActive(false);if (worker.take()) |unexpected| {@@ -183,6 +188,7 @@ test "monitor worker pause cancels publication and resume starts a fresh CPU intconst resumed = worker.take().?;defer resumed.deinit();try std.testing.expect(resumed.cpu_percent == null);+ try std.testing.expect(resumed.network_rate == null);for (resumed.processes) |row| try std.testing.expect(row.cpu_percent == null);// Exercise cancellation while enumeration may already be in progress.worker.setActive(false);diff --git a/src/ui/layout.zig b/src/ui/layout.zigindex 335f2ed..47674e3 100644--- a/src/ui/layout.zig+++ b/src/ui/layout.zig@@ -149,6 +149,8 @@ pub const IconId = enum {divide,touchpad,trackball,+ cpu,+ ram,};pub const ButtonState = enum { idle, hover, press, disabled };@@ -245,6 +247,8 @@ pub const ButtonData = struct {leading_icon: ?IconId = null,trailing_icon: ?IconId = null,stacked: bool = false,+ alignment: @import("widgets/button.zig").Alignment = .center,+ destructive: bool = false,on_click: ?*const fn (owner: ?*anyopaque, id: usize) void = null,owner: ?*anyopaque = null,id: usize = 0,diff --git a/src/ui/paint_icons.zig b/src/ui/paint_icons.zigindex 29921aa..9415bbc 100644--- a/src/ui/paint_icons.zig+++ b/src/ui/paint_icons.zig@@ -176,7 +176,7 @@ pub fn iconDistance(id: IconId, px: f32, py: f32, cx: f32, cy: f32, half: f32, tconst bar = sdSegment(px, py, cx, cy - half * 0.95, cx, cy - half * 0.05, t);break :blk @min(@max(ring, -gap), bar);},- .clock, .divide => 1000, // Embedded SVG; no procedural fallback.+ .clock, .divide, .cpu, .ram => 1000, // Embedded SVG; no procedural fallback..power_saver, .power_balanced, .power_performance => blk: {// Upper three quarters of a ring, open at the bottom, with a// needle from the hub.diff --git a/src/ui/shell_icons.zig b/src/ui/shell_icons.zigindex 0c146e7..e1acfd1 100644--- a/src/ui/shell_icons.zig+++ b/src/ui/shell_icons.zig@@ -74,6 +74,8 @@ pub fn configure(io: std.Io, root: []const u8) void {.{ IconId.volume_low, "speaker" },.{ IconId.volume_muted, "speaker-xmark" },.{ IconId.clock, "clock" },+ .{ IconId.cpu, "cpu" },+ .{ IconId.ram, "ram" },.{ IconId.lock, "lock" },.{ IconId.logout, "logout" },.{ IconId.reboot, "restart" },@@ -168,6 +170,8 @@ fn builtinSource(id: IconId) ?[]const u8 {.volume, .volume_low => @embedFile("shell-icon-speaker"),.volume_muted => @embedFile("shell-icon-speaker-xmark"),.clock => @embedFile("shell-icon-clock"),+ .cpu => @embedFile("shell-icon-cpu"),+ .ram => @embedFile("shell-icon-ram"),.lock => @embedFile("shell-icon-lock"),.logout => @embedFile("shell-icon-logout"),.reboot => @embedFile("shell-icon-restart"),@@ -258,7 +262,7 @@ fn rasterize(svg: []const u8, size: i32) ?Mask {test "bundled shell SVGs render nonempty transparent masks at fractional scales" {defer deinit();- for ([_]IconId{ .print, .usb_stick, .drive, .eject, .home, .settings, .mouse, .touchpad, .trackball, .display, .music, .headphones, .wifi, .bluetooth, .battery, .notification, .volume, .volume_muted, .power, .clock, .lock, .logout, .reboot, .divide }) |id| {+ for ([_]IconId{ .print, .usb_stick, .drive, .eject, .home, .settings, .mouse, .touchpad, .trackball, .display, .music, .headphones, .wifi, .bluetooth, .battery, .notification, .volume, .volume_muted, .power, .clock, .cpu, .ram, .lock, .logout, .reboot, .divide }) |id| {for ([_]i32{ 24, 36, 48 }) |size| {const mask = get(id, size) orelse return error.InvalidShellIcon;var visible = false;diff --git a/src/ui/widgets/button.zig b/src/ui/widgets/button.zigindex 078752e..35c954d 100644--- a/src/ui/widgets/button.zig+++ b/src/ui/widgets/button.zig@@ -86,6 +86,7 @@ test "proximity sampling respects clipping and returns button-local coordinates"pub const Variant = enum { primary, secondary, ghost, chrome };pub const Size = enum { sm, md, lg };+pub const Alignment = enum { center, left };pub const Options = struct {variant: Variant = .secondary,@@ -103,7 +104,9 @@ pub const Options = struct {/// `leading_icon` above the label rather than beside it: a tile, like the/// lock's Power and Restart.stacked: bool = false,- alignment: enum { center, left } = .center,+ alignment: Alignment = .center,+ /// A danger-colored outline and label for a destructive secondary action.+ destructive: bool = false,/// Override for chrome's tab navigation buttons, which use the ghost look.radius: ?f32 = null,};@@ -173,6 +176,8 @@ pub fn optionsOf(data: layout.ButtonData) Options {.leading_icon = data.leading_icon,.trailing_icon = data.trailing_icon,.stacked = data.stacked,+ .alignment = data.alignment,+ .destructive = data.destructive,};}@@ -199,6 +204,7 @@ pub fn paintBackground(r: *Renderer, box: Rect, opts: Options, state: State) voi.chrome => if (hovered) t.window_close_hover else clear,};if (opts.variant == .chrome) bg[3] *= t.window_close_hover_alpha;+ if (opts.destructive and opts.variant == .secondary) bg = .{ t.danger[0], t.danger[1], t.danger[2], t.danger[3] * @as(f32, if (hovered) 0.16 else 0.06) };if (opts.variant == .primary and hovered) for (0..3) |i| {bg[i] = @min(1, bg[i] * t.button_hover_brightness);};@@ -214,7 +220,7 @@ pub fn paintBackground(r: *Renderer, box: Rect, opts: Options, state: State) voi.color = bg,.radius = radius,.border_width = border_w,- .border_color = if (ring) t.controlFocusColor() else if (hovered) t.border else t.border_soft,+ .border_color = if (ring) t.controlFocusColor() else if (opts.destructive and !disabled) t.danger else if (hovered) t.border else t.border_soft,});if (adaptive_hover) {paintAdaptiveRelief(r, box, radius, t.button_relief, state.hover_elevation, t);@@ -542,7 +548,7 @@ pub fn paintContent(r: *Renderer, box: Rect, opts: Options, state: State) void {const t = r.palette orelse theme.global;const m = metrics(opts.size, t);const disabled = state.pointer == .disabled;- const fg = if (disabled) t.faint else if (opts.variant == .primary) t.on_accent else t.fg;+ const fg = if (disabled) t.faint else if (opts.variant == .primary) t.on_accent else if (opts.destructive) t.danger else t.fg;if (opts.icon) |id| {if (opts.variant == .chrome and id == .close) {paintClose(r, box, opts, state);diff --git a/tests/system_monitor.py b/tests/system_monitor.pyindex 437ec19..a4c556f 100644--- a/tests/system_monitor.py+++ b/tests/system_monitor.py@@ -125,9 +125,14 @@ def run(scale, workspace):b = box()output = ipc.get_outputs()[0]factor = image.width / output["logical_width"]- region = ((b["x"] + 16, b["y"] + 68, b["x"] + b["width"] - 16, b["y"] + 134)+ region = ((b["x"] + 16, b["y"] + 14, b["x"] + b["width"] - 16, b["y"] + 136)if graph else (b["x"], b["y"], b["x"] + b["width"], b["y"] + b["height"]))- return image.convert("RGB").crop(tuple(round(v * factor) for v in region))+ result = image.convert("RGB").crop(tuple(round(v * factor) for v in region))+ if artifacts := os.environ.get("REDIWM_TEST_ARTIFACT_DIR"):+ destination = Path(artifacts)+ destination.mkdir(parents=True, exist_ok=True)+ result.save(destination / f"monitor-{scale}-{'workspaces' if workspace else 'canvas'}-{name}.png")+ return resultdef idle(label):time.sleep(.4) # finish pending buffer release and hover transitions@@ -177,6 +182,7 @@ def run(scale, workspace):return image.getpixel((round(20 * factor), round(y * factor)))assert row_pixel("row-idle", 252) == (32, 48, 64)+ assert row_pixel("row-stripe", 284) == (34, 40, 46)move(40, 252)time.sleep(.6)assert row_pixel("row-hover", 252) == (74, 96, 118)@@ -224,10 +230,21 @@ def run(scale, workspace):assert monitor()["id"] == window_id and len(windows()) == 1# Resize through maximize and return; the controls remain usable.+ original = box()ipc.maximize(window_id)+ wait_for(lambda: box()["width"] > original["width"], "monitor did not maximize")settled()assert box()["width"] > 640- ipc.maximize(window_id)+ shot("footer-wide")+ ipc.restore(window_id)+ wait_for(lambda: box()["width"] == original["width"], "monitor did not restore its width")+ settled()+ ipc.action("set_window_size", {"id": window_id, "width": 640, "height": 480})+ wait_for(lambda: box()["width"] == 640, "monitor did not resize to its minimum width")+ settled()+ shot("footer-narrow")+ ipc.action("set_window_size", {"id": window_id, "width": original["width"], "height": original["height"]})+ wait_for(lambda: box()["width"] == original["width"], "monitor did not restore after narrow layout")settled()def fixture(ignore_term, replace_with=None):@@ -258,7 +275,8 @@ def run(scale, workspace):return childnormal = fixture(False)- chord(111) # Delete sends TERM only to the selected fixture+ shot("footer-selected")+ click(box()["width"] - 224, box()["height"] - 61)wait_for(lambda: normal.poll() is not None, "End process did not terminate fixture")assert normal.returncode == -signal.SIGTERM@@ -266,7 +284,7 @@ def run(scale, workspace):chord(111)time.sleep(.25)assert stubborn.poll() is None, "fixture did not ignore SIGTERM"- chord(42, 111) # Shift+Delete opens the named confirmation+ click(box()["width"] - 90, box()["height"] - 61)time.sleep(.2)confirmation = shot("force-confirm")assert stubborn.poll() is None, "force quit ran before confirmation"