Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -186,7 +186,10 @@ export class WindowsNativeRecordingSession implements CursorRecordingSession {
}

if (payload.asset?.id && !this.assets.has(payload.asset.id)) {
const assetDisplay = screen.getDisplayNearestPoint({ x: payload.x, y: payload.y });
// payload.x/y are physical screen pixels; `screen` works in DIPs.
const assetDisplay = screen.getDisplayNearestPoint(
screen.screenToDipPoint({ x: payload.x, y: payload.y }),
);
this.assets.set(payload.asset.id, {
id: payload.asset.id,
platform: "win32",
Expand Down
8 changes: 8 additions & 0 deletions electron/native/wgc-capture/src/cursor-sampler.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -410,6 +410,14 @@ static void runSamplingLoop(int intervalMs, HWND targetWindow, const CLSID& pngC
// main
// ─────────────────────────────────────────────────────────────────────────────
int main(int argc, char* argv[]) {
// Without this the process is DPI-unaware and Win32 virtualises every
// coordinate it hands back — GetCursorInfo().ptScreenPos and GetWindowRect
// come out divided by the primary display's scale factor — while the WGC
// capture and the consumer both work in physical pixels. On any scaled
// display the cursor then lands short of its real position, by more the
// further it is from the origin (getopenscreen/openscreen#272).
SetProcessDpiAwarenessContext(DPI_AWARENESS_CONTEXT_PER_MONITOR_AWARE_V2);

if (argc < 2) {
std::cerr << "Usage: cursor-sampler <intervalMs> [windowHandle]" << std::endl;
return 1;
Expand Down
Loading