How to implement floating docks? (aka. how to specify a parent window for a top level window)

I’m talking about a window which always stays on top of the main window but is otherwise not always on top (i.e. it can be covered by windows from other applications). A lot of applications have this kind of docks, Visual Studio is one example. I’m also quite sure applications do that on Mac OS X as well.

In Windows this is done by setting up your main window as the owner of your dock. You can’t set your window as always on top since then it covers windows from other applications as well. And if you don’t set up the owner of your dock, then it will be covered by your main window, and it’s almost impossible for users to bring it back to the top.

You can kind of emulate that in JUCE by doing something like this:

MyDockWindow::MyDockWindow(Component *ourMainWindow)
    DocumentWindow("", some_color, DocumentWindow::allButtons, false)
    // setup window
    AppLookAndFeel::setUpNativeWindowStyle(*this, true);
    // ... and so on

    // Add window to desktop now
    int flags = DocumentWindow::getDesktopWindowStyleFlags() &
    addToDesktop(flags, ourMainWindow->getPeer()->getNativeHandle());

But this messes up the internal bookkeeping of JUCE, it no longer knows which window is on top. So for instance drag operations to the docks won’t always work because JUCE thinks the main window is on top.

It is also possible to use setAlwaysOnTop(true) when the application gains focus, but setAlwaysOnTop(false) when losing focus doesn’t do the trick because at that point some other application window has focus and that window will not come on top of the docks anymore.

Is there any way to support this in JUCE?

1 Like

Would it be possible to add this in the JUCE core? I don’t know how (or why) JUCE keeps its own list of which windows are on top of which other windows, but this already has to take into account the always on top property of windows. This setting would add a third ‘layer’ in between.

I’m asking because we tried a few workarounds, and all of them are either plain broken, or they interfere with window management in some other aggravating way. For instance, using always on top has the obvious flaw that the window still covers other applications after you switch between apps. Or some of you will remember the old GIMP behaviour, where all docks showed up as separate top level windows in the taskbar.

1 Like

Has any solution been found on this problem? If so, what would it be? I am just starting to develop a new application, and this solution would be very helpful.

Still nothing. JUCE really needs to support this, I just got burned by it again today. I’m doing stupid hacks where I make an always on top window and the poll if my application is foreground and if not, then clear the always on top flag. But it has issues on Linux where then if you open a file chooser they appear under the window and are unuseable. Arg.