diff options
author | Joe Wilm <joe@jwilm.com> | 2016-12-12 09:31:48 -0800 |
---|---|---|
committer | Joe Wilm <joe@jwilm.com> | 2016-12-12 09:31:48 -0800 |
commit | 1a1b740c38cfbadff4cd985ee925ac024627d2b9 (patch) | |
tree | 98f51ebedcc1abff0101da7747403b0d8aee698f /src/main.rs | |
parent | 4e9a307bed50fc02f101eb6cbfa4d39283dd6b8c (diff) | |
download | alacritty-1a1b740c38cfbadff4cd985ee925ac024627d2b9.tar.gz alacritty-1a1b740c38cfbadff4cd985ee925ac024627d2b9.zip |
Remove need for Rc<RefCell<_>> usage
This adds a trait OnResize and a separate method handle_resize to the
display. Instead of having a callback to receive resize events, a list
of &mut OnResize are passed to this new method. Doing this allowed the
only RefCell usage in the codebase to be removed :).
Diffstat (limited to 'src/main.rs')
-rw-r--r-- | src/main.rs | 36 |
1 files changed, 13 insertions, 23 deletions
diff --git a/src/main.rs b/src/main.rs index 7ae45787..c917fe43 100644 --- a/src/main.rs +++ b/src/main.rs @@ -18,9 +18,7 @@ #[macro_use] extern crate alacritty; -use std::cell::RefCell; use std::error::Error; -use std::rc::Rc; use std::sync::Arc; use alacritty::cli; @@ -86,7 +84,7 @@ fn run(config: Config, options: cli::Options) -> Result<(), Box<Error>> { // The pty forks a process to run the shell on the slave side of the // pseudoterminal. A file descriptor for the master side is retained for // reading/writing to the shell. - let pty = tty::new(display.size()); + let mut pty = tty::new(display.size()); // Create the pseudoterminal I/O loop // @@ -108,28 +106,13 @@ fn run(config: Config, options: cli::Options) -> Result<(), Box<Error>> { // Event processor // // Need the Rc<RefCell<_>> here since a ref is shared in the resize callback - let processor = Rc::new(RefCell::new(event::Processor::new( + let mut processor = event::Processor::new( input::LoopNotifier(loop_tx), terminal.clone(), display.resize_channel(), &config, options.ref_test, - ))); - - // Configure the display resize callback - let processor_ref = processor.clone(); - display.set_resize_callback(move |size| { - // Resizing the pty lets the child processes know the window changed - // size. - pty.resize(size); - - // It's a bit funny that the event processor is in this callback since - // on some platforms it's the first to be aware of a resize event. It - // appears here since resizes are processed out-of-band from when the - // events arrive. This way, the processor state is updated at the same - // time as the rest of the system. - processor_ref.borrow_mut().resize(size) - }); + ); // Create a config monitor when config was loaded from path // @@ -144,20 +127,27 @@ fn run(config: Config, options: cli::Options) -> Result<(), Box<Error>> { // Main display loop loop { // Process input and window events - let wakeup_request = processor.borrow_mut().process_events(display.window()); + let wakeup_request = processor.process_events(display.window()); // Handle config reloads let config_updated = config_monitor.as_ref() .and_then(|monitor| monitor.pending_config()) .map(|config| { display.update_config(&config); - processor.borrow_mut().update_config(&config); + processor.update_config(&config); true }).unwrap_or(false); // Maybe draw the terminal - let terminal = terminal.lock(); + let mut terminal = terminal.lock(); if wakeup_request || config_updated { + // Handle pending resize events + // + // The second argument is a list of types that want to be notified + // of display size changes. + display.handle_resize(&mut terminal, &mut [&mut pty, &mut processor]); + + // Draw the current state of the terminal display.draw(terminal, &config); } |