From d696ce1d79fd766d303999a8611d970b1fa1a4e1 Mon Sep 17 00:00:00 2001 From: Manh Pham Date: Thu, 8 Oct 2026 13:58:43 +0700 Subject: [PATCH 1/5] Bump version from 0.2.0 to 1.0.0 --- VERSION | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/VERSION b/VERSION index 0ea3a94..3eefcb9 100644 --- a/VERSION +++ b/VERSION @@ -1 +1 @@ -0.2.0 +1.0.0 From 33121a8e67bac21f55d8b9a71f494cf08892a7eb Mon Sep 17 00:00:00 2001 From: Manh Pham Date: Thu, 8 Oct 2026 14:18:39 +0700 Subject: [PATCH 2/5] Fix text layout, the root copy's appearance and slow Services - Measure tabular figures as they are drawn: chart legends ("Write 163 K...") and axis labels ("977 K...") no longer cut; the axis is as wide as its longest label. - Put a figure, its unit and "of 30.4 GB" on one real baseline (new Canvas::baseline, Cairo and DirectWrite) instead of estimated offsets. - Shrink a stat value that doesn't fit down to 70% before cutting it, as macOS's StatGrid does; wrap the Overview hero's summary to two lines. - Hide an empty OS build ("()" and "Build" on Linux). - The pkexec root copy is told the desktop's dark preference: it reads root's dconf database and turned a System appearance light. - List services on a worker thread (about a second of systemctl on Linux) without holding the monitor lock; the Services screen opens at once. --- apps/linux/src/canvas_cairo.cpp | 11 +++++++- apps/linux/src/canvas_cairo.hpp | 3 +- apps/linux/src/platform_linux.cpp | 3 ++ apps/linux/src/window.cpp | 4 +++ apps/ui/src/page_history.cpp | 4 +-- apps/ui/src/page_overview.cpp | 14 ++++++--- apps/ui/src/page_performance.cpp | 35 +++++++++-------------- apps/ui/src/page_services.cpp | 20 ++++++++++--- apps/ui/src/page_system.cpp | 8 ++++-- apps/ui/src/pages.hpp | 4 ++- apps/ui/src/pages_common.cpp | 47 +++++++++++++++++-------------- apps/ui/src/render.cpp | 20 +++++++++++-- apps/ui/src/store.cpp | 34 ++++++++++++++++++---- apps/ui/src/store.hpp | 14 ++++++++- apps/ui/src/ui.hpp | 15 ++++++++-- apps/windows/src/canvas_d2d.cpp | 13 ++++++++- apps/windows/src/canvas_d2d.hpp | 3 +- 17 files changed, 182 insertions(+), 70 deletions(-) diff --git a/apps/linux/src/canvas_cairo.cpp b/apps/linux/src/canvas_cairo.cpp index 88a310e..687aed7 100644 --- a/apps/linux/src/canvas_cairo.cpp +++ b/apps/linux/src/canvas_cairo.cpp @@ -593,16 +593,25 @@ float CairoCanvas::draw_text(std::wstring_view value, const Rect &r, const TextS return l->width; } -float CairoCanvas::measure_text(std::wstring_view value, Font f, float tracking) { +float CairoCanvas::measure_text(std::wstring_view value, Font f, float tracking, bool tabular) { if (value.empty()) return 0; TextStyle style; style.font = f; style.trim = false; style.tracking = tracking; + style.tabular = tabular; const CachedLayout *l = layout(value, style, 10000, 10000); return l ? l->width : 0; } +float CairoCanvas::baseline(Font f) { + TextStyle style; + style.font = f; + style.trim = false; + const CachedLayout *l = layout(L"Ag", style, 1000, 1000); + return l ? static_cast(pango_layout_get_baseline(l->layout)) / PANGO_SCALE : font_spec(f).size; +} + float CairoCanvas::line_height(Font f) { TextStyle style; style.font = f; diff --git a/apps/linux/src/canvas_cairo.hpp b/apps/linux/src/canvas_cairo.hpp index fdab739..53bfc99 100644 --- a/apps/linux/src/canvas_cairo.hpp +++ b/apps/linux/src/canvas_cairo.hpp @@ -50,8 +50,9 @@ class CairoCanvas : public Canvas { void push_scale(float scale, Point about) override; void pop_transform() override; float draw_text(std::wstring_view text, const Rect &r, const TextStyle &style, Color color) override; - float measure_text(std::wstring_view text, Font font, float tracking) override; + float measure_text(std::wstring_view text, Font font, float tracking, bool tabular = false) override; float line_height(Font font) override; + float baseline(Font font) override; private: struct ShadowKey { diff --git a/apps/linux/src/platform_linux.cpp b/apps/linux/src/platform_linux.cpp index 0c738b1..6292896 100644 --- a/apps/linux/src/platform_linux.cpp +++ b/apps/linux/src/platform_linux.cpp @@ -258,6 +258,9 @@ void watch_color_scheme(std::function changed) { } bool system_prefers_dark() { + // The root copy (pkexec) is told what the desktop prefers: it can't read the user's dconf database. + if (pkexec_caller()) + if (const char *dark = std::getenv("PROCYON_DESKTOP_DARK"); dark && *dark) return dark[0] == '1'; if (GSettings *interface = interface_settings()) { gchar *scheme = g_settings_get_string(interface, "color-scheme"); const bool dark = scheme && g_strcmp0(scheme, "prefer-dark") == 0; diff --git a/apps/linux/src/window.cpp b/apps/linux/src/window.cpp index 33b61b5..4b384e1 100644 --- a/apps/linux/src/window.cpp +++ b/apps/linux/src/window.cpp @@ -383,6 +383,10 @@ class MainWindow : public Host { for (const char *name : {"DISPLAY", "WAYLAND_DISPLAY", "XAUTHORITY", "XDG_RUNTIME_DIR", "XDG_CURRENT_DESKTOP", "XDG_CONFIG_HOME", "XDG_DATA_HOME"}) if (const char *value = g_getenv(name)) args.push_back(std::string(name) + "=" + value); + // The desktop's light or dark preference as this copy reads it. The root copy can't: dconf finds + // the user's database through HOME, which pkexec sets to root's, so it would read no dark + // preference and turn a "System" appearance light. + args.push_back(std::string("PROCYON_DESKTOP_DARK=") + (platform::system_prefers_dark() ? "1" : "0")); args.emplace_back(exe); args.emplace_back("--page"); args.emplace_back(current_ ? page_name(current_->id()) : "overview"); diff --git a/apps/ui/src/page_history.cpp b/apps/ui/src/page_history.cpp index 64826d2..0699345 100644 --- a/apps/ui/src/page_history.cpp +++ b/apps/ui/src/page_history.cpp @@ -406,7 +406,7 @@ class HistoryPage : public Page { TextStyle v; v.font = Font::Headline; v.tabular = true; - const float vw = r.measure(value, Font::Headline); + const float vw = r.measure_tabular(value, Font::Headline); r.text(value, Rect{x, legend.y, vw + 2, legend.h}, v, theme.text()); x += vw + tokens::space::lg; }; @@ -565,7 +565,7 @@ class HistoryPage : public Page { headline.tabular = true; headline.halign = HAlign::Right; const std::wstring v = app_format(metric_, app_value(metric_, app)); - const float vw = r.measure(v, Font::Headline) + 6; + const float vw = r.measure_tabular(v, Font::Headline) + 2; r.text(v, Rect{head.right() - vw - 2, head.y, vw + 2, head.h}, headline, theme.text()); headline.halign = HAlign::Left; r.text(app.name.empty() ? fmt::from_utf8(app.app_id) : app.name, diff --git a/apps/ui/src/page_overview.cpp b/apps/ui/src/page_overview.cpp index a1cbd01..0aeb4c3 100644 --- a/apps/ui/src/page_overview.cpp +++ b/apps/ui/src/page_overview.cpp @@ -236,12 +236,18 @@ class OverviewPage : public Page { TextStyle body; body.font = Font::Body; body.valign = VAlign::Top; - r.text(fmt::from_utf8(info.cpu_brand) + L" · " + fmt::bytes(static_cast(info.memory_total)) + L" · " + - fmt::from_utf8(info.os_name) + L" " + fmt::from_utf8(info.os_version), - Rect{text.x, text.y + 40 + tokens::space::xs, text.w, 18}, body, theme.text_secondary()); + // The chip, memory and OS on one line, or two where they don't fit (as the macOS hero wraps), + // the badges below whichever it took. + const std::wstring summary = fmt::from_utf8(info.cpu_brand) + L" · " + + fmt::bytes(static_cast(info.memory_total)) + L" · " + + fmt::from_utf8(info.os_name) + L" " + fmt::from_utf8(info.os_version); + const bool two_lines = r.measure(summary, Font::Body) > text.w; + body.wrap = two_lines; + const float summary_h = two_lines ? 36 : 18; + r.text(summary, Rect{text.x, text.y + 40 + tokens::space::xs, text.w, summary_h}, body, theme.text_secondary()); const double uptime = s.timestamp > 0 && info.boot_time > 0 ? s.timestamp - info.boot_time : 0; float bx = text.x; - const float by = text.y + 40 + tokens::space::xs + 18 + tokens::space::xs + 4; + const float by = text.y + 40 + tokens::space::xs + summary_h + tokens::space::xs + 4; bx += r.badge(bx, by, L"Up " + fmt::duration(uptime), Renderer::Tone::Accent) + tokens::space::xs + 2; bx += r.badge(bx, by, fmt::count(s.process_count) + L" processes", Renderer::Tone::Neutral) + tokens::space::xs + 2; diff --git a/apps/ui/src/page_performance.cpp b/apps/ui/src/page_performance.cpp index ba5e558..a95f6a1 100644 --- a/apps/ui/src/page_performance.cpp +++ b/apps/ui/src/page_performance.cpp @@ -30,7 +30,7 @@ void rate_headline(Renderer &r, const Rect &trailing, double primary, double sec float right = trailing.right(); const auto entry = [&](const wchar_t *label, double value, Color color) { const auto parts = fmt::split_unit(fmt::rate(value)); - const float vw = r.measure(parts.first, Font::Metric) + r.measure(parts.second, Font::Headline) + 3; + const float vw = r.measure_tabular(parts.first, Font::Metric) + r.measure(parts.second, Font::Headline) + 3; const float lw = r.measure(label, Font::Label) + 11; const float w = std::max(vw, lw); value_text(r, Rect{right - w, trailing.y + 16, w, 32}, parts.first, parts.second, Font::Metric, theme.text(), @@ -316,14 +316,10 @@ class PerformancePage : public Page { const auto used = fmt::split_unit(fmt::bytes(static_cast(s.memory_used))); const std::wstring of = L"of " + fmt::bytes(static_cast(s.memory_total)); const float ofw = r.measure(of, Font::Body) + tokens::space::xs; + float base = 0; value_text(r, Rect{trailing.x, trailing.y + 6, trailing.w - ofw, 40}, used.first, used.second, Font::Display, - theme.text(), HAlign::Right); - TextStyle body; - body.font = Font::Body; - body.halign = HAlign::Right; - body.valign = VAlign::Bottom; - r.text(of, Rect{trailing.right() - ofw + tokens::space::xs, trailing.y + 6, ofw, 34}, body, - theme.text_tertiary()); + theme.text(), HAlign::Right, &base); + r.text_on_baseline(of, trailing.right(), base, Font::Body, theme.text_tertiary(), HAlign::Right); Rect inner = panel(r, stack.next(kPanelChrome + 220), L"Memory used", Renderer::Symbol::Waveform, MetricKind::Memory); @@ -398,12 +394,11 @@ class PerformancePage : public Page { const Rect swap_card = wide ? Rect{row.right() - swap_w, row.y, swap_w, row_h} : stack.next(kPanelChrome + 120); inner = panel(r, swap_card, os::swap_name, Renderer::Symbol::Drive); const auto swap = fmt::split_unit(fmt::bytes(static_cast(s.swap_used))); - const float vw = value_text(r, inner.take_top(32), swap.first, swap.second, Font::Metric, theme.text()); - TextStyle of_label; - of_label.font = Font::Label; - of_label.valign = VAlign::Bottom; - r.text(L"of " + fmt::bytes(static_cast(s.swap_total)), - Rect{inner.x + vw + tokens::space::xs, inner.y - 32, inner.w - vw, 28}, of_label, theme.text_tertiary()); + float swap_base = 0; + const float vw = value_text(r, inner.take_top(32), swap.first, swap.second, Font::Metric, theme.text(), + HAlign::Left, &swap_base); + r.text_on_baseline(L"of " + fmt::bytes(static_cast(s.swap_total)), inner.x + vw + tokens::space::xs, + swap_base, Font::Label, theme.text_tertiary()); inner.take_top(tokens::space::md); r.usage_bar(inner.take_top(6), s.swap_total ? static_cast(s.swap_used) / s.swap_total : 0, MetricKind::Memory); @@ -659,14 +654,12 @@ class PerformancePage : public Page { const Rect mem_card = wide ? Rect{row.right() - mem_w, row.y, mem_w, row_h} : stack.next(kPanelChrome + 80); inner = panel(r, mem_card, L"Memory", Renderer::Symbol::Stack); const auto used = fmt::split_unit(fmt::bytes(g.memory_used)); - const float vw = value_text(r, inner.take_top(32), used.first, used.second, Font::Metric, theme.text()); + float base = 0; + const float vw = value_text(r, inner.take_top(32), used.first, used.second, Font::Metric, theme.text(), + HAlign::Left, &base); if (g.memory_total > 0) { - TextStyle of; - of.font = Font::Label; - of.valign = VAlign::Bottom; - r.text(L"of " + fmt::bytes(g.memory_total), - Rect{inner.x + vw + tokens::space::xs, inner.y - 32, inner.w - vw, 28}, of, - theme.text_tertiary()); + r.text_on_baseline(L"of " + fmt::bytes(g.memory_total), inner.x + vw + tokens::space::xs, base, + Font::Label, theme.text_tertiary()); inner.take_top(tokens::space::md); r.usage_bar( inner.take_top(6), diff --git a/apps/ui/src/page_services.cpp b/apps/ui/src/page_services.cpp index e69121a..be43d2f 100644 --- a/apps/ui/src/page_services.cpp +++ b/apps/ui/src/page_services.cpp @@ -357,14 +357,25 @@ class ServicesPage : public Page { PageId id() const override { return PageId::Services; } std::wstring title() const override { return L"Services"; } + // The list comes from the store's worker (about a second on Linux): the screen opens at once with + // the last list and takes the new one on the tick after it arrives. void activate(Host &host) override { host_ = &host; - services_ = host.store().services(); - loaded_ = true; - sort(); + host.store().request_services(); + take_services(host); } void tick(Host &host) override { - if (host.store().ticks() % 5 == 0) activate(host); + if (host.store().ticks() % 5 == 0) host.store().request_services(); + take_services(host); + } + void take_services(Host &host) { + uint64_t generation = 0; + std::vector list = host.store().services(&generation); + if (generation == 0 || generation == generation_) return; + generation_ = generation; + services_ = std::move(list); + loaded_ = true; + sort(); } void paint(Host &host, const Rect &bounds) override { @@ -613,6 +624,7 @@ class ServicesPage : public Page { int filter_ = 1; // Running, like the macOS default int domain_ = 0; bool loaded_ = false; + uint64_t generation_ = 0; // the store's service listing this list came from std::vector services_; std::vector filtered_; }; diff --git a/apps/ui/src/page_system.cpp b/apps/ui/src/page_system.cpp index 03b5d49..040a85a 100644 --- a/apps/ui/src/page_system.cpp +++ b/apps/ui/src/page_system.cpp @@ -57,8 +57,10 @@ class SystemPage : public Page { TextStyle os; os.font = Font::Body; os.valign = VAlign::Top; - r.text(fmt::from_utf8(info.os_name) + L" " + fmt::from_utf8(info.os_version) + L" (" + - fmt::from_utf8(info.os_build) + L") · " + fmt::from_utf8(info.hostname), + // The build in brackets only where the OS has one (Linux distributions mostly don't). + const std::wstring build = info.os_build[0] ? L" (" + fmt::from_utf8(info.os_build) + L")" : L""; + r.text(fmt::from_utf8(info.os_name) + L" " + fmt::from_utf8(info.os_version) + build + L" · " + + fmt::from_utf8(info.hostname), Rect{inner.x, inner.y + 80, inner.w, 20}, os, theme.text_secondary()); y = card.bottom() + kSectionGap; } @@ -75,7 +77,7 @@ class SystemPage : public Page { hardware.push_back({L"Frequency", fmt::number(info.cpu_frequency_hz / 1e9, 2) + L" GHz", L""}); const std::vector software = { {L"Operating system", fmt::from_utf8(info.os_name) + L" " + fmt::from_utf8(info.os_version), - L"Build " + fmt::from_utf8(info.os_build)}, + info.os_build[0] ? L"Build " + fmt::from_utf8(info.os_build) : std::wstring()}, {L"Hostname", fmt::from_utf8(info.hostname), L""}, {L"Uptime", fmt::duration(uptime), L"Since " + fmt::date_time(info.boot_time)}, {L"Processes", fmt::count(s.process_count), fmt::count(s.thread_count) + L" threads"}, diff --git a/apps/ui/src/pages.hpp b/apps/ui/src/pages.hpp index a89ba35..b68fcbc 100644 --- a/apps/ui/src/pages.hpp +++ b/apps/ui/src/pages.hpp @@ -194,8 +194,10 @@ struct ChartSeries { void live_chart(Renderer &r, const Rect &bounds, const std::vector &series, float max, MetricKind kind, const std::function &axis_label); // Big number + unit (ValueText); returns the width used. +// A figure and its unit on one baseline (ValueText), the figure's bottom on the bounds' bottom. +// `baseline` receives that baseline, for more text on the same line ("of 30.4 GB"). float value_text(Renderer &r, const Rect &bounds, std::wstring_view value, std::wstring_view unit, Font font, - Color color, HAlign align = HAlign::Left); + Color color, HAlign align = HAlign::Left, float *baseline = nullptr); // Label / value facts in an adaptive grid (StatGrid). Returns the height used. struct Stat { std::wstring label; diff --git a/apps/ui/src/pages_common.cpp b/apps/ui/src/pages_common.cpp index a42911c..920d8e8 100644 --- a/apps/ui/src/pages_common.cpp +++ b/apps/ui/src/pages_common.cpp @@ -90,14 +90,18 @@ void live_chart(Renderer &r, const Rect &bounds, const std::vector TextStyle value; value.font = Font::Headline; value.tabular = true; - const float vw = r.measure(s.value, Font::Headline); + const float vw = r.measure_tabular(s.value, Font::Headline); r.text(s.value, Rect{x, legend.y, vw + 2, legend.h}, value, theme.text()); x += vw + tokens::space::lg; } area.take_top(tokens::space::md); Rect footer = area.take_bottom(14); area.take_bottom(tokens::space::md); - Rect axis = area.take_right(44); + // As wide as its longest label ("977 KB/s"), at least the 44 of a percentage axis. + float axis_w = 44; + for (const float v : {max, max / 2, 0.0f}) + axis_w = std::max(axis_w, r.measure_tabular(axis_label(v), Font::Caption) + 4); + Rect axis = area.take_right(axis_w); area.take_right(tokens::space::sm); const Rect chart = area; const float lw = 2; @@ -133,28 +137,20 @@ void live_chart(Renderer &r, const Rect &bounds, const std::vector } float value_text(Renderer &r, const Rect &bounds, std::wstring_view value, std::wstring_view unit, Font font, - Color color, HAlign align) { - TextStyle big; - big.font = font; - big.tabular = true; - big.trim = false; - big.valign = VAlign::Bottom; - const float vw = r.measure(value, font); + Color color, HAlign align, float *baseline) { + const float vw = r.measure_tabular(value, font); const float uw = unit.empty() ? 0 : r.measure(unit, Font::Headline) + 3; float x = bounds.x; if (align == HAlign::Right) x = bounds.right() - vw - uw; else if (align == HAlign::Center) x = bounds.cx() - (vw + uw) / 2; - r.text(value, Rect{x, bounds.y, vw + 4, bounds.h}, big, color); - if (!unit.empty()) { - // The unit sits on the value's baseline: a little above the bottom of the big glyphs. - TextStyle unit_style; - unit_style.font = Font::Headline; - unit_style.valign = VAlign::Bottom; - r.text(unit, Rect{x + vw + 3, bounds.y, uw + 4, bounds.h - std::round(r.line_height(font) * 0.16f)}, unit_style, - r.theme().text_secondary()); - } + // The figure's line ends at the bottom of the bounds; the unit shares its baseline (macOS's + // firstTextBaseline), whatever the two fonts' sizes. + const float base = bounds.bottom() - r.line_height(font) + r.baseline(font); + r.text_on_baseline(value, x, base, font, color, HAlign::Left, true); + if (!unit.empty()) r.text_on_baseline(unit, x + vw + 3, base, Font::Headline, r.theme().text_secondary()); + if (baseline) *baseline = base; return vw + uw; } @@ -190,7 +186,17 @@ float stat_grid(Renderer &r, const Rect &bounds, const std::vector &stats, TextStyle value; value.font = Font::Stat; value.tabular = true; - r.text(s.value, value_rect, value, theme.text()); + // As macOS's StatGrid (lineLimit 1, minimumScaleFactor 0.7): a value too wide for its column is + // drawn smaller, down to 70%, before it is cut short. + const float needed = r.measure_tabular(s.value, Font::Stat); + if (needed > value_rect.w && value_rect.w > 0) { + const float scale = std::max(0.7f, value_rect.w / needed); + r.canvas().push_scale(scale, Point{value_rect.x, value_rect.cy()}); + r.text(s.value, Rect{value_rect.x, value_rect.y, value_rect.w / scale, value_rect.h}, value, theme.text()); + r.canvas().pop_transform(); + } else { + r.text(s.value, value_rect, value, theme.text()); + } if (!s.detail.empty()) { TextStyle detail; detail.font = Font::Caption; @@ -388,8 +394,7 @@ std::vector top_apps_panel(Host &host, const Rect &card, std::wstring headline.tabular = true; headline.halign = HAlign::Right; const std::wstring v = value(row); - // Tabular figures run a little wider than the measured proportional ones. - const float vw = r.measure(v, Font::Headline) + 6; + const float vw = r.measure_tabular(v, Font::Headline) + 2; r.text(v, Rect{top.right() - vw - 2, top.y, vw + 2, top.h}, headline, v == fmt::unavailable ? theme.text_tertiary() : theme.text()); headline.halign = HAlign::Left; diff --git a/apps/ui/src/render.cpp b/apps/ui/src/render.cpp index ca7b069..ac14a7d 100644 --- a/apps/ui/src/render.cpp +++ b/apps/ui/src/render.cpp @@ -277,13 +277,29 @@ float Renderer::text(std::wstring_view value, const Rect &r, const TextStyle &st return canvas_.draw_text(value, r, style, color); } -float Renderer::measure(std::wstring_view value, Font font, float tracking) { +float Renderer::measure(std::wstring_view value, Font font, float tracking, bool tabular) { if (value.empty()) return 0; - return canvas_.measure_text(value, font, tracking); + return canvas_.measure_text(value, font, tracking, tabular); } float Renderer::line_height(Font font) { return canvas_.line_height(font); } +float Renderer::baseline(Font font) { return canvas_.baseline(font); } + +float Renderer::text_on_baseline(std::wstring_view value, float x, float baseline_y, Font font, Color color, + HAlign align, bool tabular) { + if (value.empty()) return 0; + const float w = measure(value, font, 0, tabular); + TextStyle style; + style.font = font; + style.tabular = tabular; + style.trim = false; + style.valign = VAlign::Top; + const float left = align == HAlign::Right ? x - w : align == HAlign::Center ? x - w / 2 : x; + text(value, Rect{left, baseline_y - baseline(font), w + 2, line_height(font)}, style, color); + return w; +} + // --------------------------------------------------------------------------------------------- // Components // --------------------------------------------------------------------------------------------- diff --git a/apps/ui/src/store.cpp b/apps/ui/src/store.cpp index b90f8f9..7be31f1 100644 --- a/apps/ui/src/store.cpp +++ b/apps/ui/src/store.cpp @@ -33,6 +33,7 @@ Store::Store() : alert_settings_(AlertSettings::load()) { Store::~Store() { stop(); + if (services_thread_.joinable()) services_thread_.join(); flush_history(); if (monitor_) pc_monitor_destroy(monitor_); } @@ -411,11 +412,34 @@ std::vector Store::volumes() { return std::vector(rows, rows + std::max(0, count)); } -std::vector Store::services() { - std::lock_guard lock(monitor_mutex_); - const pc_service *rows = nullptr; - const int32_t count = pc_monitor_services(monitor_, &rows); - return std::vector(rows, rows + std::max(0, count)); +void Store::request_services() { + // One listing at a time; a request during one (after Start or Stop) gets one more afterwards, so + // the screen never settles on a list taken before the change. + if (services_busy_.exchange(true)) { + services_again_ = true; + return; + } + if (services_thread_.joinable()) services_thread_.join(); // the previous one, finished + // pc_monitor_services touches only the monitor's own service list, never the sampler's data, + // so it runs without monitor_mutex_: the sampler isn't held up for the second it takes. + services_thread_ = std::thread([this] { + do { + services_again_ = false; + const pc_service *rows = nullptr; + const int32_t count = pc_monitor_services(monitor_, &rows); + std::vector list(rows, rows + std::max(0, count)); + std::lock_guard lock(services_mutex_); + services_ = std::move(list); + ++services_generation_; + } while (services_again_.exchange(false)); + services_busy_ = false; + }); +} + +std::vector Store::services(uint64_t *generation) const { + std::lock_guard lock(services_mutex_); + if (generation) *generation = services_generation_; + return services_; } pc_result Store::service_control(int32_t domain, const std::string &label, int32_t action) { diff --git a/apps/ui/src/store.hpp b/apps/ui/src/store.hpp index 1b23134..892526c 100644 --- a/apps/ui/src/store.hpp +++ b/apps/ui/src/store.hpp @@ -196,7 +196,13 @@ class Store { std::vector open_files(int32_t pid, bool &complete); std::vector connections(int32_t pid, bool &complete); std::vector volumes(); - std::vector services(); + // Services take about a second to list on Linux (systemctl over every unit): they are listed on a + // worker thread, as the macOS app does, while the Services screen shows the last list. + // request_services() starts a listing unless one runs; services() is the last one, with the + // number of listings so far (0: none yet) so the page knows when to take a new one. + void request_services(); + std::vector services(uint64_t *generation = nullptr) const; + bool services_loading() const { return services_busy_.load(); } pc_result service_control(int32_t domain, const std::string &label, int32_t action); std::vector startup_items(); pc_result startup_set_enabled(int32_t scope, const std::string &label, bool enabled); @@ -218,6 +224,12 @@ class Store { pc_system_info info_{}; std::thread thread_; + std::thread services_thread_; + std::atomic services_busy_{false}; + std::atomic services_again_{false}; // asked during a listing: list once more after it + mutable std::mutex services_mutex_; + std::vector services_; + uint64_t services_generation_ = 0; std::mutex wake_mutex_; std::condition_variable wake_; std::atomic running_{false}; diff --git a/apps/ui/src/ui.hpp b/apps/ui/src/ui.hpp index cdeb2cf..5533352 100644 --- a/apps/ui/src/ui.hpp +++ b/apps/ui/src/ui.hpp @@ -279,8 +279,12 @@ class Canvas { // Draws `text` in `r`; returns the laid-out width. virtual float draw_text(std::wstring_view text, const Rect &r, const TextStyle &style, Color color) = 0; - virtual float measure_text(std::wstring_view text, Font font, float tracking) = 0; + // `tabular`: measured with tabular figures, as text drawn with TextStyle::tabular is laid out + // (wider digits than the proportional ones). + virtual float measure_text(std::wstring_view text, Font font, float tracking, bool tabular = false) = 0; virtual float line_height(Font font) = 0; + // From the top of a line of `font` to its baseline: lets text of different sizes share a baseline. + virtual float baseline(Font font) = 0; }; // ---- renderer: the component vocabulary of design/components.md over a Canvas ---- @@ -312,8 +316,15 @@ class Renderer { // Text. Returns the laid-out width. float text(std::wstring_view value, const Rect &r, const TextStyle &style, Color color); - float measure(std::wstring_view value, Font font, float tracking = 0); + float measure(std::wstring_view value, Font font, float tracking = 0, bool tabular = false); + // The width `value` takes when drawn with tabular figures (TextStyle::tabular). + float measure_tabular(std::wstring_view value, Font font) { return measure(value, font, 0, true); } float line_height(Font font); + float baseline(Font font); + // Draws `value` on the baseline at `baseline_y`, starting at `x` (ending there for HAlign::Right); + // returns its width. Text of different fonts drawn this way lines up as one line. + float text_on_baseline(std::wstring_view value, float x, float baseline_y, Font font, Color color, + HAlign align = HAlign::Left, bool tabular = false); // ---- components (design/components.md) ---- void card(const Rect &r, std::optional tint = std::nullopt, float radius = tokens::radius::lg); diff --git a/apps/windows/src/canvas_d2d.cpp b/apps/windows/src/canvas_d2d.cpp index 5b1fb4c..c8bbb40 100644 --- a/apps/windows/src/canvas_d2d.cpp +++ b/apps/windows/src/canvas_d2d.cpp @@ -729,16 +729,27 @@ float D2DCanvas::draw_text(std::wstring_view value, const Rect &r, const TextSty return metrics.widthIncludingTrailingWhitespace; } -float D2DCanvas::measure_text(std::wstring_view value, Font font, float tracking) { +float D2DCanvas::measure_text(std::wstring_view value, Font font, float tracking, bool tabular) { if (value.empty()) return 0; TextStyle style; style.font = font; style.trim = false; style.tracking = tracking; + style.tabular = tabular; const CachedLayout *l = layout(value, style, 10000, 10000); return l ? l->metrics.widthIncludingTrailingWhitespace : 0; } +float D2DCanvas::baseline(Font font) { + TextStyle style; + style.font = font; + const CachedLayout *l = layout(L"Ag", style, 1000, 1000); + DWRITE_LINE_METRICS line{}; + UINT32 lines = 0; + if (!l || FAILED(l->layout->GetLineMetrics(&line, 1, &lines)) || lines == 0) return font_spec(font).size; + return line.baseline; +} + float D2DCanvas::line_height(Font font) { TextStyle style; style.font = font; diff --git a/apps/windows/src/canvas_d2d.hpp b/apps/windows/src/canvas_d2d.hpp index b1d4da6..29574ca 100644 --- a/apps/windows/src/canvas_d2d.hpp +++ b/apps/windows/src/canvas_d2d.hpp @@ -68,8 +68,9 @@ class D2DCanvas : public Canvas { void push_scale(float scale, Point about) override; void pop_transform() override; float draw_text(std::wstring_view text, const Rect &r, const TextStyle &style, Color color) override; - float measure_text(std::wstring_view text, Font font, float tracking) override; + float measure_text(std::wstring_view text, Font font, float tracking, bool tabular = false) override; float line_height(Font font) override; + float baseline(Font font) override; private: struct ShadowKey { From 62dc3dc1bae02639a6dd8d0ba5588cc4110b0fce Mon Sep 17 00:00:00 2001 From: Manh Pham Date: Thu, 8 Oct 2026 14:25:03 +0700 Subject: [PATCH 3/5] Return freed memory while running in the background on Linux The background-only state measured 42 MB p90 on CI (32 MB on average) against the 30 MB target: the first samples read every desktop entry, GPU and sensor, and glibc kept the freed pages. Trim after the third sample and once a minute while hidden. bench-linux.py also records the per-second memory samples in its JSON, to tell growth from a startup peak. --- apps/linux/src/window.cpp | 6 ++++++ scripts/bench-linux.py | 2 ++ 2 files changed, 8 insertions(+) diff --git a/apps/linux/src/window.cpp b/apps/linux/src/window.cpp index 4b384e1..ce6648e 100644 --- a/apps/linux/src/window.cpp +++ b/apps/linux/src/window.cpp @@ -1214,6 +1214,10 @@ class MainWindow : public Host { if (current_) current_->tick(*this); for (auto &overlay : overlays_) overlay->tick(*this); if (screenshot_ && ++screenshot_samples_ == 6) take_screenshot(); + // In the background, return what the samples freed: the first ones read every desktop entry, + // GPU and sensor once, and glibc keeps freed pages of the sampler's arena otherwise. Then once + // a minute, which costs a few microseconds. + if (hidden_ && (++hidden_samples_ == 3 || hidden_samples_ % 60 == 0)) malloc_trim(0); update_tray(); repaint(); } @@ -1331,6 +1335,7 @@ class MainWindow : public Host { // freed pages, so the background footprint is the sampler's, not the window's. canvas_.trim(); malloc_trim(0); + hidden_samples_ = 0; } void show_again() { @@ -1420,6 +1425,7 @@ class MainWindow : public Host { int screenshot_samples_ = 0; bool failed_ = false; bool start_in_background_ = false; + int hidden_samples_ = 0; // samples since the window was hidden bool first_frame_reported_ = false; std::unique_ptr tray_; bool handed_over_ = false; // a root copy runs in this one's place diff --git a/scripts/bench-linux.py b/scripts/bench-linux.py index fae2f3e..ec33d76 100755 --- a/scripts/bench-linux.py +++ b/scripts/bench-linux.py @@ -134,12 +134,14 @@ def probe(page, warmup, duration): memory.append(private_bytes(process.pid)) time.sleep(1) ticks1, t1 = cpu_ticks(process.pid), time.monotonic() + samples = list(memory) # in time order, for the JSON: shows growth or a startup peak memory.sort() result.update( cpu_percent_of_core=(ticks1 - ticks0) / TICKS / (t1 - t0) * 100, memory_p90_bytes=memory[min(len(memory) - 1, int(len(memory) * 0.9))], memory_peak_bytes=memory[-1], memory_average_bytes=statistics.mean(memory), + memory_samples_bytes=samples, ) return result finally: From 756d2bbf27b956cfaeef13d299aaa73dfde91c93 Mon Sep 17 00:00:00 2001 From: Manh Pham Date: Thu, 8 Oct 2026 14:38:46 +0700 Subject: [PATCH 4/5] Record the largest anonymous memory regions in the Linux bench The background-only state grows in 8-11 MB steps on CI (22.6, 33.8, then 42.0 MB) and not on a desktop. The JSON now lists the largest private anonymous regions with the mapping before each, to tell the heap, thread arenas and library allocations apart. --- scripts/bench-linux.py | 23 +++++++++++++++++++++++ 1 file changed, 23 insertions(+) diff --git a/scripts/bench-linux.py b/scripts/bench-linux.py index ec33d76..f2ff04d 100755 --- a/scripts/bench-linux.py +++ b/scripts/bench-linux.py @@ -99,6 +99,27 @@ def private_bytes(pid): return 0 +def anonymous_mappings(pid, top=12): + """The largest private anonymous regions of a process (Anonymous: in /proc//smaps), with the + name of the region before them, which tells the heap from thread arenas and library allocations.""" + regions, current = [], None + try: + with open(f"/proc/{pid}/smaps") as f: + for line in f: + head = line.split() + if head and "-" in head[0] and len(head) >= 5 and not head[0].endswith(":"): + current = {"range": head[0], "name": head[5] if len(head) > 5 else "", "anonymous_kb": 0} + regions.append(current) + elif head and head[0] == "Anonymous:" and current is not None: + current["anonymous_kb"] = int(head[1]) + except OSError: + return [] + for i, region in enumerate(regions): + if not region["name"] and i > 0: + region["after"] = regions[i - 1]["name"] + return sorted((r for r in regions if r["anonymous_kb"]), key=lambda r: -r["anonymous_kb"])[:top] + + def probe(page, warmup, duration): """Launches the app on `page` (or in the background), then samples its CPU and memory.""" args = [str(APP), "--no-settings"] @@ -135,6 +156,7 @@ def probe(page, warmup, duration): time.sleep(1) ticks1, t1 = cpu_ticks(process.pid), time.monotonic() samples = list(memory) # in time order, for the JSON: shows growth or a startup peak + regions = anonymous_mappings(process.pid) memory.sort() result.update( cpu_percent_of_core=(ticks1 - ticks0) / TICKS / (t1 - t0) * 100, @@ -142,6 +164,7 @@ def probe(page, warmup, duration): memory_peak_bytes=memory[-1], memory_average_bytes=statistics.mean(memory), memory_samples_bytes=samples, + largest_anonymous_regions=regions, ) return result finally: From 58c306802281c67724cdb69db40bb183dd8c8c58 Mon Sep 17 00:00:00 2001 From: Manh Pham Date: Thu, 8 Oct 2026 14:44:26 +0700 Subject: [PATCH 5/5] Turn off GDK's OpenGL context in Cairo bench runs On Xvfb GDK still opens an OpenGL context on llvmpipe though the Cairo renderer never draws with it: libLLVM held 7 MB of private memory on the runner, and the background-only state grew in 8-11 MB steps on some runs (42 MB against the 30 MB target). With GDK_DEBUG=gl-disable (GTK 4.14) and GDK_DISABLE=gl (later versions) it measures 7 MB here. --- docs/development.md | 3 ++- scripts/bench-linux.py | 10 ++++++++-- 2 files changed, 10 insertions(+), 3 deletions(-) diff --git a/docs/development.md b/docs/development.md index 07c2c58..651c4b9 100644 --- a/docs/development.md +++ b/docs/development.md @@ -167,7 +167,8 @@ first frame, which times startup), samples CPU time from `/proc//stat` and second, and measures `background` with `--background`. The CLI's numbers are compared with `/proc/stat`, `/proc/meminfo` and the process list. Output: `dist/bench-linux.json`. The same options as the Windows script, plus `--renderer`: on Xvfb, which has no GPU, GTK's GL renderer runs on Mesa's llvmpipe, whose buffers count as the app's -private memory (110-180 MB against about 35 MB of Procyon's own), so CI measures with `--renderer cairo`. +private memory (110-180 MB against about 35 MB of Procyon's own), so CI measures with `--renderer cairo`, which also +turns off the OpenGL context GDK would still open there (`GDK_DEBUG=gl-disable`, `GDK_DISABLE=gl`). ## Development diff --git a/scripts/bench-linux.py b/scripts/bench-linux.py index f2ff04d..eb64078 100755 --- a/scripts/bench-linux.py +++ b/scripts/bench-linux.py @@ -16,8 +16,8 @@ On a display without a GPU (Xvfb on a CI runner) GTK draws through Mesa's software OpenGL (llvmpipe), whose buffers and JIT land in the app's private memory: 110-180 MB where the same screen holds about -35 MB on a desktop, whose GL buffers live in GPU memory. --renderer cairo (GSK_RENDERER) measures -Procyon's own footprint there; CI passes it. +35 MB on a desktop, whose GL buffers live in GPU memory. --renderer cairo (GSK_RENDERER, with GDK's +OpenGL context off too) measures Procyon's own footprint there; CI passes it. Shared CI runners are noisy: a fixed piece of work is timed alongside each measurement; its slowdown against the fastest one of the run says how slow the runner was. A missed CPU or startup target whose @@ -127,6 +127,12 @@ def probe(page, warmup, duration): env = dict(os.environ, PROCYON_BENCH="1") if RENDERER: env["GSK_RENDERER"] = RENDERER + if RENDERER == "cairo": + # GDK still opens an OpenGL context on llvmpipe (libLLVM, 7 MB of private memory on the + # runner, growing as it compiles) though nothing draws with it: off too. GTK 4.14 spells + # it GDK_DEBUG=gl-disable, later versions GDK_DISABLE=gl. + env["GDK_DEBUG"] = "gl-disable" + env["GDK_DISABLE"] = "gl" calibration = calibrate() started = time.monotonic() process = subprocess.Popen(args, env=env, stderr=subprocess.PIPE, stdout=subprocess.DEVNULL, text=True)