[gtk/wip/chergert/quartz4u: 104/116] macos: fix positioning to be surface relative



commit bc6eca724dc5cb194a884f9a9300598e5b2241f3
Author: Christian Hergert <chergert redhat com>
Date:   Thu Jun 18 16:41:24 2020 -0700

    macos: fix positioning to be surface relative

 gdk/macos/gdkmacosdevice.c          | 13 +++++++++----
 gdk/macos/gdkmacossurface-private.h |  3 +++
 gdk/macos/gdkmacossurface.c         | 24 ++++++++++++++++++++++++
 3 files changed, 36 insertions(+), 4 deletions(-)
---
diff --git a/gdk/macos/gdkmacosdevice.c b/gdk/macos/gdkmacosdevice.c
index 454e2f6e9f..8e621fa6fe 100644
--- a/gdk/macos/gdkmacosdevice.c
+++ b/gdk/macos/gdkmacosdevice.c
@@ -156,8 +156,10 @@ gdk_macos_device_query_state (GdkDevice        *device,
 {
   GdkDisplay *display;
   NSPoint point;
-  gint x_tmp;
-  gint y_tmp;
+  int sx = 0;
+  int sy = 0;
+  int x_tmp;
+  int y_tmp;
 
   g_assert (GDK_IS_MACOS_DEVICE (device));
   g_assert (!surface || GDK_IS_MACOS_SURFACE (surface));
@@ -171,11 +173,14 @@ gdk_macos_device_query_state (GdkDevice        *device,
                                           point.x, point.y,
                                           &x_tmp, &y_tmp);
 
+  if (surface)
+    _gdk_macos_surface_get_root_coords (GDK_MACOS_SURFACE (surface), &sx, &sy);
+
   if (win_x)
-    *win_x = x_tmp;
+    *win_x = x_tmp - sx;
 
   if (win_y)
-    *win_y = y_tmp;
+    *win_y = y_tmp - sy;
 
   if (mask)
     *mask = _gdk_macos_display_get_current_keyboard_modifiers (GDK_MACOS_DISPLAY (display)) |
diff --git a/gdk/macos/gdkmacossurface-private.h b/gdk/macos/gdkmacossurface-private.h
index 83bb8ea80d..217813dda5 100644
--- a/gdk/macos/gdkmacossurface-private.h
+++ b/gdk/macos/gdkmacossurface-private.h
@@ -120,6 +120,9 @@ gboolean           _gdk_macos_surface_is_tracking             (GdkMacosSurface
 void               _gdk_macos_surface_monitor_changed         (GdkMacosSurface    *self);
 GdkMonitor        *_gdk_macos_surface_get_best_monitor        (GdkMacosSurface    *self);
 void               _gdk_macos_surface_reposition_children     (GdkMacosSurface    *self);
+void               _gdk_macos_surface_get_root_coords         (GdkMacosSurface    *self,
+                                                               int                *x,
+                                                               int                *y);
 
 G_END_DECLS
 
diff --git a/gdk/macos/gdkmacossurface.c b/gdk/macos/gdkmacossurface.c
index 5f5051112d..4e3d223044 100644
--- a/gdk/macos/gdkmacossurface.c
+++ b/gdk/macos/gdkmacossurface.c
@@ -1010,3 +1010,27 @@ _gdk_macos_surface_get_view (GdkMacosSurface *self)
 
   return [self->window contentView];
 }
+
+void
+_gdk_macos_surface_get_root_coords (GdkMacosSurface *self,
+                                    int             *x,
+                                    int             *y)
+{
+  GdkSurface *surface;
+  int out_x = 0;
+  int out_y = 0;
+
+  g_return_if_fail (GDK_IS_MACOS_SURFACE (self));
+
+  for (surface = GDK_SURFACE (self); surface; surface = surface->parent)
+    {
+      out_x += surface->x;
+      out_y += surface->y;
+    }
+
+  if (x)
+    *x = out_x;
+
+  if (y)
+    *y = out_y;
+}


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