[X11] Don't re-set input focus if the given window already has it (fixes Godot stealing input focus on i3) #86671
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Fixes #86442
Currently,
DisplayServerX11
will set the input focus to a given window (viaXSetInputFocus()
) in a bunch of places. All this change does is checks to see if the given window already has input focus, and if so, skips setting input focus.This fixes an issue I've been having in every version of Godot 4 with the i3 window manager when Godot launches the external editor (VS Code in my case), where input focus would visually seem to be on the external editor, but Godot would continue to receive all my key presses. (See in the issue linked above for a more detailed explanation.)
I don't know X11 very well, but what I think is happening, is Godot is re-setting the input focus to itself when it gets the mouse click to open the external editor, but that doesn't happen immediately, it happens sometime after VS Code has already gotten focus. So, shortly after VS Code gets focus, it gets yanked back to Godot.
In some ways, this is kind of the inverse of PR #86441, which some users of other alternative window managers say fixes similar problems for them (but not me).