From 6623e1ff86b2830072de0f42a4c48ea702cba320 Mon Sep 17 00:00:00 2001 From: Wez Furlong Date: Sat, 3 Mar 2018 17:57:09 -0800 Subject: [PATCH] We can now spawn additional windows However, https://github.com/tomaka/winit/issues/414 makes this unsafe. --- src/gliumwindows.rs | 30 ++++++++++++++++++++++++++++-- src/main.rs | 20 +++++--------------- src/opengl/render.rs | 2 +- 3 files changed, 34 insertions(+), 18 deletions(-) diff --git a/src/gliumwindows.rs b/src/gliumwindows.rs index 1dd961402..a94a8cd31 100644 --- a/src/gliumwindows.rs +++ b/src/gliumwindows.rs @@ -1,9 +1,12 @@ //! Generic system dependent windows via glium+glutin #![allow(dead_code)] +use super::{spawn_window, GuiEventLoop}; use clipboard::{Clipboard, ClipboardImpl, Paste}; +use config::Config; use failure::Error; use font::FontConfiguration; +use futures; use glium::{self, glutin}; use glium::glutin::{ElementState, MouseCursor}; use opengl::render::Renderer; @@ -64,6 +67,8 @@ impl term::TerminalHost for Host { pub struct TerminalWindow { host: Host, + event_loop: Rc, + config: Rc, renderer: Renderer, width: u16, height: u16, @@ -81,13 +86,19 @@ pub struct TerminalWindow { impl TerminalWindow { pub fn new( - event_loop: &super::GuiEventLoop, + event_loop: &Rc, terminal: Terminal, pty: MasterPty, process: Child, fonts: &Rc, - palette: term::color::ColorPalette, + config: &Rc, ) -> Result { + let palette = config + .colors + .as_ref() + .map(|p| p.clone().into()) + .unwrap_or_else(term::color::ColorPalette::default); + let (cell_height, cell_width) = { // Urgh, this is a bit repeaty, but we need to satisfy the borrow checker let font = fonts.default_font()?; @@ -126,6 +137,8 @@ impl TerminalWindow { Ok(TerminalWindow { host, + event_loop: Rc::clone(event_loop), + config: Rc::clone(config), renderer, width, height, @@ -518,6 +531,19 @@ impl TerminalWindow { self.is_fullscreen = self.window_position.take(); window.set_fullscreen(Some(window.get_current_monitor())); } + } else if c == 'y' && self.last_modifiers.contains(KeyModifiers::SUPER) { + // CMD-y to open a new window + println!("open a new one!"); + let event_loop = Rc::clone(&self.event_loop); + let config = Rc::clone(&self.config); + let fonts = Rc::clone(&self.renderer.fonts); + self.event_loop + .core + .spawn(futures::future::poll_fn(move || { + spawn_window(&event_loop, None, &config, &fonts) + .map(futures::Async::Ready) + .map_err(|_| ()) + })); } else { self.terminal .key_down(KeyCode::Char(c), self.last_modifiers, &mut self.host)?; diff --git a/src/main.rs b/src/main.rs index 1214fbb45..5f29a4cb0 100644 --- a/src/main.rs +++ b/src/main.rs @@ -103,7 +103,7 @@ struct Windows { pub struct GuiEventLoop { event_loop: RefCell, windows: Rc>, - core: futurecore::Core, + pub core: futurecore::Core, poll: remotemio::IOMgr, poll_rx: Receiver, paster: GuiSender, @@ -403,7 +403,7 @@ fn run() -> Result<(), Error> { None }; - let event_loop = GuiEventLoop::new()?; + let event_loop = Rc::new(GuiEventLoop::new()?); spawn_window(&event_loop, cmd, &config, &fontconfig)?; @@ -412,7 +412,7 @@ fn run() -> Result<(), Error> { } fn spawn_window( - event_loop: &GuiEventLoop, + event_loop: &Rc, cmd: Option>, config: &Rc, fontconfig: &Rc, @@ -458,18 +458,8 @@ fn spawn_window( config.hyperlink_rules.clone(), ); - let window = gliumwindows::TerminalWindow::new( - event_loop, - terminal, - master, - child, - fontconfig, - config - .colors - .as_ref() - .map(|p| p.clone().into()) - .unwrap_or_else(term::color::ColorPalette::default), - )?; + let window = + gliumwindows::TerminalWindow::new(event_loop, terminal, master, child, fontconfig, config)?; event_loop.add_window(window) } diff --git a/src/opengl/render.rs b/src/opengl/render.rs index a5052f6cc..b72b9adbd 100644 --- a/src/opengl/render.rs +++ b/src/opengl/render.rs @@ -248,7 +248,7 @@ void main() { pub struct Renderer { width: u16, height: u16, - fonts: Rc, + pub fonts: Rc, cell_height: usize, cell_width: usize, descender: isize,