godot
godot copied to clipboard
Saving script from floating script window moves window focus back to the main editor window
Godot version
master (3710f06929)
System information
Godot v4.1.beta (3710f0692) - Arch Linux #1 ZEN SMP PREEMPT_DYNAMIC Sat, 10 Jun 2023 00:35:19 +0000 - Vulkan (Forward+) - dedicated AMD Radeon R9 380 Series (RADV TONGA) () - AMD Ryzen 5 5600X 6-Core Processor (12 Threads)
Issue description
Using i3wm, tiling window manager.
If I'm in the floating script window and I hit Ctrl+S to save, the window focus gets switched to the main Godot window.
I'd expect it to stay on the script window instead.
Note: this happens only when the script is associated with a scene. A standalone script does not trigger the focus switch.
Steps to reproduce
Float script window, use ctrl+s to save, see focus returned to main godot editor window.
Following screencap of this exact sequence. I switch focus to the script window, type "pass" and press ctrl+s. and you can see the blue square around the windows showing current focus move back to the main window.
https://github.com/godotengine/godot/assets/1187609/8638d269-3f82-4f75-b559-f6ed8d148d65
Minimal reproduction project
You only need a scene with a script attached.
Note: this happens only when the script is associated with a scene. A standalone script does not trigger the focus switch.
For me this also happens on scripts that aren't associated with a scene.
I have tracked on Linux, where the Main Window gets brought to the foreground, when the "Saving Scene" popup appears:
https://github.com/godotengine/godot/blob/ef155c1aeb216fa5a732913b6f2dc321e4b512dc/platform/linuxbsd/x11/display_server_x11.cpp#L1435
Not sure, how to prevent this from happening.
This happens for me on MacOS too. Godot v4.1.stable - macOS 12.5.0 - Vulkan (Forward+) - integrated Apple M2 - Apple M2 (8 Threads)
I can confirm on my windows machine this also occurs, and expanding this issue there is a stutter when using an undocked script and adding a breakpoint, after that when you press F10/F11 to scroll through your code, it stutters back to the main Godot window and instantly goes back to the script editor, which is also not expected behaviour.
I read this and other issues about the problem. Given that the focus change can't be workarounded, as the OS may change focus automatically on exclusive popups as stated in this comment, I think the following are the possible solutions:
- Reparent the progress dialog on the currently focused window just before it appears. This allows to restore the focus to the right window once the progress dialog is hidden. Unfortunately, it seems that it's not possible to get the currently focused window without visiting the scene tree (if I'm wrong, let me know), so it's necessary to keep a list of windows somewhere to check their focus.
- Make the progress dialog non-exclusive. I tested this and works, but I'm not sure how many bugs I can introduce by doing this.
~~3. Get rid of that annoying popup and move the progress somewhere else~~
I'll work on solution 1 in the following days.
Unfortunately, it seems that it's not possible to get the currently focused window
See #79261, which implements this functionality.
Unfortunately, it seems that it's not possible to get the currently focused window
See #79261, which implements this functionality.
Very nice, I'll build the solution for this issue on that PR.
I personally just mapped 'save script' to Ctrl+S (by default it is 'Ctrl+Alt+S', but Ctrl+S seems to work as well, except it tries to save the main scene which triggers the change of focus). Then you get two actions mapped to Ctrl+S but Godot doesn't seem to mind.
I just found that solution a couple days ago. Before that I just thought this floating script window feature was unusable with window managers.