From c7c9b54459f3f2838533b9ce4f2a1fa705204830 Mon Sep 17 00:00:00 2001 From: Cem Karan Date: Fri, 18 Dec 2015 09:53:14 -0500 Subject: [PATCH] Incorporated code from Matt Reagan on the Cocoa-dev mailing list for fast window position updates. This is a direct copy of Matt's code, which is able to determine the current position of a window while it's being dragged. --- src/cocoa_window.m | 27 +++++++++++++++++++++++---- 1 file changed, 23 insertions(+), 4 deletions(-) diff --git a/src/cocoa_window.m b/src/cocoa_window.m index d1075d2cf..36cf81f7d 100644 --- a/src/cocoa_window.m +++ b/src/cocoa_window.m @@ -938,13 +938,32 @@ void _glfwPlatformSetWindowTitle(_GLFWwindow* window, const char *title) void _glfwPlatformGetWindowPos(_GLFWwindow* window, int* xpos, int* ypos) { - const NSRect contentRect = - [window->ns.object contentRectForFrameRect:[window->ns.object frame]]; + // Code from Matt Reagan on the Cocoa-dev mailing list. + CGRect rect; + CGWindowID windowID = (CGWindowID)[window->ns.object windowNumber]; + CFArrayRef windowArray = CGWindowListCopyWindowInfo(kCGWindowListOptionIncludingWindow, windowID); + + if (CFArrayGetCount(windowArray)) + { + CFDictionaryRef windowInfoDictionary = (CFDictionaryRef)CFArrayGetValueAtIndex ((CFArrayRef)windowArray, 0); + + if (CFDictionaryContainsKey(windowInfoDictionary, kCGWindowBounds)) + { + CFDictionaryRef bounds = (CFDictionaryRef)CFDictionaryGetValue(windowInfoDictionary, kCGWindowBounds); + + if (bounds) + { + CGRectMakeWithDictionaryRepresentation(bounds, &rect); + } + } + } + + CFRelease(windowArray); if (xpos) - *xpos = contentRect.origin.x; + *xpos = rect.origin.x; if (ypos) - *ypos = transformY(contentRect.origin.y + contentRect.size.height); + *ypos = rect.origin.y; } void _glfwPlatformSetWindowPos(_GLFWwindow* window, int x, int y)