I am wondering whether it is allowed to start multiple modal loops using runModalForWindow(). In my application, I have the following setup: When the user presses button A in the non-modal window A, modal window B will be opened using runModalForWindow(). In modal window B, there is a button B. If the user presses this button B, modal window C will be opened using runModalForWindow(). While modal window C is open, windows A and B shall be blocked from user input and while modal window B is open, window A shall be blocked.
This kind of works with runModalForWindow() but there's a little issue that I've encountered which makes me wonder whether what I'm doing here is allowed. While modal window C is opened, I can actually move modal window B in front of modal window C. B doesn't accept any input but it actually can be moved in front of C. Window A, however, can never be moved in front of B (or C)... it always stays in the background.
Does anybody have an idea why B can be moved in front of C whereas A can never be moved in front of B or C? Is it allowed to use runModalForWindow() several times?
A modal window has its level
set to NSModalPanelWindowLevel
. This is a window level that's in front of normal windows. That's why you can't bring window A in front of window B.
However, windows B and C are both at the same level. Therefore, the window server doesn't enforce window C being always in front of window B.
You could try to work around this by setting window C's level to something above NSModalPanelWindowLevel
, but that can get problematic in the general case. If you increase the level too much, it may end up in front of system UI elements, like the menu bar or bezel indicators like the volume-changed indicator.
You could also make window C a child of window B using addChildWindow(_:ordered)
. That will enforce the specified ordering. It does have some side effects. For example, if you move window B, window C will move, too, to keep the relative positioning the same.