macos: use input_region to specify tracking areas

We want our tracking area to be limited to the input region so that we
don't pass along events outside of them for the window. This improves the
chances we click-out of a popover with a large shadow.

This still doesn't let us pass-through clicks for large shadows on top-
level windows though.
This commit is contained in:
Christian Hergert 2022-02-04 17:24:13 -08:00
parent a080f1197a
commit f207402228
3 changed files with 30 additions and 2 deletions

View File

@ -45,7 +45,6 @@
options = (NSTrackingMouseEnteredAndExited |
NSTrackingMouseMoved |
NSTrackingInVisibleRect |
NSTrackingActiveAlways);
trackingArea = [[NSTrackingArea alloc] initWithRect:rect
options:options
@ -57,9 +56,26 @@
return self;
}
-(void)setInputArea:(const cairo_rectangle_int_t *)area
{
NSRect rect = NSMakeRect (area->x, area->y, area->width, area->height);
NSTrackingAreaOptions options;
[self removeTrackingArea:trackingArea];
options = (NSTrackingMouseEnteredAndExited |
NSTrackingMouseMoved |
NSTrackingActiveAlways);
trackingArea = [[NSTrackingArea alloc] initWithRect:rect
options:options
owner:(id)self
userInfo:nil];
[self addTrackingArea:trackingArea];
}
-(void)setOpaqueRegion:(cairo_region_t *)region
{
/* Do nothing */
/* Handled in Subclass */
}
-(BOOL)acceptsFirstMouse

View File

@ -42,5 +42,6 @@
-(void)setNeedsInvalidateShadow: (BOOL)invalidate;
-(NSTrackingArea *)trackingArea;
-(void)setOpaqueRegion:(cairo_region_t *)region;
-(void)setInputArea:(const cairo_rectangle_int_t *)area;
@end

View File

@ -94,6 +94,17 @@ static void
gdk_macos_surface_set_input_region (GdkSurface *surface,
cairo_region_t *region)
{
GdkMacosSurface *self = (GdkMacosSurface *)surface;
cairo_rectangle_int_t rect;
g_assert (GDK_IS_MACOS_SURFACE (self));
if (self->window == NULL)
return;
cairo_region_get_extents (region, &rect);
[(GdkMacosBaseView *)[self->window contentView] setInputArea:&rect];
}
static void