Read the current display's DPI scale factor. Computed from physical screen dimensions (pixels / mm). Snapped to the nearest 0.25 and clamped to [1.0, 4.0] — EDID often lies about millimetres so we want stable integer-ish steps. A real Wayland-style desktop environment with explicit scale settings is out of scope here; this matches what most X11 users actually run (fractional scaling via Xft.dpi is
(display: *mut x11::xlib::Display, screen: i32)
| 194 | /// users actually run (fractional scaling via Xft.dpi is the |
| 195 | /// only thing GTK/Qt honour by default). |
| 196 | pub fn display_scale(display: *mut x11::xlib::Display, screen: i32) -> f64 { |
| 197 | unsafe { |
| 198 | let pixels = x11::xlib::XDisplayWidth(display, screen) as f64; |
| 199 | let mm = x11::xlib::XDisplayWidthMM(display, screen) as f64; |
| 200 | if mm <= 0.0 || pixels <= 0.0 { return 1.0; } |
| 201 | let dpi = pixels / (mm / 25.4); |
| 202 | // 96 DPI = scale 1.0. Snap to 0.25 steps. |
| 203 | let raw = (dpi / 96.0).max(1.0).min(4.0); |
| 204 | (raw * 4.0).round() / 4.0 |
| 205 | } |
| 206 | } |
| 207 | |
| 208 | pub fn display() -> *mut x11::xlib::Display { unsafe { DISPLAY } } |
| 209 | pub fn window() -> x11::xlib::Window { unsafe { X11_WINDOW } } |
no outgoing calls
no test coverage detected