[gtk/macos-ci: 1/3] macos: handle point conversion on older macOS




commit 28a6f0df0522e1271badd1722387b5e18e16e3b6
Author: Christian Hergert <chergert redhat com>
Date:   Tue Jan 5 13:52:11 2021 -0800

    macos: handle point conversion on older macOS
    
    On older systems, the availability of some methods seem to be incorrect
    based on Apple documentation. This works around the issue by using
    the rect conversion on older systems.

 gdk/macos/GdkMacosWindow.c            |  4 ++--
 gdk/macos/gdkmacosdisplay-translate.c |  4 ++--
 gdk/macos/gdkmacosutils-private.h     | 31 +++++++++++++++++++++++++++++++
 3 files changed, 35 insertions(+), 4 deletions(-)
---
diff --git a/gdk/macos/GdkMacosWindow.c b/gdk/macos/GdkMacosWindow.c
index e85ebf8805..f4fcd01ad5 100644
--- a/gdk/macos/GdkMacosWindow.c
+++ b/gdk/macos/GdkMacosWindow.c
@@ -466,7 +466,7 @@
 
   inTrackManualResize = YES;
 
-  mouse_location = [self convertPointToScreen:[self mouseLocationOutsideOfEventStream]];
+  mouse_location = convert_nspoint_to_screen (self, [self mouseLocationOutsideOfEventStream]);
   mdx = initialResizeLocation.x - mouse_location.x;
   mdy = initialResizeLocation.y - mouse_location.y;
 
@@ -588,7 +588,7 @@
     }
 
   initialResizeFrame = [self frame];
-  initialResizeLocation = [self convertPointToScreen:[self mouseLocationOutsideOfEventStream]];
+  initialResizeLocation = convert_nspoint_to_screen (self, [self mouseLocationOutsideOfEventStream]);
 }
 
 -(NSDragOperation)draggingEntered:(id <NSDraggingInfo>)sender
diff --git a/gdk/macos/gdkmacosdisplay-translate.c b/gdk/macos/gdkmacosdisplay-translate.c
index b638b87ab9..e6551581a2 100644
--- a/gdk/macos/gdkmacosdisplay-translate.c
+++ b/gdk/macos/gdkmacosdisplay-translate.c
@@ -700,7 +700,7 @@ get_surface_point_from_screen_point (GdkSurface *surface,
   NSPoint point;
 
   nswindow = _gdk_macos_surface_get_native (GDK_MACOS_SURFACE (surface));
-  point = [nswindow convertPointFromScreen:screen_point];
+  point = convert_nspoint_from_screen (nswindow, screen_point);
 
   *x = point.x;
   *y = surface->height - point.y;
@@ -821,7 +821,7 @@ get_surface_from_ns_event (GdkMacosDisplay *self,
         }
       else
         {
-          *screen_point = [(GdkMacosWindow *)[nsevent window] convertPointToScreen:point];
+          *screen_point = convert_nspoint_to_screen ([nsevent window], point);
           *x = point.x;
           *y = surface->height - point.y;
         }
diff --git a/gdk/macos/gdkmacosutils-private.h b/gdk/macos/gdkmacosutils-private.h
index 6b81fd28ac..dd8d3b296a 100644
--- a/gdk/macos/gdkmacosutils-private.h
+++ b/gdk/macos/gdkmacosutils-private.h
@@ -40,5 +40,36 @@ struct _GdkPoint
 };
 typedef struct _GdkPoint GdkPoint;
 
+static inline NSPoint
+convert_nspoint_from_screen (NSWindow *window,
+                             NSPoint   point)
+{
+#ifdef AVAILABLE_MAC_OS_X_VERSION_10_15_AND_LATER
+  return [window convertPointFromScreen:point];
+#else
+  /* Apple documentation claims that convertPointFromScreen is available
+   * on 10.12+. However, that doesn't seem to be the case when using it.
+   * Instead, we'll just use it on modern 10.15 systems and fallback to
+   * converting using rects on older systems.
+   */
+  return [window convertRectFromScreen:NSMakeRect (point.x, point.y, 0, 0)].origin;
+#endif
+}
+
+static inline NSPoint
+convert_nspoint_to_screen (NSWindow *window,
+                           NSPoint   point)
+{
+#ifdef AVAILABLE_MAC_OS_X_VERSION_10_15_AND_LATER
+  return [window convertPointToScreen:point];
+#else
+  /* Apple documentation claims that convertPointToScreen is available
+   * on 10.12+. However, that doesn't seem to be the case when using it.
+   * Instead, we'll just use it on modern 10.15 systems and fallback to
+   * converting using rects on older systems.
+   */
+  return [window convertRectToScreen:NSMakeRect (point.x, point.y, 0, 0)].origin;
+#endif
+}
 
 #endif /* __GDK_MACOS_UTILS_PRIVATE_H__ */


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