dcomp-overlay
A small transparent window that floats over every other window on Windows: drawn with
DirectComposition, Direct2D and DirectWrite onto per-pixel transparency, never in the taskbar
or Alt-Tab, never taking the keyboard focus, dragged by the parts the caller says. It knows
nothing about what it shows. The caller describes a Scene and the overlay draws it, sizes
itself to it and reports clicks by id.
| Item | What it is |
|---|---|
Overlay::spawn(options, scene, on_event) | Opens the window on a thread of its own and returns once it exists. on_event is called on that thread for every Event. |
Overlay::set_scene, move_to, set_visible, close | Queue a command and return at once (close waits for the thread). Dropping the handle closes the window. |
Scene | Its size in logical pixels, the Items drawn in order (Rect with rounded corners, Circle, one-line Text cut with an ellipsis, and Path, a filled outline such as an icon) and the HitRegions: Click(id) or Drag. Builder methods rect, circle, text, icon (SVG path data in a view×view box, 24 for Material Design Icons, scaled into a rect; arcs and relative commands resolved by svgtypes, nonzero fill as in SVG; data that does not parse draws nothing), click (or click_rounded, whose highlight has round corners), drag, scroll (a region the mouse wheel turns, reported as Event::Wheel; add it under the click regions, which keep their clicks over it); hit(point) is the hit test (Hit::Scroll where only a scroll region is), scroll_at(point) the scroll region under a point whatever lies over it. A click region under the pointer gets the hand cursor and a lighter wash (HOVER, PRESSED), drawn by the overlay itself (highlighted). tip(id, text) gives a click region a tooltip, shown after the pointer rests on it 450 ms, in its own click-through topmost window beside the pointer, its text wrapped at TIP_WIDTH and measured by DirectWrite; paragraph draws wrapped text in a scene. |
Options | Title, starting Position (usually one saved from Event::Moved), what a press on empty scene does (Empty::ClickThrough, Drag or Block), who answers the pointer (Input), whether it activates, whether it starts shown. |
Event | Ready, Clicked { id }, Wheel { id, notches } (whole notches, positive up; a touchpad's fractions add up across events), Pointer(PointerEvent) (only with Input::Pointer), Moved { position }, DpiChanged, DrawFailed, Closed. |
Input, PointerEvent, Mouse | Input::Regions (the default): the overlay washes the click region under the pointer and reports clicks and the wheel by region id. Input::Pointer: the caller owns the pointer. Every move, leave, press, drag, release, cancelled press and wheel turn comes as Event::Pointer(PointerEvent) at its scene point (the wheel in fractional notches), and the overlay washes nothing and reports no Clicked or Wheel; what a press means and what is highlighted are drawn by the caller in its next scene. Regions still decide what the window takes (so what is click-through), the hand cursor, tooltips, and where the window is dragged from. Mouse is the pure part: what a run of mouse messages means, tested without a window. |
Overlay::timings(), Timings, Snapshot, Stat | What the window measures about itself, shared and readable from any thread without a lock: each scene draw's time (µs) and how long each mouse message waited in the queue (ms, GetTickCount less the message's own tick), each in a fixed ring of the last 64. snapshot() reads the last value, the largest, how many are over the gap between scenes (GAP_MS, 33 ms, until the caller says its own with Timings::set_gap_ms: a caller that draws once per display refresh gives the refresh period, and a draw over it finds the next scene already waiting) and the count; line() words it for a log. Nothing is allocated on the window's thread. |
Phases, Driver, Created (in Timings, Snapshot) | Where a draw's time goes, in the same rings: BeginDraw, Clear, paint (and within it rect, circle, text and path), EndDraw, Commit. Also which Direct3D driver the device runs on (Driver::Warp is the software fallback), the surface size in pixels, and how many text layouts, path geometries and text formats draws made rather than reused (Snapshot::created; kept while a scene keeps asking for them, and keyed by shape, not by position or size: a path is cached as its shape in the unit square and drawn under a scale and a move, and a line of text whose size is not a quarter pixel is laid out once at 16 px and drawn scaled, so the count is flat for a steady scene and for one whose items move, change colour or are scaled) and how many lookups found theirs (Snapshot::hits). Snapshot::phases_line() prints them. |
Scene::highlight(id, pointer) | The wash over the hovered click region as one item, which the window paints after the scene's own; highlighted is the same as a copy of the scene. |
place, default_position, Position, PxRect | Keeping a saved position on a monitor that still exists, as pure functions. |
Error, Call | Which call failed, with its HRESULT; Unsupported off Windows; Closed. |
Scenes are in logical pixels (1/96 inch); positions in physical pixels of the virtual screen, which is what Windows reports and a caller saves. The window is per-monitor DPI aware (v2). It draws only when the scene changes, its scale changes, or the graphics device is lost.
Off Windows the scene, hit test and placement build and are tested; Overlay::spawn returns
Error::Unsupported.
Example
examples/rows.rs: four rows under a header the window is dragged by, a dot per row that a
click turns over, a heartbeat dot that changes the scene every second. Built from guest:
nix develop ~/dashboard#windows -c cargo build --release --target x86_64-pc-windows-gnu -p dcomp-overlay --example rows
It must run in the interactive session to be seen (see CLAUDE.md).
mise run test