diff --git a/src/font/mod.rs b/src/font/mod.rs index 5899aacf0..85c222561 100644 --- a/src/font/mod.rs +++ b/src/font/mod.rs @@ -69,6 +69,10 @@ impl Default for FontSystemSelection { } } +thread_local! { + static DEFAULT_FONT_SYSTEM: RefCell = RefCell::new(Default::default()); +} + impl FontSystemSelection { fn new_font_system(self) -> Rc { 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 { diff --git a/src/gliumwindows.rs b/src/gliumwindows.rs index 4efad080a..870d7e840 100644 --- a/src/gliumwindows.rs +++ b/src/gliumwindows.rs @@ -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(()); } diff --git a/src/guiloop/glutinloop.rs b/src/guiloop/glutinloop.rs index 782064e51..7f31e49c1 100644 --- a/src/guiloop/glutinloop.rs +++ b/src/guiloop/glutinloop.rs @@ -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, - config: &Arc, - fonts: &Rc, - ) { - let myself = Rc::clone(events); + pub fn schedule_spawn_new_window(&self, config: &Arc) { 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 Result<(), Error>>( - events: &Rc, + &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"); diff --git a/src/main.rs b/src/main.rs index 89d899288..dbb09797e 100644 --- a/src/main.rs +++ b/src/main.rs @@ -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() {