godot icon indicating copy to clipboard operation
godot copied to clipboard

godot xfce4 focus steal

Open Mequam opened this issue 1 year ago • 1 comments

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.

https://user-images.githubusercontent.com/49560528/222922924-af92e9bc-3d29-4ec0-865b-a6f6d2afc189.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.

Mequam avatar Mar 04 '23 18:03 Mequam

CC @bruvzg

akien-mga avatar Mar 10 '23 09:03 akien-mga

related? https://github.com/godotengine/godot/issues/74587#issuecomment-1466538062

compese avatar Mar 20 '23 15:03 compese

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

compese avatar Mar 27 '23 21:03 compese

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.

ttencate avatar Jun 28 '23 07:06 ttencate

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.

crestofthebeast avatar Jul 03 '23 07:07 crestofthebeast

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

Quicksilver151 avatar Jul 29 '23 21:07 Quicksilver151

Possibly related issue I found when testing https://github.com/godotengine/godot/pull/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.

PorkrollPosadist avatar Jul 30 '23 02:07 PorkrollPosadist

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 avatar Sep 05 '23 18:09 anthonyfinch

@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?

anthonyfinch avatar Sep 09 '23 23:09 anthonyfinch

I would love to make a pull request if the code I added seems like it's ok, the main reason I waited earlier was to make sure I wasn't the only one with the problem (looks like im not).

The biggest thing I would be worried about with pull requesting it would be the quality of my patches, i'm not super familiar with the X api that the engine was using and one of the biggest things that I was worried about is that my changes are either sub optimal for code organization, or that they could induce further bugs into the engine that I would be unaware of.

I would be more than happy to submit a pull request if I was sure that

  1. my changes were high quality enough to actually be in the engine and
  2. they do not induce additional bugs (im particularly worried about the engine not grabbing focus when it should)
  3. this is a wide(enough) spread problem (appears to be the case :D)

if you want to help I would LOVE to have someone else look over the changes that I made and double check that their not gonna do anything crazy or wonky, I also (maybe?) vaguely remember thinking of a better way to implement this solution , but it's been so long since i've worked on this I can't remember if I implemented it or (perhaps more frustratingly) what that solution was.

I will prolly attempt to do a quick review of all the changes I made before making a pull request myself, but if anyone wants to help out and speed run that process it'll be a while before I can get to that with the school semester starting.

If anyone does want to help by reviewing my changes, please be BRUTAL with me, I want the code that goes in to be good and am suspect that there might be a better way to do this :D.

anyways

tl;dr

I will submit a pull request with the changes that we think work for at least two people after either I double check the code and green light it or can get an ok from someone else.

On Sat, Sep 9, 2023 at 7:10 PM Anthony Finch @.***> wrote:

@Mequam https://github.com/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?

— Reply to this email directly, view it on GitHub https://github.com/godotengine/godot/issues/74378#issuecomment-1712659317, or unsubscribe https://github.com/notifications/unsubscribe-auth/AL2DXUEOYW6X4G2IIFRTBOTXZTZP5ANCNFSM6AAAAAAVPWFW2Y . You are receiving this because you were mentioned.Message ID: @.***>

Mequam avatar Sep 10 '23 00:09 Mequam

@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!

anthonyfinch avatar Sep 10 '23 10:09 anthonyfinch

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.

Calinou avatar Sep 10 '23 14:09 Calinou

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.

unlessgames avatar Sep 21 '23 18:09 unlessgames

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

Araly avatar Sep 24 '23 11:09 Araly

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

Mequam avatar Oct 10 '23 21:10 Mequam

@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.

Mequam avatar Oct 10 '23 21:10 Mequam

I just posted PR https://github.com/godotengine/godot/pull/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

dsnopek avatar Dec 22 '23 15:12 dsnopek

Could some of you reproducing this issue test if https://github.com/godotengine/godot/pull/86671 solves the problem for you?

akien-mga avatar Jan 09 '24 13:01 akien-mga

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.

https://github.com/godotengine/godot/assets/2766569/18c43bbb-8239-445b-96da-cc765f7c949b

limbonaut avatar Jan 09 '24 17:01 limbonaut

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!

ttencate avatar Jan 22 '24 19:01 ttencate

Hello, i got the same issue.

EndeavourOs Gnome PaperWm

Entharia avatar Feb 26 '24 15:02 Entharia

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

troykinsella avatar Mar 14 '24 05:03 troykinsella

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.

dsnopek avatar Mar 14 '24 12:03 dsnopek

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. :tada:

troykinsella avatar Mar 14 '24 14:03 troykinsella

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 :tada:

limbonaut avatar Mar 14 '24 15:03 limbonaut