diff options
author | Joe Wilm <joe@jwilm.com> | 2016-06-29 10:21:02 -0700 |
---|---|---|
committer | Joe Wilm <joe@jwilm.com> | 2016-06-29 10:21:02 -0700 |
commit | 22789f35c7ab90a5ada70fdca25ca1c626eb1ca5 (patch) | |
tree | 4588f58a30b542a09fedc143f8ed710115440923 /src/main.rs | |
parent | 69ed81d2495c6eb548c44e73c0e9ed359d3820f0 (diff) | |
download | r-alacritty-22789f35c7ab90a5ada70fdca25ca1c626eb1ca5.tar.gz r-alacritty-22789f35c7ab90a5ada70fdca25ca1c626eb1ca5.tar.bz2 r-alacritty-22789f35c7ab90a5ada70fdca25ca1c626eb1ca5.zip |
Implement terminal resizing
The resize event is received from glutin on the update thread, but the
renderer needs to be informed as well for updating the viewport and
projection matrix. This is achieved with an mpsc::channel.
To support resizing, the grid now offers methods for growing and
shrinking, and there are several implementations available for
clear_region based on different Range* types.
Core resize logic is all in Term::resize. It attempts to keep as much
context as possible when shinking the window. When growing, it's
basically just adding rows.
Diffstat (limited to 'src/main.rs')
-rw-r--r-- | src/main.rs | 18 |
1 files changed, 18 insertions, 0 deletions
diff --git a/src/main.rs b/src/main.rs index 49f2655e..de0ea05e 100644 --- a/src/main.rs +++ b/src/main.rs @@ -65,6 +65,7 @@ fn handle_event<W>(event: Event, writer: &mut W, terminal: &mut Term, pty_parser: &mut ansi::Parser, + render_tx: &mpsc::Sender<(u32, u32)>, input_processor: &mut input::Processor) -> ShouldExit where W: Write { @@ -78,6 +79,10 @@ fn handle_event<W>(event: Event, let encoded = c.encode_utf8(); writer.write(encoded.as_slice()).unwrap(); }, + glutin::Event::Resized(w, h) => { + terminal.resize(w as f32, h as f32); + render_tx.send((w, h)).expect("render thread active"); + }, glutin::Event::KeyboardInput(state, _code, key) => { input_processor.process(state, key, &mut WriteNotifier(writer), *terminal.mode()) }, @@ -165,6 +170,8 @@ fn main() { let window = Arc::new(window); let window_ref = window.clone(); + let (render_tx, render_rx) = mpsc::channel::<(u32, u32)>(); + let update_thread = thread::spawn_named("Update", move || { 'main_loop: loop { let mut writer = BufWriter::new(&writer); @@ -192,6 +199,7 @@ fn main() { &mut writer, &mut *terminal, &mut pty_parser, + &render_tx, &mut input_processor); if res == ShouldExit::Yes { break; @@ -205,6 +213,7 @@ fn main() { &mut writer, &mut *terminal, &mut pty_parser, + &render_tx, &mut input_processor); if res == ShouldExit::Yes { @@ -249,6 +258,15 @@ fn main() { gl::Clear(gl::COLOR_BUFFER_BIT); } + // Receive any resize events; only call gl::Viewport on last available + let mut new_size = None; + while let Ok(val) = render_rx.try_recv() { + new_size = Some(val); + } + if let Some((w, h)) = new_size.take() { + renderer.resize(w as i32, h as i32); + } + // Need scope so lock is released when swap_buffers is called { // Flag that it's time for render |