How to get the NSView from glfwGetCocoaWindow()? (without obj-c++)

so i need to get NSView as i’m making a window to pipe through some graphics from a plugin (using the vst3sdk).

i’ve looked
here:
but unfortunately i can only get the NSWindow ID from it? and theres not much else there regarding NSView

if i look at the cocoa_window.m file at line 327 here

it seems like its there? i just don’t know how to get it from my c++ code and currently have to compile the file as obj-c++ and use:

  NSWindow* nsWindow = glfwGetCocoaWindow(editorWindow);
  NSView* nsView = nsWindow.contentView;
  view->attached(nsView, Steinberg::kPlatformTypeNSView);

(which is something i’d rather avoid if i can!)

I don’t think there is a way to do this without Objective-C/C++. The GLFW Cocoa source code is itself Objective-C. A simple approach might be to make a very small library which does the work you need in Objective-C and thus you can stay in C/C++ for the rest of your code.

ah i was afraid of that! unfortunately i’ve never looked at obj-c or obj-c++ before today… is there a reason the NSWindow can be exposed via glfwGetCocoaWindow() but there isn’t something like a glfwGetCocoaView() which can expose the NSView in your C++ code?

with that aside i have started to write a getNSView obj-c++ file…

#import <Cocoa/Cocoa.h>

NSView *getNSView(GLFWwindow *glfwWindow)
{
  NSWindow* nsWindow = glfwGetCocoaWindow(glfwWindow);
  NSView* nsView = nsWindow.contentView;

  return nsView;
}

where in my main c++ code i originally had this?

  editorWindow = glfwCreateWindow(
    dimensions.getWidth(), dimensions.getHeight(),
    "VST 3 SDK", nullptr, nullptr);

  glfwSetWindowAttrib(editorWindow, GLFW_RESIZABLE, false);

  NSWindow* nsWindow = glfwGetCocoaWindow(editorWindow);
  NSView* nsView = nsWindow.contentView;
  view->attached(nsView, Steinberg::kPlatformTypeNSView);

here theres the definition for glfwGetCocoaWindow()? could it be possible to simply add my own glfwGetCocoaView() through a patch?

for example?

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 NULL;
    }

    return window->ns.view;
}

You can definitely add that to your own fork of GLFW, and potentially submit a PR. I don’t know if it will be accepted as I think the reason this wasn’t included was that the most users of the API would need to write in Objective-C to access the native functionality, and GLFW tries to be lightweight by minimizing API surface area.