mirror of
https://github.com/italicsjenga/winit-sonoma-fix.git
synced 2025-01-23 10:26:34 +11:00
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:
parent
fd1a3eda1c
commit
bf413ecb83
3 changed files with 28 additions and 1 deletions
|
@ -3,6 +3,8 @@
|
||||||
- On X11, the `Moved` event is no longer sent when the window is resized without changing position.
|
- On X11, the `Moved` event is no longer sent when the window is resized without changing position.
|
||||||
- `MouseCursor` and `CursorState` now implement `Default`.
|
- `MouseCursor` and `CursorState` now implement `Default`.
|
||||||
- `WindowBuilder::with_resizable` implemented for Windows.
|
- `WindowBuilder::with_resizable` implemented for Windows.
|
||||||
|
- On X11, if width or height is reported as 0, the DPI is now 1.0 instead of +inf.
|
||||||
|
- On X11, the environment variable `WINIT_HIDPI_FACTOR` has been added for overriding DPI factor.
|
||||||
|
|
||||||
# Version 0.15.0 (2018-05-22)
|
# Version 0.15.0 (2018-05-22)
|
||||||
|
|
||||||
|
|
|
@ -1,4 +1,5 @@
|
||||||
use std::slice;
|
use std::{env, slice};
|
||||||
|
use std::str::FromStr;
|
||||||
|
|
||||||
use super::*;
|
use super::*;
|
||||||
use super::ffi::{
|
use super::ffi::{
|
||||||
|
@ -53,6 +54,22 @@ pub fn calc_dpi_factor(
|
||||||
(width_px, height_px): (u32, u32),
|
(width_px, height_px): (u32, u32),
|
||||||
(width_mm, height_mm): (u64, u64),
|
(width_mm, height_mm): (u64, u64),
|
||||||
) -> f64 {
|
) -> 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 = (
|
let ppmm = (
|
||||||
(width_px as f64 * height_px as f64) / (width_mm as f64 * height_mm as f64)
|
(width_px as f64 * height_px as f64) / (width_mm as f64 * height_mm as f64)
|
||||||
).sqrt();
|
).sqrt();
|
||||||
|
|
|
@ -344,6 +344,10 @@ impl Window {
|
||||||
/// Returns the ratio between the backing framebuffer resolution and the
|
/// Returns the ratio between the backing framebuffer resolution and the
|
||||||
/// window size in screen pixels. This is typically one for a normal display
|
/// window size in screen pixels. This is typically one for a normal display
|
||||||
/// and two for a retina display.
|
/// and two for a retina display.
|
||||||
|
///
|
||||||
|
/// ## Platform-specific
|
||||||
|
/// On X11 the DPI factor can be overridden using the `WINIT_HIDPI_FACTOR` environment
|
||||||
|
/// variable.
|
||||||
#[inline]
|
#[inline]
|
||||||
pub fn hidpi_factor(&self) -> f32 {
|
pub fn hidpi_factor(&self) -> f32 {
|
||||||
self.window.hidpi_factor()
|
self.window.hidpi_factor()
|
||||||
|
@ -467,6 +471,10 @@ impl MonitorId {
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Returns the ratio between the monitor's physical pixels and logical pixels.
|
/// Returns the ratio between the monitor's physical pixels and logical pixels.
|
||||||
|
///
|
||||||
|
/// ## Platform-specific
|
||||||
|
/// On X11 the DPI factor can be overridden using the `WINIT_HIDPI_FACTOR` environment
|
||||||
|
/// variable.
|
||||||
#[inline]
|
#[inline]
|
||||||
pub fn get_hidpi_factor(&self) -> f32 {
|
pub fn get_hidpi_factor(&self) -> f32 {
|
||||||
self.inner.get_hidpi_factor()
|
self.inner.get_hidpi_factor()
|
||||||
|
|
Loading…
Add table
Reference in a new issue