From 8cbd7680944b8a453f86d6c5e6ba4e8c3aeccb6e Mon Sep 17 00:00:00 2001 From: Joe Wilm Date: Fri, 11 Nov 2016 17:40:12 -0800 Subject: [PATCH] Fix resize on macOS leaving screen blank This still has a problem where intermediate sizes are not drawn. Apparently cocoa blocks the event loop during resize. This needs to be fixed in Glutin. Resolves #16. --- src/main.rs | 27 +++++++++++++++++++-------- 1 file changed, 19 insertions(+), 8 deletions(-) diff --git a/src/main.rs b/src/main.rs index 9a4a2cb6..38ecde39 100644 --- a/src/main.rs +++ b/src/main.rs @@ -75,7 +75,7 @@ use term::Term; use tty::process_should_exit; /// Channel used by resize handling on mac -static mut RESIZE_SENDER: Option> = None; +static mut RESIZE_CALLBACK: Option> = None; #[derive(Clone)] pub struct Flag(Arc); @@ -98,9 +98,7 @@ impl Flag { /// Resize handling for Mac fn window_resize_handler(width: u32, height: u32) { unsafe { - if let Some(ref tx) = RESIZE_SENDER { - let _ = tx.send((width, height)); - } + RESIZE_CALLBACK.as_ref().map(|func| func(width, height)); } } @@ -189,16 +187,29 @@ fn main() { let pty_io = terminal.tty().reader(); let (tx, rx) = mpsc::channel(); - unsafe { - RESIZE_SENDER = Some(tx.clone()); - } let signal_flag = Flag::new(false); - let terminal = Arc::new(FairMutex::new(terminal)); let window = Arc::new(window); + // Setup the rsize callback for osx + let terminal_ref = terminal.clone(); + let signal_flag_ref = signal_flag.clone(); + let proxy = window.create_window_proxy(); + let tx2 = tx.clone(); + unsafe { + RESIZE_CALLBACK = Some(Box::new(move |width: u32, height: u32| { + let _ = tx2.send((width, height)); + if !signal_flag_ref.0.swap(true, Ordering::AcqRel) { + // We raised the signal flag + let mut terminal = terminal_ref.lock(); + terminal.dirty = true; + proxy.wakeup_event_loop(); + } + })); + } + let event_loop = EventLoop::new( terminal.clone(), window.create_window_proxy(),