diff --git a/CONTRIBUTORS.md b/CONTRIBUTORS.md index d2706831..26a2936a 100644 --- a/CONTRIBUTORS.md +++ b/CONTRIBUTORS.md @@ -154,6 +154,7 @@ video tutorials. - Jonathan Mercier - Marcel Metz - Liam Middlebrook + - mightgoyardstill - Ave Milia - Icyllis Milica - Jonathan Miller diff --git a/README.md b/README.md index 95ac99c4..787560a6 100644 --- a/README.md +++ b/README.md @@ -180,6 +180,7 @@ information on what to include when reporting a bug. - [Win32] Added a version info resource to the GLFW DLL - [Win32] Made hidden helper window use its own window class - [Win32] Bugfix: The foreground lock timeout was overridden, ignoring the user + - [Cocoa] Added `glfwGetCocoaView` native access function (#2235) - [Cocoa] Moved main menu creation to GLFW initialization time (#1649) - [Cocoa] Bugfix: Touching event queue from secondary thread before main thread would abort (#1649) diff --git a/docs/news.md b/docs/news.md index 823c0d6e..2eefc1b9 100644 --- a/docs/news.md +++ b/docs/news.md @@ -7,6 +7,12 @@ ### New features in version 3.4 {#features_34} +#### Cocoa NSView native access function {#native_cocoa_nsview_34} + +GLFW now provides the @ref glfwGetCocoaView native access function +for returning the Cocoa NSView. + + #### Runtime platform selection {#runtime_platform_34} GLFW now supports being compiled for multiple backends and selecting between diff --git a/include/GLFW/glfw3native.h b/include/GLFW/glfw3native.h index 46072920..92f0d324 100644 --- a/include/GLFW/glfw3native.h +++ b/include/GLFW/glfw3native.h @@ -286,6 +286,23 @@ GLFWAPI CGDirectDisplayID glfwGetCocoaMonitor(GLFWmonitor* monitor); * @ingroup native */ GLFWAPI id glfwGetCocoaWindow(GLFWwindow* window); + +/*! @brief Returns the `NSView` of the specified window. + * + * @return The `NSView` of the specified window, or `nil` if an + * [error](@ref error_handling) occurred. + * + * @errors Possible errors include @ref GLFW_NOT_INITIALIZED and @ref + * GLFW_PLATFORM_UNAVAILABLE. + * + * @thread_safety This function may be called from any thread. Access is not + * synchronized. + * + * @since Added in version 3.4. + * + * @ingroup native + */ +GLFWAPI id glfwGetCocoaView(GLFWwindow* window); #endif #if defined(GLFW_EXPOSE_NATIVE_NSGL) diff --git a/src/cocoa_window.m b/src/cocoa_window.m index 7e90cf99..96b6ca61 100644 --- a/src/cocoa_window.m +++ b/src/cocoa_window.m @@ -2053,5 +2053,20 @@ GLFWAPI id glfwGetCocoaWindow(GLFWwindow* handle) return window->ns.object; } +GLFWAPI id glfwGetCocoaView(GLFWwindow* handle) +{ + _GLFWwindow* window = (_GLFWwindow*) handle; + _GLFW_REQUIRE_INIT_OR_RETURN(nil); + + if (_glfw.platform.platformID != GLFW_PLATFORM_COCOA) + { + _glfwInputError(GLFW_PLATFORM_UNAVAILABLE, + "Cocoa: Platform not initialized"); + return nil; + } + + return window->ns.view; +} + #endif // _GLFW_COCOA