mirror of
https://github.com/wez/wezterm.git
synced 2024-12-27 15:37:29 +03:00
allow looking up the font system from the gui thread
This helps remove the Rc<events> thing from a couple of places
This commit is contained in:
parent
2ece60b45c
commit
7afd586ad0
@ -69,6 +69,10 @@ impl Default for FontSystemSelection {
|
||||
}
|
||||
}
|
||||
|
||||
thread_local! {
|
||||
static DEFAULT_FONT_SYSTEM: RefCell<FontSystemSelection> = RefCell::new(Default::default());
|
||||
}
|
||||
|
||||
impl FontSystemSelection {
|
||||
fn new_font_system(self) -> Rc<FontSystem> {
|
||||
match self {
|
||||
@ -100,6 +104,16 @@ impl FontSystemSelection {
|
||||
"CoreText",
|
||||
]
|
||||
}
|
||||
|
||||
pub fn set_default(self) {
|
||||
DEFAULT_FONT_SYSTEM.with(|def| {
|
||||
*def.borrow_mut() = self;
|
||||
});
|
||||
}
|
||||
|
||||
pub fn get_default() -> Self {
|
||||
DEFAULT_FONT_SYSTEM.with(|def| *def.borrow())
|
||||
}
|
||||
}
|
||||
|
||||
impl std::str::FromStr for FontSystemSelection {
|
||||
|
@ -38,7 +38,8 @@ impl HostHelper for Host {
|
||||
&self,
|
||||
func: F,
|
||||
) {
|
||||
GuiEventLoop::with_window(&self.event_loop, self.display.gl_window().id(), func);
|
||||
self.event_loop
|
||||
.with_window(self.display.gl_window().id(), func);
|
||||
}
|
||||
|
||||
fn toggle_full_screen(&mut self) {
|
||||
@ -623,11 +624,7 @@ impl GliumTerminalWindow {
|
||||
match event.state {
|
||||
ElementState::Pressed => {
|
||||
if mods == KeyModifiers::SUPER && key == KeyCode::Char('n') {
|
||||
GuiEventLoop::schedule_spawn_new_window(
|
||||
&self.event_loop,
|
||||
&self.host.config,
|
||||
&self.host.fonts,
|
||||
);
|
||||
self.event_loop.schedule_spawn_new_window(&self.host.config);
|
||||
return Ok(());
|
||||
}
|
||||
|
||||
|
@ -1,6 +1,6 @@
|
||||
use super::GuiSystem;
|
||||
use crate::config::Config;
|
||||
use crate::font::FontConfiguration;
|
||||
use crate::font::{FontConfiguration, FontSystemSelection};
|
||||
use crate::futurecore;
|
||||
use crate::gliumwindows;
|
||||
pub use crate::gliumwindows::GliumTerminalWindow;
|
||||
@ -239,15 +239,14 @@ 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.core.spawn(futures::future::poll_fn(move || {
|
||||
let myself = Self::get().expect("to be called on gui thread");
|
||||
let fonts = Rc::new(FontConfiguration::new(
|
||||
Arc::clone(&config),
|
||||
FontSystemSelection::get_default(),
|
||||
));
|
||||
Self::do_spawn_new_window(&myself, &config, &fonts)
|
||||
.map(futures::Async::Ready)
|
||||
.map_err(|_| ())
|
||||
@ -255,13 +254,13 @@ impl GuiEventLoop {
|
||||
}
|
||||
|
||||
pub fn with_window<F: Send + 'static + Fn(&mut TerminalWindow) -> Result<(), Error>>(
|
||||
events: &Rc<Self>,
|
||||
&self,
|
||||
window_id: WindowId,
|
||||
func: F,
|
||||
) {
|
||||
Future::with_executor(
|
||||
GlutinGuiExecutor {
|
||||
tx: events.gui_tx.clone(),
|
||||
tx: self.gui_tx.clone(),
|
||||
},
|
||||
move || {
|
||||
let myself = Self::get().expect("to be called on gui thread");
|
||||
|
@ -114,6 +114,8 @@ fn main() -> Result<(), Error> {
|
||||
println!("Using configuration: {:#?}\nopts: {:#?}", config, opts);
|
||||
|
||||
let font_system = opts.font_system.unwrap_or(config.font_system);
|
||||
font_system.set_default();
|
||||
|
||||
let fontconfig = Rc::new(FontConfiguration::new(Arc::clone(&config), font_system));
|
||||
|
||||
let cmd = if !opts.prog.is_empty() {
|
||||
|
Loading…
Reference in New Issue
Block a user