mirror of
https://github.com/wez/wezterm.git
synced 2024-12-28 07:55:03 +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 {
|
impl FontSystemSelection {
|
||||||
fn new_font_system(self) -> Rc<FontSystem> {
|
fn new_font_system(self) -> Rc<FontSystem> {
|
||||||
match self {
|
match self {
|
||||||
@ -100,6 +104,16 @@ impl FontSystemSelection {
|
|||||||
"CoreText",
|
"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 {
|
impl std::str::FromStr for FontSystemSelection {
|
||||||
|
@ -38,7 +38,8 @@ impl HostHelper for Host {
|
|||||||
&self,
|
&self,
|
||||||
func: F,
|
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) {
|
fn toggle_full_screen(&mut self) {
|
||||||
@ -623,11 +624,7 @@ impl GliumTerminalWindow {
|
|||||||
match event.state {
|
match event.state {
|
||||||
ElementState::Pressed => {
|
ElementState::Pressed => {
|
||||||
if mods == KeyModifiers::SUPER && key == KeyCode::Char('n') {
|
if mods == KeyModifiers::SUPER && key == KeyCode::Char('n') {
|
||||||
GuiEventLoop::schedule_spawn_new_window(
|
self.event_loop.schedule_spawn_new_window(&self.host.config);
|
||||||
&self.event_loop,
|
|
||||||
&self.host.config,
|
|
||||||
&self.host.fonts,
|
|
||||||
);
|
|
||||||
return Ok(());
|
return Ok(());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1,6 +1,6 @@
|
|||||||
use super::GuiSystem;
|
use super::GuiSystem;
|
||||||
use crate::config::Config;
|
use crate::config::Config;
|
||||||
use crate::font::FontConfiguration;
|
use crate::font::{FontConfiguration, FontSystemSelection};
|
||||||
use crate::futurecore;
|
use crate::futurecore;
|
||||||
use crate::gliumwindows;
|
use crate::gliumwindows;
|
||||||
pub use crate::gliumwindows::GliumTerminalWindow;
|
pub use crate::gliumwindows::GliumTerminalWindow;
|
||||||
@ -239,15 +239,14 @@ impl GuiEventLoop {
|
|||||||
events.add_window(window)
|
events.add_window(window)
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn schedule_spawn_new_window(
|
pub fn schedule_spawn_new_window(&self, config: &Arc<Config>) {
|
||||||
events: &Rc<Self>,
|
|
||||||
config: &Arc<Config>,
|
|
||||||
fonts: &Rc<FontConfiguration>,
|
|
||||||
) {
|
|
||||||
let myself = Rc::clone(events);
|
|
||||||
let config = Arc::clone(config);
|
let config = Arc::clone(config);
|
||||||
let fonts = Rc::clone(fonts);
|
self.core.spawn(futures::future::poll_fn(move || {
|
||||||
events.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)
|
Self::do_spawn_new_window(&myself, &config, &fonts)
|
||||||
.map(futures::Async::Ready)
|
.map(futures::Async::Ready)
|
||||||
.map_err(|_| ())
|
.map_err(|_| ())
|
||||||
@ -255,13 +254,13 @@ impl GuiEventLoop {
|
|||||||
}
|
}
|
||||||
|
|
||||||
pub fn with_window<F: Send + 'static + Fn(&mut TerminalWindow) -> Result<(), Error>>(
|
pub fn with_window<F: Send + 'static + Fn(&mut TerminalWindow) -> Result<(), Error>>(
|
||||||
events: &Rc<Self>,
|
&self,
|
||||||
window_id: WindowId,
|
window_id: WindowId,
|
||||||
func: F,
|
func: F,
|
||||||
) {
|
) {
|
||||||
Future::with_executor(
|
Future::with_executor(
|
||||||
GlutinGuiExecutor {
|
GlutinGuiExecutor {
|
||||||
tx: events.gui_tx.clone(),
|
tx: self.gui_tx.clone(),
|
||||||
},
|
},
|
||||||
move || {
|
move || {
|
||||||
let myself = Self::get().expect("to be called on gui thread");
|
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);
|
println!("Using configuration: {:#?}\nopts: {:#?}", config, opts);
|
||||||
|
|
||||||
let font_system = opts.font_system.unwrap_or(config.font_system);
|
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 fontconfig = Rc::new(FontConfiguration::new(Arc::clone(&config), font_system));
|
||||||
|
|
||||||
let cmd = if !opts.prog.is_empty() {
|
let cmd = if !opts.prog.is_empty() {
|
||||||
|
Loading…
Reference in New Issue
Block a user