From 68a44a660283f24e3d0bcc2998f646971051a655 Mon Sep 17 00:00:00 2001 From: Alvin Unreal Date: Thu, 14 May 2026 15:58:03 +0200 Subject: [PATCH] Fix Windows pet input after reload --- apps/desktop/src/check-packaging-contract.ts | 1 + apps/desktop/src/pet-window.ts | 17 ++++++++++++++++- 2 files changed, 17 insertions(+), 1 deletion(-) diff --git a/apps/desktop/src/check-packaging-contract.ts b/apps/desktop/src/check-packaging-contract.ts index 0eb515dd..2f6dc61a 100644 --- a/apps/desktop/src/check-packaging-contract.ts +++ b/apps/desktop/src/check-packaging-contract.ts @@ -114,6 +114,7 @@ assert.match(petWindowSource, /function installMousePassthroughAndDrag/, "pet wi assert.match(petWindowSource, /setIgnoreMouseEvents\(true, \{ forward: true \}\)/, "transparent pet window background must use OS-level mouse passthrough."); assert.match(petWindowSource, /setIgnoreMouseEvents\(false\)/, "visible pet and bubble hit targets must re-enable mouse handling."); assert.match(petWindowSource, /openpets:pet-ready/, "pet windows must resync passthrough after each renderer reload."); +assert.match(petWindowSource, /function installMousePassthroughAndDrag[\s\S]*?const rearmPassthroughAfterLoad[\s\S]*?process\.platform !== "win32"[\s\S]*?window\.setIgnoreMouseEvents\(false\);[\s\S]*?window\.setIgnoreMouseEvents\(true, \{ forward: true \}\);/, "Windows pet reloads must toggle forwarded mouse passthrough to re-register hover and drag tracking."); assert.match(petWindowSource, /did-finish-load", rearmAfterLoad/, "pet windows must re-arm mouse passthrough after every content load."); assert.match(petWindowSource, /did-fail-load", handleLoadFailure/, "pet windows must restore passthrough after failed content loads."); assert.match(petWindowSource, /window\.setIgnoreMouseEvents\(false\);[\s\S]*?await window\.loadFile/, "pet reloads must reset OS mouse passthrough before navigation."); diff --git a/apps/desktop/src/pet-window.ts b/apps/desktop/src/pet-window.ts index 3e874fa5..57b5aae4 100644 --- a/apps/desktop/src/pet-window.ts +++ b/apps/desktop/src/pet-window.ts @@ -148,6 +148,21 @@ function installMousePassthroughAndDrag(window: BrowserWindow): void { else window.setIgnoreMouseEvents(false); }; + const rearmPassthroughAfterLoad = (): void => { + if (window.isDestroyed()) return; + if (process.platform !== "win32") { + setPassthrough(true); + return; + } + + // On Windows, rapid pet HTML reloads can leave Chromium's forwarded mouse + // tracking stale while the cursor is already over the transparent window. + // Toggle passthrough after each completed reload so hover/drag mousemove + // forwarding is re-registered without requiring the cursor to leave/re-enter. + window.setIgnoreMouseEvents(false); + window.setIgnoreMouseEvents(true, { forward: true }); + }; + const handleHitTest = (event: IpcMainEvent, interactive: unknown): void => { if (!isFromWindow(event)) return; rendererReady = true; @@ -190,7 +205,7 @@ function installMousePassthroughAndDrag(window: BrowserWindow): void { const rearmAfterLoad = (): void => { dragging = null; debug("pet.window", "load rearm passthrough", { windowId: window.id }); - setPassthrough(true); + rearmPassthroughAfterLoad(); }; const handleDomReady = (): void => {