diff --git a/src/guiloop/x11.rs b/src/guiloop/x11.rs index e27ce4599..672c580ef 100644 --- a/src/guiloop/x11.rs +++ b/src/guiloop/x11.rs @@ -214,19 +214,25 @@ impl GuiEventLoop { /// Run a function with access to the mutable version of the window with /// the specified window id - pub fn with_window Result<(), Error>>( + pub fn with_window Result<(), Error>>( &self, window_id: WindowId, func: F, ) -> Result<(), Error> { - let mut windows = self.windows.borrow_mut(); - - let window = windows - .by_id - .get_mut(&window_id) - .ok_or_else(|| format_err!("no window_id {:?} in the windows_by_id map", window_id))?; - - func(window) + Future::with_executor( + X11GuiExecutor { + tx: self.gui_tx.clone(), + }, + move || { + let myself = Self::get().expect("to be called on gui thread"); + let mut windows = myself.windows.borrow_mut(); + if let Some(window) = windows.by_id.get_mut(&window_id) { + func(window) + } else { + bail!("no such window {:?}", window_id); + } + }, + ); } fn do_spawn_new_window( @@ -242,19 +248,21 @@ impl GuiEventLoop { events.add_window(window) } - pub fn schedule_spawn_new_window( - events: &Rc, - config: &Arc, - fonts: &Rc, - ) { - let myself = Rc::clone(events); + pub fn schedule_spawn_new_window(&self, config: &Arc) { let config = Arc::clone(config); - let fonts = Rc::clone(fonts); - events.core.spawn(futures::future::poll_fn(move || { - Self::do_spawn_new_window(&myself, &config, &fonts) - .map(futures::Async::Ready) - .map_err(|_| ()) - })); + Future::with_executor( + X11GuiExecutor { + tx: self.gui_tx.clone(), + }, + move || { + let myself = Self::get().expect("to be called on gui thread"); + let fonts = Rc::new(FontConfiguration::new( + Arc::clone(&config), + FontSystemSelection::get_default(), + )); + myself.do_spawn_new_window(&config, &fonts) + }, + ); } pub fn add_window(&self, window: X11TerminalWindow) -> Result<(), Error> { diff --git a/src/xwindows/xwin.rs b/src/xwindows/xwin.rs index c4607735b..f2c812eac 100644 --- a/src/xwindows/xwin.rs +++ b/src/xwindows/xwin.rs @@ -10,7 +10,6 @@ use crate::guiloop::x11::{GuiEventLoop, WindowId}; use crate::guiloop::SessionTerminated; use crate::mux::renderable::Renderable; use failure::Error; -use futures; use std::rc::Rc; use term::{self, KeyCode, KeyModifiers, MouseButton, MouseEvent, MouseEventKind}; use xcb; @@ -25,17 +24,7 @@ struct Host { impl HostHelper for Host { fn with_window Result<(), Error>>(&self, func: F) { - let events = Rc::clone(&self.event_loop); - let window_id = self.window.window.window_id; - - self.event_loop - .core - .spawn(futures::future::poll_fn(move || { - events - .with_window(window_id, &func) - .map(futures::Async::Ready) - .map_err(|_| ()) - })); + self.event_loop.with_window(window_id, func); } fn toggle_full_screen(&mut self) {} @@ -224,11 +213,9 @@ impl X11TerminalWindow { }; if let Some((code, mods)) = self.decode_key(key_press) { if mods == KeyModifiers::SUPER && code == KeyCode::Char('n') { - GuiEventLoop::schedule_spawn_new_window( - &self.host.event_loop, - &self.host.config, - &self.host.fonts, - ); + self.host + .event_loop + .schedule_spawn_new_window(&self.host.config); return Ok(()); }