diff options
author | Joe Wilm <joe@jwilm.com> | 2016-12-29 21:38:22 -0500 |
---|---|---|
committer | Joe Wilm <joe@jwilm.com> | 2016-12-29 21:38:22 -0500 |
commit | a91a3f2dce121a179a9371cd0ad1e548cf3d7731 (patch) | |
tree | 311f1ee1b60eb9fb11bad3bdee8812d3be5590b8 /src/event.rs | |
parent | b704dafb2420df6f7fca64980a2f52c1a00bcef5 (diff) | |
download | alacritty-a91a3f2dce121a179a9371cd0ad1e548cf3d7731.tar.gz alacritty-a91a3f2dce121a179a9371cd0ad1e548cf3d7731.zip |
Fix pty read sometimes not triggering draw
There was a lot of complexity around the threadsafe `Flag` type and
waking up the event loop. The idea was to prevent unnecessary calls to
the glutin window's wakeup_event_loop() method which can be expensive.
This complexity made it difficult to get synchronization between the pty
reader and the render thread correct. Now, the `dirty` flag on the
terminal is also used to prevent spurious wakeups. It is only changed
when the mutex is held, so race conditions associated with that flag
shouldn't happen.
Diffstat (limited to 'src/event.rs')
-rw-r--r-- | src/event.rs | 26 |
1 files changed, 9 insertions, 17 deletions
diff --git a/src/event.rs b/src/event.rs index c516f151..bfcb3f3c 100644 --- a/src/event.rs +++ b/src/event.rs @@ -105,7 +105,6 @@ impl<N: Notify> Processor<N> { fn handle_event<'a>( processor: &mut input::Processor<'a, N>, event: glutin::Event, - wakeup_request: &mut bool, ref_test: bool, resize_tx: &mpsc::Sender<(u32, u32)>, ) { @@ -135,18 +134,14 @@ impl<N: Notify> Processor<N> { }, glutin::Event::Resized(w, h) => { resize_tx.send((w, h)).expect("send new size"); - - // Previously, this marked the terminal state as "dirty", but - // now the wakeup_request controls whether a display update is - // triggered. - *wakeup_request = true; + processor.ctx.terminal.dirty = true; }, glutin::Event::KeyboardInput(state, _code, key, mods, string) => { processor.process_key(state, key, mods, string); }, glutin::Event::MouseInput(state, button) => { processor.mouse_input(state, button); - *wakeup_request = true; + processor.ctx.terminal.dirty = true; }, glutin::Event::MouseMoved(x, y) => { let x = limit(x, 0, processor.ctx.size_info.width as i32); @@ -155,17 +150,17 @@ impl<N: Notify> Processor<N> { processor.mouse_moved(x as u32, y as u32); if !processor.ctx.selection.is_empty() { - *wakeup_request = true; + processor.ctx.terminal.dirty = true; } }, glutin::Event::Focused(true) => { - *wakeup_request = true; + processor.ctx.terminal.dirty = true; }, glutin::Event::MouseWheel(scroll_delta, touch_phase) => { processor.on_mouse_wheel(scroll_delta, touch_phase); }, glutin::Event::Awakened => { - *wakeup_request = true; + processor.ctx.terminal.dirty = true; }, _ => (), } @@ -176,13 +171,11 @@ impl<N: Notify> Processor<N> { &mut self, term: &'a FairMutex<Term>, window: &Window - ) -> (MutexGuard<'a, Term>, bool) { - let mut wakeup_request = false; - + ) -> MutexGuard<'a, Term> { // Terminal is lazily initialized the first time an event is returned // from the blocking WaitEventsIterator. Otherwise, the pty reader would // be blocked the entire time we wait for input! - let terminal; + let mut terminal; { // Ditto on lazy initialization for context and processor. @@ -195,7 +188,6 @@ impl<N: Notify> Processor<N> { Processor::handle_event( &mut processor, $event, - &mut wakeup_request, self.ref_test, &self.resize_tx, ) @@ -206,7 +198,7 @@ impl<N: Notify> Processor<N> { Some(event) => { terminal = term.lock(); context = ActionContext { - terminal: &terminal, + terminal: &mut terminal, notifier: &mut self.notifier, selection: &mut self.selection, mouse: &mut self.mouse, @@ -230,7 +222,7 @@ impl<N: Notify> Processor<N> { } } - (terminal, wakeup_request) + terminal } pub fn update_config(&mut self, config: &Config) { |