1
1
mirror of https://github.com/wez/wezterm.git synced 2024-12-26 23:04:49 +03:00

maybe remove a couple of poll_fn uses from x11

(I can't compile it locally atm)
This commit is contained in:
Wez Furlong 2019-03-04 19:58:51 +00:00
parent 152300ef5a
commit ac016c0494
2 changed files with 33 additions and 38 deletions

View File

@ -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<F: FnOnce(&mut TerminalWindow) -> Result<(), Error>>(
pub fn with_window<F: Send + 'static + Fn(&mut TerminalWindow) -> 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<Self>,
config: &Arc<Config>,
fonts: &Rc<FontConfiguration>,
) {
let myself = Rc::clone(events);
pub fn schedule_spawn_new_window(&self, config: &Arc<Config>) {
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> {

View File

@ -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<F: 'static + Fn(&mut TerminalWindow) -> 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(());
}