From 4901b5d77d73db59f0c1545719ec6d1404aad979 Mon Sep 17 00:00:00 2001 From: cashmere Date: Sun, 16 Aug 2026 08:21:37 +0200 Subject: Run detached and reload config live --- src/state.rs | 44 +++++++++++++++++++++++++++++++++++++++++++- 1 file changed, 43 insertions(+), 1 deletion(-) (limited to 'src/state.rs') diff --git a/src/state.rs b/src/state.rs index 2853731..dc7ff15 100644 --- a/src/state.rs +++ b/src/state.rs @@ -188,6 +188,44 @@ impl State { .map(|cmd| cmd.output.as_raw_fd()) } + pub fn reload_config( + &mut self, + conn: &mut Connection, + config_path: &Path, + ) -> anyhow::Result> { + let config = Config::new(Some(config_path))?; + let command_changed = config.command != self.shared_state.config.command; + let status_cmd = if command_changed { + match config.command.as_deref() { + Some(command) => Some(StatusCmd::new(command)?), + None => None, + } + } else { + self.shared_state.status_cmd.take() + }; + + if command_changed && let Some(mut old_status_cmd) = self.shared_state.status_cmd.take() { + let _ = old_status_cmd.child.kill(); + } + + self.shared_state.config = config; + self.shared_state.status_cmd = status_cmd; + if command_changed || self.has_error { + self.shared_state.blocks_cache = BlocksCache::default(); + } else { + self.shared_state + .blocks_cache + .config_changed(&self.shared_state.config); + } + self.has_error = false; + for bar in &mut self.bars { + bar.config_changed(conn, &self.shared_state); + } + self.draw_all(conn); + + Ok(command_changed.then(|| self.status_cmd_fd()).flatten()) + } + pub fn register_output(&mut self, conn: &mut Connection, output: Output) { if !self.shared_state.config.output_enabled(&output.name) { return; @@ -264,7 +302,11 @@ impl State { }); } - pub fn focused_window_updated(&mut self, conn: &mut Connection, output: Option) { + pub fn focused_window_updated( + &mut self, + conn: &mut Connection, + output: Option, + ) { self.for_each_bar(output, |bar, ss| { bar.set_focused_window(ss.wm_info_provider.get_focused_window(&bar.output)); bar.frame(conn, ss); -- cgit v1.3.1