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

[X11] Fix Godot stealing focus on alternative window managers #86441

Merged
merged 1 commit into from
Jan 18, 2024

Conversation

dsnopek
Copy link
Contributor

@dsnopek dsnopek commented Dec 22, 2023

This is taking the changes from https://github.com/Mequam/funky-godot/tree/mequam/feat/xfce4_focus_grab and turning them into a PR (as @Mequam, the original author, requested on #74378)

Unfortunately, these changes don't fix the issue I am experiencing, but since others (including the original author) wanted to see these changes as a PR, I've gone ahead and created one. :-) It's my understanding that these changes do fix some of the problems from that issue.

@dsnopek dsnopek added this to the 4.x milestone Dec 22, 2023
@dsnopek dsnopek requested a review from a team as a code owner December 22, 2023 15:23
@YuriSizov YuriSizov modified the milestones: 4.x, 4.3 Dec 22, 2023
@dsnopek dsnopek changed the title [X11] Fix Godot stealing focus on alternative window managers [X11] Fix Godot stealing focus on alternative window managers (from Mequam) Dec 31, 2023
@akien-mga akien-mga requested a review from bruvzg January 9, 2024 12:49
Copy link
Member

@bruvzg bruvzg left a comment

Choose a reason for hiding this comment

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

This looks reasonable to me (have not tested it so far). I guess it can be combined with #86671, to only grab re-focus if it's not already focused and some other window of the same app have focus (with exception for ButtonPress which should only check the current window focus).

platform/linuxbsd/x11/display_server_x11.cpp Outdated Show resolved Hide resolved
Copy link
Member

@bruvzg bruvzg left a comment

Choose a reason for hiding this comment

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

This looks reasonable to me (have not tested it so far). I guess it can be combined with #86671, to only grab re-focus if it's not already focused and some other window of the same app have focus (with exception for ButtonPress which should only check the current window focus).

@dsnopek
Copy link
Contributor Author

dsnopek commented Jan 9, 2024

Thanks for the review!

This looks reasonable to me (have not tested it so far). I guess it can be combined with #86671, to only grab re-focus if it's not already focused and some other window of the same app have focus

Yes, I don't think the two PRs should conflict functionality-wise (there may end up being a Git conflict after one of them is merged, because of the proximity of the changed lines) although logically they are working in kind of inverse directions of each other.

Personally, when I test this PR with i3, it doesn't fix any issues for me, but it also doesn't appear to break anything.

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 (Fedora 39 KDE with X11, rebased against 96296e4), it works as expected.

This fixes a longstanding issue in Godot 4 where focus is stolen while the editor loads (or when a project starts), which causes some keypresses to be released if you're currently focusing on another window. I initially thought this was due to use of Window.request_attention() somewhere, but it's not – it still occurs if you make Window.request_attention() a no-op in the engine source code.

A perfect example of this is when you try to run diagonally in a game while the Godot editor loads, but one of the movement keypresses will be released after the editor is done loading. This PR fixes this issue completely. Previously, I could reproduce this pretty much every time, but I've tried 10+ times with this PR and couldn't reproduce the issue once.

I tested the editor quickly and couldn't notice any regressions in editor popup behavior.

Before

On both videos, I'm not releasing any keys while running.

simplescreenrecorder-2024-01-17_19.54.53.mp4

After (this PR)

simplescreenrecorder-2024-01-17_19.54.31.mp4

@akien-mga akien-mga added the cherrypick:4.2 Considered for cherry-picking into a future 4.2.x release label Jan 18, 2024
@akien-mga akien-mga changed the title [X11] Fix Godot stealing focus on alternative window managers (from Mequam) [X11] Fix Godot stealing focus on alternative window managers Jan 18, 2024
@akien-mga akien-mga merged commit 4aff0ab into godotengine:master Jan 18, 2024
15 checks passed
@akien-mga
Copy link
Member

Thanks!

@YuriSizov YuriSizov removed the cherrypick:4.2 Considered for cherry-picking into a future 4.2.x release label Jan 25, 2024
@YuriSizov
Copy link
Contributor

Cherry-picked for 4.2.2.

@ckdarby
Copy link

ckdarby commented Jan 27, 2024

@YuriSizov God's work cherry picking this commit before 4.3. Thank you!!

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.

8 participants