[gtk/macos-ci] macos: be more compatible with older macOS




commit 3719709ea50be95c7b653706e59aad6f1ce94440
Author: Christian Hergert <chergert redhat com>
Date:   Mon Jan 4 19:21:58 2021 -0800

    macos: be more compatible with older macOS

 gdk/macos/GdkMacosWindow.c            |  8 ++++++--
 gdk/macos/gdkmacosclipboard-private.h |  4 ++++
 gdk/macos/gdkmacosdisplay-translate.c |  4 ++--
 gdk/macos/gdkmacosutils-private.h     | 26 +++++++++++++++++++++++---
 4 files changed, 35 insertions(+), 7 deletions(-)
---
diff --git a/gdk/macos/GdkMacosWindow.c b/gdk/macos/GdkMacosWindow.c
index e85ebf8805..3afcdeb826 100644
--- a/gdk/macos/GdkMacosWindow.c
+++ b/gdk/macos/GdkMacosWindow.c
@@ -38,6 +38,10 @@
 #include "gdkmonitorprivate.h"
 #include "gdksurfaceprivate.h"
 
+#ifndef AVAILABLE_MAC_OS_X_VERSION_10_15_AND_LATER
+typedef NSString *CALayerContentsGravity;
+#endif
+
 @implementation GdkMacosWindow
 
 -(BOOL)windowShouldClose:(id)sender
@@ -466,7 +470,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 +592,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/gdkmacosclipboard-private.h b/gdk/macos/gdkmacosclipboard-private.h
index ab37d707a5..01a562c2b8 100644
--- a/gdk/macos/gdkmacosclipboard-private.h
+++ b/gdk/macos/gdkmacosclipboard-private.h
@@ -27,6 +27,10 @@
 
 G_BEGIN_DECLS
 
+#ifndef AVAILABLE_MAC_OS_X_VERSION_10_13_AND_LATER
+typedef NSString *NSPasteboardType;
+#endif
+
 #define GDK_TYPE_MACOS_CLIPBOARD (_gdk_macos_clipboard_get_type())
 
 G_DECLARE_FINAL_TYPE (GdkMacosClipboard, _gdk_macos_clipboard, GDK, MACOS_CLIPBOARD, GdkClipboard)
diff --git a/gdk/macos/gdkmacosdisplay-translate.c b/gdk/macos/gdkmacosdisplay-translate.c
index b638b87ab9..629acb517c 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_from_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..d774f3053c 100644
--- a/gdk/macos/gdkmacosutils-private.h
+++ b/gdk/macos/gdkmacosutils-private.h
@@ -33,12 +33,32 @@ queue_contains (GQueue *queue,
   return queue->head == link_ || link_->prev || link_->next;
 }
 
-struct _GdkPoint
+typedef struct _GdkPoint
 {
   int x;
   int y;
-};
-typedef struct _GdkPoint GdkPoint;
+} GdkPoint;
 
+static inline NSPoint
+convert_nspoint_from_screen (NSWindow *window,
+                             NSPoint   point)
+{
+  /* convertPointFromScreen is only available on 10.12 and doesn't seem to
+   * actually be usable, even from 10.13. So instead we'll use this which
+   * is available from 10.7+.
+   */
+  return [window convertRectFromScreen:NSMakeRect (point.x, point.y, 1, 1)].origin;
+}
+
+static inline NSPoint
+convert_nspoint_to_screen (NSWindow *window,
+                           NSPoint   point)
+{
+  /* convertPointToScreen is only available on 10.12 and doesn't seem to
+   * actually be usable, even from 10.13. So instead we'll use this which
+   * is available from 10.7+.
+   */
+  return [window convertRectToScreen:NSMakeRect (point.x, point.y, 1, 1)].origin;
+}
 
 #endif /* __GDK_MACOS_UTILS_PRIVATE_H__ */


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