[gtk/wip/chergert/quartz4u] macos: discover NSWindow if one was not provided
- From: Christian Hergert <chergert src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gtk/wip/chergert/quartz4u] macos: discover NSWindow if one was not provided
- Date: Sat, 9 May 2020 19:04:41 +0000 (UTC)
commit 70ff231ea62735f0be1bfa4f074f5ff6ca48c0c6
Author: Christian Hergert <chergert redhat com>
Date: Sat May 9 12:03:44 2020 -0700
macos: discover NSWindow if one was not provided
gdk/macos/gdkmacosdisplay-private.h | 3 +++
gdk/macos/gdkmacosdisplay-translate.c | 18 ++++++++++++----
gdk/macos/gdkmacosdisplay.c | 40 +++++++++++++++++++++++++++++++++++
3 files changed, 57 insertions(+), 4 deletions(-)
---
diff --git a/gdk/macos/gdkmacosdisplay-private.h b/gdk/macos/gdkmacosdisplay-private.h
index 6d31144415..01c20ccfe2 100644
--- a/gdk/macos/gdkmacosdisplay-private.h
+++ b/gdk/macos/gdkmacosdisplay-private.h
@@ -64,6 +64,9 @@ void _gdk_macos_display_remove_frame_callback (GdkMacosDisp
GdkMacosSurface *surface);
void _gdk_macos_display_synthesize_motion (GdkMacosDisplay *self,
GdkMacosSurface *surface);
+NSWindow *_gdk_macos_display_find_native_under_pointer (GdkMacosDisplay *self,
+ int *x,
+ int *y);
G_END_DECLS
diff --git a/gdk/macos/gdkmacosdisplay-translate.c b/gdk/macos/gdkmacosdisplay-translate.c
index a1e107ef03..1ab1fdbeec 100644
--- a/gdk/macos/gdkmacosdisplay-translate.c
+++ b/gdk/macos/gdkmacosdisplay-translate.c
@@ -711,7 +711,20 @@ _gdk_macos_display_translate (GdkMacosDisplay *self,
/* Make sure the event has a window */
if (!(nswindow = [nsevent window]))
- return NULL;
+ {
+ int x_tmp;
+ int y_tmp;
+
+ if (!(nswindow = _gdk_macos_display_find_native_under_pointer (self, &x_tmp, &y_tmp)))
+ return NULL;
+
+ point.x = x_tmp;
+ point.y = y_tmp;
+ }
+ else
+ {
+ point = [[nswindow contentView] convertPoint:[nsevent locationInWindow] fromView:nil];
+ }
/* Ignore unless it is for a GdkMacosWindow */
if (!GDK_IS_MACOS_WINDOW (nswindow))
@@ -739,9 +752,6 @@ _gdk_macos_display_translate (GdkMacosDisplay *self,
if (!(surface = [window getGdkSurface]))
return NULL;
- /* Get the location of event within toplevel coordinates */
- point = [[window contentView] convertPoint:[nsevent locationInWindow] fromView:nil];
-
/* Quartz handles resizing on its own, so stay out of the way. */
if (test_resize (nsevent, surface, point.x, point.y))
return NULL;
diff --git a/gdk/macos/gdkmacosdisplay.c b/gdk/macos/gdkmacosdisplay.c
index bc60017710..8646cca36b 100644
--- a/gdk/macos/gdkmacosdisplay.c
+++ b/gdk/macos/gdkmacosdisplay.c
@@ -799,3 +799,43 @@ _gdk_macos_display_remove_frame_callback (GdkMacosDisplay *self,
if (self->awaiting_frames.length == 0)
gdk_display_link_source_pause ((GdkDisplayLinkSource *)self->frame_source);
}
+
+NSWindow *
+_gdk_macos_display_find_native_under_pointer (GdkMacosDisplay *self,
+ int *x,
+ int *y)
+{
+ NSPoint point;
+ int x_tmp;
+ int y_tmp;
+
+ g_assert (GDK_IS_MACOS_DISPLAY (self));
+
+ point = [NSEvent mouseLocation];
+
+ _gdk_macos_display_from_display_coords (self, point.x, point.y, &x_tmp, &y_tmp);
+
+ for (const GList *iter = self->surfaces.head; iter; iter = iter->next)
+ {
+ GdkSurface *surface = iter->data;
+
+ g_assert (GDK_IS_MACOS_SURFACE (surface));
+
+ if (x_tmp >= surface->x &&
+ x_tmp < surface->x + surface->width &&
+ y_tmp >= surface->y &&
+ y_tmp < surface->y + surface->height)
+ {
+ *x = x_tmp - surface->x;
+ *y = y_tmp - surface->y;
+
+ return _gdk_macos_surface_get_native (GDK_MACOS_SURFACE (surface));
+ }
+ }
+
+ *x = 0;
+ *y = 0;
+
+ return NULL;
+}
+
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]