mirror of
https://github.com/servo/servo.git
synced 2025-08-04 05:00:08 +01:00
refactor(window): get hidpi factor from winit across platform
This commit is contained in:
parent
679af055e2
commit
e0699492db
1 changed files with 8 additions and 20 deletions
|
@ -620,30 +620,18 @@ impl Window {
|
||||||
Some(device_pixels_per_px) => TypedScale::new(device_pixels_per_px),
|
Some(device_pixels_per_px) => TypedScale::new(device_pixels_per_px),
|
||||||
None => match opts::get().output_file {
|
None => match opts::get().output_file {
|
||||||
Some(_) => TypedScale::new(1.0),
|
Some(_) => TypedScale::new(1.0),
|
||||||
None => self.platform_hidpi_factor()
|
None => match self.kind {
|
||||||
|
WindowKind::Window(ref window, ..) => {
|
||||||
|
TypedScale::new(window.get_hidpi_factor() as f32)
|
||||||
|
}
|
||||||
|
WindowKind::Headless(..) => {
|
||||||
|
TypedScale::new(1.0)
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
#[cfg(not(target_os = "windows"))]
|
|
||||||
fn platform_hidpi_factor(&self) -> TypedScale<f32, DeviceIndependentPixel, DevicePixel> {
|
|
||||||
match self.kind {
|
|
||||||
WindowKind::Window(ref window, ..) => {
|
|
||||||
TypedScale::new(window.get_hidpi_factor() as f32)
|
|
||||||
}
|
|
||||||
WindowKind::Headless(..) => {
|
|
||||||
TypedScale::new(1.0)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
#[cfg(target_os = "windows")]
|
|
||||||
fn platform_hidpi_factor(&self) -> TypedScale<f32, DeviceIndependentPixel, DevicePixel> {
|
|
||||||
let hdc = unsafe { user32::GetDC(::std::ptr::null_mut()) };
|
|
||||||
let ppi = unsafe { gdi32::GetDeviceCaps(hdc, winapi::wingdi::LOGPIXELSY) };
|
|
||||||
TypedScale::new(ppi as f32 / 96.0)
|
|
||||||
}
|
|
||||||
|
|
||||||
/// Has no effect on Android.
|
/// Has no effect on Android.
|
||||||
pub fn set_cursor(&self, cursor: CursorKind) {
|
pub fn set_cursor(&self, cursor: CursorKind) {
|
||||||
match self.kind {
|
match self.kind {
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue