Windows shown at wrong order

Christiaan Hofman <[email protected]> Tue, 25 Jan 2011 17:22:01 +0100
Newsgroups gmane.comp.macosx.devel
Message-ID <[email protected]>
I am having a strange situation with windows that are not shown in the right z order. In particular, I have a window at NSNormalWindowLevel, and another window at NSPopUpMenuWindowLevel. The latter one is being faded out, revealing the normal level window. At least that's the intention. However what I see is that the window at normal level is shown on top of the window that's fading out. 

This is the relevant code fragment:

    [fullScreenWindow setLevel:NSPopUpMenuWindowLevel];
    // trick to make sure the main window shows up in the same space as the fullscreen window
    [fullScreenWindow addChildWindow:mainWindow ordered:NSWindowBelow];
    [fullScreenWindow removeChildWindow:mainWindow];
    // these can change due to the child window trick
    [mainWindow setLevel:NSNormalWindowLevel];

After this code, mainWindow is shown on top of fullScreenWindow, even though it has a much lower level. That seems wrong to me. What's going on? Anyone can tell me how I can avoid this obvious bug?

Thanks,
Christiaan