Skip to content

The agent that grows with you

fix(desktop): pet overlay stays clickable on Linux and survives a replaced close

brooklyn!f003387212de
diff --git a/apps/desktop/electron/main.ts b/apps/desktop/electron/main.ts
index ed9512ddbf6..d8f5c1b35e0 100644
--- a/apps/desktop/electron/main.ts
+++ b/apps/desktop/electron/main.ts
@@ -321,6 +321,7 @@ import { LEGACY_OAUTH_PARTITION, resolveOauthPartition } from './oauth-partition
import { mintGatewayWsTicket as mintOauthGatewayWsTicket, requestWithOauthFallback } from './oauth-rest-request'
import { wireOauthSessionResponse } from './oauth-session-response'
import { createParentStartMarkerResolver, parentWatchdogEnv } from './parent-process-identity'
+import { petOverlayClickThrough } from './pet-overlay'
import { placePetOverlay, registerPetOverlayIpc } from './pet-overlay-ipc'
import {
pendingNotice as pendingPluginCompatNotice,
@@ -14353,8 +14354,11 @@ function spawnPetOverlayWindow(bounds) {
// sits over the desktop eating clicks (the invisible "dead zone" bug). The
// wake indicator already uses this spawn-time ignore pattern. forward:true
// keeps mousemove flowing to the page so the renderer can re-arm
- // interactivity the moment the cursor touches a solid sprite pixel.
- win.setIgnoreMouseEvents(true, { forward: true })
+ // interactivity the moment the cursor touches a solid sprite pixel. Linux
+ // has no forward, so there the overlay stays a solid window instead.
+ if (petOverlayClickThrough()) {
+ win.setIgnoreMouseEvents(true, { forward: true })
+ }
try {
// Electron docs: macOS may transform process type on each
@@ -14381,12 +14385,14 @@ function spawnPetOverlayWindow(bounds) {
installWindowRendererLifecycle(win, { kind: 'overlay', callbacks: { log: rememberLog } })
win.on('closed', () => {
- petOverlayClosing = false
-
- if (petOverlayWindow === win) {
- petOverlayWindow = null
+ // A stale window openPetOverlay replaced must not touch its replacement.
+ if (petOverlayWindow !== win) {
+ return
}
+ petOverlayWindow = null
+ petOverlayClosing = false
+
// If the overlay went away on its own (e.g. ⌘W), tell the main renderer to
// pop the pet back in so it doesn't stay hidden. Harmless echo when we're
// the ones who closed it (popInPet already cleared the active flag).
@@ -14419,9 +14425,12 @@ function openPetOverlay(bounds) {
// A previous close was requested but never finished (close() can be aborted
// on macOS) — force the stale window down before spawning a replacement so
- // two overlays can never coexist.
+ // two overlays can never coexist. Detach it first so its 'closed' handler
+ // (sync or not) can't pop the pet back in over the replacement.
if (petOverlayWindow && !petOverlayWindow.isDestroyed()) {
- petOverlayWindow.destroy()
+ const stale = petOverlayWindow
+ petOverlayWindow = null
+ stale.destroy()
}
petOverlayClosing = false
@@ -14469,10 +14478,6 @@ function rehomePetOverlay() {
}
petOverlayWindow.setBounds(resolved)
- // Re-assert click-through after a display-driven move so a re-home can never
- // leave a mouse-enabled transparent region behind (same bug class as the
- // spawn-time default above).
- petOverlayWindow.setIgnoreMouseEvents(true, { forward: true })
if (mainWindow && !mainWindow.isDestroyed()) {
mainWindow.webContents.send('hermes:pet-overlay:control', { type: 'bounds', bounds: resolved })
diff --git a/apps/desktop/electron/pet-overlay-ipc.ts b/apps/desktop/electron/pet-overlay-ipc.ts
index dfe12c2a84a..59d8dd527da 100644
--- a/apps/desktop/electron/pet-overlay-ipc.ts
+++ b/apps/desktop/electron/pet-overlay-ipc.ts
@@ -2,7 +2,7 @@
// main.ts; window handles stay injected because main.ts owns their lifecycle.
import { type BrowserWindow, ipcMain, screen } from 'electron'
-import { resolvePetOverlayBounds } from './pet-overlay'
+import { petOverlayClickThrough, resolvePetOverlayBounds } from './pet-overlay'
export interface PetOverlayIpcDeps {
getMainWindow: () => BrowserWindow | null
@@ -115,6 +115,11 @@ export function registerPetOverlayIpc({
ipcMain.on('hermes:pet-overlay:ignore-mouse', (_event, ignore) => {
const petOverlayWindow = getPetOverlayWindow()
+ // No forward on Linux: an ignoring overlay could never be re-armed.
+ if (Boolean(ignore) && !petOverlayClickThrough()) {
+ return
+ }
+
if (petOverlayWindow && !petOverlayWindow.isDestroyed()) {
petOverlayWindow.setIgnoreMouseEvents(Boolean(ignore), { forward: true })
}
diff --git a/apps/desktop/electron/pet-overlay.test.ts b/apps/desktop/electron/pet-overlay.test.ts
index 2a037fa9509..a1949af284e 100644
--- a/apps/desktop/electron/pet-overlay.test.ts
+++ b/apps/desktop/electron/pet-overlay.test.ts
@@ -9,7 +9,13 @@ import assert from 'node:assert/strict'
import { test } from 'vitest'
-import { clampRectToWorkArea, resolvePetOverlayBounds } from './pet-overlay'
+import { clampRectToWorkArea, petOverlayClickThrough, resolvePetOverlayBounds } from './pet-overlay'
+
+test('petOverlayClickThrough is off on Linux, where forward:true never re-arms the sprite', () => {
+ assert.equal(petOverlayClickThrough('darwin'), true)
+ assert.equal(petOverlayClickThrough('win32'), true)
+ assert.equal(petOverlayClickThrough('linux'), false)
+})
// A laptop panel left behind after a bigger external monitor is unplugged.
const LAPTOP = [{ workArea: { x: 0, y: 0, width: 1366, height: 728 } }]
diff --git a/apps/desktop/electron/pet-overlay.ts b/apps/desktop/electron/pet-overlay.ts
index bfa227dfebf..abfe9c501db 100644
--- a/apps/desktop/electron/pet-overlay.ts
+++ b/apps/desktop/electron/pet-overlay.ts
@@ -24,6 +24,13 @@ const MIN_SIZE = 80
const clamp = (v, lo, hi) => Math.max(lo, Math.min(v, hi))
+/**
+ * Whether the overlay may start click-through. `setIgnoreMouseEvents(true, { forward: true })`
+ * only forwards pointer moves on macOS/Windows; on Linux an ignoring overlay never hears the
+ * cursor re-enter the sprite, so it stays a solid window (the X11 HUD makes the same call).
+ */
+export const petOverlayClickThrough = (platform = process.platform) => platform !== 'linux'
+
/**
* Keep the WHOLE rect inside `workArea`: size is capped to the work area, then
* the origin is clamped so no edge crosses it.