mirror of
https://github.com/niri-wm/niri.git
synced 2026-06-21 02:01:55 +07:00
Parse the config on the file watcher thread
It takes a while, so let's not block the main thread.
This commit is contained in:
+12
-4
@@ -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();
|
||||
|
||||
+3
-4
@@ -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;
|
||||
|
||||
Reference in New Issue
Block a user