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

Godot steals focus on Xfce 4 #74378

Open
Mequam opened this issue Mar 4, 2023 · 25 comments
Open

Godot steals focus on Xfce 4 #74378

Mequam opened this issue Mar 4, 2023 · 25 comments

Comments

@Mequam
Copy link
Contributor

Mequam commented Mar 4, 2023

Godot version

4.0.stable.official.92bee43ad

System information

x86_64 Linux 6.2.2-arch1-1, Intel Core i5-7200U, xfce4

Issue description

When changing workspace on xfce4 godot (both editor and exported games) grabs input focus from any previously opened programs.

focus_steal.mp4

Interestingly I was unable to reproduce the bug on gnome, so whatever the problem is I suspect it is specific to xfce4.

From my testing this appears to be happening because xfce4 issues an extra MapNotify event which the engine uses as an indicator to grab focus.

I have a fix that works for my setup: https://github.com/Mequam/funky-godot/tree/mequam/feat/xfce4_focus_grab but I figured I should make sure that other people are having the same issue before submitting a PR.

Steps to reproduce

Open up godot and some other program.
Focus the other program.
Leave the workspace and return to the workspace.

Minimal reproduction project

N/A, any project works.

@akien-mga
Copy link
Member

CC @bruvzg

@compese
Copy link

compese commented Mar 20, 2023

related? #74587 (comment)

@compese
Copy link

compese commented Mar 27, 2023

I've naively removed all XSetInputFocus calls from 4.0-stable and it solves the problem for me for the time being (seeing this issue in XMonad ). It seems like sometimes XSetInputFocus is getting called inappropriately i.e. when another application has focus. I'm not an X11 programmer but my guess is Godot is getting faked out by tiling window manager abilities like resizing a window without focusing on it.

e.g.
I have a terminal and Godot open. They're tiled and the terminal is focused. Then I expand the terminal (which concurrently shrinks Godot) while keeping focus on the terminal. AFAICT, in this scenario Godot thinks it should then have focus because it's been resized even though the user has not actually focused Godot. i.e. Godot mistakes resizing as a focus request.

Similar behavior happens if I swap the terminal and Godot while keeping focus on the terminal. Godot incorrectly interprets window re-positioning as a focus request.

I've also seen similar behavior in LXDE, LXQT, and XFCE where Godot immediately steals back focus after leaving Godot via alt-tab (this is random and only occurs ~1/20 times). Though my guess is this is a similar but different code path than the tiling issues since this is random while the tiling issues seem to be deterministic with clear causes (moving, resizing). However, random occurrences of focus stealing (unrelated to move/resize) I've seen in XMonad may be the same as the alt-tab issue in the other WMs

@ttencate
Copy link
Contributor

Also seeing focus stealing in i3. I have Godot and VS Code in a tiled setup side by side, but whenever I resize the focused VS Code window (using keyboard or mouse), Godot gets focused.

@crestofthebeast
Copy link

crestofthebeast commented Jul 3, 2023

You can see some issues with focus in PaperWM in the mentioned issue up there. Additionally, godot pretty much doesnt let me focus anything else in qtile. Definitely some weird stuff going on.

EDIT: minor updates.
Godot seems to pretty much intercept all text input when running (only the editor, not the project manager) on qtile.
godot --single-window does a whole load of nothing to fix it, unfortunately.

@Quicksilver151
Copy link

You can see some issues with focus in PaperWM in the mentioned issue up there. Additionally, godot pretty much doesnt let me focus anything else in qtile. Definitely some weird stuff going on.

Qtile user here. same issues. also facing an additional issue since godot 4.1
My setup has it such that when a window force resizes itself, its automatically set to a floating window.
Godot seems to auto set its window size with some actions in the editor. such as running the game with f5.
So each time i run my godot project, the editor window is set to floating mode.
This does not occur in godot 4.0 btw

@PorkrollPosadist
Copy link
Contributor

PorkrollPosadist commented Jul 30, 2023

Possibly related issue I found when testing #80036 for regressions. On XFCE, the minimized state of a window goes out of sync when changing workspaces. Minimize a dialog, switch to alternate workspace, switch back, and the dialog becomes visible again. And yet, based on the XFCE pager, the icon for the window is still greyed out, indicating it is minimized.

There are probably some edge cases with X11 window mapping / unmapping that the Godot display server isn't responding to appropriately.

@anthonyfinch
Copy link

Just to chime in that I have had the same issue, on 4.1.1 now. I am using PaperWM with gnome (another tiling wm!) and Godot will just start stealing focus from any other app so I can't access them. The only way I can escape is to minimize Godot, which allows selecting other windows.
The only other workaround I have is to make Godot fullscreen, which seems to stop it being so greedy.

