Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion VERSION
Original file line number Diff line number Diff line change
@@ -1 +1 @@
0.2.0
1.0.0
11 changes: 10 additions & 1 deletion apps/linux/src/canvas_cairo.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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<float>(pango_layout_get_baseline(l->layout)) / PANGO_SCALE : font_spec(f).size;
}

float CairoCanvas::line_height(Font f) {
TextStyle style;
style.font = f;
Expand Down
3 changes: 2 additions & 1 deletion apps/linux/src/canvas_cairo.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
3 changes: 3 additions & 0 deletions apps/linux/src/platform_linux.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -258,6 +258,9 @@ void watch_color_scheme(std::function<void()> 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;
Expand Down
10 changes: 10 additions & 0 deletions apps/linux/src/window.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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");
Expand Down Expand Up @@ -1210,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();
}
Expand Down Expand Up @@ -1327,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() {
Expand Down Expand Up @@ -1416,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> tray_;
bool handed_over_ = false; // a root copy runs in this one's place
Expand Down
4 changes: 2 additions & 2 deletions apps/ui/src/page_history.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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;
};
Expand Down Expand Up @@ -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,
Expand Down
14 changes: 10 additions & 4 deletions apps/ui/src/page_overview.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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<int64_t>(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<int64_t>(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;
Expand Down
35 changes: 14 additions & 21 deletions apps/ui/src/page_performance.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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(),
Expand Down Expand Up @@ -316,14 +316,10 @@ class PerformancePage : public Page {
const auto used = fmt::split_unit(fmt::bytes(static_cast<int64_t>(s.memory_used)));
const std::wstring of = L"of " + fmt::bytes(static_cast<int64_t>(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);
Expand Down Expand Up @@ -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<int64_t>(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<int64_t>(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<int64_t>(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<float>(s.swap_used) / s.swap_total : 0,
MetricKind::Memory);
Expand Down Expand Up @@ -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),
Expand Down
20 changes: 16 additions & 4 deletions apps/ui/src/page_services.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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<pc_service> 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 {
Expand Down Expand Up @@ -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<pc_service> services_;
std::vector<size_t> filtered_;
};
Expand Down
8 changes: 5 additions & 3 deletions apps/ui/src/page_system.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
Expand All @@ -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<Stat> 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"},
Expand Down
4 changes: 3 additions & 1 deletion apps/ui/src/pages.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -194,8 +194,10 @@ struct ChartSeries {
void live_chart(Renderer &r, const Rect &bounds, const std::vector<ChartSeries> &series, float max, MetricKind kind,
const std::function<std::wstring(float)> &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;
Expand Down
47 changes: 26 additions & 21 deletions apps/ui/src/pages_common.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -90,14 +90,18 @@ void live_chart(Renderer &r, const Rect &bounds, const std::vector<ChartSeries>
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;
Expand Down Expand Up @@ -133,28 +137,20 @@ void live_chart(Renderer &r, const Rect &bounds, const std::vector<ChartSeries>
}

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;
}

Expand Down Expand Up @@ -190,7 +186,17 @@ float stat_grid(Renderer &r, const Rect &bounds, const std::vector<Stat> &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;
Expand Down Expand Up @@ -388,8 +394,7 @@ std::vector<TopAppRow> 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;
Expand Down
Loading