tracing and changes

This commit is contained in:
2026-09-13 16:25:47 +01:00
parent 74f59be3f8
commit 57201bc0ff
17 changed files with 306 additions and 47 deletions
+7 -1
View File
@@ -39,10 +39,16 @@ impl Bar {
.collect();
// One inbox per distinct service any module wants.
let wanted: BTreeSet<&'static str> = routes.values().flatten().map(|s| s.0).collect();
let inputs = wanted
tracing::debug!(?routes, "module routes: wanted msg types per module");
let inputs: BTreeMap<&'static str, Inbox> = wanted
.into_iter()
.map(|key| (key, Inbox::new(key)))
.collect();
tracing::debug!(
modules = modules.len(),
services = ?inputs.keys().copied().collect::<Vec<_>>(),
"spawning wanted services"
);
Self {
active_popup: None,
modules,
+22 -6
View File
@@ -27,27 +27,43 @@ pub(crate) use msg::{Message, Msg};
/// Height of the bar in logical pixels.
const BAR_HEIGHT: u32 = 36;
fn main() -> Result<(), iced_layershell::Error> {
let args = args::Args::parse();
/// Default log filter per build profile. Debug builds log barbar's own crates
/// at `debug` while dependency noise (iced_layershell/sctk/cosmic_text/wgpu…)
/// stays at `warn`; release builds log `warn` and above. `RUST_LOG` overrides.
const DEFAULT_FILTER: &str = if cfg!(debug_assertions) {
"warn,core=debug,common=debug,modules=debug,services=debug"
} else {
"warn"
};
let config_handle = File::open(args.config);
fn main() -> Result<(), iced_layershell::Error> {
let filter = tracing_subscriber::EnvFilter::try_from_default_env()
.unwrap_or_else(|_| tracing_subscriber::EnvFilter::new(DEFAULT_FILTER));
tracing_subscriber::fmt().with_env_filter(filter).init();
let args = args::Args::parse();
tracing::debug!(config = %args.config.display(), "parsed args");
let config_handle = File::open(&args.config);
let config: BarbarConfig;
if let Ok(mut config_file) = config_handle {
let mut string = String::new();
config_file.read_to_string(&mut string).unwrap();
config = toml::from_str(&string).unwrap();
tracing::info!(config = %args.config.display(), "config loaded");
} else {
println!("cant open config file");
tracing::warn!(config = %args.config.display(), "cannot open config file");
return Ok(());
}
let start_mode = match config.monitor {
Some(x) => StartMode::TargetScreen(x),
let start_mode = match &config.monitor {
Some(x) => StartMode::TargetScreen(x.clone()),
None => StartMode::Active,
};
let modules = config.modules.clone().unwrap_or_default();
let order = config.order;
tracing::info!(monitor = ?config.monitor, "starting barbar daemon");
daemon(
move || {
+2
View File
@@ -48,6 +48,7 @@ pub fn open_popup(bar: &mut Bar, module_id: String, bounds: Rectangle) -> Task<M
let (id, task) = popup_open(settings);
bar.popup_id = Some(id);
tracing::debug!(module = %module_id, ?id, size = ?(w, h), "popup opened");
task
}
@@ -55,6 +56,7 @@ pub fn open_popup(bar: &mut Bar, module_id: String, bounds: Rectangle) -> Task<M
/// `Msg::WindowClosed`, so popup content keeps rendering until then.
pub fn close_popup(bar: &mut Bar) -> Task<Message> {
if let Some(id) = bar.popup_id {
tracing::debug!(?id, "requesting popup close");
return Task::done(Message::Effect(ModuleEffect::ClosePopup(id)));
}
Task::none()
+17 -4
View File
@@ -26,6 +26,7 @@ fn handle_event(bar: &mut Bar, event: Msg) -> Task<Message> {
if bar.popup_id == Some(id) {
bar.popup_id = None;
bar.active_popup = None;
tracing::debug!(?id, "popup window closed");
}
Task::none()
}
@@ -37,12 +38,19 @@ fn route(bar: &mut Bar, wire: Wire) -> Task<Message> {
match wire.to {
Target::Module(id) => match bar.modules.get_mut(id) {
Some(module) => module.update(wire).map(Message::Effect),
None => Task::none(),
None => {
tracing::warn!(module = id, "wire routed to unknown module");
Task::none()
}
},
Target::Service(key) => {
if let Some(inbox) = bar.inputs.get(key) {
inbox.send(wire);
if !inbox.send(wire) {
tracing::warn!(service = key, "service inbox closed");
}
} else {
tracing::warn!(service = key, "wire routed to unknown service");
}
Task::none()
}
@@ -51,7 +59,8 @@ fn route(bar: &mut Bar, wire: Wire) -> Task<Message> {
// Fan out by route key; the payload is opaque here, each module
// downcasts it. New services never touch this file.
let topic = Service(key);
bar.modules
let tasks: Vec<_> = bar
.modules
.iter_mut()
.filter(|(id, _)| {
bar.routes
@@ -59,7 +68,9 @@ fn route(bar: &mut Bar, wire: Wire) -> Task<Message> {
.is_some_and(|keys| keys.contains(&topic))
})
.map(|(_, module)| module.update(wire.clone()).map(Message::Effect))
.fold(Task::none(), |acc, t| acc.chain(t))
.collect();
tracing::debug!(topic = key, subscribers = tasks.len(), "fan-out");
tasks.into_iter().fold(Task::none(), |acc, t| acc.chain(t))
}
}
}
@@ -70,8 +81,10 @@ fn handle_effect(bar: &mut Bar, effect: ModuleEffect) -> Task<Message> {
ModuleEffect::RequestPopup(module_id, element_id) => {
// Toggle: close if already open for this module, else open.
if bar.active_popup.as_deref() == Some(module_id.as_str()) {
tracing::debug!(module = %module_id, "closing popup");
popup::close_popup(bar)
} else {
tracing::debug!(module = %module_id, "opening popup");
popup::capture_bounds(module_id, element_id)
}
}
+34 -6
View File
@@ -1,5 +1,5 @@
use common::Wire;
use iced::widget::{container, row, text};
use iced::widget::{container, row, space, text};
use iced::{window, Alignment, Element, Length, Theme};
use crate::app::Bar;
@@ -33,21 +33,49 @@ fn bar_view(bar: &Bar) -> Element<'_, Message> {
.view(None)
.map(|w| Message::Event(Msg::Wire(w)))
})
.collect::<Vec<Element<Message>>>());
.collect::<Vec<Element<Message>>>())
.spacing(8);
let middle = row(bar
.order
.1
.iter()
.map(|x| bar.modules.get(x.to_string()).unwrap().view(None)));
.map(|x| {
bar.modules
.get(x.to_string())
.unwrap()
.view(None)
.map(|w| Message::Event(Msg::Wire(w)))
})
.collect::<Vec<Element<Message>>>())
.spacing(8);
let right = row(bar
.order
.2
.iter()
.map(|x| bar.modules.get(x.to_string()).unwrap().view(None)));
.map(|x| {
bar.modules
.get(x.to_string())
.unwrap()
.view(None)
.map(|w| Message::Event(Msg::Wire(w)))
})
.collect::<Vec<Element<Message>>>())
.spacing(8);
container(left.width(Length::Fill).align_y(Alignment::Center))
let row = row![
left,
space::horizontal(),
middle,
space::horizontal(),
right,
]
.width(Length::Fill);
container(row)
.padding(8)
.align_x(Alignment::Center)
.width(Length::Fill)
.align_y(Alignment::Center)
.into()
}