wezterm.gui.screens: add optional effective_dpi field

This commit implements it for Windows. The other systems
report None for now.
This commit is contained in:
Wez Furlong 2023-08-06 09:11:11 -07:00
parent 18d93fce5a
commit 6ccbc723ba
No known key found for this signature in database
GPG Key ID: 7A7F66A31EC9B387
8 changed files with 29 additions and 0 deletions

View File

@ -21,6 +21,7 @@ pub struct ScreenInfo {
pub height: isize,
pub scale: f64,
pub max_fps: Option<usize>,
pub effective_dpi: Option<f64>,
}
impl_lua_conversion_dynamic!(ScreenInfo);
@ -46,6 +47,7 @@ impl From<window::screen::ScreenInfo> for ScreenInfo {
height: info.rect.height(),
scale: info.scale,
max_fps: info.max_fps,
effective_dpi: info.effective_dpi,
}
}
}

View File

@ -55,6 +55,7 @@ winapi = { version = "0.3", features = [
"handleapi",
"imm",
"libloaderapi",
"shellscalingapi",
"synchapi",
"sysinfoapi",
"winerror",

View File

@ -229,6 +229,7 @@ pub fn nsscreen_to_screen_info(screen: *mut Object) -> ScreenInfo {
rect,
scale: 1.0,
max_fps,
effective_dpi: None,
}
}

View File

@ -511,6 +511,7 @@ impl ConnectionOps for WaylandConnection {
rect,
scale,
max_fps: None,
effective_dpi: None,
},
);
});

View File

@ -234,6 +234,7 @@ impl OutputHandler {
rect,
scale,
max_fps: None,
effective_dpi: None,
},
);
}

View File

@ -5,6 +5,7 @@ use crate::screen::{ScreenInfo, Screens};
use crate::spawn::*;
use crate::{Appearance, ScreenRect};
use anyhow::Context;
use config::ConfigHandle;
use std::cell::RefCell;
use std::collections::HashMap;
use std::ffi::OsString;
@ -14,6 +15,7 @@ use std::rc::Rc;
use winapi::shared::minwindef::*;
use winapi::shared::windef::*;
use winapi::shared::winerror::{ERROR_INSUFFICIENT_BUFFER, ERROR_SUCCESS};
use winapi::um::shellscalingapi::{GetDpiForMonitor, MDT_EFFECTIVE_DPI};
use winapi::um::winbase::INFINITE;
use winapi::um::wingdi::{
DEVMODEW, DISPLAY_DEVICEW, DM_DISPLAYFREQUENCY, QDC_ONLY_ACTIVE_PATHS, QDC_VIRTUAL_MODE_AWARE,
@ -177,6 +179,7 @@ pub(crate) struct ScreenInfoHelper {
active_handle: HMONITOR,
friendly_names: HashMap<String, String>,
gdi_to_adapater: HashMap<String, String>,
config: ConfigHandle,
}
impl ScreenInfoHelper {
@ -189,6 +192,7 @@ impl ScreenInfoHelper {
active_handle: unsafe { MonitorFromWindow(GetFocus(), MONITOR_DEFAULTTONEAREST) },
friendly_names: gdi_display_name_to_friendly_monitor_names()?,
gdi_to_adapater: gdi_display_name_to_adapter_names(),
config: config::configuration(),
})
}
@ -218,6 +222,22 @@ impl ScreenInfoHelper {
};
let monitor_name = info.monitor_name(&mi);
let mut effective_dpi = None;
if let Some(dpi) = info.config.dpi_by_screen.get(&monitor_name).copied() {
effective_dpi.replace(dpi);
} else if let Some(dpi) = info.config.dpi {
effective_dpi.replace(dpi);
} else {
let mut dpi_x = 0;
let mut dpi_y = 0;
GetDpiForMonitor(mon, MDT_EFFECTIVE_DPI, &mut dpi_x, &mut dpi_y);
if dpi_x != 0 {
effective_dpi.replace(dpi_x as f64);
}
}
let screen_info = ScreenInfo {
name: monitor_name.clone(),
rect: euclid::rect(
@ -228,6 +248,7 @@ impl ScreenInfoHelper {
),
scale: 1.0,
max_fps,
effective_dpi,
};
info.virtual_rect = info.virtual_rect.union(&screen_info.rect);

View File

@ -276,6 +276,7 @@ impl ConnectionOps for XConnection {
rect: bounds,
scale: 1.0,
max_fps,
effective_dpi: None,
};
by_name.insert(name, info);
}

View File

@ -15,4 +15,5 @@ pub struct ScreenInfo {
pub rect: ScreenRect,
pub scale: f64,
pub max_fps: Option<usize>,
pub effective_dpi: Option<f64>,
}