Author SHA1 Message Date
Muse 4a3a6b25fe monitor/system-overview (Rust): re-screenshot against fixed widgets (Gitea main 3baaa13) 2026-12-05 23:54:03 +00:00
Muse 749f3149aa Merge remote-tracking branch 'origin/main' into monitor-apps/system-overview 2026-12-05 23:51:12 +00:00
Muse 3baaa13f40 Merge fix/inst-proportions into main 2026-12-05 23:29:59 +00:00
Muse 7feeac848d Merge fix/monitor-widget-proportions: dynamic graph margins, scaled fonts, tach + audit proportions 2026-12-05 22:24:09 +00:00
Muse 7995eac6ac Monitor widgets: dynamic graph margins, scaled fonts, tach + audit proportions
- Graphs (History/Net/Temp): dynamic left margin from the widest
  Y label (5 labels, top hangs below / bottom sits above gridline),
  legend on top with wrap/split so totals never clip; Net Y labels
  humanised (KB/s, MB/s) and scaled from the series max so no series
  rides the top edge; Temp keeps the PY layout (now bold top-right,
  threshold label above the line, min/max/avg bottom line).
- XTachometer: numerals ~7.5% of dial diameter, bold, placed by
  per-label radial extent so wide labels never cross the dial rim;
  RPM bold centred in-dial below the top numerals; readout inside
  below the hub; redline numerals red; redline is a rim arc, not a
  filled sector (red-on-red made the redline numerals invisible).
- Audit proportions in all 14 widgets: scaled fonts from widget
  dimensions (titles 16 bold, body 14-16, hero 20-32 bold), CoreGrid
  waste-minimising layout (8 cores -> 4x2), UsageBar labels outside
  the bar with the value name (CPU) and absolute gradient stops,
  StackBar title+total header (absolute GiB, total 30.3) with a
  centred block, VerticalBar value inside the bar + peak label above
  the line, ArcGauge redesigned to arc-line no-needle (C/PY style),
  DonutGauge centre label = value name with 8-10% ring, ProcessList
  13px rows / 23px pitch with colour-coded CPU bars and a 68px PID
  column (7-digit live PIDs no longer bleed into the name), LoadBadge
  PY two-line layout with 1/5/15-min sub-labels + core count,
  MonitorButton/Grid name+status+detail cells with ceil(sqrt(n))
  grid geometry, SysBox hero top-left + max + bar % label.
- Scaled-font plumbing: DrawTarget::set_scaled_font (default no-op),
  draw_text_scaled / text_width_scaled / clamp_font_px in
  xframe-core; X11 binds scalable misc-fixed XLFDs (cached per
  px/bold) with bitmap fallbacks.
- Demo runner only sets text=kind when the widget did not seed its
  own text, so seeded value names (CPU, Disk) survive.
2026-12-05 22:23:27 +00:00
Muse c7a9a10e2a System Overview monitor app (Stage 2): XSysBox x4 + XLoadBadge + XDonutGauge x2 + XUsageBar x3, live /proc data, 500 ms refresh 2026-12-05 19:55:38 +00:00
8 changed files with 1144 additions and 241 deletions

No files matched your search

