From 56e11ebd17838274c87352e622a556fbf10d20ec Mon Sep 17 00:00:00 2001 From: Todd White Date: Tue, 14 Jul 2026 20:08:55 -0400 Subject: [PATCH] Wayland: build pointer enter/leave with enterExitEventWithType: +[NSEvent mouseEventWithType:] raises an NSInvalidArgumentException ("mouseEvent with wrong type") for NSMouseEntered and NSMouseExited, because GSMouseEventMask does not include those types. The leave handler reaches this whenever the pointer leaves while a button is held, for example at the start of a drag, so both handlers must use the enter/exit event constructor instead. --- Source/wayland/WaylandServer+Cursor.m | 26 ++++++++++++-------------- 1 file changed, 12 insertions(+), 14 deletions(-) diff --git a/Source/wayland/WaylandServer+Cursor.m b/Source/wayland/WaylandServer+Cursor.m index f6ea49e9..2ae7a676 100644 --- a/Source/wayland/WaylandServer+Cursor.m +++ b/Source/wayland/WaylandServer+Cursor.m @@ -87,19 +87,17 @@ gcontext = GSCurrentContext(); eventLocation = NSMakePoint(sx, window->height - sy); - event = [NSEvent mouseEventWithType:NSMouseEntered + /* NSMouseEntered must be built with the enter/exit constructor; + * +mouseEventWithType: rejects it ("mouseEvent with wrong type"). */ + event = [NSEvent enterExitEventWithType:NSMouseEntered location:eventLocation modifierFlags:wlconfig->modifiers timestamp:wlconfig->pointer.last_timestamp windowNumber:window->window_id context:gcontext eventNumber:serial - clickCount:0 - pressure:0.0 - buttonNumber:0 - deltaX:deltaX - deltaY:deltaY - deltaZ:0.]; + trackingNumber:0 + userData:NULL]; [GSCurrentServer() postEvent:event atStart:NO]; } @@ -143,19 +141,19 @@ gcontext = GSCurrentContext(); eventLocation = NSMakePoint(wlconfig->pointer.x, wlconfig->pointer.y); - event = [NSEvent mouseEventWithType:NSMouseExited + /* NSMouseExited is not a plain mouse event: +mouseEventWithType: + * rejects it ("mouseEvent with wrong type"). This path is reached + * whenever the pointer leaves while a button is held - notably at + * the start of a drag - so it must use the enter/exit constructor. */ + event = [NSEvent enterExitEventWithType:NSMouseExited location:eventLocation modifierFlags:0 timestamp:wlconfig->pointer.last_timestamp windowNumber:window->window_id context:gcontext eventNumber:serial - clickCount:0 - pressure:0.0 - buttonNumber:0 - deltaX:0 - deltaY:0 - deltaZ:0.]; + trackingNumber:0 + userData:NULL]; [GSCurrentServer() postEvent:event atStart:NO]; }