diff --git a/src/frontend/gui/mod.rs b/src/frontend/gui/mod.rs index 08db6424a..a4b7f81ce 100644 --- a/src/frontend/gui/mod.rs +++ b/src/frontend/gui/mod.rs @@ -56,7 +56,7 @@ impl Executor for GuiExecutor { } impl FrontEnd for GuiFrontEnd { - fn gui_executor(&self) -> Box { + fn executor(&self) -> Box { Box::new(GuiExecutor {}) } diff --git a/src/frontend/gui/termwindow.rs b/src/frontend/gui/termwindow.rs index ebbdb1a25..f359818f6 100644 --- a/src/frontend/gui/termwindow.rs +++ b/src/frontend/gui/termwindow.rs @@ -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()), diff --git a/src/frontend/mod.rs b/src/frontend/mod.rs index 88eeb0c4d..1ac67f73d 100644 --- a/src/frontend/mod.rs +++ b/src/frontend/mod.rs @@ -36,11 +36,11 @@ thread_local! { static FRONT_END: RefCell>> = RefCell::new(None); } -pub fn gui_executor() -> Option> { +pub fn executor() -> Box { 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; + fn executor(&self) -> Box; } impl_downcast!(FrontEnd); diff --git a/src/frontend/muxserver/mod.rs b/src/frontend/muxserver/mod.rs index 069cad35e..b6fbd0e0a 100644 --- a/src/frontend/muxserver/mod.rs +++ b/src/frontend/muxserver/mod.rs @@ -58,7 +58,7 @@ impl MuxServerFrontEnd { } impl FrontEnd for MuxServerFrontEnd { - fn gui_executor(&self) -> Box { + fn executor(&self) -> Box { Box::new(MuxExecutor { tx: self.tx.clone(), }) diff --git a/src/mux/mod.rs b/src/mux/mod.rs index e920816f1..342008d65 100644 --- a/src/mux/mod.rs +++ b/src/mux/mod.rs @@ -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, tab_id: TabId, mut reader: Box { 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, tab_id: TabId, mut reader: Box>) { 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(); diff --git a/src/server/client.rs b/src/server/client.rs index 167ac7510..d6343ea82 100644 --- a/src/server/client.rs +++ b/src/server/client.rs @@ -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) diff --git a/src/server/listener.rs b/src/server/listener.rs index 41db39ed4..0d1c2bb3c 100644 --- a/src/server/listener.rs +++ b/src/server/listener.rs @@ -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 ClientSession { 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 ClientSession { fn process_pdu(&mut self, pdu: Pdu) -> Future { 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 ClientSession { 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 ClientSession { }) } - 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 ClientSession { 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 ClientSession { }) } - 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 ClientSession { 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) diff --git a/src/server/tab.rs b/src/server/tab.rs index 02fa767e0..515b0b70b 100644 --- a/src/server/tab.rs +++ b/src/server/tab.rs @@ -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(()) });