aboutsummaryrefslogtreecommitdiff
path: root/src/main.rs
diff options
context:
space:
mode:
authorIvan Molodetskikh <yalterz@gmail.com>2025-02-12 20:53:19 +0300
committerIvan Molodetskikh <yalterz@gmail.com>2025-02-12 20:56:32 +0300
commitef80bcc83414d2e9a1cd14cc62ee021968e67128 (patch)
treea4bda62687da273dc76f07159e119792966f8e7f /src/main.rs
parenteb8bd3894a188d34d870f4d79813f75163a318b8 (diff)
downloadniri-ef80bcc83414d2e9a1cd14cc62ee021968e67128.tar.gz
niri-ef80bcc83414d2e9a1cd14cc62ee021968e67128.tar.bz2
niri-ef80bcc83414d2e9a1cd14cc62ee021968e67128.zip
Parse the config on the file watcher thread
It takes a while, so let's not block the main thread.
Diffstat (limited to 'src/main.rs')
-rw-r--r--src/main.rs16
1 files changed, 12 insertions, 4 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();