+13
View File
@@ -94,6 +94,19 @@ impl DrawTarget for CtxTarget<'_> {
fn set_font(&mut self, metrics: FontMetrics) {
self.font_metrics = Some(metrics);
// Rebind the regular font: a scaled draw may have left a
// different font in the GC.
self.ctx.bind_font();
}
fn set_scaled_font(&mut self, px: i32, bold: bool) -> bool {
match self.ctx.bind_scaled_font(px, bold) {
Some(metrics) => {
self.font_metrics = Some(metrics);
true
}
None => false,
}
}
fn set_font_px(&mut self, px: i32, proportional: bool) -> Option<FontMetrics> {
+79 -1
View File
@@ -8,6 +8,7 @@ use x11rb::connection::Connection;
use x11rb::protocol::xproto::*;
use x11rb::rust_connection::RustConnection;
use x11rb::COPY_FROM_PARENT;
use xframe_core::font::FontMetrics;
pub type Conn = RustConnection;
@@ -555,6 +556,13 @@ pub struct DrawCtx<'a> {
pub gc: Gcontext,
pub font: Font,
colors: RefCell<HashMap<(u8, u8, u8), u32>>,
/// Scaled fonts opened by `bind_scaled_font`, keyed by
/// (pixel size, bold). Process-lifetime, like the C++ cache.
scaled_fonts: RefCell<HashMap<(i32, bool), (Font, FontMetrics)>>,
/// The font currently bound into the GC (starts as `font`).
/// `text_width` measures with this font, so it stays correct
/// after a scaled draw.
current_font: RefCell<Font>,
}
impl<'a> DrawCtx<'a> {
@@ -565,6 +573,8 @@ impl<'a> DrawCtx<'a> {
gc,
font,
colors: RefCell::new(HashMap::new()),
scaled_fonts: RefCell::new(HashMap::new()),
current_font: RefCell::new(font),
}
}
@@ -731,7 +741,7 @@ impl<'a> DrawCtx<'a> {
}
pub fn text_width(&self, text: &str) -> i32 {
self.x.text_width(self.font, text)
self.x.text_width(*self.current_font.borrow(), text)
}
/// Draw text with the GC font; the GC font must be set by the caller
@@ -771,6 +781,74 @@ impl<'a> DrawCtx<'a> {
.x
.conn
.change_gc(self.gc, &ChangeGCAux::new().font(self.font));
*self.current_font.borrow_mut() = self.font;
}
/// Bind a scaled font (`px` pixels, bold when `bold`) into the GC
/// and return its metrics. The misc-fixed XLFD is scalable, so the
/// requested size loads exactly; bitmap fallbacks (the only sizes
/// the server has: bold 13/14/15/18/20, medium 13/18/20) and
/// `fixed` cover a server without the scalable face. Results are
/// cached per (px, bold). `None` when nothing loads, in which case
/// the previously bound font stays active.
pub fn bind_scaled_font(&self, px: i32, bold: bool) -> Option<FontMetrics> {
if let Some(&(font, metrics)) =
self.scaled_fonts.borrow().get(&(px, bold))
{
let _ = self
.x
.conn
.change_gc(self.gc, &ChangeGCAux::new().font(font));
*self.current_font.borrow_mut() = font;
return Some(metrics);
}
let weight = if bold { "bold" } else { "medium" };
let mut candidates: Vec<String> = vec![format!(
"-misc-fixed-{weight}-r-normal--{px}-*-75-75-c-*-iso8859-1"
)];
let bitmaps: &[i32] = if bold {
&[18, 20, 15, 14, 13]
} else {
&[20, 18, 13]
};
for size in bitmaps {
candidates.push(format!(
"-misc-fixed-{weight}-r-normal--{size}-120-100-100-c-60-iso8859-1"
));
}
candidates.push("fixed".to_string());
for name in &candidates {
let Ok(fid) = self.x.conn.generate_id() else {
continue;
};
let Ok(cookie) = self.x.conn.open_font(fid, name.as_bytes()) else {
continue;
};
if cookie.check().is_err() {
continue;
}
let Ok(reply) = self.x.conn.query_font(fid) else {
continue;
};
let Ok(reply) = reply.reply() else {
continue;
};
let metrics = FontMetrics {
ascent: reply.font_ascent as i32,
descent: reply.font_descent as i32,
char_width: reply.max_bounds.character_width as i32,
};
let _ = self
.x
.conn
.change_gc(self.gc, &ChangeGCAux::new().font(fid));
self.scaled_fonts
.borrow_mut()
.insert((px, bold), (fid, metrics));
*self.current_font.borrow_mut() = fid;
return Some(metrics);
}
None
}
pub fn put_rgba(&self, dst_x: i16, dst_y: i16, rgba: &[u8], w: u16, h: u16) {
+47
View File
@@ -21,6 +21,16 @@ pub trait DrawTarget {
fn set_line_width(&mut self, width: u32);
/// Install a font for subsequent `draw_string` calls.
fn set_font(&mut self, metrics: FontMetrics);
/// Install a scaled font (pixel size `px`, bold when `bold`) for
/// subsequent `draw_string` calls. Returns true when a font at
/// (approximately) that size was bound. Default: no-op returning
/// false — the caller then draws with the current font (the
/// Canvas / test targets have no X server to open fonts on).
/// Live targets (CtxTarget) bind a scalable misc-fixed XLFD,
/// falling back to the nearest bitmap size.
fn set_scaled_font(&mut self, _px: i32, _bold: bool) -> bool {
false
}
/// Fill a rectangle (top-left `x, y`, size `w` x `h`).
fn fill_rect(&mut self, x: i32, y: i32, w: i32, h: i32);
/// Draw a rectangle outline.
@@ -81,6 +91,43 @@ pub fn set_line_width(target: &mut (impl DrawTarget + ?Sized), line_width: i32)
target.set_line_width(line_width.max(1) as u32);
}
/// Clamp a font size derived from a widget dimension to `[lo, hi]`
/// (sane minimum 11 px so text never shrinks to unreadable).
/// Mirrors `xframe::clamp_font_px` in C++ and `_fpx` in Python.
pub fn clamp_font_px(value: i32, lo: i32, hi: i32) -> i32 {
value.max(lo).min(hi)
}
/// Draw `text` at baseline `(x, y)` in a scaled font (`px`, `bold`),
/// falling back to the current font on targets without scaled fonts.
/// The caller sets the foreground colour first.
pub fn draw_text_scaled(
target: &mut (impl DrawTarget + ?Sized),
px: i32,
bold: bool,
x: i32,
y: i32,
text: &str,
) {
if text.is_empty() {
return;
}
let _ = target.set_scaled_font(px, bold);
target.draw_string(x, y, text);
}
/// Width of `text` in a scaled font (`px`, `bold`), or in the current
/// font on targets without scaled fonts.
pub fn text_width_scaled(
target: &mut (impl DrawTarget + ?Sized),
px: i32,
bold: bool,
text: &str,
) -> i32 {
let _ = target.set_scaled_font(px, bold);
target.text_width(text)
}
/// C++ `xf::fill_rounded_rect`: the Part 4 rounded body — Rectangle A +
/// Rectangle B + 4 fill arcs. Degenerate radii fall back to a plain fill.
pub fn fill_rounded_rect(
@@ -0,0 +1,37 @@
# System Overview — monitor app
A system overview in one 1024x768 window, in the btop style: four
`XSysBox` composite boxes (CPU / MEM / NET / DISK), one `XLoadBadge`
(live load averages + uptime), two `XDonutGauge`s (CPU, Disk) and three
`XUsageBar`s (Memory, Disk, Network). All values are read live from
`/proc` (`stat`, `meminfo`, `net/dev`, `loadavg`, `uptime`) and
`statvfs("/")`, refreshed every 500 ms. No seeded demo data is shown:
the SysBox history graphs are flushed with live ticks before the
screenshot is taken (60 samples at 500 ms ≈ 30 s of run time).
Window title: `System Overview - monitor`.
## Widgets used
- `XSysBox` × 4 — CPU, MEM, NET (KB/s), DISK /
- `XLoadBadge` × 1 — 1 / 5 / 15 min load averages + uptime
- `XDonutGauge` × 2 — CPU, Disk /
- `XUsageBar` × 3 — Memory, Disk /, Network KB/s
## Build and run
```sh
make # builds ./system-overview
./system-overview # needs an X display; Esc / q / window-close quits
```
## Source
- C: `examples/monitor/system-overview/main.cpp` in
https://github.com/cnmcdee/lightgui
- Rust: `crates/xframe-demo/examples/monitor_system_overview.rs` in
https://github.com/cnmcdee/lightgui_rust
- Python: `examples/monitor_system_overview/main.py` in
https://github.com/cnmcdee/lightgui_python
Walkthrough: https://www.lightgui.com/monitor-system-overview/
@@ -0,0 +1,367 @@
//! System Overview - monitor app (Stage 2, btop-widget project).
//!
//! One 1024x768 window: four `XSysBox` composites (CPU / MEM / NET /
//! DISK), one `XLoadBadge` (live load averages + uptime), two
//! `XDonutGauge`s (CPU, Disk) and three `XUsageBar`s (Memory, Disk,
//! Network). All values are read live from `/proc` (`stat`, `meminfo`,
//! `net/dev`, `loadavg`, `uptime`) and `df -k /`, refreshed every
//! 500 ms. The seeded demo history is cleared at startup, so the
//! SysBox graphs show live ticks only.
//!
//! Run it from the workspace root:
//! cargo run -p xframe-demo --example monitor_system_overview
//! Press Esc or `q`, or close the window, to quit.
use std::fs;
use std::process::{Command, ExitCode};
use std::time::{Duration, Instant};
use x11rb::connection::Connection;
use x11rb::protocol::xproto::*;
use x11rb::protocol::Event;
use xframe_common::style::FONT_DEFAULT;
use xframe_common::target::CtxTarget;
use xframe_common::x11::{DrawCtx, X11};
use xframe_core::StyleManager;
use xframe_demo::register_styles;
use xframe_widgets::{MonitorWidget, Widget};
const WIN_W: u16 = 1024;
const WIN_H: u16 = 768;
const KEY_ESCAPE: u32 = 0xff1b;
// ---------------------------------------------------------------------------
// Live data from /proc
// ---------------------------------------------------------------------------
#[derive(Default)]
struct LiveData {
cpu_pct: f64,
mem_pct: f64,
net_kbps: f64,
disk_pct: f64,
load1: f64,
load5: f64,
load15: f64,
uptime_secs: u64,
}
#[derive(Default)]
struct Sampler {
prev_idle: u64,
prev_total: u64,
prev_rx: u64,
prev_instant: Option<Instant>,
}
fn read_cpu(s: &mut Sampler) -> Option<f64> {
let stat = fs::read_to_string("/proc/stat").ok()?;
let line = stat.lines().next()?;
let mut it = line.split_whitespace().skip(1).map(|v| v.parse::<u64>().ok());
let nums: Vec<u64> = (0..8).map(|_| it.next().flatten()).collect::<Option<Vec<_>>>()?;
let idle_now = nums[3] + nums[4];
let total_now: u64 = nums.iter().sum();
if s.prev_total == 0 {
s.prev_idle = idle_now;
s.prev_total = total_now;
return None;
}
let d_total = total_now.saturating_sub(s.prev_total);
let d_idle = idle_now.saturating_sub(s.prev_idle);
s.prev_idle = idle_now;
s.prev_total = total_now;
if d_total == 0 {
return None;
}
Some(100.0 * (1.0 - d_idle as f64 / d_total as f64))
}
fn read_mem() -> Option<f64> {
let meminfo = fs::read_to_string("/proc/meminfo").ok()?;
let mut total = 0u64;
let mut avail = 0u64;
for line in meminfo.lines() {
let mut parts = line.split_whitespace();
match parts.next() {
Some("MemTotal:") => total = parts.next()?.parse().ok()?,
Some("MemAvailable:") => avail = parts.next()?.parse().ok()?,
_ => {}
}
}
if total == 0 {
return None;
}
Some(100.0 * (1.0 - avail as f64 / total as f64))
}
fn read_net(s: &mut Sampler) -> Option<f64> {
let dev = fs::read_to_string("/proc/net/dev").ok()?;
let mut rx_total = 0u64;
for line in dev.lines().skip(2) {
let mut parts = line.split(':');
let iface = parts.next()?.trim();
if iface == "lo" {
continue;
}
let fields: Vec<&str> = parts.next()?.split_whitespace().collect();
rx_total += fields.first()?.parse::<u64>().ok()?;
}
let now = Instant::now();
let prev = s.prev_instant.replace(now)?;
let dt = now.duration_since(prev).as_secs_f64();
if dt <= 0.0 {
return None;
}
let out = (rx_total.saturating_sub(s.prev_rx)) as f64 / dt / 1024.0;
s.prev_rx = rx_total;
Some(out)
}
fn read_disk() -> Option<f64> {
// `df -k /`: second line is `fs 1K-blocks Used Available Use% /`.
let out = Command::new("df").arg("-k").arg("/").output().ok()?;
let text = String::from_utf8_lossy(&out.stdout);
let line = text.lines().nth(1)?;
let fields: Vec<&str> = line.split_whitespace().collect();
let pct = fields.get(4)?.trim_end_matches('%').parse::<f64>().ok()?;
Some(pct)
}
fn read_load(d: &mut LiveData) {
if let Ok(s) = fs::read_to_string("/proc/loadavg") {
let mut it = s.split_whitespace();
d.load1 = it.next().and_then(|v| v.parse().ok()).unwrap_or(0.0);
d.load5 = it.next().and_then(|v| v.parse().ok()).unwrap_or(0.0);
d.load15 = it.next().and_then(|v| v.parse().ok()).unwrap_or(0.0);
}
if let Ok(s) = fs::read_to_string("/proc/uptime") {
d.uptime_secs = s
.split_whitespace()
.next()
.and_then(|v| v.parse::<f64>().ok())
.map(|v| v as u64)
.unwrap_or(0);
}
}
fn sample(s: &mut Sampler, d: &mut LiveData) {
if let Some(v) = read_cpu(s) {
d.cpu_pct = v;
}
if let Some(v) = read_mem() {
d.mem_pct = v;
}
if let Some(v) = read_net(s) {
d.net_kbps = v;
}
if let Some(v) = read_disk() {
d.disk_pct = v;
}
read_load(d);
}
/// A SysBox with its seeded demo history replaced by an empty live series.
fn sysbox(name: &str, title: &str, unit: &str, max: f64, x: i32, y: i32, w: i32, h: i32) -> MonitorWidget {
let mut m = MonitorWidget::new(name, "SysBox", x, y, w, h);
m.title = title.to_string();
m.unit = unit.to_string();
m.state.max = max;
m.series.clear();
m.add_series(title);
m
}
fn main() -> ExitCode {
let x = match X11::connect() {
Ok(x) => x,
Err(e) => {
eprintln!("monitor_system_overview: {}", e);
return ExitCode::from(1);
}
};
let font = match x.open_font(&[FONT_DEFAULT, "fixed"]) {
Ok(f) => f,
Err(e) => {
eprintln!("monitor_system_overview: {}", e);
return ExitCode::from(1);
}
};
let event_mask = EventMask::EXPOSURE
| EventMask::KEY_PRESS
| EventMask::STRUCTURE_NOTIFY
| EventMask::BUTTON_PRESS
| EventMask::BUTTON_RELEASE
| EventMask::POINTER_MOTION;
let (win, gc) = match x.create_window(100, 100, WIN_W, WIN_H, "System Overview - monitor", event_mask) {
Ok(t) => t,
Err(e) => {
eprintln!("monitor_system_overview: {}", e);
return ExitCode::from(1);
}
};
let mut styles = StyleManager::new();
register_styles(&mut styles);
// Row 0: load badge across the top (84px: loads / labels / uptime rows).
let mut badge = MonitorWidget::new("badge", "LoadBadge", 16, 12, 992, 84);
// Rows 1-2: 2x2 grid of system boxes.
let mut cpu = sysbox("cpu", "CPU", "%", 100.0, 16, 108, 488, 200);
let mut mem = sysbox("mem", "MEM", "%", 100.0, 520, 108, 488, 200);
let mut net = sysbox("net", "NET", " KB/s", 1000.0, 16, 320, 488, 200);
let mut disk = sysbox("disk", "DISK /", "%", 100.0, 520, 320, 488, 200);
// Row 3: donut gauges + usage bars.
let mut donut_cpu = MonitorWidget::new("CPU", "DonutGauge", 16, 532, 180, 180);
let mut donut_disk = MonitorWidget::new("Disk /", "DonutGauge", 212, 532, 180, 180);
let mut bar_mem = MonitorWidget::new("bar_mem", "UsageBar", 408, 532, 600, 44);
bar_mem.set_text("Memory");
let mut bar_disk = MonitorWidget::new("bar_disk", "UsageBar", 408, 596, 600, 44);
bar_disk.set_text("Disk /");
let mut bar_net = MonitorWidget::new("bar_net", "UsageBar", 408, 660, 600, 44);
bar_net.set_text("Network KB/s");
bar_net.set_range(0.0, 1000.0);
let ctx = DrawCtx::new(&x, win, gc, font);
ctx.bind_font();
let mut target = CtxTarget::new(&ctx);
if !styles.resolve_font("default", &mut target) && !styles.resolve_font("dark", &mut target) {
eprintln!("monitor_system_overview: warning: no font resolved, labels will be blank");
}
let mut sampler = Sampler::default();
let mut data = LiveData::default();
sample(&mut sampler, &mut data);
// `push` = one live tick: value + history sample for the SysBoxes.
let push = |cpu: &mut MonitorWidget,
mem: &mut MonitorWidget,
net: &mut MonitorWidget,
disk: &mut MonitorWidget,
badge: &mut MonitorWidget,
donut_cpu: &mut MonitorWidget,
donut_disk: &mut MonitorWidget,
bar_mem: &mut MonitorWidget,
bar_disk: &mut MonitorWidget,
bar_net: &mut MonitorWidget,
d: &LiveData| {
cpu.push_value(d.cpu_pct);
cpu.set_value(d.cpu_pct);
mem.push_value(d.mem_pct);
mem.set_value(d.mem_pct);
net.push_value(d.net_kbps);
net.set_value(d.net_kbps);
disk.push_value(d.disk_pct);
disk.set_value(d.disk_pct);
badge.set_loads([d.load1, d.load5, d.load15], d.uptime_secs);
donut_cpu.set_value(d.cpu_pct);
donut_disk.set_value(d.disk_pct);
bar_mem.set_value(d.mem_pct);
bar_disk.set_value(d.disk_pct);
bar_net.set_value(d.net_kbps);
};
push(
&mut cpu, &mut mem, &mut net, &mut disk, &mut badge, &mut donut_cpu, &mut donut_disk,
&mut bar_mem, &mut bar_disk, &mut bar_net, &data,
);
let redraw = |cpu: &MonitorWidget,
mem: &MonitorWidget,
net: &MonitorWidget,
disk: &MonitorWidget,
badge: &MonitorWidget,
donut_cpu: &MonitorWidget,
donut_disk: &MonitorWidget,
bar_mem: &MonitorWidget,
bar_disk: &MonitorWidget,
bar_net: &MonitorWidget,
ctx: &DrawCtx,
target: &mut CtxTarget,
styles: &mut StyleManager| {
ctx.clear(255, 255, 255, WIN_W, WIN_H);
badge.draw(target, styles);
cpu.draw(target, styles);
mem.draw(target, styles);
net.draw(target, styles);
disk.draw(target, styles);
donut_cpu.draw(target, styles);
donut_disk.draw(target, styles);
bar_mem.draw(target, styles);
bar_disk.draw(target, styles);
bar_net.draw(target, styles);
ctx.flush();
};
redraw(
&cpu, &mem, &net, &disk, &badge, &donut_cpu, &donut_disk, &bar_mem, &bar_disk, &bar_net,
&ctx, &mut target, &mut styles,
);
let mut last_tick = Instant::now();
loop {
if last_tick.elapsed() >= Duration::from_millis(500) {
last_tick = Instant::now();
sample(&mut sampler, &mut data);
push(
&mut cpu, &mut mem, &mut net, &mut disk, &mut badge, &mut donut_cpu,
&mut donut_disk, &mut bar_mem, &mut bar_disk, &mut bar_net, &data,
);
redraw(
&cpu, &mem, &net, &disk, &badge, &donut_cpu, &donut_disk, &bar_mem, &bar_disk,
&mut bar_net, &ctx, &mut target, &mut styles,
);
}
let ev = match x.conn.poll_for_event() {
Ok(ev) => ev,
Err(e) => {
eprintln!("monitor_system_overview: {}", e);
break;
}
};
let Some(ev) = ev else {
std::thread::sleep(Duration::from_millis(10));
continue;
};
let mut handled = false;
match ev {
Event::Expose(_) => {
redraw(
&cpu, &mem, &net, &disk, &badge, &donut_cpu, &donut_disk, &bar_mem,
&bar_disk, &bar_net, &ctx, &mut target, &mut styles,
);
}
Event::ButtonPress(ev) => {
handled = badge.on_button_press(ev.event_x as i32, ev.event_y as i32, ev.detail as u32)
|| cpu.on_button_press(ev.event_x as i32, ev.event_y as i32, ev.detail as u32)
|| mem.on_button_press(ev.event_x as i32, ev.event_y as i32, ev.detail as u32)
|| net.on_button_press(ev.event_x as i32, ev.event_y as i32, ev.detail as u32)
|| disk.on_button_press(ev.event_x as i32, ev.event_y as i32, ev.detail as u32);
}
Event::ButtonRelease(ev) => {
handled = badge.on_button_release(ev.event_x as i32, ev.event_y as i32, ev.detail as u32)
|| cpu.on_button_release(ev.event_x as i32, ev.event_y as i32, ev.detail as u32);
}
Event::MotionNotify(ev) => {
handled = badge.on_motion(ev.event_x as i32, ev.event_y as i32)
|| cpu.on_motion(ev.event_x as i32, ev.event_y as i32);
}
Event::KeyPress(ev) => {
let keysym = x.keysym_for_keycode(ev.detail);
if keysym == KEY_ESCAPE || keysym == b'q' as u32 {
break;
}
}
Event::ClientMessage(ev)
if ev.type_ == x.wm_protocols && ev.data.as_data32()[0] == x.wm_delete =>
{
break;
}
_ => {}
}
if handled {
redraw(
&cpu, &mem, &net, &disk, &badge, &donut_cpu, &donut_disk, &bar_mem, &bar_disk,
&mut bar_net, &ctx, &mut target, &mut styles,
);
}
}
ExitCode::from(0)
}
Binary file not shown.

After

Width:  |  Height:  |  Size: 9.2 KiB

+8 -3
View File
@@ -108,9 +108,14 @@ pub fn run_widget_with_csv(
};
widget.set_bounds(gx as i32, gy as i32, gw as i32, gh as i32);
// Label text: the registry `kind` approximates the C++ constructor's
// default text (see the module docs of the binary).
let kind = widget.kind().to_string();
widget.set_text(&kind);
// default text (see the module docs of the binary) -- but only when
// the widget did not seed its own text (e.g. the monitor demos seed
// a value name such as "CPU" / "Disk"; overwriting it with the kind
// would show the class name instead of the value name).
if widget.state().text.is_empty() {
let kind = widget.kind().to_string();
widget.set_text(&kind);
}
if let Some(text) = &csv {
if let Err(e) = widget.load_csv_data(text) {
eprintln!("xframe-demo: --csv: {}", e);
File diff suppressed because it is too large. Load diff