From f20740222883972826d9343c44284532dd377412 Mon Sep 17 00:00:00 2001 From: Christian Hergert Date: Fri, 4 Feb 2022 17:24:13 -0800 Subject: [PATCH] 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. --- gdk/macos/GdkMacosBaseView.c | 20 ++++++++++++++++++-- gdk/macos/GdkMacosBaseView.h | 1 + gdk/macos/gdkmacossurface.c | 11 +++++++++++ 3 files changed, 30 insertions(+), 2 deletions(-) diff --git a/gdk/macos/GdkMacosBaseView.c b/gdk/macos/GdkMacosBaseView.c index ddce1241a3..a86d9712b2 100644 --- a/gdk/macos/GdkMacosBaseView.c +++ b/gdk/macos/GdkMacosBaseView.c @@ -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 diff --git a/gdk/macos/GdkMacosBaseView.h b/gdk/macos/GdkMacosBaseView.h index 7fcfc7e43b..2eb6f72721 100644 --- a/gdk/macos/GdkMacosBaseView.h +++ b/gdk/macos/GdkMacosBaseView.h @@ -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 diff --git a/gdk/macos/gdkmacossurface.c b/gdk/macos/gdkmacossurface.c index b28fb27083..a2c7bb485d 100644 --- a/gdk/macos/gdkmacossurface.c +++ b/gdk/macos/gdkmacossurface.c @@ -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 -- 2.30.2