Cocoa: Added glfwGetCocoaView native access function

Resolves #2235

Co-authored-by: mightgoyardstill <mightgoyardstill@users.noreply.github.com>
This commit is contained in:
Doug Binks 2024-02-20 13:20:30 +00:00
parent 0bb605cd79
commit 1fb7f0e120
5 changed files with 40 additions and 0 deletions

View File

@ -154,6 +154,7 @@ video tutorials.
- Jonathan Mercier
- Marcel Metz
- Liam Middlebrook
- mightgoyardstill
- Ave Milia
- Icyllis Milica
- Jonathan Miller

View File

@ -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)

View File

@ -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

View File

@ -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)

View File

@ -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