diff options
author | Joe Wilm <joe@jwilm.com> | 2016-12-11 22:02:03 -0800 |
---|---|---|
committer | Joe Wilm <joe@jwilm.com> | 2016-12-11 22:02:03 -0800 |
commit | 4b63bddd55853e878ec0f85b4613dd02749a3811 (patch) | |
tree | 02faaf58b29e3e8c5767bca1c2254376d2f47fb6 /src/main.rs | |
parent | 79e02b0b2f2feb127ff1c7dc998d4696e005003a (diff) | |
download | alacritty-4b63bddd55853e878ec0f85b4613dd02749a3811.tar.gz alacritty-4b63bddd55853e878ec0f85b4613dd02749a3811.zip |
Track terminal cells on mouse movement
The cell under the cursor is now tracked in the input processor at
`self.mouse.line` and `self.mouse.column`. This could probably be
optimized to only compute the cell when in certain states, but the
calculation is cheap.
Diffstat (limited to 'src/main.rs')
-rw-r--r-- | src/main.rs | 41 |
1 files changed, 24 insertions, 17 deletions
diff --git a/src/main.rs b/src/main.rs index d4194c28..7ae45787 100644 --- a/src/main.rs +++ b/src/main.rs @@ -18,9 +18,10 @@ #[macro_use] extern crate alacritty; +use std::cell::RefCell; use std::error::Error; -use std::sync::Arc; use std::rc::Rc; +use std::sync::Arc; use alacritty::cli; use alacritty::config::{self, Config}; @@ -85,18 +86,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 = Rc::new(tty::new(display.size())); - - // When the display is resized, inform the kernel of changes to pty - // dimensions. - // - // TODO: The Rc on pty is needed due to a borrowck error here. The borrow - // checker says that `pty` is still borrowed when it is dropped at the end - // of the `run` function. - let pty_ref = pty.clone(); - display.set_resize_callback(move |size| { - pty_ref.resize(size); - }); + let pty = tty::new(display.size()); // Create the pseudoterminal I/O loop // @@ -116,13 +106,30 @@ fn run(config: Config, options: cli::Options) -> Result<(), Box<Error>> { let loop_tx = event_loop.channel(); // Event processor - let mut processor = event::Processor::new( + // + // Need the Rc<RefCell<_>> here since a ref is shared in the resize callback + let processor = Rc::new(RefCell::new(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 // @@ -137,14 +144,14 @@ fn run(config: Config, options: cli::Options) -> Result<(), Box<Error>> { // Main display loop loop { // Process input and window events - let wakeup_request = processor.process_events(display.window()); + let wakeup_request = processor.borrow_mut().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.update_config(&config); + processor.borrow_mut().update_config(&config); true }).unwrap_or(false); |