diff options
Diffstat (limited to 'src')
| -rw-r--r-- | src/main.rs | 16 | ||||
| -rw-r--r-- | src/niri.rs | 7 |
2 files changed, 15 insertions, 8 deletions
diff --git a/src/main.rs b/src/main.rs index 7252d4ca..0a79af2d 100644 --- a/src/main.rs +++ b/src/main.rs @@ -5,7 +5,7 @@ use std::fmt::Write as _; use std::fs::{self, File}; use std::io::{self, Write}; use std::os::fd::FromRawFd; -use std::path::PathBuf; +use std::path::{Path, PathBuf}; use std::process::Command; use std::{env, mem}; @@ -230,12 +230,20 @@ fn main() -> Result<(), Box<dyn std::error::Error>> { // Set up config file watcher. let _watcher = { + // Parsing the config actually takes > 20 ms on my beefy machine, so let's do it on the + // watcher thread. + let process = |path: &Path| { + Config::load(path).map_err(|err| { + warn!("{:?}", err.context("error loading config")); + }) + }; + let (tx, rx) = calloop::channel::sync_channel(1); - let watcher = Watcher::new(watch_path.clone(), |_| (), tx); + let watcher = Watcher::new(watch_path.clone(), process, tx); event_loop .handle() - .insert_source(rx, move |event, _, state| match event { - calloop::channel::Event::Msg(()) => state.reload_config(watch_path.clone()), + .insert_source(rx, |event, _, state| match event { + calloop::channel::Event::Msg(config) => state.reload_config(config), calloop::channel::Event::Closed => (), }) .unwrap(); diff --git a/src/niri.rs b/src/niri.rs index b1b9a90c..6dc38bc3 100644 --- a/src/niri.rs +++ b/src/niri.rs @@ -1118,13 +1118,12 @@ impl State { } } - pub fn reload_config(&mut self, path: PathBuf) { + pub fn reload_config(&mut self, config: Result<Config, ()>) { let _span = tracy_client::span!("State::reload_config"); - let mut config = match Config::load(&path) { + let mut config = match config { Ok(config) => config, - Err(err) => { - warn!("{:?}", err.context("error loading config")); + Err(()) => { self.niri.config_error_notification.show(); self.niri.queue_redraw_all(); return; |
