Skip to content

Add project setting to ignore joypad events if the app is unfocused#115119

Open
Nintorch wants to merge 1 commit intogodotengine:masterfrom
Nintorch:joypad-unfocused
Open

Add project setting to ignore joypad events if the app is unfocused#115119
Nintorch wants to merge 1 commit intogodotengine:masterfrom
Nintorch:joypad-unfocused

Conversation

@Nintorch
Copy link
Contributor

@Nintorch Nintorch commented Jan 19, 2026

Supersedes #82965
Closes #16832

Also fixes #115110

This PR is based on #82965 and this PR addresses the problems pointed out in the reviews of the original PR, particularly that the Input class shouldn't depend on DisplayServer and the PR should also handle multiple windows.
This PR adds a project setting that allows the joypad events to be ignored if the application (or any of its windows) is unfocused.

2026-01-19.12-40-30.mp4
2026-01-19.12-55-34.mp4

TODO:

Copy link
Member

@Calinou Calinou left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Tested locally on Linux/X11, it mostly works as expected.

Some feedback:

  • Clicking the window border in game embedding doesn't count as focusing the application, while it should. You need to click on the viewport instead.
  • When the window loses focus, stick movement will sometimes still be registered, leading to a "ghost input". This is more common if you are actively moving the stick at the time the window loses focus.
gamepad_unfocused.mp4

@Nintorch
Copy link
Contributor Author

Thank you for your review, Calinou! I will try to fix these issues later when I can!

@Nintorch Nintorch requested a review from a team as a code owner January 20, 2026 13:47
@Nintorch Nintorch requested a review from a team January 20, 2026 13:47
@Nintorch
Copy link
Contributor Author

Nintorch commented Jan 20, 2026

Tested locally on Linux/X11, it mostly works as expected.

Some feedback:

  • Clicking the window border in game embedding doesn't count as focusing the application, while it should. You need to click on the viewport instead.
  • When the window loses focus, stick movement will sometimes still be registered, leading to a "ghost input". This is more common if you are actively moving the stick at the time the window loses focus.

I tried to fix these issues, they seem to be fixed now on my local branch( https://github.com/Nintorch/godot/actions/runs/21173143271 ). Tested on Windows 11.

There's another issue that when I switch from the viewport to the embedder window (the window that embeds the game process), inputs get reset, but if I press them again they work. Not sure if I should fix this issue here or in a separate PR, because it's already reported in a separate issue: #115110

@kimimaru4000
Copy link

Hey @Nintorch thanks a lot for the PR! I wanted to chime in regarding #115110 and mention that I experience that same issue in an exported build as well. I'll add that detail to the issue for completeness.

@Nintorch
Copy link
Contributor Author

I decided to also fix #115110 in this PR as well :)
https://drive.google.com/file/d/1y6oSny6j9dd7SeZLaK_QjNZdSwDURZni/view?usp=sharing

Copy link
Member

@Calinou Calinou left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Works great now 🙂

gamepad_no_focus.mp4

The only remaining issue is that buttons pressed beforehand will not be seen as pressed by Godot once the window gains focus. For axes, this will sometimes happen (due to the value changing very often), but it's less likely to happen if you are fully holding a trigger (common with digital triggers) or a stick in a cardinal direction. That said, this issue is commonly found in other programs that disallow background input, so it's not critical and can be resolved in a future PR.

@Nintorch
Copy link
Contributor Author

Thank you for your review, Calinou! I will try to add a property for this feature soon!

Co-Authored-By: Christoph Taucher <4498502+chtau@users.noreply.github.com>
GLOBAL_DEF("collada/use_ambient", false);

// Input settings
GLOBAL_DEF("input_devices/config/ignore_joypad_on_unfocused_application", false);

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The double negative ("ignore" -- "unfocused") makes it harder to understand the meaning of the setting. I would recommend a name such as accept_joypad_inputs_when_application_unfocused with the default value true.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I tend to disagree, as the action the user would take here is specifically to ignore joypad events on unfocused apps. That's a double negative indeed, but "unfocused app" to me is a well-defined object, so not really a negation per se, if that makes sense. And a setting like "accept" that defaults to true doesn't seem expected to me, if I want to diverge from default behavior, I would expect to enable an option that disables that behavior (so indeed it's enabling a negative option).

But my native language (French) has no issue with double negatives so I may be biased. To me the original setting sounds much clearer than the one you propose, but maybe others would think differently.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Personally, I'm not sure this is a double negative (even though my native language is not English either), I've always thought double negatives are grammar errors and they can be seen in sentences like "I didn't see nothing", "I ain't got no time for that", "But I ain't stupid neither" (Left 4 Dead 2 reference :D), see also https://professorscottsenglish.com/english-grammar/common-grammar-mistakes/double-negatives/why-double-negatives-are-grammatically-incorrect-sometimes/ (I'm not sure how reputable this website is, though)
So basically joypad events should be read when the application is focused, and ignored if it's unfocused.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It would be double negation if it was "a non-unfocused" for example

GLOBAL_DEF("collada/use_ambient", false);

// Input settings
GLOBAL_DEF("input_devices/config/ignore_joypad_on_unfocused_application", false);
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
GLOBAL_DEF("input_devices/config/ignore_joypad_on_unfocused_application", false);
GLOBAL_DEF("input_devices/joypads/ignore_joypad_on_unfocused_application", false);

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

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[Input] Input.is_joy_button_pressed is returning false when changing window focus Games receive joypad input even if the game window is not focused

5 participants