Make PopupMenu hide after its parent window loss focus
Previously PopupMenus were still on screen after their parent was minimized. It was quite annoying, especially in Editor, because it limits its fps to 1 per second when minimized, even if one of the popup menus is still visible. It's also worth mentioning that no other app I use behaves like this. Their popups always hide after minimizing the main window or they can't just be minimized while popup is visible.
Before
https://github.com/user-attachments/assets/632e1957-c731-46b6-8749-e64a220e4fe9
After
https://github.com/user-attachments/assets/6d9b0e1e-421f-495f-b422-0267a104f8a2
I decided to fix this by adding two flags which are also visible from scripts:
Window::return_to_transient(default:false)PopupMenu::hide_on_parent_unfocused(default:true)
Also I had to add auxiliary const method Window::get_transient_parent() to be able to use the "focus_exited" signal of the parent window from its child popup.
Previous behavior can be achieved by setting return_to_transient to true and hide_on_parent_unfocused to false.
Three things I'm not sure about are:
- naming of the
PopupMenu::hide_on_parent_unfocusedand related stuff (I chose this name because there isPopup::_parent_focused()method. - using thread guards in setter and getter of the
Window::return_to_transientflag. Honestly, I don't even know what exactly doERR_MAIN_THREAD_GUARDandERR_READ_THREAD_GUARD_Vmacros do - Haven't tested on .NET version of Godot.
Can't reproduce the bug on Windows.
Can't reproduce the bug on Windows.
Yep, it seems to be a Linux only issue (and maybe macOS), but it needs to be fixed somehow. Looks like it's due to how different OSes handle popups. And I don't think it'll be changed by them in the future. These are different approaches.
Honestly, I was waiting for some feedback about my naming before writing documentation, but ok, this is it.
Needs rebase
I have no idea what it failed. I'll see tomorow. And also, to be honest I completely forgot about this PR. So maybe don't merge it for now, I should test everything again, especially after the rebase. But today I already don't have time for that (it's too late).