godot icon indicating copy to clipboard operation
godot copied to clipboard

Saving script from floating script window moves window focus back to the main editor window

Open nyxkn opened this issue 1 year ago • 1 comments

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.

nyxkn avatar Jun 25 '23 14:06 nyxkn

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.

robbertzzz avatar Jul 10 '23 12:07 robbertzzz

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.

Sauermann avatar Jul 10 '23 23:07 Sauermann

This happens for me on MacOS too. Godot v4.1.stable - macOS 12.5.0 - Vulkan (Forward+) - integrated Apple M2 - Apple M2 (8 Threads)

saikyun avatar Jul 15 '23 16:07 saikyun

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.

sian2005 avatar Jul 19 '23 10:07 sian2005

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:

  1. 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.
  2. 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.

trollodel avatar Jul 23 '23 14:07 trollodel

Unfortunately, it seems that it's not possible to get the currently focused window

See #79261, which implements this functionality.

Sauermann avatar Jul 23 '23 14:07 Sauermann

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.

trollodel avatar Jul 23 '23 14:07 trollodel

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.

lamdevhs avatar Sep 28 '23 17:09 lamdevhs