From 729eef0c933831bccfeac6a355bdb410787fbe5f Mon Sep 17 00:00:00 2001 From: Christian Duerr Date: Sat, 5 Oct 2019 02:29:26 +0200 Subject: Update to winit/glutin EventLoop 2.0 This takes the latest glutin master to port Alacritty to the EventLoop 2.0 rework. This changes a big part of the event loop handling by pushing the event loop in a separate thread from the renderer and running both in parallel. Fixes #2796. Fixes #2694. Fixes #2643. Fixes #2625. Fixes #2618. Fixes #2601. Fixes #2564. Fixes #2456. Fixes #2438. Fixes #2334. Fixes #2254. Fixes #2217. Fixes #1789. Fixes #1750. Fixes #1125. --- alacritty/src/config/monitor.rs | 58 +++++++++++++++++++++++++++++++++++++++++ 1 file changed, 58 insertions(+) create mode 100644 alacritty/src/config/monitor.rs (limited to 'alacritty/src/config/monitor.rs') diff --git a/alacritty/src/config/monitor.rs b/alacritty/src/config/monitor.rs new file mode 100644 index 00000000..8dc5379a --- /dev/null +++ b/alacritty/src/config/monitor.rs @@ -0,0 +1,58 @@ +use std::path::PathBuf; +use std::sync::mpsc; +use std::time::Duration; + +use notify::{watcher, DebouncedEvent, RecursiveMode, Watcher}; + +use alacritty_terminal::event::{Event, EventListener}; +use alacritty_terminal::util; + +use crate::event::EventProxy; + +pub struct Monitor { + _thread: ::std::thread::JoinHandle<()>, +} + +impl Monitor { + pub fn new

(path: P, event_proxy: EventProxy) -> Monitor + where + P: Into, + { + let path = path.into(); + + Monitor { + _thread: util::thread::spawn_named("config watcher", move || { + let (tx, rx) = mpsc::channel(); + // The Duration argument is a debouncing period. + let mut watcher = + watcher(tx, Duration::from_millis(10)).expect("Unable to spawn file watcher"); + let config_path = ::std::fs::canonicalize(path).expect("canonicalize config path"); + + // Get directory of config + let mut parent = config_path.clone(); + parent.pop(); + + // Watch directory + watcher + .watch(&parent, RecursiveMode::NonRecursive) + .expect("watch alacritty.yml dir"); + + loop { + match rx.recv().expect("watcher event") { + DebouncedEvent::Rename(..) => continue, + DebouncedEvent::Write(path) + | DebouncedEvent::Create(path) + | DebouncedEvent::Chmod(path) => { + if path != config_path { + continue; + } + + event_proxy.send_event(Event::ConfigReload(path)); + }, + _ => {}, + } + } + }), + } + } +} -- cgit