Parse the config on the file watcher thread
Browse files at this commitef80bcc83414d2e9a1cd14cc62ee021968e67128Parent: eb8bd382 changed files +15 -8
- src/main.rs +12 -4
- src/niri.rs +3 -4
src/main.rsmodified+12 -4
| @@ -5,7 +5,7 @@ use std::fmt::Write as _; | |||
| 5 | use std::fs::{self, File}; | 5 | use std::fs::{self, File}; |
| 6 | use std::io::{self, Write}; | 6 | use std::io::{self, Write}; |
| 7 | use std::os::fd::FromRawFd; | 7 | use std::os::fd::FromRawFd; |
| 8 | -use std::path::PathBuf; | 8 | +use std::path::{Path, PathBuf}; |
| 9 | use std::process::Command; | 9 | use std::process::Command; |
| 10 | use std::{env, mem}; | 10 | use std::{env, mem}; |
| 11 | 11 | ||
| @@ -230,12 +230,20 @@ fn main() -> Result<(), Box<dyn std::error::Error>> { | |||
| 230 | 230 | ||
| 231 | // Set up config file watcher. | 231 | // Set up config file watcher. |
| 232 | let _watcher = { | 232 | let _watcher = { |
| 233 | + // Parsing the config actually takes > 20 ms on my beefy machine, so let's do it on the | ||
| 234 | + // watcher thread. | ||
| 235 | + let process = |path: &Path| { | ||
| 236 | + Config::load(path).map_err(|err| { | ||
| 237 | + warn!("{:?}", err.context("error loading config")); | ||
| 238 | + }) | ||
| 239 | + }; | ||
| 240 | + | ||
| 233 | let (tx, rx) = calloop::channel::sync_channel(1); | 241 | let (tx, rx) = calloop::channel::sync_channel(1); |
| 234 | - let watcher = Watcher::new(watch_path.clone(), |_| (), tx); | 242 | + let watcher = Watcher::new(watch_path.clone(), process, tx); |
| 235 | event_loop | 243 | event_loop |
| 236 | .handle() | 244 | .handle() |
| 237 | - .insert_source(rx, move |event, _, state| match event { | 245 | + .insert_source(rx, |event, _, state| match event { |
| 238 | - calloop::channel::Event::Msg(()) => state.reload_config(watch_path.clone()), | 246 | + calloop::channel::Event::Msg(config) => state.reload_config(config), |
| 239 | calloop::channel::Event::Closed => (), | 247 | calloop::channel::Event::Closed => (), |
| 240 | }) | 248 | }) |
| 241 | .unwrap(); | 249 | .unwrap(); |
src/niri.rsmodified+3 -4
| @@ -1118,13 +1118,12 @@ impl State { | |||
| 1118 | } | 1118 | } |
| 1119 | } | 1119 | } |
| 1120 | 1120 | ||
| 1121 | - pub fn reload_config(&mut self, path: PathBuf) { | 1121 | + pub fn reload_config(&mut self, config: Result<Config, ()>) { |
| 1122 | let _span = tracy_client::span!("State::reload_config"); | 1122 | let _span = tracy_client::span!("State::reload_config"); |
| 1123 | 1123 | ||
| 1124 | - let mut config = match Config::load(&path) { | 1124 | + let mut config = match config { |
| 1125 | Ok(config) => config, | 1125 | Ok(config) => config, |
| 1126 | - Err(err) => { | 1126 | + Err(()) => { |
| 1127 | - warn!("{:?}", err.context("error loading config")); | ||
| 1128 | self.niri.config_error_notification.show(); | 1127 | self.niri.config_error_notification.show(); |
| 1129 | self.niri.queue_redraw_all(); | 1128 | self.niri.queue_redraw_all(); |
| 1130 | return; | 1129 | return; |