aboutsummaryrefslogtreecommitdiff
path: root/src/main.rs
diff options
context:
space:
mode:
authorJoe Wilm <joe@jwilm.com>2016-10-27 10:05:04 -0700
committerJoe Wilm <joe@jwilm.com>2016-10-27 10:16:08 -0700
commit06ea6c8e565af0fdddc4de80f59435cfe05670c2 (patch)
tree76f5b8b667862da0bde080fc694761052bf46ff5 /src/main.rs
parent0958c0f0f28664fe2f48ad1b552b69b0ced731c1 (diff)
downloadalacritty-06ea6c8e565af0fdddc4de80f59435cfe05670c2.tar.gz
alacritty-06ea6c8e565af0fdddc4de80f59435cfe05670c2.zip
Move config reloading to separate thread
This feature was previously shoved into the renderer due to initial proof of concept. Now, providing config updates to other systems is possible. This will be especially important for key bindings!
Diffstat (limited to 'src/main.rs')
-rw-r--r--src/main.rs44
1 files changed, 41 insertions, 3 deletions
diff --git a/src/main.rs b/src/main.rs
index 01c5f511..8a2159e8 100644
--- a/src/main.rs
+++ b/src/main.rs
@@ -118,14 +118,14 @@ mod gl {
fn main() {
// Load configuration
- let config = match Config::load() {
+ let (config, config_path) = match Config::load() {
Err(err) => match err {
// Use default config when not found
- config::Error::NotFound => Config::default(),
+ config::Error::NotFound => (Config::default(), None),
// Exit when there's a problem with it
_ => die!("{}", err),
},
- Ok(config) => config,
+ Ok((config, path)) => (config, Some(path)),
};
let font = config.font();
@@ -225,11 +225,25 @@ fn main() {
tx
);
+ let (config_tx, config_rx) = mpsc::channel();
+
+ // create a config watcher when config is loaded from disk
+ let _config_reloader = config_path.map(|config_path| {
+ config::Watcher::new(config_path, ConfigHandler {
+ tx: config_tx,
+ window: window.create_window_proxy(),
+ })
+ });
+
// Main loop
loop {
// Wait for something to happen
processor.process_events(&window);
+ if let Ok(config) = config_rx.try_recv() {
+ display.update_config(&config);
+ }
+
// Maybe draw the terminal
let terminal = terminal.lock();
signal_flag.set(false);
@@ -242,11 +256,31 @@ fn main() {
}
}
+ // FIXME need file watcher to work with custom delegates before
+ // joining config reloader is possible
+ // config_reloader.join().ok();
+
// shutdown
event_loop_handle.join().ok();
println!("Goodbye");
}
+struct ConfigHandler {
+ tx: mpsc::Sender<config::Config>,
+ window: ::glutin::WindowProxy,
+}
+
+impl config::OnConfigReload for ConfigHandler {
+ fn on_config_reload(&mut self, config: Config) {
+ if let Err(..) = self.tx.send(config) {
+ err_println!("Failed to notify of new config");
+ return;
+ }
+
+ self.window.wakeup_event_loop();
+ }
+}
+
struct Display {
window: Arc<glutin::Window>,
renderer: QuadRenderer,
@@ -257,6 +291,10 @@ struct Display {
}
impl Display {
+ pub fn update_config(&mut self, config: &Config) {
+ self.renderer.update_config(config);
+ }
+
pub fn new(window: Arc<glutin::Window>,
renderer: QuadRenderer,
glyph_cache: GlyphCache,