Would love to help get this fixed but don't know where I would start. Is there any more helpful info I can provide?

@anthonyfinch
Copy link

@Mequam - I have built a version of Godot 4.1.1 for my own use using your patch and so far i can report that it fixes the issue for me too (using PaperWM on Gnome)
Are you planning on raising a PR? Anything I can do to help?

@Mequam
Copy link
Contributor Author

Mequam commented Sep 10, 2023 via email

@anthonyfinch
Copy link

@Mequam I'm happy to take a nosier look at your changes and offer any opinions if I have any. I am also not an X11 api expert however!

@Calinou
Copy link
Member

Calinou commented Sep 10, 2023

I think you can open a PR right away and we can discuss the solution there. This is better than risking the code eventually being forgotten in this issue.

@unlessgames
Copy link

Hey @Mequam thanks for the fix! I've also tested it and my issues with my tiling window manager are resolved as well #80170.

Not knowing much about the code, the most I can comment is it would be more aligned with the rest of the file if you called your function _is_window_focused and used the same loop format as all the other instances of that iteration in there, so

for(KeyValue<WindowID, WindowData> &E : windows){

instead of

for (KeyValue<int, DisplayServerX11::WindowData> wid : windows) {

Any chance you could submit a pull request? I am sure actually knowledgable people will comment and review your changes that way.

In case you don't have the time to deal with this then let me know and I'll submit it for you.

@Araly
Copy link

Araly commented Sep 24, 2023

I have the same issue on Gnome (tested both X11 and Wayland), both when using the Forge WM, and when Forge is disabled. I think on losing focus, Gnome shakes the windows, and it makes Godot freak out. I have no idea if or how you can disable the shaking

@Mequam
Copy link
Contributor Author

Mequam commented Oct 10, 2023

@unlessgames if you would be willing to submit this as a pull request that would be awesome!

@Mequam
Copy link
Contributor Author

Mequam commented Oct 10, 2023

@unlessgames thanks for the feedback!

I'll try and get it submitted myself is possible, but like I said earlier this project is on my back burner at the moment thanks to college and work, so if you do submit it as a pull request just make sure to tell me so I don't submit a second one on accident lol.

@dsnopek
Copy link
Contributor

dsnopek commented Dec 22, 2023

I just posted PR #86441, which was created from @Mequam's branch at https://github.com/Mequam/funky-godot/tree/mequam/feat/xfce4_focus_grab, since some folks here wanted it!

Unfortunately, it doesn't fix the X11 input focus issues that I'm personally experiencing with i3

@akien-mga
Copy link
Member

Could some of you reproducing this issue test if #86671 solves the problem for you?

@akien-mga akien-mga changed the title godot xfce4 focus steal Godot steals focus on Xfce 4 Jan 9, 2024
@limbonaut
Copy link

limbonaut commented Jan 9, 2024

Could some of you reproducing this issue test if #86671 solves the problem for you?

Don't know about XFCE, but I've tested it on PaperWM GNOME, and it still steals focus like nuts.

steal_focus.mp4

@ttencate
Copy link
Contributor

For the record: there may be multiple issues. The issue @compese described here on XMonad and which I confirmed here on i3 seems to be fixed on master (0bcc0e9), even if I revert 64a52e0 from #86671.

So out of curiosity, I did a git bisect, and found that 40d69c2 (merged in #86441) was the commit that fixed the issues I was seeing, not #86671. So, thanks @Mequam and @dsnopek!

@Entharia
Copy link

Hello, i got the same issue.

EndeavourOs
Gnome
PaperWm

@troykinsella
Copy link

troykinsella commented Mar 14, 2024

Confirming this behaviour in Qtile on Xorg as well. Godot 4.2.1 stable.

@dsnopek
Copy link
Contributor

dsnopek commented Mar 14, 2024

Confirming this behaviour in Qtile on Xorg as well. Godot 4.2.1 stable.

Can you test if it's fixed for you in Godot 4.3-dev4? A number of X11 focus fixes have already been merged for Godot 4.3.

@troykinsella
Copy link

Can you test if it's fixed for you in Godot 4.3-dev4? A number of X11 focus fixes have already been merged for Godot 4.3.

Yes, the focus issue is absent in 4.3-dev4. 🎉

@limbonaut
Copy link

Could some of you reproducing this issue test if #86671 solves the problem for you?

With the latest 4.2 branch, the issue is resolved for GNOME PaperWM extension 🎉

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