mirror of
https://github.com/niri-wm/niri.git
synced 2026-06-23 02:05:33 +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::fs::{self, File};
|
||||||
use std::io::{self, Write};
|
use std::io::{self, Write};
|
||||||
use std::os::fd::FromRawFd;
|
use std::os::fd::FromRawFd;
|
||||||
use std::path::PathBuf;
|
use std::path::{Path, PathBuf};
|
||||||
use std::process::Command;
|
use std::process::Command;
|
||||||
use std::{env, mem};
|
use std::{env, mem};
|
||||||
|
|
||||||
@@ -230,12 +230,20 @@ fn main() -> Result<(), Box<dyn std::error::Error>> {
|
|||||||
|
|
||||||
// Set up config file watcher.
|
// Set up config file watcher.
|
||||||
let _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 (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
|
event_loop
|
||||||
.handle()
|
.handle()
|
||||||
.insert_source(rx, move |event, _, state| match event {
|
.insert_source(rx, |event, _, state| match event {
|
||||||
calloop::channel::Event::Msg(()) => state.reload_config(watch_path.clone()),
|
calloop::channel::Event::Msg(config) => state.reload_config(config),
|
||||||
calloop::channel::Event::Closed => (),
|
calloop::channel::Event::Closed => (),
|
||||||
})
|
})
|
||||||
.unwrap();
|
.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 _span = tracy_client::span!("State::reload_config");
|
||||||
|
|
||||||
let mut config = match Config::load(&path) {
|
let mut config = match config {
|
||||||
Ok(config) => config,
|
Ok(config) => config,
|
||||||
Err(err) => {
|
Err(()) => {
|
||||||
warn!("{:?}", err.context("error loading config"));
|
|
||||||
self.niri.config_error_notification.show();
|
self.niri.config_error_notification.show();
|
||||||
self.niri.queue_redraw_all();
|
self.niri.queue_redraw_all();
|
||||||
return;
|
return;
|
||||||
|
|||||||
Reference in New Issue
Block a user