From e1ac292eeb5d2d554d8259bdf6b2697d5b44d69d Mon Sep 17 00:00:00 2001 From: ciregenz Date: Tue, 16 Jun 2026 08:03:34 -0700 Subject: [PATCH] [eric] mouseclamp: also clamp off-window releases whose event has no window (key-window fallback + screen->window map), closes the gap that still crashed RootView::UpdateCursor on 1.2.84 --- electron/native/mouseclamp/mouseclamp.mm | 17 ++++++++++++++--- 1 file changed, 14 insertions(+), 3 deletions(-) diff --git a/electron/native/mouseclamp/mouseclamp.mm b/electron/native/mouseclamp/mouseclamp.mm index ff1b5f9d..1bc7869f 100644 --- a/electron/native/mouseclamp/mouseclamp.mm +++ b/electron/native/mouseclamp/mouseclamp.mm @@ -24,9 +24,20 @@ static NSEvent *ClampOffWindowRelease(NSEvent *event) { return event; } NSWindow *win = [event window]; + NSPoint p; + if (win && [win contentView]) { + // Normal case: the captured window rode along on the event. + p = [event locationInWindow]; + } else { + // The original gap: a release off the source window (easy with a second + // display) can arrive with no window attached, so the old code fail-opened + // here and the crash slipped through. Fall back to the key/main window and + // map the screen-space location into it so we can still snap it. + win = [NSApp keyWindow] ?: [NSApp mainWindow]; + if (!win || ![win contentView]) return event; + p = [win convertPointFromScreen:[event locationInWindow]]; + } NSView *content = [win contentView]; - if (!content) return event; - NSPoint p = [event locationInWindow]; NSSize ws = [win frame].size; NSRect cb = [content frame]; // all the misfire-prone arithmetic lives in clamp_decision() so the property @@ -40,7 +51,7 @@ static NSEvent *ClampOffWindowRelease(NSEvent *event) { location:NSMakePoint(d.x, d.y) modifierFlags:[event modifierFlags] timestamp:[event timestamp] - windowNumber:[event windowNumber] + windowNumber:[win windowNumber] context:nil eventNumber:[event eventNumber] clickCount:[event clickCount]