I am implementing a IMGUI system in Lua after watching Casey's lecture on the subject. I have got the basic stuff working but now, I want to implement "windows" that will hold widgets and expand/contract depending on widget dimensions. The problem that I have encountered is: if I allow users to change the position of these windows (say, by dragging and dropping), it is possible that a window might overlap another window in a way that the two different widgets occupy the same 2D position on screen. If the lower widget's call comes before upper widget's call, the both widgets will register as active and code associated with both of them will be executed.
I guess this is basically a window focus problem which is generally handled by window managers and not windowing toolkits; however, in a game editor, this behavior (of having multiple windows and being able to drag windows and overlap them) is sometimes useful.
Is there any way to solve this problem with immediate mode paradigm?
Added: One obvious way would be to only do MouseOnWidget tests if their corresponding window is in focus; if not, widgets are only rendered. However, this just shifts the problem from overlapping widgets to overlapping windows (how to know which window to bring into focus by click/hover when many of them are overlapping).