Refine GdkQuartzNSWindow convertPointToScreen:

and convertPointFromScreen:, making them handle all MacOS versions
so that all of the if-deffing happens in the function definitions.
This happens to fix issue 1518 because it turns out that contrary
to the annotation in the 10.14 nNSWindow.h, convertPointToScreen and
convertPointFromScreen originate in 10.14, not 10.12.

Closes: https://gitlab.gnome.org/GNOME/gtk/issues/1518
This commit is contained in:
John Ralls 2018-12-14 16:10:35 -08:00
parent baa283b73b
commit aeec73f53f
3 changed files with 36 additions and 53 deletions

View File

@ -379,22 +379,46 @@
initialPositionKnown = NO;
}
#if MAC_OS_X_VERSION_MIN_REQUIRED < 101200
- (NSPoint)convertPointToScreen:(NSPoint)point
{
NSRect inrect = NSMakeRect (point.x, point.y, 0.0, 0.0);
NSRect outrect = [self convertRectToScreen: inrect];
return (NSPoint)((CGRect)outrect).origin;
#if MAC_OS_X_VERSION_MAX_ALLOWED >= 101400
if (gdk_quartz_osx_version () >= GDK_OSX_MOJAVE)
{
return [super convertPointToScreen: point];
}
#endif
if (gdk_quartz_osx_version () >= GDK_OSX_LION)
{
NSRect inrect = NSMakeRect (point.x, point.y, 0.0, 0.0);
NSRect outrect = [self convertRectToScreen: inrect];
return (NSPoint)((CGRect)outrect).origin;
}
#if MAC_OS_X_VERSION_MIN_REQUIRED < 1070
return [self convertBaseToScreen:point];
#endif
}
- (NSPoint)convertPointFromScreen:(NSPoint)point
{
NSRect inrect = NSMakeRect (point.x, point.y, 0.0, 0.0);
NSRect outrect = [self convertRectFromScreen: inrect];
return (NSPoint)((CGRect)outrect).origin;
}
#if MAC_OS_X_VERSION_MAX_ALLOWED >= 101400
if (gdk_quartz_osx_version () >= GDK_OSX_MOJAVE)
{
return [super convertPointToScreen: point];
}
#endif
if (gdk_quartz_osx_version () >= GDK_OSX_LION)
{
NSRect inrect = NSMakeRect (point.x, point.y, 0.0, 0.0);
NSRect outrect = [self convertRectFromScreen: inrect];
return (NSPoint)((CGRect)outrect).origin;
}
#if MAC_OS_X_VERSION_MIN_REQUIRED < 1070
return [self convertScreenToBase:point];
#endif
}
- (BOOL)trackManualMove
{
@ -407,11 +431,8 @@
if (!inManualMove)
return NO;
#if MAC_OS_X_VERSION_MIN_REQUIRED < 1070
currentLocation = [self convertBaseToScreen:[self mouseLocationOutsideOfEventStream]];
#else
currentLocation = [self convertPointToScreen:[self mouseLocationOutsideOfEventStream]];
#endif
newOrigin.x = currentLocation.x - initialMoveLocation.x;
newOrigin.y = currentLocation.y - initialMoveLocation.y;
@ -442,11 +463,7 @@
inManualMove = YES;
#if MAC_OS_X_VERSION_MIN_REQUIRED < 1070
initialMoveLocation = [self convertBaseToScreen:[self mouseLocationOutsideOfEventStream]];
#else
initialMoveLocation = [self convertPointToScreen:[self mouseLocationOutsideOfEventStream]];
#endif
initialMoveLocation.x -= frame.origin.x;
initialMoveLocation.y -= frame.origin.y;
}
@ -462,12 +479,7 @@
return NO;
inTrackManualResize = YES;
#if MAC_OS_X_VERSION_MIN_REQUIRED < 1070
mouse_location = [self convertBaseToScreen:[self mouseLocationOutsideOfEventStream]];
#else
mouse_location = [self convertPointToScreen:[self mouseLocationOutsideOfEventStream]];
#endif
mdx = initialResizeLocation.x - mouse_location.x;
mdy = initialResizeLocation.y - mouse_location.y;
@ -552,12 +564,7 @@
resizeEdge = edge;
initialResizeFrame = [self frame];
#if MAC_OS_X_VERSION_MIN_REQUIRED < 1070
initialResizeLocation = [self convertBaseToScreen:[self mouseLocationOutsideOfEventStream]];
#else
initialResizeLocation = [self convertPointToScreen:[self mouseLocationOutsideOfEventStream]];
#endif
}
@ -690,13 +697,7 @@ update_context_from_dragging_info (id <NSDraggingInfo> sender)
- (NSDragOperation)draggingUpdated:(id <NSDraggingInfo>)sender
{
NSPoint point = [sender draggingLocation];
NSPoint screen_point;
#if MAC_OS_X_VERSION_MIN_REQUIRED < 1070
screen_point = [self convertBaseToScreen:point];
#else
screen_point = [self convertPointToScreen:point];
#endif
NSPoint screen_point = [self convertPointToScreen:point];
GdkEvent *event;
int gx, gy;
@ -724,13 +725,7 @@ update_context_from_dragging_info (id <NSDraggingInfo> sender)
- (BOOL)performDragOperation:(id <NSDraggingInfo>)sender
{
NSPoint point = [sender draggingLocation];
NSPoint screen_point;
#if MAC_OS_X_VERSION_MIN_REQUIRED < 1070
screen_point = [self convertBaseToScreen:point];
#else
screen_point = [self convertPointToScreen:point];
#endif
NSPoint screen_point = [self convertPointToScreen:point];
GdkEvent *event;
int gy, gx;

View File

@ -53,10 +53,8 @@
#ifdef AVAILABLE_MAC_OS_X_VERSION_10_7_AND_LATER
-(void)setStyleMask:(NSUInteger)styleMask;
#endif
#if MAC_OS_X_VERSION_MIN_REQUIRED < 101200
- (NSPoint)convertPointToScreen:(NSPoint)point;
- (NSPoint)convertPointFromScreen:(NSPoint)point;
#endif
@end

View File

@ -379,12 +379,7 @@ get_window_point_from_screen_point (GdkWindow *window,
GdkQuartzNSWindow *nswindow;
nswindow = (GdkQuartzNSWindow*)(((GdkWindowImplQuartz *)window->impl)->toplevel);
#if MAC_OS_X_VERSION_MIN_REQUIRED < 1070
point = [nswindow convertScreenToBase:screen_point];
#else
point = [nswindow convertPointFromScreen:screen_point];
#endif
*x = point.x;
*y = window->height - point.y;
}
@ -460,12 +455,7 @@ get_toplevel_from_ns_event (NSEvent *nsevent,
}
else
{
if (gdk_quartz_osx_version () >= GDK_OSX_LION)
*screen_point = [(GdkQuartzNSWindow*)[nsevent window] convertPointToScreen:point];
#if MAC_OS_X_VERSION_MIN_REQUIRED < 10700
else
*screen_point = [[nsevent window] convertBaseToScreen:point];
#endif
*screen_point = [(GdkQuartzNSWindow*)[nsevent window] convertPointToScreen:point];
*x = point.x;
*y = toplevel->height - point.y;
}