mirror of
https://github.com/wez/wezterm.git
synced 2024-12-23 05:12:40 +03:00
simplify executor acquisition
This commit is contained in:
parent
29e4843517
commit
c8f39b9adf
@ -56,7 +56,7 @@ impl Executor for GuiExecutor {
|
||||
}
|
||||
|
||||
impl FrontEnd for GuiFrontEnd {
|
||||
fn gui_executor(&self) -> Box<dyn Executor> {
|
||||
fn executor(&self) -> Box<dyn Executor> {
|
||||
Box::new(GuiExecutor {})
|
||||
}
|
||||
|
||||
|
@ -4,7 +4,7 @@ use super::utilsprites::RenderMetrics;
|
||||
use crate::clipboard::SystemClipboard;
|
||||
use crate::config::Config;
|
||||
use crate::font::{FontConfiguration, FontSystemSelection};
|
||||
use crate::frontend::{front_end, gui_executor};
|
||||
use crate::frontend::{executor, front_end};
|
||||
use crate::keyassignment::{KeyAssignment, KeyMap, SpawnTabDomain};
|
||||
use crate::mux::renderable::Renderable;
|
||||
use crate::mux::tab::{Tab, TabId};
|
||||
@ -545,7 +545,7 @@ impl TermWindow {
|
||||
}
|
||||
|
||||
pub fn spawn_new_window(&mut self) {
|
||||
promise::Future::with_executor(gui_executor().unwrap(), move || {
|
||||
promise::Future::with_executor(executor(), move || {
|
||||
let mux = Mux::get().unwrap();
|
||||
let fonts = Rc::new(FontConfiguration::new(
|
||||
Arc::clone(mux.config()),
|
||||
|
@ -36,11 +36,11 @@ thread_local! {
|
||||
static FRONT_END: RefCell<Option<Rc<dyn FrontEnd>>> = RefCell::new(None);
|
||||
}
|
||||
|
||||
pub fn gui_executor() -> Option<Box<dyn Executor>> {
|
||||
pub fn executor() -> Box<dyn Executor> {
|
||||
let locked = EXECUTOR.lock().unwrap();
|
||||
match locked.as_ref() {
|
||||
Some(exec) => Some(exec.clone_executor()),
|
||||
None => None,
|
||||
Some(exec) => exec.clone_executor(),
|
||||
None => panic!("executor machinery not yet configured"),
|
||||
}
|
||||
}
|
||||
|
||||
@ -63,7 +63,7 @@ impl FrontEndSelection {
|
||||
FrontEndSelection::OpenGL => gui::GuiFrontEnd::try_new(mux),
|
||||
}?;
|
||||
|
||||
EXECUTOR.lock().unwrap().replace(front_end.gui_executor());
|
||||
EXECUTOR.lock().unwrap().replace(front_end.executor());
|
||||
FRONT_END.with(|f| *f.borrow_mut() = Some(Rc::clone(&front_end)));
|
||||
|
||||
Ok(front_end)
|
||||
@ -105,6 +105,6 @@ pub trait FrontEnd: Downcast {
|
||||
window_id: WindowId,
|
||||
) -> Fallible<()>;
|
||||
|
||||
fn gui_executor(&self) -> Box<dyn Executor>;
|
||||
fn executor(&self) -> Box<dyn Executor>;
|
||||
}
|
||||
impl_downcast!(FrontEnd);
|
||||
|
@ -58,7 +58,7 @@ impl MuxServerFrontEnd {
|
||||
}
|
||||
|
||||
impl FrontEnd for MuxServerFrontEnd {
|
||||
fn gui_executor(&self) -> Box<dyn Executor> {
|
||||
fn executor(&self) -> Box<dyn Executor> {
|
||||
Box::new(MuxExecutor {
|
||||
tx: self.tx.clone(),
|
||||
})
|
||||
|
@ -1,5 +1,5 @@
|
||||
use crate::config::Config;
|
||||
use crate::frontend::gui_executor;
|
||||
use crate::frontend::executor;
|
||||
use crate::mux::tab::{Tab, TabId};
|
||||
use crate::mux::window::{Window, WindowId};
|
||||
use crate::ratelim::RateLimiter;
|
||||
@ -68,7 +68,7 @@ fn read_from_tab_pty(config: Arc<Config>, tab_id: TabId, mut reader: Box<dyn std
|
||||
Ok(size) => {
|
||||
lim.blocking_admittance_check(size as u32);
|
||||
let data = buf[0..size].to_vec();
|
||||
Future::with_executor(gui_executor().unwrap(), move || {
|
||||
Future::with_executor(executor(), move || {
|
||||
let mux = Mux::get().unwrap();
|
||||
if let Some(tab) = mux.get_tab(tab_id) {
|
||||
tab.advance_bytes(
|
||||
@ -84,7 +84,7 @@ fn read_from_tab_pty(config: Arc<Config>, tab_id: TabId, mut reader: Box<dyn std
|
||||
}
|
||||
}
|
||||
}
|
||||
Future::with_executor(gui_executor().unwrap(), move || {
|
||||
Future::with_executor(executor(), move || {
|
||||
let mux = Mux::get().unwrap();
|
||||
mux.remove_tab(tab_id);
|
||||
Ok(())
|
||||
|
@ -1,4 +1,4 @@
|
||||
use crate::frontend::gui_executor;
|
||||
use crate::frontend::executor;
|
||||
use crate::mux::domain::DomainId;
|
||||
use crate::mux::renderable::Renderable;
|
||||
use crate::mux::Mux;
|
||||
@ -28,7 +28,7 @@ struct Paste {
|
||||
|
||||
fn schedule_next_paste(paste: &Arc<Mutex<Paste>>) {
|
||||
let paste = Arc::clone(paste);
|
||||
promise::Future::with_executor(gui_executor().unwrap(), move || {
|
||||
promise::Future::with_executor(executor(), move || {
|
||||
let mut locked = paste.lock().unwrap();
|
||||
let mux = Mux::get().unwrap();
|
||||
let tab = mux.get_tab(locked.tab_id).unwrap();
|
||||
|
@ -1,5 +1,5 @@
|
||||
use crate::config::{Config, SshDomain, TlsDomainClient, UnixDomain};
|
||||
use crate::frontend::gui_executor;
|
||||
use crate::frontend::executor;
|
||||
use crate::mux::domain::alloc_domain_id;
|
||||
use crate::mux::domain::DomainId;
|
||||
use crate::mux::Mux;
|
||||
@ -65,7 +65,7 @@ macro_rules! rpc {
|
||||
fn process_unilateral(local_domain_id: DomainId, decoded: DecodedPdu) -> Fallible<()> {
|
||||
if let Some(tab_id) = decoded.pdu.tab_id() {
|
||||
let pdu = decoded.pdu;
|
||||
Future::with_executor(gui_executor().unwrap(), move || {
|
||||
Future::with_executor(executor(), move || {
|
||||
let mux = Mux::get().unwrap();
|
||||
let client_domain = mux
|
||||
.get_domain(local_domain_id)
|
||||
@ -540,7 +540,7 @@ impl Client {
|
||||
}
|
||||
}
|
||||
}
|
||||
Future::with_executor(gui_executor().unwrap(), move || {
|
||||
Future::with_executor(executor(), move || {
|
||||
let mux = Mux::get().unwrap();
|
||||
let client_domain = mux
|
||||
.get_domain(local_domain_id)
|
||||
|
@ -1,6 +1,6 @@
|
||||
use crate::config::{Config, TlsDomainServer, UnixDomain};
|
||||
use crate::create_user_owned_dirs;
|
||||
use crate::frontend::gui_executor;
|
||||
use crate::frontend::executor;
|
||||
use crate::mux::tab::{Tab, TabId};
|
||||
use crate::mux::{Mux, MuxNotification, MuxSubscriber};
|
||||
use crate::ratelim::RateLimiter;
|
||||
@ -41,7 +41,7 @@ impl LocalListener {
|
||||
for stream in self.listener.incoming() {
|
||||
match stream {
|
||||
Ok(stream) => {
|
||||
Future::with_executor(gui_executor().unwrap(), move || {
|
||||
Future::with_executor(executor(), move || {
|
||||
let mut session = ClientSession::new(stream);
|
||||
thread::spawn(move || session.run());
|
||||
Ok(())
|
||||
@ -182,12 +182,12 @@ mod not_ossl {
|
||||
match stream {
|
||||
Ok(stream) => {
|
||||
stream.set_nodelay(true).ok();
|
||||
let executor = gui_executor().unwrap();
|
||||
let executor = executor();
|
||||
let acceptor = self.acceptor.clone();
|
||||
|
||||
match acceptor.accept(stream) {
|
||||
Ok(stream) => {
|
||||
Future::with_executor(gui_executor().unwrap(), move || {
|
||||
Future::with_executor(executor(), move || {
|
||||
let mut session = ClientSession::new(stream, executor);
|
||||
thread::spawn(move || session.run());
|
||||
Ok(())
|
||||
@ -320,7 +320,7 @@ mod ossl {
|
||||
break;
|
||||
}
|
||||
|
||||
Future::with_executor(gui_executor().unwrap(), move || {
|
||||
Future::with_executor(executor(), move || {
|
||||
let mut session = ClientSession::new(stream);
|
||||
thread::spawn(move || session.run());
|
||||
Ok(())
|
||||
@ -632,7 +632,7 @@ impl<S: ReadAndWrite> ClientSession<S> {
|
||||
for tab_id in tabs_to_output.drain() {
|
||||
let surfaces = Arc::clone(&self.surfaces_by_tab);
|
||||
let sender = self.to_write_tx.clone();
|
||||
Future::with_executor(gui_executor().unwrap(), move || {
|
||||
Future::with_executor(executor(), move || {
|
||||
let mux = Mux::get().unwrap();
|
||||
let tab = mux
|
||||
.get_tab(tab_id)
|
||||
@ -685,36 +685,34 @@ impl<S: ReadAndWrite> ClientSession<S> {
|
||||
fn process_pdu(&mut self, pdu: Pdu) -> Future<Pdu> {
|
||||
match pdu {
|
||||
Pdu::Ping(Ping {}) => Future::ok(Pdu::Pong(Pong {})),
|
||||
Pdu::ListTabs(ListTabs {}) => {
|
||||
Future::with_executor(gui_executor().unwrap(), move || {
|
||||
let mux = Mux::get().unwrap();
|
||||
let mut tabs = vec![];
|
||||
for window_id in mux.iter_windows().into_iter() {
|
||||
let window = mux.get_window(window_id).unwrap();
|
||||
for tab in window.iter() {
|
||||
let (rows, cols) = tab.renderer().physical_dimensions();
|
||||
tabs.push(WindowAndTabEntry {
|
||||
window_id,
|
||||
tab_id: tab.tab_id(),
|
||||
title: tab.get_title(),
|
||||
size: PtySize {
|
||||
cols: cols as u16,
|
||||
rows: rows as u16,
|
||||
pixel_height: 0,
|
||||
pixel_width: 0,
|
||||
},
|
||||
});
|
||||
}
|
||||
Pdu::ListTabs(ListTabs {}) => Future::with_executor(executor(), move || {
|
||||
let mux = Mux::get().unwrap();
|
||||
let mut tabs = vec![];
|
||||
for window_id in mux.iter_windows().into_iter() {
|
||||
let window = mux.get_window(window_id).unwrap();
|
||||
for tab in window.iter() {
|
||||
let (rows, cols) = tab.renderer().physical_dimensions();
|
||||
tabs.push(WindowAndTabEntry {
|
||||
window_id,
|
||||
tab_id: tab.tab_id(),
|
||||
title: tab.get_title(),
|
||||
size: PtySize {
|
||||
cols: cols as u16,
|
||||
rows: rows as u16,
|
||||
pixel_height: 0,
|
||||
pixel_width: 0,
|
||||
},
|
||||
});
|
||||
}
|
||||
log::error!("ListTabs {:#?}", tabs);
|
||||
Ok(Pdu::ListTabsResponse(ListTabsResponse { tabs }))
|
||||
})
|
||||
}
|
||||
}
|
||||
log::error!("ListTabs {:#?}", tabs);
|
||||
Ok(Pdu::ListTabsResponse(ListTabsResponse { tabs }))
|
||||
}),
|
||||
|
||||
Pdu::WriteToTab(WriteToTab { tab_id, data }) => {
|
||||
let surfaces = Arc::clone(&self.surfaces_by_tab);
|
||||
let sender = self.to_write_tx.clone();
|
||||
Future::with_executor(gui_executor().unwrap(), move || {
|
||||
Future::with_executor(executor(), move || {
|
||||
let mux = Mux::get().unwrap();
|
||||
let tab = mux
|
||||
.get_tab(tab_id)
|
||||
@ -727,7 +725,7 @@ impl<S: ReadAndWrite> ClientSession<S> {
|
||||
Pdu::SendPaste(SendPaste { tab_id, data }) => {
|
||||
let surfaces = Arc::clone(&self.surfaces_by_tab);
|
||||
let sender = self.to_write_tx.clone();
|
||||
Future::with_executor(gui_executor().unwrap(), move || {
|
||||
Future::with_executor(executor(), move || {
|
||||
let mux = Mux::get().unwrap();
|
||||
let tab = mux
|
||||
.get_tab(tab_id)
|
||||
@ -738,21 +736,19 @@ impl<S: ReadAndWrite> ClientSession<S> {
|
||||
})
|
||||
}
|
||||
|
||||
Pdu::Resize(Resize { tab_id, size }) => {
|
||||
Future::with_executor(gui_executor().unwrap(), move || {
|
||||
let mux = Mux::get().unwrap();
|
||||
let tab = mux
|
||||
.get_tab(tab_id)
|
||||
.ok_or_else(|| format_err!("no such tab {}", tab_id))?;
|
||||
tab.resize(size)?;
|
||||
Ok(Pdu::UnitResponse(UnitResponse {}))
|
||||
})
|
||||
}
|
||||
Pdu::Resize(Resize { tab_id, size }) => Future::with_executor(executor(), move || {
|
||||
let mux = Mux::get().unwrap();
|
||||
let tab = mux
|
||||
.get_tab(tab_id)
|
||||
.ok_or_else(|| format_err!("no such tab {}", tab_id))?;
|
||||
tab.resize(size)?;
|
||||
Ok(Pdu::UnitResponse(UnitResponse {}))
|
||||
}),
|
||||
|
||||
Pdu::SendKeyDown(SendKeyDown { tab_id, event }) => {
|
||||
let surfaces = Arc::clone(&self.surfaces_by_tab);
|
||||
let sender = self.to_write_tx.clone();
|
||||
Future::with_executor(gui_executor().unwrap(), move || {
|
||||
Future::with_executor(executor(), move || {
|
||||
let mux = Mux::get().unwrap();
|
||||
let tab = mux
|
||||
.get_tab(tab_id)
|
||||
@ -765,7 +761,7 @@ impl<S: ReadAndWrite> ClientSession<S> {
|
||||
Pdu::SendMouseEvent(SendMouseEvent { tab_id, event }) => {
|
||||
let surfaces = Arc::clone(&self.surfaces_by_tab);
|
||||
let sender = self.to_write_tx.clone();
|
||||
Future::with_executor(gui_executor().unwrap(), move || {
|
||||
Future::with_executor(executor(), move || {
|
||||
let mux = Mux::get().unwrap();
|
||||
let tab = mux
|
||||
.get_tab(tab_id)
|
||||
@ -788,7 +784,7 @@ impl<S: ReadAndWrite> ClientSession<S> {
|
||||
})
|
||||
}
|
||||
|
||||
Pdu::Spawn(spawn) => Future::with_executor(gui_executor().unwrap(), move || {
|
||||
Pdu::Spawn(spawn) => Future::with_executor(executor(), move || {
|
||||
let mux = Mux::get().unwrap();
|
||||
let domain = mux.get_domain(spawn.domain_id).ok_or_else(|| {
|
||||
format_err!("domain {} not found on this server", spawn.domain_id)
|
||||
@ -813,7 +809,7 @@ impl<S: ReadAndWrite> ClientSession<S> {
|
||||
Pdu::GetTabRenderChanges(GetTabRenderChanges { tab_id, .. }) => {
|
||||
let surfaces = Arc::clone(&self.surfaces_by_tab);
|
||||
let sender = self.to_write_tx.clone();
|
||||
Future::with_executor(gui_executor().unwrap(), move || {
|
||||
Future::with_executor(executor(), move || {
|
||||
let mux = Mux::get().unwrap();
|
||||
let tab = mux
|
||||
.get_tab(tab_id)
|
||||
|
@ -1,5 +1,5 @@
|
||||
use crate::clipboard::SystemClipboard;
|
||||
use crate::frontend::gui_executor;
|
||||
use crate::frontend::executor;
|
||||
use crate::mux::domain::DomainId;
|
||||
use crate::mux::renderable::Renderable;
|
||||
use crate::mux::tab::{alloc_tab_id, Tab, TabId};
|
||||
@ -113,7 +113,7 @@ impl MouseState {
|
||||
*highlight.lock().unwrap() = r.highlight.clone();
|
||||
something_changed.store(true, Ordering::SeqCst);
|
||||
}
|
||||
Future::with_executor(gui_executor().unwrap(), move || {
|
||||
Future::with_executor(executor(), move || {
|
||||
Self::next(&state)?;
|
||||
Ok(())
|
||||
});
|
||||
|
Loading…
Reference in New Issue
Block a user