1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
//! Windows-only helpers. Process DPI awareness has to be established before
//! anything asks the OS about monitors, because xcap branches on it: when
//! the process is not DPI-aware it refuses `GetDpiForMonitor` and derives
//! the scale factor from `DESKTOPHORZRES / HORZRES` instead — a ratio
//! against the *virtualized* logical width, which reports 1.5002180337905884
//! rather than 1.5 on a 150% display.
//!
//! winit establishes awareness too, but only when the event loop is built,
//! which is long after monitors are enumerated and captured — and never at
//! all for `doctor`, `windows`, and `shoot`.
/// `DPI_AWARENESS_CONTEXT_PER_MONITOR_AWARE_V2`. This is the context winit
/// prefers as well, so the process ends up in the same state no matter which
/// of us wins the race to set it.
const PER_MONITOR_AWARE_V2: isize = -4;
// Requires Windows 10 1703 or newer. Rust itself has required Windows 10
// since 1.78, so anything that can run this binary already has the entry
// point; a static link is safe and keeps the module free of dependencies.
unsafe extern "system"
/// Declare this process per-monitor DPI-aware. Best-effort and idempotent:
/// Windows refuses the call once awareness is already set — by an earlier
/// call, an application manifest, or an app-compatibility override — which
/// is not an error. Returns whether *this* call established it.
/// Whether the process is in fact per-monitor v2 aware. Reported by
/// `doctor`, because an external override that forces a different awareness
/// mode silently degrades every scale factor we print and save.