Files
punktfunk/crates/pf-win-display/src/lib.rs
T
enricobuehlerandClaude Fable 5 1945052e66 fix(capture/vdisplay): descriptor-following defers while a topology reassert is in flight
The exclusive-topology reassert's forced re-commit transiently bounces the
virtual display's mode; the descriptor poller can sample that EVICTION state
and recreate the ring at a mode the recovery chain is about to undo (field
log 2026-07-27 10:30:44Z: hdr=true → false → recreate → recovery restores
true → second recreate). New pf-win-display::topology_churn latch (deadline
semantics — self-expiring, so a lost release can never wedge descriptor-
following off): the watchdog holds it for interval+3s each fighting round and
releases on "stable again"; poll_display_hdr consumes samples but acts on
nothing while held — which also keeps the negotiated-depth pin-back from
issuing a CCD write mid-eviction, where it would fight the reassert itself.
The deliberate recreate_ring_in_place recovery path is unaffected.

Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
2026-07-27 15:37:05 +02:00

46 lines
2.5 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;
/// Bind display-config writes to the input desktop so a UAC / lock screen can't refuse them.
#[cfg(target_os = "windows")]
mod input_desktop;
#[cfg(target_os = "windows")]
pub mod monitor_devnode;
/// Cross-crate "topology churn in flight" latch (pure std — no Windows surface, so unconditionally
/// compiled and unit-tested on every platform).
pub mod topology_churn;
#[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))
}