mirror of
https://github.com/wez/wezterm.git
synced 2024-11-23 15:04:36 +03:00
simplify frontend/gui dispatching
Now that the mux is in its own crate, the paths in the gui side can be a bit more shallow, and we can remove a trait.
This commit is contained in:
parent
d40e502fab
commit
34c545dbde
@ -1,47 +0,0 @@
|
||||
use anyhow::Error;
|
||||
use downcast_rs::{impl_downcast, Downcast};
|
||||
use std::cell::RefCell;
|
||||
use std::rc::Rc;
|
||||
|
||||
pub mod gui;
|
||||
|
||||
pub use config::FrontEndSelection;
|
||||
|
||||
thread_local! {
|
||||
static FRONT_END: RefCell<Option<Rc<dyn FrontEnd>>> = RefCell::new(None);
|
||||
}
|
||||
|
||||
pub fn front_end() -> Option<Rc<dyn FrontEnd>> {
|
||||
let mut res = None;
|
||||
FRONT_END.with(|f| {
|
||||
if let Some(me) = &*f.borrow() {
|
||||
res = Some(Rc::clone(me));
|
||||
}
|
||||
});
|
||||
res
|
||||
}
|
||||
|
||||
pub fn shutdown() {
|
||||
FRONT_END.with(|f| drop(f.borrow_mut().take()));
|
||||
}
|
||||
|
||||
pub fn try_new(sel: FrontEndSelection) -> Result<Rc<dyn FrontEnd>, Error> {
|
||||
let front_end = match sel {
|
||||
FrontEndSelection::Software => gui::GuiFrontEnd::try_new_swrast(),
|
||||
FrontEndSelection::OldSoftware => gui::GuiFrontEnd::try_new_no_opengl(),
|
||||
FrontEndSelection::OpenGL => gui::GuiFrontEnd::try_new(),
|
||||
};
|
||||
|
||||
let front_end = front_end?;
|
||||
|
||||
FRONT_END.with(|f| *f.borrow_mut() = Some(Rc::clone(&front_end)));
|
||||
|
||||
Ok(front_end)
|
||||
}
|
||||
|
||||
pub trait FrontEnd: Downcast {
|
||||
/// Run the event loop. Does not return until there is either a fatal
|
||||
/// error, or until there are no more windows left to manage.
|
||||
fn run_forever(&self) -> anyhow::Result<()>;
|
||||
}
|
||||
impl_downcast!(FrontEnd);
|
@ -1,7 +1,9 @@
|
||||
use crate::frontend::FrontEnd;
|
||||
use ::window::*;
|
||||
use anyhow::Error;
|
||||
use config::configuration;
|
||||
pub use config::FrontEndSelection;
|
||||
use mux::{Mux, MuxNotification};
|
||||
use std::cell::RefCell;
|
||||
use std::rc::Rc;
|
||||
use std::sync::atomic::{AtomicBool, Ordering};
|
||||
|
||||
@ -34,17 +36,17 @@ pub fn is_opengl_enabled() -> bool {
|
||||
}
|
||||
|
||||
impl GuiFrontEnd {
|
||||
pub fn try_new_no_opengl() -> anyhow::Result<Rc<dyn FrontEnd>> {
|
||||
pub fn try_new_no_opengl() -> anyhow::Result<Rc<GuiFrontEnd>> {
|
||||
USE_OPENGL.store(false, Ordering::Release);
|
||||
Self::try_new()
|
||||
}
|
||||
|
||||
pub fn try_new_swrast() -> anyhow::Result<Rc<dyn FrontEnd>> {
|
||||
pub fn try_new_swrast() -> anyhow::Result<Rc<GuiFrontEnd>> {
|
||||
::window::prefer_swrast();
|
||||
Self::try_new()
|
||||
}
|
||||
|
||||
pub fn try_new() -> anyhow::Result<Rc<dyn FrontEnd>> {
|
||||
pub fn try_new() -> anyhow::Result<Rc<GuiFrontEnd>> {
|
||||
#[cfg(all(unix, not(target_os = "macos")))]
|
||||
{
|
||||
if !configuration().enable_wayland {
|
||||
@ -71,10 +73,8 @@ impl GuiFrontEnd {
|
||||
});
|
||||
Ok(front_end)
|
||||
}
|
||||
}
|
||||
|
||||
impl FrontEnd for GuiFrontEnd {
|
||||
fn run_forever(&self) -> anyhow::Result<()> {
|
||||
pub fn run_forever(&self) -> anyhow::Result<()> {
|
||||
self.connection
|
||||
.schedule_timer(std::time::Duration::from_millis(200), move || {
|
||||
if mux::activity::Activity::count() == 0 {
|
||||
@ -89,3 +89,35 @@ impl FrontEnd for GuiFrontEnd {
|
||||
self.connection.run_message_loop()
|
||||
}
|
||||
}
|
||||
|
||||
thread_local! {
|
||||
static FRONT_END: RefCell<Option<Rc<GuiFrontEnd>>> = RefCell::new(None);
|
||||
}
|
||||
|
||||
pub fn front_end() -> Option<Rc<GuiFrontEnd>> {
|
||||
let mut res = None;
|
||||
FRONT_END.with(|f| {
|
||||
if let Some(me) = &*f.borrow() {
|
||||
res = Some(Rc::clone(me));
|
||||
}
|
||||
});
|
||||
res
|
||||
}
|
||||
|
||||
pub fn shutdown() {
|
||||
FRONT_END.with(|f| drop(f.borrow_mut().take()));
|
||||
}
|
||||
|
||||
pub fn try_new(sel: FrontEndSelection) -> Result<Rc<GuiFrontEnd>, Error> {
|
||||
let front_end = match sel {
|
||||
FrontEndSelection::Software => GuiFrontEnd::try_new_swrast(),
|
||||
FrontEndSelection::OldSoftware => GuiFrontEnd::try_new_no_opengl(),
|
||||
FrontEndSelection::OpenGL => GuiFrontEnd::try_new(),
|
||||
};
|
||||
|
||||
let front_end = front_end?;
|
||||
|
||||
FRONT_END.with(|f| *f.borrow_mut() = Some(Rc::clone(&front_end)));
|
||||
|
||||
Ok(front_end)
|
||||
}
|
@ -1,5 +1,5 @@
|
||||
use crate::frontend::gui::selection::{SelectionCoordinate, SelectionRange};
|
||||
use crate::frontend::gui::termwindow::TermWindow;
|
||||
use crate::gui::selection::{SelectionCoordinate, SelectionRange};
|
||||
use crate::gui::termwindow::TermWindow;
|
||||
use mux::domain::DomainId;
|
||||
use mux::pane::{Pane, PaneId};
|
||||
use mux::renderable::*;
|
@ -5,7 +5,7 @@
|
||||
//! be rendered as a popup/context menu if the system supports it; at the
|
||||
//! time of writing our window layer doesn't provide an API for context
|
||||
//! menus.
|
||||
use crate::frontend::gui::termwindow::{ClipboardHelper, SpawnWhere, TermWindow};
|
||||
use crate::gui::termwindow::{ClipboardHelper, SpawnWhere, TermWindow};
|
||||
use crate::termwiztermtab::TermWizTerminal;
|
||||
use anyhow::anyhow;
|
||||
use config::configuration;
|
@ -1,4 +1,4 @@
|
||||
use crate::frontend::gui::termwindow::TermWindow;
|
||||
use crate::gui::termwindow::TermWindow;
|
||||
use crate::termwiztermtab::{allocate, TermWizTerminal};
|
||||
use mux::pane::{Pane, PaneId};
|
||||
use mux::tab::{Tab, TabId};
|
@ -1,5 +1,5 @@
|
||||
use crate::frontend::gui::selection::{SelectionCoordinate, SelectionRange};
|
||||
use crate::frontend::gui::termwindow::TermWindow;
|
||||
use crate::gui::selection::{SelectionCoordinate, SelectionRange};
|
||||
use crate::gui::termwindow::TermWindow;
|
||||
use mux::domain::DomainId;
|
||||
use mux::pane::{Pane, PaneId, Pattern, SearchResult};
|
||||
use mux::renderable::*;
|
@ -5,13 +5,13 @@ use super::utilsprites::RenderMetrics;
|
||||
use crate::font::shaper::GlyphInfo;
|
||||
use crate::font::units::*;
|
||||
use crate::font::FontConfiguration;
|
||||
use crate::frontend::gui::overlay::{
|
||||
use crate::gui::overlay::{
|
||||
confirm_close_pane, confirm_close_tab, launcher, start_overlay, start_overlay_pane,
|
||||
tab_navigator, CopyOverlay, SearchOverlay,
|
||||
};
|
||||
use crate::frontend::gui::scrollbar::*;
|
||||
use crate::frontend::gui::selection::*;
|
||||
use crate::frontend::gui::tabbar::{TabBarItem, TabBarState};
|
||||
use crate::gui::scrollbar::*;
|
||||
use crate::gui::selection::*;
|
||||
use crate::gui::tabbar::{TabBarItem, TabBarState};
|
||||
use ::wezterm_term::input::MouseButton as TMB;
|
||||
use ::wezterm_term::input::MouseEventKind as TMEK;
|
||||
use ::window::bitmaps::atlas::{OutOfTextureSpace, SpriteSlice};
|
||||
@ -982,7 +982,7 @@ impl TermWindow {
|
||||
|
||||
fn apply_icon(window: &Window) -> anyhow::Result<()> {
|
||||
let icon_image =
|
||||
image::load_from_memory(include_bytes!("../../../../assets/icon/terminal.png"))?;
|
||||
image::load_from_memory(include_bytes!("../../../assets/icon/terminal.png"))?;
|
||||
let image = icon_image.to_bgra();
|
||||
let (width, height) = image.dimensions();
|
||||
window.set_icon(Image::from_raw(
|
@ -20,7 +20,7 @@ use tabout::{tabulate_output, Alignment, Column};
|
||||
mod scripting;
|
||||
|
||||
mod connui;
|
||||
mod frontend;
|
||||
mod gui;
|
||||
use config::keyassignment;
|
||||
mod markdown;
|
||||
mod server;
|
||||
@ -29,7 +29,7 @@ mod stats;
|
||||
mod termwiztermtab;
|
||||
mod update;
|
||||
|
||||
use crate::frontend::{front_end, FrontEndSelection};
|
||||
use crate::gui::{front_end, FrontEndSelection};
|
||||
use crate::server::client::{unix_connect_with_retry, Client};
|
||||
use crate::server::domain::{ClientDomain, ClientDomainConfig};
|
||||
use mux::activity::Activity;
|
||||
@ -332,7 +332,7 @@ async fn async_run_ssh(opts: SshCommand) -> anyhow::Result<()> {
|
||||
|
||||
fn run_ssh(config: config::ConfigHandle, opts: SshCommand) -> anyhow::Result<()> {
|
||||
let front_end_selection = opts.front_end.unwrap_or(config.front_end);
|
||||
let gui = crate::frontend::try_new(front_end_selection)?;
|
||||
let gui = crate::gui::try_new(front_end_selection)?;
|
||||
|
||||
// Set up the mux with no default domain; there's a good chance that
|
||||
// we'll need to show authentication UI and we don't want its domain
|
||||
@ -372,7 +372,7 @@ fn run_serial(config: config::ConfigHandle, opts: &SerialCommand) -> anyhow::Res
|
||||
Mux::set_mux(&mux);
|
||||
|
||||
let front_end = opts.front_end.unwrap_or(config.front_end);
|
||||
let gui = crate::frontend::try_new(front_end)?;
|
||||
let gui = crate::gui::try_new(front_end)?;
|
||||
block_on(domain.attach())?; // FIXME: blocking
|
||||
|
||||
{
|
||||
@ -417,7 +417,7 @@ fn run_mux_client(config: config::ConfigHandle, opts: &ConnectCommand) -> anyhow
|
||||
Mux::set_mux(&mux);
|
||||
|
||||
let front_end_selection = opts.front_end.unwrap_or(config.front_end);
|
||||
let gui = crate::frontend::try_new(front_end_selection)?;
|
||||
let gui = crate::gui::try_new(front_end_selection)?;
|
||||
let opts = opts.clone();
|
||||
|
||||
let cmd = if !opts.prog.is_empty() {
|
||||
@ -571,7 +571,7 @@ fn run_terminal_gui(config: config::ConfigHandle, opts: StartCommand) -> anyhow:
|
||||
Mux::set_mux(&mux);
|
||||
|
||||
let front_end_selection = opts.front_end.unwrap_or(config.front_end);
|
||||
let gui = crate::frontend::try_new(front_end_selection)?;
|
||||
let gui = crate::gui::try_new(front_end_selection)?;
|
||||
let activity = Activity::new();
|
||||
let do_auto_connect = !opts.no_auto_connect;
|
||||
|
||||
@ -657,7 +657,7 @@ fn main() {
|
||||
terminate_with_error(e);
|
||||
}
|
||||
Mux::shutdown();
|
||||
frontend::shutdown();
|
||||
gui::shutdown();
|
||||
}
|
||||
|
||||
fn maybe_show_configuration_error_window() {
|
||||
|
Loading…
Reference in New Issue
Block a user