Skip to content

Commit 8a522b8

Browse files
authored
Wayland: build pointer enter/leave with enterExitEventWithType: (#165)
+[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.
1 parent ae50120 commit 8a522b8

1 file changed

Lines changed: 12 additions & 14 deletions

File tree

Source/wayland/WaylandServer+Cursor.m

Lines changed: 12 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -87,19 +87,17 @@
8787
gcontext = GSCurrentContext();
8888
eventLocation = NSMakePoint(sx, window->height - sy);
8989

90-
event = [NSEvent mouseEventWithType:NSMouseEntered
90+
/* NSMouseEntered must be built with the enter/exit constructor;
91+
* +mouseEventWithType: rejects it ("mouseEvent with wrong type"). */
92+
event = [NSEvent enterExitEventWithType:NSMouseEntered
9193
location:eventLocation
9294
modifierFlags:wlconfig->modifiers
9395
timestamp:wlconfig->pointer.last_timestamp
9496
windowNumber:window->window_id
9597
context:gcontext
9698
eventNumber:serial
97-
clickCount:0
98-
pressure:0.0
99-
buttonNumber:0
100-
deltaX:deltaX
101-
deltaY:deltaY
102-
deltaZ:0.];
99+
trackingNumber:0
100+
userData:NULL];
103101

104102
[GSCurrentServer() postEvent:event atStart:NO];
105103
}
@@ -143,19 +141,19 @@
143141
gcontext = GSCurrentContext();
144142

145143
eventLocation = NSMakePoint(wlconfig->pointer.x, wlconfig->pointer.y);
146-
event = [NSEvent mouseEventWithType:NSMouseExited
144+
/* NSMouseExited is not a plain mouse event: +mouseEventWithType:
145+
* rejects it ("mouseEvent with wrong type"). This path is reached
146+
* whenever the pointer leaves while a button is held - notably at
147+
* the start of a drag - so it must use the enter/exit constructor. */
148+
event = [NSEvent enterExitEventWithType:NSMouseExited
147149
location:eventLocation
148150
modifierFlags:0
149151
timestamp:wlconfig->pointer.last_timestamp
150152
windowNumber:window->window_id
151153
context:gcontext
152154
eventNumber:serial
153-
clickCount:0
154-
pressure:0.0
155-
buttonNumber:0
156-
deltaX:0
157-
deltaY:0
158-
deltaZ:0.];
155+
trackingNumber:0
156+
userData:NULL];
159157

160158
[GSCurrentServer() postEvent:event atStart:NO];
161159
}

0 commit comments

Comments
 (0)