Fix DPI with 0 width/hight reported by xorg (#544)

* Fix DPI with 0 width/hight reported by xorg

* Add `WINIT_HIDPI_FACTOR` env variable

It is now possible to override the DPI factor using the
`WINIT_HIDPI_FACTOR` environment variable on X11.

The changelog also has been updated to introduce all current changes
made.

* Add documentation for the environment variable

* Fix nitpicks

* Learning the alphabet

* Panic with error message if DPI env var is <= 0
This commit is contained in:
Christian Duerr 2018-06-03 16:41:47 +00:00 committed by Francesca Frangipane
parent fd1a3eda1c
commit bf413ecb83
3 changed files with 28 additions and 1 deletions

View file

@ -1,4 +1,5 @@
use std::slice;
use std::{env, slice};
use std::str::FromStr;
use super::*;
use super::ffi::{
@ -53,6 +54,22 @@ pub fn calc_dpi_factor(
(width_px, height_px): (u32, u32),
(width_mm, height_mm): (u64, u64),
) -> f64 {
// Override DPI if `WINIT_HIDPI_FACTOR` variable is set
if let Ok(dpi_factor_str) = env::var("WINIT_HIDPI_FACTOR") {
if let Ok(dpi_factor) = f64::from_str(&dpi_factor_str) {
if dpi_factor <= 0. {
panic!("Expected `WINIT_HIDPI_FACTOR` to be bigger than 0, got '{}'", dpi_factor);
}
return dpi_factor;
}
}
// See http://xpra.org/trac/ticket/728 for more information
if width_mm == 0 || width_mm == 0 {
return 1.0;
}
let ppmm = (
(width_px as f64 * height_px as f64) / (width_mm as f64 * height_mm as f64)
).sqrt();