[gtk/wip/chergert/macos-iosurface: 6/11] macos: use input_region to specify tracking areas




commit 5860e792efc49de3d879d09705f3f37bc3798085
Author: Christian Hergert <christian hergert me>
Date:   Fri Feb 4 17:24:13 2022 -0800

    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 c5cf05edf8..c637bd0685 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


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]