Initial commit
This commit is contained in:
parent
3100ee0591
commit
633467b6f2
13 changed files with 158 additions and 41 deletions
90
src/main.rs
90
src/main.rs
|
|
@ -1,3 +1,9 @@
|
|||
macro_rules! asset {
|
||||
($n:literal) => {
|
||||
concat!(env!("CARGO_MANIFEST_DIR"), "/assets/", $n)
|
||||
};
|
||||
}
|
||||
|
||||
mod bar;
|
||||
mod notifications;
|
||||
mod theme;
|
||||
|
|
@ -12,9 +18,13 @@ pub struct App {
|
|||
workspaces: Vec<Workspace>,
|
||||
active_ws: WorkspaceId,
|
||||
time_str: String,
|
||||
stats_str: String,
|
||||
// GObject handle — manipulated directly in update() to avoid update_view conflicts.
|
||||
workspace_box: gtk4::Box,
|
||||
cpu_lbl: gtk4::Label,
|
||||
mem_lbl: gtk4::Label,
|
||||
pwr_lbl: gtk4::Label,
|
||||
bat_lbl: gtk4::Label,
|
||||
wifi_lbl: gtk4::Label,
|
||||
wifi_img: gtk4::Image,
|
||||
}
|
||||
|
||||
#[derive(Debug)]
|
||||
|
|
@ -22,7 +32,7 @@ pub enum AppInput {
|
|||
WorkspaceList(Vec<Workspace>),
|
||||
ActiveWorkspace(WorkspaceId),
|
||||
ClockTick,
|
||||
StatsUpdate(String),
|
||||
StatsUpdate(bar::stats::Stats),
|
||||
}
|
||||
|
||||
#[relm4::component(pub)]
|
||||
|
|
@ -37,6 +47,7 @@ impl SimpleComponent for App {
|
|||
set_title: Some("aster"),
|
||||
set_default_height: 32,
|
||||
|
||||
#[name = "center_box"]
|
||||
gtk::CenterBox {
|
||||
#[wrap(Some)]
|
||||
set_start_widget = >k::Box {
|
||||
|
|
@ -56,18 +67,6 @@ impl SimpleComponent for App {
|
|||
#[watch]
|
||||
set_label: &model.time_str,
|
||||
},
|
||||
|
||||
#[wrap(Some)]
|
||||
set_end_widget = >k::Box {
|
||||
set_orientation: gtk::Orientation::Horizontal,
|
||||
set_spacing: 8,
|
||||
set_margin_end: 8,
|
||||
|
||||
gtk::Label {
|
||||
#[watch]
|
||||
set_label: &model.stats_str,
|
||||
}
|
||||
},
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -84,17 +83,42 @@ impl SimpleComponent for App {
|
|||
root.set_anchor(Edge::Right, true);
|
||||
root.set_exclusive_zone(32);
|
||||
|
||||
let cpu_lbl = stat_label(4);
|
||||
let mem_lbl = stat_label(4);
|
||||
let pwr_lbl = stat_label(5);
|
||||
let bat_lbl = stat_label(4);
|
||||
let wifi_lbl = gtk4::Label::new(None);
|
||||
wifi_lbl.set_ellipsize(gtk4::pango::EllipsizeMode::End);
|
||||
wifi_lbl.set_max_width_chars(12);
|
||||
let wifi_img = gtk4::Image::from_paintable(Some(&svg_texture(asset!("WiFi Connecting.svg"))));
|
||||
|
||||
let mut model = App {
|
||||
workspaces: vec![],
|
||||
active_ws: 1,
|
||||
time_str: bar::clock::current(),
|
||||
stats_str: String::new(),
|
||||
workspace_box: gtk4::Box::new(gtk4::Orientation::Horizontal, 4),
|
||||
cpu_lbl: cpu_lbl.clone(),
|
||||
mem_lbl: mem_lbl.clone(),
|
||||
pwr_lbl: pwr_lbl.clone(),
|
||||
bat_lbl: bat_lbl.clone(),
|
||||
wifi_lbl: wifi_lbl.clone(),
|
||||
wifi_img: wifi_img.clone(),
|
||||
};
|
||||
let widgets = view_output!();
|
||||
|
||||
model.workspace_box = widgets.workspace_box.clone();
|
||||
|
||||
let stats_box = gtk4::Box::new(gtk4::Orientation::Horizontal, 8);
|
||||
stats_box.set_margin_end(8);
|
||||
stats_box.append(&stat_pair(asset!("CPU.svg"), &cpu_lbl));
|
||||
stats_box.append(&stat_pair(asset!("RAM Usage.svg"), &mem_lbl));
|
||||
stats_box.append(&stat_pair(asset!("Power Draw.svg"), &pwr_lbl));
|
||||
stats_box.append(&stat_pair(asset!("Battery.svg"), &bat_lbl));
|
||||
let wifi_pair = gtk4::Box::new(gtk4::Orientation::Horizontal, 4);
|
||||
wifi_pair.append(&wifi_img);
|
||||
wifi_pair.append(&wifi_lbl);
|
||||
stats_box.append(&wifi_pair);
|
||||
widgets.center_box.set_end_widget(Some(&stats_box));
|
||||
|
||||
theme::apply();
|
||||
bar::workspaces::spawn_watcher(sender.clone());
|
||||
bar::clock::spawn_ticker(sender.clone());
|
||||
|
|
@ -119,8 +143,13 @@ impl SimpleComponent for App {
|
|||
AppInput::ClockTick => {
|
||||
self.time_str = bar::clock::current();
|
||||
}
|
||||
AppInput::StatsUpdate(s) => {
|
||||
self.stats_str = s;
|
||||
AppInput::StatsUpdate(stats) => {
|
||||
self.cpu_lbl.set_label(&stats.cpu);
|
||||
self.mem_lbl.set_label(&stats.mem);
|
||||
self.pwr_lbl.set_label(&stats.power);
|
||||
self.bat_lbl.set_label(&stats.bat);
|
||||
self.wifi_lbl.set_label(&stats.wifi_ssid);
|
||||
self.wifi_img.set_paintable(Some(&svg_texture(stats.wifi_icon)));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -138,8 +167,29 @@ impl App {
|
|||
}
|
||||
}
|
||||
|
||||
fn stat_pair(icon_path: &str, label: >k4::Label) -> gtk4::Box {
|
||||
let pair = gtk4::Box::new(gtk4::Orientation::Horizontal, 4);
|
||||
pair.append(>k4::Image::from_paintable(Some(&svg_texture(icon_path))));
|
||||
pair.append(label);
|
||||
pair
|
||||
}
|
||||
|
||||
fn svg_texture(path: &str) -> gtk4::gdk::Texture {
|
||||
let svg = std::fs::read_to_string(path)
|
||||
.unwrap_or_default()
|
||||
.replace("currentColor", "white");
|
||||
let bytes = gtk4::glib::Bytes::from_owned(svg.into_bytes());
|
||||
gtk4::gdk::Texture::from_bytes(&bytes).expect("svg load")
|
||||
}
|
||||
|
||||
fn stat_label(width_chars: i32) -> gtk4::Label {
|
||||
let lbl = gtk4::Label::new(None);
|
||||
lbl.set_width_chars(width_chars);
|
||||
lbl.set_xalign(1.0);
|
||||
lbl
|
||||
}
|
||||
|
||||
fn main() {
|
||||
// Reload theme CSS on SIGHUP (e.g. after pywal runs).
|
||||
relm4::spawn(async {
|
||||
use tokio::signal::unix::{signal, SignalKind};
|
||||
let mut stream = signal(SignalKind::hangup()).expect("SIGHUP handler");
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue