From 49619276995787d35fd46be02239f60999e2fbbd Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Michal=20Hornick=C3=BD?= Date: Thu, 19 Jul 2018 09:08:21 +0200 Subject: [PATCH 1/4] [x11-backend] Retrieve DPI from Xft.dpi XResource --- src/platform/linux/x11/util/randr.rs | 31 ++++++++++++++++++++++++---- 1 file changed, 27 insertions(+), 4 deletions(-) diff --git a/src/platform/linux/x11/util/randr.rs b/src/platform/linux/x11/util/randr.rs index e730469ba3..5054dbdb01 100644 --- a/src/platform/linux/x11/util/randr.rs +++ b/src/platform/linux/x11/util/randr.rs @@ -79,6 +79,24 @@ impl From<*mut ffi::XRRCrtcInfo> for MonitorRepr { } impl XConnection { + // Retrieve DPI from Xft.dpi property + pub unsafe fn get_xft_dpi(&self) -> Option { + (self.xlib.XrmInitialize)(); + let resource_manager_str = (self.xlib.XResourceManagerString)(self.display); + if resource_manager_str == ptr::null_mut() { + return None; + } + if let Ok(res) = ::std::ffi::CStr::from_ptr(resource_manager_str).to_str() { + let name : &str = "Xft.dpi:\t"; + for pair in res.split("\n") { + if pair.starts_with(&name) { + let res = &pair[name.len()..]; + return f64::from_str(&res).ok(); + } + } + } + None + } pub unsafe fn get_output_info( &self, resources: *mut ffi::XRRScreenResources, @@ -101,10 +119,15 @@ impl XConnection { (*output_info).nameLen as usize, ); let name = String::from_utf8_lossy(name_slice).into(); - let hidpi_factor = calc_dpi_factor( - repr.get_dimensions(), - ((*output_info).mm_width as u64, (*output_info).mm_height as u64), - ); + let hidpi_factor = if let Some(dpi) = self.get_xft_dpi() { + dpi / 96. + } else { + calc_dpi_factor( + repr.get_dimensions(), + ((*output_info).mm_width as u64, (*output_info).mm_height as u64), + ) + }; + (self.xrandr.XRRFreeOutputInfo)(output_info); Some((name, hidpi_factor)) } From e361a6d2bbab46eeb9536c36d1b4d360856d6726 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Michal=20Hornick=C3=BD?= Date: Thu, 19 Jul 2018 09:19:00 +0200 Subject: [PATCH 2/4] Update CHANGELOG.md --- CHANGELOG.md | 1 + 1 file changed, 1 insertion(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index 25b287ee76..94be3f7861 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -3,6 +3,7 @@ - On Windows, fix `CursorMoved(0, 0)` getting dispatched on window focus. - On macOS, fix command key event left and right reverse. - On FreeBSD, NetBSD, and OpenBSD, fix build of X11 backend. +- X11 - Dpi scaling factor behavior changed. First, winit tries to read it from "Xft.dpi" XResource, and uses DPI calculation from xrandr dimensions as fallback behavior. # Version 0.19.0 (2019-03-06) From 00b96b8040ac32afbdde2729ea34820ab96e57a2 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Michal=20Hornick=C3=BD?= Date: Thu, 19 Jul 2018 09:21:04 +0200 Subject: [PATCH 3/4] Update window.rs --- src/window.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/window.rs b/src/window.rs index cf36044880..1bc0dbf618 100644 --- a/src/window.rs +++ b/src/window.rs @@ -485,7 +485,7 @@ impl MonitorId { /// /// ## Platform-specific /// - /// - **X11:** Can be overridden using the `WINIT_HIDPI_FACTOR` environment variable. + /// - **X11:** This respects Xft.dpi XResource, and can be overridden using the `WINIT_HIDPI_FACTOR` environment variable. /// - **Android:** Always returns 1.0. #[inline] pub fn get_hidpi_factor(&self) -> f64 { From ca5e5d881de10c09023b57ca042a4fba8fe4e70e Mon Sep 17 00:00:00 2001 From: Osspial Date: Sun, 7 Apr 2019 12:48:07 -0400 Subject: [PATCH 4/4] Update CHANGELOG.md --- CHANGELOG.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 94be3f7861..9333b1d7da 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -3,7 +3,7 @@ - On Windows, fix `CursorMoved(0, 0)` getting dispatched on window focus. - On macOS, fix command key event left and right reverse. - On FreeBSD, NetBSD, and OpenBSD, fix build of X11 backend. -- X11 - Dpi scaling factor behavior changed. First, winit tries to read it from "Xft.dpi" XResource, and uses DPI calculation from xrandr dimensions as fallback behavior. +- On X11, change DPI scaling factor behavior. First, winit tries to read it from "Xft.dpi" XResource, and uses DPI calculation from xrandr dimensions as fallback behavior. # Version 0.19.0 (2019-03-06)