godot icon indicating copy to clipboard operation
godot copied to clipboard

Make PopupMenu hide after its parent window loss focus

Open Nikitf777 opened this issue 1 year ago • 2 comments

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_unfocused and related stuff (I chose this name because there is Popup::_parent_focused() method.
  • using thread guards in setter and getter of the Window::return_to_transient flag. Honestly, I don't even know what exactly do ERR_MAIN_THREAD_GUARD and ERR_READ_THREAD_GUARD_V macros do
  • Haven't tested on .NET version of Godot.

Nikitf777 avatar Oct 16 '24 18:10 Nikitf777

Can't reproduce the bug on Windows.

KoBeWi avatar Oct 17 '24 12:10 KoBeWi

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.

Nikitf777 avatar Oct 17 '24 15:10 Nikitf777

Honestly, I was waiting for some feedback about my naming before writing documentation, but ok, this is it.

Nikitf777 avatar Oct 22 '24 15:10 Nikitf777

Needs rebase

Repiteo avatar Nov 18 '25 20:11 Repiteo

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).

Nikitf777 avatar Nov 18 '25 22:11 Nikitf777