diff --git a/Cargo.lock b/Cargo.lock index ca35aa7a1..5337b36a1 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -694,6 +694,13 @@ dependencies = [ "unicode-width", ] +[[package]] +name = "color-types" +version = "0.1.0" +dependencies = [ + "lazy_static", +] + [[package]] name = "color_quant" version = "1.1.0" @@ -4790,6 +4797,7 @@ version = "0.1.0" dependencies = [ "allsorts", "anyhow", + "color-types", "config", "core-foundation 0.9.1", "core-text", @@ -4814,10 +4822,10 @@ dependencies = [ "unicode-general-category 0.3.0", "unicode-segmentation", "walkdir", + "wezterm-input-types", "wezterm-term", "wezterm-toast-notification", "winapi 0.3.9", - "window", ] [[package]] @@ -5138,6 +5146,7 @@ dependencies = [ "clipboard", "clipboard-win", "cocoa", + "color-types", "config", "core-foundation 0.7.0", "core-graphics 0.19.2", @@ -5167,6 +5176,7 @@ dependencies = [ "wayland-client", "wayland-egl", "wayland-protocols", + "wezterm-font", "wezterm-input-types", "wgpu", "winapi 0.3.9", diff --git a/color-types/Cargo.toml b/color-types/Cargo.toml new file mode 100644 index 000000000..dd5ed7c95 --- /dev/null +++ b/color-types/Cargo.toml @@ -0,0 +1,11 @@ +[package] +name = "color-types" +version = "0.1.0" +authors = ["Wez Furlong"] +edition = "2018" +repository = "https://github.com/wez/wezterm" +description = "Types for working with colors" +license = "MIT" + +[dependencies] +lazy_static = "1.4" diff --git a/window/src/color.rs b/color-types/src/lib.rs similarity index 100% rename from window/src/color.rs rename to color-types/src/lib.rs diff --git a/wezterm-font/Cargo.toml b/wezterm-font/Cargo.toml index 80a493eec..a81a0279d 100644 --- a/wezterm-font/Cargo.toml +++ b/wezterm-font/Cargo.toml @@ -10,6 +10,7 @@ edition = "2018" allsorts = { git = "https://github.com/yeslogic/allsorts.git", rev="3947164a201ab5e15d5f23204faaaaaad52531aa" } anyhow = "1.0" config = { path = "../config" } +color-types = { path = "../color-types" } enum-display-derive = "0.1" euclid = "0.22" freetype = { path = "../deps/freetype" } @@ -27,9 +28,9 @@ tinyvec = "1.1" # Note: constrained by the allsorts crate unicode-segmentation = "1.7" unicode-general-category = "0.3" walkdir = "2" +wezterm-input-types = { path = "../wezterm-input-types" } wezterm-term = { path = "../term", features=["use_serde"] } wezterm-toast-notification = { path = "../wezterm-toast-notification" } -window = { path = "../window" } [target.'cfg(any(target_os = "android", all(unix, not(target_os = "macos"))))'.dependencies] fontconfig = { path = "../deps/fontconfig" } diff --git a/wezterm-font/src/lib.rs b/wezterm-font/src/lib.rs index 590449f56..3bac4a7fb 100644 --- a/wezterm-font/src/lib.rs +++ b/wezterm-font/src/lib.rs @@ -16,7 +16,6 @@ use std::time::Duration; use thiserror::Error; use wezterm_term::CellAttributes; use wezterm_toast_notification::ToastNotification; -use window::default_dpi; mod hbwrap; @@ -186,10 +185,9 @@ pub struct FontConfiguration { impl FontConfigInner { /// Create a new empty configuration - pub fn new(config: Option) -> anyhow::Result { + pub fn new(config: Option, dpi: usize) -> anyhow::Result { let config = config.unwrap_or_else(|| configuration()); let locator = new_locator(config.font_locator); - let dpi = config.dpi.unwrap_or_else(|| default_dpi()) as usize; Ok(Self { fonts: RefCell::new(HashMap::new()), locator, @@ -552,8 +550,8 @@ impl FontConfigInner { impl FontConfiguration { /// Create a new empty configuration - pub fn new(config: Option) -> anyhow::Result { - let inner = Rc::new(FontConfigInner::new(config)?); + pub fn new(config: Option, dpi: usize) -> anyhow::Result { + let inner = Rc::new(FontConfigInner::new(config, dpi)?); Ok(Self { inner }) } diff --git a/wezterm-font/src/rasterizer/freetype.rs b/wezterm-font/src/rasterizer/freetype.rs index 87cd49448..0fe9f2d6f 100644 --- a/wezterm-font/src/rasterizer/freetype.rs +++ b/wezterm-font/src/rasterizer/freetype.rs @@ -4,10 +4,10 @@ use crate::units::*; use crate::{ftwrap, RasterizedGlyph}; use ::freetype::{FT_GlyphSlotRec_, FT_Glyph_Format, FT_Matrix}; use anyhow::bail; +use color_types::linear_u8_to_srgb8; use std::cell::RefCell; use std::mem; use std::slice; -use window::color::linear_u8_to_srgb8; pub struct FreeTypeRasterizer { has_color: bool, diff --git a/wezterm-font/src/units.rs b/wezterm-font/src/units.rs index 6a4ba273f..9c1e3375a 100644 --- a/wezterm-font/src/units.rs +++ b/wezterm-font/src/units.rs @@ -1,3 +1,3 @@ -pub type PixelUnit = window::PixelUnit; +pub type PixelUnit = wezterm_input_types::PixelUnit; pub type PixelLength = euclid::Length; pub type IntPixelLength = isize; diff --git a/wezterm-gui/src/main.rs b/wezterm-gui/src/main.rs index 1ce3c1e48..5f3160c09 100644 --- a/wezterm-gui/src/main.rs +++ b/wezterm-gui/src/main.rs @@ -419,7 +419,10 @@ pub fn run_ls_fonts(config: config::ConfigHandle, cmd: &LsFontsCommand) -> anyho // a fully baked GUI environment running config::assign_error_callback(|err| eprintln!("{}", err)); - let font_config = wezterm_font::FontConfiguration::new(Some(config.clone()))?; + let font_config = wezterm_font::FontConfiguration::new( + Some(config.clone()), + config.dpi.unwrap_or_else(|| ::window::default_dpi()) as usize, + )?; if let Some(text) = &cmd.text { let line = Line::from_text(text, &CellAttributes::default()); diff --git a/wezterm-gui/src/shapecache.rs b/wezterm-gui/src/shapecache.rs index 5f6e94acc..b8c5f6b3a 100644 --- a/wezterm-gui/src/shapecache.rs +++ b/wezterm-gui/src/shapecache.rs @@ -331,9 +331,15 @@ mod test { }; config.font_rules.clear(); config.compute_extra_defaults(None); - config::use_this_configuration(config); + config::use_this_configuration(config.clone()); - let fonts = Rc::new(FontConfiguration::new(None).unwrap()); + let fonts = Rc::new( + FontConfiguration::new( + None, + config.dpi.unwrap_or_else(|| ::window::default_dpi()) as usize, + ) + .unwrap(), + ); let render_metrics = RenderMetrics::new(&fonts).unwrap(); let mut glyph_cache = GlyphCache::new_in_memory(&fonts, 128, &render_metrics).unwrap(); @@ -376,7 +382,16 @@ mod test { let bench_result = benchmarking::measure_function(move |measurer| { let text: String = (0..n).map(|_| ' ').collect(); - let fonts = Rc::new(FontConfiguration::new(None).unwrap()); + let fonts = Rc::new( + FontConfiguration::new( + None, + config::configuration() + .dpi + .unwrap_or_else(|| ::window::default_dpi()) + as usize, + ) + .unwrap(), + ); let style = TextStyle::default(); let font = fonts.resolve_font(&style).unwrap(); let line = Line::from_text(&text, &CellAttributes::default()); @@ -400,11 +415,18 @@ mod test { .is_test(true) .filter_level(log::LevelFilter::Trace) .try_init(); - if !config::configuration().experimental_shape_post_processing { + let config = config::configuration(); + if !config.experimental_shape_post_processing { return; } - let fonts = Rc::new(FontConfiguration::new(None).unwrap()); + let fonts = Rc::new( + FontConfiguration::new( + None, + config.dpi.unwrap_or_else(|| ::window::default_dpi()) as usize, + ) + .unwrap(), + ); let render_metrics = RenderMetrics::new(&fonts).unwrap(); let mut glyph_cache = GlyphCache::new_in_memory(&fonts, 128, &render_metrics).unwrap(); diff --git a/wezterm-gui/src/termwindow/mod.rs b/wezterm-gui/src/termwindow/mod.rs index 77a3a84b1..62c286ec2 100644 --- a/wezterm-gui/src/termwindow/mod.rs +++ b/wezterm-gui/src/termwindow/mod.rs @@ -392,7 +392,10 @@ impl TermWindow { let window_background = load_background_image(&config); - let fontconfig = Rc::new(FontConfiguration::new(Some(config.clone()))?); + let fontconfig = Rc::new(FontConfiguration::new( + Some(config.clone()), + config.dpi.unwrap_or_else(|| ::window::default_dpi()) as usize, + )?); let mux = Mux::get().expect("to be main thread with mux running"); let size = match mux.get_active_tab_for_window(mux_window_id) { Some(tab) => tab.get_size(), diff --git a/wezterm-gui/src/termwindow/resize.rs b/wezterm-gui/src/termwindow/resize.rs index 946a0ac2d..5c2830a8c 100644 --- a/wezterm-gui/src/termwindow/resize.rs +++ b/wezterm-gui/src/termwindow/resize.rs @@ -235,7 +235,10 @@ impl super::TermWindow { pub fn reset_font_and_window_size(&mut self) -> anyhow::Result<()> { let config = &self.config; let size = config.initial_size(); - let fontconfig = Rc::new(FontConfiguration::new(Some(config.clone()))?); + let fontconfig = Rc::new(FontConfiguration::new( + Some(config.clone()), + config.dpi.unwrap_or_else(|| ::window::default_dpi()) as usize, + )?); let render_metrics = RenderMetrics::new(&fontconfig)?; let terminal_size = PtySize { diff --git a/window/Cargo.toml b/window/Cargo.toml index 7e5cfc5bb..f5e2c5814 100644 --- a/window/Cargo.toml +++ b/window/Cargo.toml @@ -24,6 +24,7 @@ async-task = "4.0" async-trait = "0.1" anyhow = "1.0" config = { path = "../config" } +color-types = { path = "../color-types" } thiserror = "1.0" bitflags = "1.0" euclid = "0.22" @@ -39,6 +40,7 @@ resize = "0.5" serde = {version="1.0", features = ["rc", "derive"]} tiny-skia = "0.5" glium = { version = "0.28", default-features = false} +wezterm-font = { path = "../wezterm-font" } wezterm-input-types = { path = "../wezterm-input-types" } [target."cfg(windows)".dependencies] diff --git a/window/src/lib.rs b/window/src/lib.rs index 7580310c1..b73209fd1 100644 --- a/window/src/lib.rs +++ b/window/src/lib.rs @@ -4,7 +4,7 @@ use std::any::Any; use std::rc::Rc; use thiserror::Error; pub mod bitmaps; -pub mod color; +pub use color_types as color; mod configuration; pub mod connection; pub mod os;