OSX: WindowID of plugin editor


#1

I need to get the WindowID of the plugin editor’s view. I tried thePluginEditor->getPeer()->getNativeHandle() but that one is not correct, at least not for VST32 Bit, because it is a Carbon interface in a Cocoa one (?).

How can I get that WindowID reliably?


#2

So far I’ve come up with this:

The native handle returned by JUCE is a NSView* . From the NSView, I get the reference to the NSWindow (= DocumentWindow with native title bar). Then I traverse the child windows recursively (always only taking first one) until I reach the last child, which is the plugin editor’s view, and I use that windowID.

There seems to be a problem though, and I assume it’s a JUCE bug: The first time this all works, but after removing the plugin from the DocumentWindow and adding it as child to another component, then putting it back into the DocumentWindow, there’s a problem. In fact after doing so, the number of child windows reported by the NSWindow is not 1 anymore, but 2, which is wrong. It seems that the JUCE code forgets to remove the NSWindow children?


#3

Well, NSWindows don’t actually have “children” in the same way that MS Windows does. The best they can do it to create a window group, which keeps a bunch of windows in sync, and that’s what I do. AFAIK I’m doing it correctly, but there’s a lot of scope for ref-counting issues, since the parent will keep a ref-count to its attached windows, so even after juce has released it, the host could still hang on to that object.


#4

I’m not sure if you like that suggestion, but I would personally find it very useful to be able to get the native handle of the window of the AudioProcessor without even showing that window on screen. Thus I could add it myself to whatever other OS windows I want to, without directly relying on JUCE. For the code I’m working on right now, this would avoid me much hassle. I know that the current plugin editor code cannot be changed easily to meet that demand though, so I assume you’ll not be up for it.


#5

Sorry, sounds like I could burn a lot of time trying to sort that out for you, and I doubt if anyone else would ever need it.