diff options
| author | cashmere <cashmere@autistici.org> | 2026-08-16 08:21:37 +0200 |
|---|---|---|
| committer | cashmere <cashmere@autistici.org> | 2026-08-16 08:21:37 +0200 |
| commit | 4901b5d77d73db59f0c1545719ec6d1404aad979 (patch) | |
| tree | 0b3233e82387ffe7a9cd5c0934971a665e0575a9 /src/state.rs | |
| parent | 91b84d1f1bfbc5de2eb140a48185a5252b1b592e (diff) | |
| download | i3bar-mango-4901b5d77d73db59f0c1545719ec6d1404aad979.tar.gz | |
Diffstat (limited to 'src/state.rs')
| -rw-r--r-- | src/state.rs | 44 |
1 files changed, 43 insertions, 1 deletions
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<Self>, + config_path: &Path, + ) -> anyhow::Result<Option<RawFd>> { + 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<Self>, 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<Self>, output: Option<WlOutput>) { + pub fn focused_window_updated( + &mut self, + conn: &mut Connection<Self>, + output: Option<WlOutput>, + ) { self.for_each_bar(output, |bar, ss| { bar.set_focused_window(ss.wm_info_provider.get_focused_window(&bar.output)); bar.frame(conn, ss); |
