mirror of
https://github.com/wez/wezterm.git
synced 2024-11-10 15:04:32 +03:00
x11: query Xft.dpi from the root window
We should now be using the root window specified default dpi if the dpi is left unspecified in the wezterm configuration. refs: #515
This commit is contained in:
parent
aceb4933a9
commit
18cb179227
@ -8,6 +8,7 @@ use std::cell::RefCell;
|
||||
use std::collections::{HashMap, HashSet};
|
||||
use std::rc::{Rc, Weak};
|
||||
use wezterm_term::CellAttributes;
|
||||
use window::default_dpi;
|
||||
|
||||
mod hbwrap;
|
||||
|
||||
@ -295,7 +296,7 @@ impl FontConfigInner {
|
||||
|
||||
let font_size = config.font_size * *self.font_scale.borrow();
|
||||
let dpi =
|
||||
*self.dpi_scale.borrow() as u32 * config.dpi.unwrap_or(::window::DEFAULT_DPI) as u32;
|
||||
*self.dpi_scale.borrow() as u32 * config.dpi.unwrap_or_else(|| default_dpi()) as u32;
|
||||
let metrics = shaper.metrics(font_size, dpi).with_context(|| {
|
||||
format!(
|
||||
"obtaining metrics for font_size={} @ dpi {}",
|
||||
|
@ -462,7 +462,7 @@ impl TermWindow {
|
||||
pixel_height: ((rows_with_tab_bar * render_metrics.cell_size.height as u16)
|
||||
+ config.window_padding.top
|
||||
+ config.window_padding.bottom) as usize,
|
||||
dpi: config.dpi.unwrap_or(::window::DEFAULT_DPI) as usize,
|
||||
dpi: config.dpi.unwrap_or_else(|| ::window::default_dpi()) as usize,
|
||||
};
|
||||
|
||||
log::trace!(
|
||||
|
@ -31,7 +31,7 @@ impl super::TermWindow {
|
||||
|
||||
let (prior_font, prior_dpi) = self
|
||||
.fonts
|
||||
.change_scaling(font_scale, dimensions.dpi as f64 / ::window::DEFAULT_DPI);
|
||||
.change_scaling(font_scale, dimensions.dpi as f64 / ::window::default_dpi());
|
||||
match RenderMetrics::new(&self.fonts) {
|
||||
Ok(metrics) => {
|
||||
self.render_metrics = metrics;
|
||||
@ -233,7 +233,7 @@ impl super::TermWindow {
|
||||
pixel_height: ((rows_with_tab_bar * render_metrics.cell_size.height as u16)
|
||||
+ config.window_padding.top
|
||||
+ config.window_padding.bottom) as usize,
|
||||
dpi: config.dpi.unwrap_or(::window::DEFAULT_DPI) as usize,
|
||||
dpi: config.dpi.unwrap_or_else(|| ::window::default_dpi()) as usize,
|
||||
};
|
||||
|
||||
self.apply_scale_change(&dimensions, 1.0);
|
||||
|
@ -22,6 +22,10 @@ pub trait ConnectionOps {
|
||||
res
|
||||
}
|
||||
|
||||
fn default_dpi(&self) -> f64 {
|
||||
crate::DEFAULT_DPI
|
||||
}
|
||||
|
||||
fn init() -> Fallible<Rc<Connection>> {
|
||||
let conn = Rc::new(Connection::create_new()?);
|
||||
CONN.with(|m| *m.borrow_mut() = Some(Rc::clone(&conn)));
|
||||
|
@ -11,9 +11,16 @@ mod timerlist;
|
||||
use configuration::{config, WindowConfigHandle};
|
||||
|
||||
#[cfg(target_os = "macos")]
|
||||
pub const DEFAULT_DPI: f64 = 72.0;
|
||||
pub(crate) const DEFAULT_DPI: f64 = 72.0;
|
||||
#[cfg(not(target_os = "macos"))]
|
||||
pub const DEFAULT_DPI: f64 = 96.0;
|
||||
pub(crate) const DEFAULT_DPI: f64 = 96.0;
|
||||
|
||||
pub fn default_dpi() -> f64 {
|
||||
match Connection::get() {
|
||||
Some(conn) => conn.default_dpi(),
|
||||
None => DEFAULT_DPI,
|
||||
}
|
||||
}
|
||||
|
||||
mod egl;
|
||||
|
||||
|
@ -17,6 +17,7 @@ use xcb_util::ffi::keysyms::{xcb_key_symbols_alloc, xcb_key_symbols_free, xcb_ke
|
||||
|
||||
pub struct XConnection {
|
||||
pub conn: xcb_util::ewmh::Connection,
|
||||
pub default_dpi: f64,
|
||||
pub screen_num: i32,
|
||||
pub root: xcb::xproto::Window,
|
||||
pub keyboard: Keyboard,
|
||||
@ -177,6 +178,10 @@ impl ConnectionOps for XConnection {
|
||||
*self.should_terminate.borrow_mut() = true;
|
||||
}
|
||||
|
||||
fn default_dpi(&self) -> f64 {
|
||||
self.default_dpi
|
||||
}
|
||||
|
||||
fn run_message_loop(&self) -> anyhow::Result<()> {
|
||||
self.conn.flush();
|
||||
|
||||
@ -394,9 +399,17 @@ impl XConnection {
|
||||
|
||||
let xrm =
|
||||
crate::x11::xrm::parse_root_resource_manager(&conn, root).unwrap_or(HashMap::new());
|
||||
let default_dpi = xrm
|
||||
.get("Xft.dpi")
|
||||
.as_ref()
|
||||
.map(|s| s.as_str())
|
||||
.unwrap_or("96")
|
||||
.parse::<f64>()
|
||||
.unwrap_or(crate::DEFAULT_DPI);
|
||||
|
||||
let conn = XConnection {
|
||||
conn,
|
||||
default_dpi,
|
||||
cursor_font_id,
|
||||
screen_num,
|
||||
root,
|
||||
|
@ -188,7 +188,7 @@ impl XWindowInner {
|
||||
Dimensions {
|
||||
pixel_width: self.width as usize,
|
||||
pixel_height: self.height as usize,
|
||||
dpi: crate::DEFAULT_DPI as usize,
|
||||
dpi: conn.default_dpi as usize,
|
||||
},
|
||||
self.is_fullscreen().unwrap_or(false),
|
||||
)
|
||||
|
Loading…
Reference in New Issue
Block a user