Files
punktfunk/crates/pf-win-display/src/lib.rs
T
enricobuehler 845a97601d feat(pf-frame,pf-win-display): leaf primitives for the lid-closed first-frame fix
Three leaf-crate additions the IDD-push capturer (pf-capture, plan §W6 C6)
builds on — committed ahead so the capture-crate extraction and the HID
compose kick can land on top:

- pf-frame session_tuning::DisplayWakeRequest — RAII PowerCreateRequest/
  PowerSetRequest(PowerRequestDisplayRequired + SystemRequired), the
  service-grade 'someone is watching this screen' assertion (visible in
  powercfg /requests), held for a capture session so the console cannot
  drop into display-off mid-stream. Object-lifetime, unlike the
  thread-bound ES_* flags in on_hot_thread. Prevention only: no power
  request turns an already-off display back on — that wake is input's
  job (the virtual-mouse compose kick).

- pf-win-display win_display::desktop_bounds() — the virtual-desktop
  bounds as the union of every ACTIVE CCD path's source rect. From the
  CCD database (global), NOT GetSystemMetrics (a per-session view), so
  a non-console-session host still aims HID absolute coordinates at the
  console's real layout.

- pf-win-display console_session_mismatch() — the session guard from
  3d9b3290, copied into the leaf so pf-capture reads it as a peer
  instead of reaching into the orchestrator (relocation authored by the
  W6 extraction session).

Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
2026-07-17 11:17:29 +02:00

40 lines
2.2 KiB
Rust

//! Windows display-topology helpers (plan §W6), extracted from the host's `windows/{win_display,
//! monitor_devnode,display_events}.rs` so the IDD-push capturer (`pf-capture`) and the pf-vdisplay
//! backend (the host) depend on them as a leaf PEER instead of the capturer reaching back into the
//! orchestrator. Windows-only; compiles to an empty lib elsewhere.
//!
//! - [`win_display`]: CCD/GDI path activation, mode-setting, HDR advanced-colour toggles, and the
//! source-desktop geometry the capturer duplicates.
//! - [`monitor_devnode`]: PnP monitor devnode enable/disable (the parallel-display isolation lever).
//! - [`display_events`]: the `WM_DISPLAYCHANGE` / device-arrival watch that lets a capture stall say
//! whether an OS display event coincided with it.
#[cfg(target_os = "windows")]
pub mod display_events;
#[cfg(target_os = "windows")]
pub mod monitor_devnode;
#[cfg(target_os = "windows")]
pub mod win_display;
/// `Some((own_session, console_session))` when this process is NOT in the active console session —
/// the state where every `SetDisplayConfig`/CDS write fails `ERROR_ACCESS_DENIED`, GDI reads
/// describe the wrong session's displays, and input compose kicks go nowhere (the lid-closed /
/// non-console field failure mode). The IDD-push capturer uses it to phrase a diagnostic when the
/// driver won't attach. (A byte-copy of the host's `interactive::console_session_mismatch`: it lives
/// here too so `pf-capture` gets it as a leaf peer instead of reaching into the orchestrator.)
#[cfg(target_os = "windows")]
pub fn console_session_mismatch() -> Option<(u32, u32)> {
use windows::Win32::System::RemoteDesktop::{
ProcessIdToSessionId, WTSGetActiveConsoleSessionId,
};
use windows::Win32::System::Threading::GetCurrentProcessId;
let mut own: u32 = 0;
// SAFETY: `own` is a live local out-param for this synchronous call; no pointer escapes it.
if unsafe { ProcessIdToSessionId(GetCurrentProcessId(), &mut own) }.is_err() {
return None;
}
// SAFETY: takes no arguments and returns the console session id by value.
let console = unsafe { WTSGetActiveConsoleSessionId() };
(console != 0xFFFF_FFFF && own != console).then_some((own, console))
}