diff --git a/wezterm-gui/src/frontend.rs b/wezterm-gui/src/frontend.rs index 7740eb747..bbc7ecdf8 100644 --- a/wezterm-gui/src/frontend.rs +++ b/wezterm-gui/src/frontend.rs @@ -35,10 +35,10 @@ impl GuiFrontEnd { }); let fe = Rc::downgrade(&front_end); mux.subscribe(move |n| { - if let Some(_fe) = fe.upgrade() { + if let Some(fe) = fe.upgrade() { match n { MuxNotification::WindowCreated(mux_window_id) => { - if !is_switching_workspace() { + if !fe.is_switching_workspace() { let mux = Mux::get().expect("mux started and running on main thread"); let window = mux.get_window(mux_window_id).expect("new window notif to have valid window"); if window.get_workspace() == mux.active_workspace_for_client(&client_id) { @@ -72,7 +72,7 @@ impl GuiFrontEnd { promise::spawn::spawn(async move { let mux = Mux::get().expect("mux started and running on main thread"); mux.set_active_workspace_for_client(&client_id, &workspace); - switch_workspace(&workspace); + crate::frontend::front_end().switch_workspace(&workspace); drop(activity); }).detach(); } else { @@ -181,44 +181,20 @@ impl GuiFrontEnd { pub fn forget_known_window(&self, window: &Window) { self.known_windows.borrow_mut().retain(|w| w != window); } + + pub fn is_switching_workspace(&self) -> bool { + *self.switching_workspaces.borrow() + } } thread_local! { static FRONT_END: RefCell>> = RefCell::new(None); } -pub fn record_known_window(window: Window) { - FRONT_END.with(|f| { - f.borrow_mut() - .as_mut() - .map(|f| f.record_known_window(window)) - }); -} - -pub fn forget_known_window(window: &Window) { - FRONT_END.with(|f| { - f.borrow_mut() - .as_mut() - .map(|f| f.forget_known_window(window)) - }); -} - -pub fn is_switching_workspace() -> bool { +pub fn front_end() -> Rc { FRONT_END - .with(|f| { - f.borrow() - .as_ref() - .map(|f| *f.switching_workspaces.borrow()) - }) - .unwrap_or(false) -} - -pub fn switch_workspace(new_name: &str) { - FRONT_END.with(|f| { - f.borrow_mut() - .as_mut() - .map(|f| f.switch_workspace(new_name)) - }); + .with(|f| f.borrow().as_ref().map(Rc::clone)) + .expect("to be called on gui thread") } pub struct WorkspaceSwitcher { @@ -244,7 +220,7 @@ impl WorkspaceSwitcher { impl Drop for WorkspaceSwitcher { fn drop(&mut self) { - switch_workspace(&self.new_name); + front_end().switch_workspace(&self.new_name); } } diff --git a/wezterm-gui/src/termwindow/mod.rs b/wezterm-gui/src/termwindow/mod.rs index c405671f6..f030db5ba 100644 --- a/wezterm-gui/src/termwindow/mod.rs +++ b/wezterm-gui/src/termwindow/mod.rs @@ -2,6 +2,7 @@ use super::renderstate::*; use super::utilsprites::RenderMetrics; use crate::cache::LruCache; +use crate::frontend::front_end; use crate::glium::texture::SrgbTexture2d; use crate::overlay::{ confirm_close_pane, confirm_close_tab, confirm_close_window, confirm_quit_program, launcher, @@ -346,7 +347,7 @@ impl TermWindow { // Immediately kill the tabs and allow the window to close mux.kill_window(self.mux_window_id); window.close(); - crate::frontend::forget_known_window(window); + front_end().forget_known_window(window); } WindowCloseConfirmation::AlwaysPrompt => { let tab = match mux.get_active_tab_for_window(self.mux_window_id) { @@ -354,7 +355,7 @@ impl TermWindow { None => { mux.kill_window(self.mux_window_id); window.close(); - crate::frontend::forget_known_window(window); + front_end().forget_known_window(window); return; } }; @@ -367,7 +368,7 @@ impl TermWindow { if can_close { mux.kill_window(self.mux_window_id); window.close(); - crate::frontend::forget_known_window(window); + front_end().forget_known_window(window); return; } let window = self.window.clone().unwrap(); @@ -776,7 +777,7 @@ impl TermWindow { } crate::update::start_update_checker(); - crate::frontend::record_known_window(window); + front_end().record_known_window(window); Ok(()) } @@ -849,7 +850,7 @@ impl TermWindow { if gl.is_context_lost() { log::error!("opengl context was lost; should reinit"); window.close(); - crate::frontend::forget_known_window(window); + front_end().forget_known_window(window); return false; } @@ -965,7 +966,7 @@ impl TermWindow { MuxNotification::WindowRemoved(window_id) => { if window_id == self.mux_window_id { window.close(); - crate::frontend::forget_known_window(window); + front_end().forget_known_window(window); } } _ => {} @@ -2547,7 +2548,7 @@ impl TermWindow { impl Drop for TermWindow { fn drop(&mut self) { if let Some(window) = self.window.take() { - crate::frontend::forget_known_window(&window); + front_end().forget_known_window(&window); } } }