[gtk/wip/chergert/for-main] macos: fix window activation during shadow click-through
- From: Christian Hergert <chergert src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gtk/wip/chergert/for-main] macos: fix window activation during shadow click-through
- Date: Fri, 11 Mar 2022 01:27:25 +0000 (UTC)
commit b0e7e215ccf5a1493f943bf0c88dbb776624e03b
Author: Christian Hergert <christian hergert me>
Date: Thu Mar 10 17:26:56 2022 -0800
macos: fix window activation during shadow click-through
If we are clicking through the shadow of a window, we need to take special
care to not raise the old window on mouseUp. This is normally done by the
display server for us, so we need to use the proper API that is public to
handle this (rather than CGSSetWindowTags()). Doing so requires us to
dispatch the event to the NSView and then cancel the activcation from
the mouseDown: event there.
gdk/macos/GdkMacosView.c | 10 ++++++++++
gdk/macos/GdkMacosWindow.c | 4 ++--
gdk/macos/gdkmacosdisplay-translate.c | 18 ++++++++++++++----
3 files changed, 26 insertions(+), 6 deletions(-)
---
diff --git a/gdk/macos/GdkMacosView.c b/gdk/macos/GdkMacosView.c
index 52a55a7cef..4cea135146 100644
--- a/gdk/macos/GdkMacosView.c
+++ b/gdk/macos/GdkMacosView.c
@@ -56,6 +56,16 @@
return NO;
}
+-(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];
+}
+
-(void)setFrame:(NSRect)rect
{
[super setFrame:rect];
diff --git a/gdk/macos/GdkMacosWindow.c b/gdk/macos/GdkMacosWindow.c
index 836ded78e8..1d81dbe917 100644
--- a/gdk/macos/GdkMacosWindow.c
+++ b/gdk/macos/GdkMacosWindow.c
@@ -262,9 +262,9 @@ typedef NSString *CALayerContentsGravity;
inShowOrHide = YES;
if (makeKey && [self canBecomeKeyWindow])
- [self makeKeyAndOrderFront:nil];
+ [self makeKeyAndOrderFront:self];
else
- [self orderFront:nil];
+ [self orderFront:self];
inShowOrHide = NO;
diff --git a/gdk/macos/gdkmacosdisplay-translate.c b/gdk/macos/gdkmacosdisplay-translate.c
index 4ad12ba778..92523f8895 100644
--- a/gdk/macos/gdkmacosdisplay-translate.c
+++ b/gdk/macos/gdkmacosdisplay-translate.c
@@ -1159,15 +1159,25 @@ _gdk_macos_display_translate (GdkMacosDisplay *self,
if (test_resize (nsevent, surface, x, y))
return NULL;
- if ((event_type == NSEventTypeRightMouseDown ||
- event_type == NSEventTypeOtherMouseDown ||
- event_type == NSEventTypeLeftMouseDown))
+ if (event_type == NSEventTypeRightMouseDown ||
+ event_type == NSEventTypeOtherMouseDown ||
+ event_type == NSEventTypeLeftMouseDown)
{
if (![NSApp isActive])
[NSApp activateIgnoringOtherApps:YES];
if (![window isKeyWindow])
- [window makeKeyWindow];
+ {
+ /* 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];
+ [window showAndMakeKey:YES];
+ _gdk_macos_display_clear_sorting (self);
+ }
}
switch ((int)event_type)
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]