Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@
- On X11, the `Moved` event is no longer sent when the window is resized without changing position.
- `MouseCursor` and `CursorState` now implement `Default`.
- `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)

Expand Down
19 changes: 18 additions & 1 deletion src/platform/linux/x11/util/randr.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
use std::slice;
use std::{env, slice};
use std::str::FromStr;

use super::*;
use super::ffi::{
Expand Down Expand Up @@ -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();
Expand Down
8 changes: 8 additions & 0 deletions src/window.rs
Original file line number Diff line number Diff line change
Expand Up @@ -344,6 +344,10 @@ impl Window {
/// Returns the ratio between the backing framebuffer resolution and the
/// window size in screen pixels. This is typically one for a normal 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]
pub fn hidpi_factor(&self) -> f32 {
self.window.hidpi_factor()
Expand Down Expand Up @@ -467,6 +471,10 @@ impl MonitorId {
}

/// 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]
pub fn get_hidpi_factor(&self) -> f32 {
self.inner.get_hidpi_factor()
Expand Down