Skip to content
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

Give focus to game on run #692

Open
DanielPri opened this issue Aug 2, 2024 · 9 comments
Open

Give focus to game on run #692

DanielPri opened this issue Aug 2, 2024 · 9 comments

Comments

@DanielPri
Copy link

Godot version

4.2.2.stable.official

VS Code version

1.92.0

Godot Tools VS Code extension version

2.1.0

System information

Windows 11

Problem statement

When running the game, focus is still on VS Code editor, requiring an Alt-tab to switch focus to the game.
Is it possible to optionally give focus to the game automatically? While a very small QoL feature, it would be very appreciated!
I could not find this setting in the command line documentation for godot, and yet when running directly from godot engine focus is given to the game.

Proposed solution

Optionally give focus to the game automatically upon run/run with debug.
Perhaps by using a powershell command?

@DaelonSuzuka
Copy link
Collaborator

When I hit F5 to launch the game, it opens on top of VSCode and is focused, UNLESS I interact with VSCode during the brief delay while the game is launching, in which case I get the behavior you're describing.

@sangold
Copy link

sangold commented Aug 4, 2024

It is weird, the run window used to behave like you described @DaelonSuzuka but I too now have the same issue. When hitting F5, the window does not pop into focus and stay behind. I tried to find what changed but couldn't find any changes on neither the project settings nor the vscode settings. The launch config looks standard:

"configurations": [
		{
			"name": "GDScript: Launch Project",
			"type": "godot",
			"request": "launch",
			"project": "${workspaceFolder}",
			"debug_collisions": false,
			"debug_paths": false,
			"debug_navigation": false,
			"additional_options": ""
		}
	]

I run into the issue on both 4.2.2 and I just tried 4.3 to see and still the same. TBH, not sure how much the plugin can solve this.

@DanielPri
Copy link
Author

For clarity, I do not interact with VSCode during the brief delay as it launches. (tried again a few more times to be sure)
Tried seeing if it behaves differently if running through F5, or by using mouse to navigate to the Run->Start Debugging option, and still the game launches without focus.
Although as sangold mentionned, there might not be a solution plugin-side.

@Jules5
Copy link

Jules5 commented Dec 25, 2024

I have the exact same issue. It was working well for months and then suddenly vscode keeps the focus when launching the game. I tried reinstalling both the extension and vscode without success. @DanielPri did you find something that fixes this?

EDIT: Note that if I hit F5 then quickly focus another window on my second screen, the game does appear on top of vscode!

@DanielPri
Copy link
Author

@Jules5 sorry, never did find an actual solution

@DaelonSuzuka DaelonSuzuka marked this as a duplicate of #776 Jan 17, 2025
@btarg
Copy link
Contributor

btarg commented Feb 1, 2025

I have found that after clicking play / hitting F5, holding alt+tab will make the game window appear above Code, where you can spam-click it to get focus quickly (since in Win11 at least on my end, the alt-tab switcher breaks visually when a new window spawns while its open)
Would giving the game window focus perhaps need to be a Godot feature, rather than a plugin feature?

@Calinou
Copy link
Member

Calinou commented Feb 6, 2025

Would giving the game window focus perhaps need to be a Godot feature, rather than a plugin feature?

You should be able to emulate this in your project by calling DisplayServer.window_move_to_foreground() in an autoloaded script's _ready() function.

I don't know if this should be added as a CLI argument to Godot though. The general expectation is that the OS window manager will always move it to the foreground when the process starts, like any other process on the system. It's strange that this does not happen when VS Code is starting Godot.

I suggest trying to pass the --fullscreen or --maximized options using VS Code too.

@Jules5
Copy link

Jules5 commented Feb 7, 2025

Unfortunately I tried DisplayServer.window_move_to_foreground() but it doesn't fix the issue, even if I put it in a _process function.
Same with the --fullscreen and --maximized options, they works but the game window is still under vscode.

@btarg
Copy link
Contributor

btarg commented Feb 11, 2025

Can confirm that DisplayServer.window_move_to_foreground() does not work.
It seems like it is in the foreground, but bugged. The mouse cursor is locked to the window's boundaries while the window is not on top of VS Code.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

6 participants