[gtk/wip/chergert/for-main] macos: add quirk for preventing window activation



commit 593d98470ec7d9afcdf2cbc6e2c569f4ed487667
Author: Christian Hergert <christian hergert me>
Date:   Thu Mar 10 23:49:04 2022 -0800

    macos: add quirk for preventing window activation
    
    We don't want this in some cases, such as when using server-side
    decorations or we get in the way of NSWindow.

 gdk/macos/GdkMacosView.c              | 16 ++++++++++------
 gdk/macos/GdkMacosWindow.c            |  6 ++++++
 gdk/macos/GdkMacosWindow.h            |  1 +
 gdk/macos/gdkmacosdisplay-translate.c |  8 +++++++-
 4 files changed, 24 insertions(+), 7 deletions(-)
---
diff --git a/gdk/macos/GdkMacosView.c b/gdk/macos/GdkMacosView.c
index 4cea135146..18de78aa19 100644
--- a/gdk/macos/GdkMacosView.c
+++ b/gdk/macos/GdkMacosView.c
@@ -24,6 +24,7 @@
 
 #import "GdkMacosLayer.h"
 #import "GdkMacosView.h"
+#import "GdkMacosWindow.h"
 
 @implementation GdkMacosView
 
@@ -58,12 +59,15 @@
 
 -(void)mouseDown:(NSEvent *)nsevent
 {
-  /* We should only hit this when we are trying to click through
-   * the shadow of a window into another window. Just request
-   * that the application not activate this window on mouseUp.
-   * See gdkmacosdisplay-translate.c for the other half of this.
-   */
-  [NSApp preventWindowOrdering];
+  if ([(GdkMacosWindow *)[self window] needsMouseDownQuirk])
+    /* We should only hit this when we are trying to click through
+     * the shadow of a window into another window. Just request
+     * that the application not activate this window on mouseUp.
+     * See gdkmacosdisplay-translate.c for the other half of this.
+     */
+    [NSApp preventWindowOrdering];
+  else
+    [super mouseDown:nsevent];
 }
 
 -(void)setFrame:(NSRect)rect
diff --git a/gdk/macos/GdkMacosWindow.c b/gdk/macos/GdkMacosWindow.c
index d2d69f8b3e..1967bd89e0 100644
--- a/gdk/macos/GdkMacosWindow.c
+++ b/gdk/macos/GdkMacosWindow.c
@@ -827,4 +827,10 @@ typedef NSString *CALayerContentsGravity;
   [(GdkMacosView *)[self contentView] swapBuffer:buffer withDamage:damage];
 }
 
+-(BOOL)needsMouseDownQuirk
+{
+  return GDK_IS_MACOS_TOPLEVEL_SURFACE (gdk_surface) &&
+    !GDK_MACOS_TOPLEVEL_SURFACE (gdk_surface)->decorated;
+}
+
 @end
diff --git a/gdk/macos/GdkMacosWindow.h b/gdk/macos/GdkMacosWindow.h
index cb8b2efad1..3a514ea857 100644
--- a/gdk/macos/GdkMacosWindow.h
+++ b/gdk/macos/GdkMacosWindow.h
@@ -69,5 +69,6 @@
 -(BOOL)trackManualResize;
 -(void)setDecorated:(BOOL)decorated;
 -(void)swapBuffer:(GdkMacosBuffer *)buffer withDamage:(const cairo_region_t *)damage;
+-(BOOL)needsMouseDownQuirk;
 
 @end
diff --git a/gdk/macos/gdkmacosdisplay-translate.c b/gdk/macos/gdkmacosdisplay-translate.c
index 92523f8895..9caddca811 100644
--- a/gdk/macos/gdkmacosdisplay-translate.c
+++ b/gdk/macos/gdkmacosdisplay-translate.c
@@ -1168,13 +1168,19 @@ _gdk_macos_display_translate (GdkMacosDisplay *self,
 
       if (![window isKeyWindow])
         {
+          NSWindow *orig_window = [nsevent window];
+
           /* To get NSApp to supress activating the window we might
            * have clicked through the shadow of, we need to dispatch
            * the event and handle it in GdkMacosView:mouseDown to call
            * [NSApp preventWindowOrdering]. Calling it here will not
            * do anything as the event is not registered.
            */
-          [NSApp sendEvent:nsevent];
+          if (orig_window &&
+              GDK_IS_MACOS_WINDOW (orig_window) &&
+              [(GdkMacosWindow *)orig_window needsMouseDownQuirk])
+            [NSApp sendEvent:nsevent];
+
           [window showAndMakeKey:YES];
           _gdk_macos_display_clear_sorting (self);
         }


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