-
-
Notifications
You must be signed in to change notification settings - Fork 10.6k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Closing windows restoring z-ordered focus / how to implement menu command for top-most window #727
Comments
You probably need to keep track of your last-focused main document then. As soon as you start introducing any other window than your "document" window you'll run into the same problem. |
I tried that approach as well - but it didn't work out, e.g.:
Now the first Close operation works but the menu bar is still the focus so there is no active document anymore and the second Close operation doesn't do anything. I could require that the user click in the window again to get focus but that's confusing compared to how GUIs typically work. It might be possible to extend this to keeping track of all documents in focus order. E.g.:
|
Well the whole point of tracking the last active document is that when a menu is open you don't lose this information of which one is active. Sent from my fax machine
|
Maybe I'm not following how to track the active document state. How can I do this without querying the window focus value? It's also possible that things are behaving as you would expect, but it's pretty different than typical desktop applications which I think will be confusing. |
Also, just to clearly spell out the user experience:
I can track the last active document by querying the focus state of the window as I iterate the application state for documents. This provides a solution for most commands that need to route to the active document. File/Close is different though because it changes which document is active. If the mechanism to do this is querying the focus state, that has been transferred to the menu bar so there is no longer any active document until the users clicks on a window. |
You were doing the right thing.
|
But again that doesn't work (at least with a single state value). The sequence looks like this: Initial state:
1st Close Command:
Next frame:
2nd close command:
If the internal ImGui z-order structure is mirrored application side, then this can be made to work but it doesn't seem like you are suggesting that. |
Why not keep a (unique) stack of focused windows locally then? After each close command, just close the .top(), pop the stack and set focus to the new .top() ? |
Yes that's possible to do and I've suggested it a couple of times in the thread. What I'd like to establish is how we expect the problem to be solved. My first thought was exactly the same as Omar - just track the last active document, and that worked great until I hit the case for closing the window. So if the thinking is that maintaining an application side copy of the ImGui window z-order for command processing is the right way to solve the problem, then we're done. But I think there is a bigger issue with menu bar focus behavior. It was a minor issue discussed in #622 but this case creates user confusion without a workaround applied. |
OK. I see what you are saying. In that sort of case you expect the menu-bar so give back focus to highest remaining window in the z-order, and the case discussed in #622 also would need to be honored. Actually as part of #323 I am already doing something along the line of #622 but it is still wip. Will get back to this later. You might try to add Otherwise as johanwendin pointed out you can easily maintain a stack locally. That's not how I'd expect the problem to be solved for end-users but would be a easy to implement workaround in the meanwhile. |
…dow in descending z-order (part of #727)
FYI I have committed a small fix to restore focus when closing a window but this doesn't fix your issue here because the mainmenubar window is still taking focus at the moment. |
Forgot to link it in this topic, but as part of #787 work, on October 23 I have pushed a change that makes the Main Menu Bar restore focus after being used: It doesn't fully solve the discussion here (which can presumably currently be solved by tracking z-order of documents on the user side) but relates somehow. |
I am trying to implement a generic command (e.g. File/Close) that should apply to the top-most window. My assumption is that I should write something like this:
I was thinking I could implement by using IsWindowFocused() but this doesn't work because the menu bar claims focus.
Does this seem like the right strategy or is there another approach that should be used?
The text was updated successfully, but these errors were encountered: