bevy icon indicating copy to clipboard operation
bevy copied to clipboard

`close_on_esc` does nothing if window was immediately focused on creation

Open Gyrobifastigium opened this issue 3 years ago • 6 comments

https://github.com/bevyengine/bevy/blob/55957330351828e84bfc63cf8e151e2805e9d278/crates/bevy_window/src/system.rs#L46

On Linux with i3 WM, sometimes the app window will be focused on creation with no initial WindowFocused event. When this happens, close_on_esc does nothing until you unfocus and refocus the window to send a WindowFocused event.

Gyrobifastigium avatar Aug 10 '22 07:08 Gyrobifastigium

This might be related to IntelliJ. When I start my game from the terminal instead, there seems to always be an initial WindowFocused event. Also, rarely when started from IntelliJ, the game window will be (apparently) focused, and will register mouse click events, but all keyboard events will get sent to IntelliJ itself instead of the game window.

EDIT: Actually I was able to reproduce the no initial WindowFocused event in a terminal. It's just way less common there for some reason.

Gyrobifastigium avatar Aug 10 '22 08:08 Gyrobifastigium

As far as I can tell, this must be a winit bug/issue.

A search in winit's docs for 'focus' suggest that it doesn't expose any other way for getting window focus.

Alternatively, your window manager is lying to your programs about their focus state.

DJMcNab avatar Aug 10 '22 08:08 DJMcNab

This sounds like correct behaviour, only the focused window should be able to read keyboard input.

You can configure i3 to focus a window on creation though. in .config/i3/config add something like: for_window [class="bevy_game"] floating enable focus

xprop can assist in knowing the window class of your application.

AxiomaticSemantics avatar Nov 12 '22 07:11 AxiomaticSemantics

The behavior is that close_on_esc doesn't work (and rarely, keyboard input events aren't even received) despite the fact that the window is focused on creation.

benfrankel avatar Nov 12 '22 22:11 benfrankel

This reminded me of some changes I've got stashed from a couple months ago that would fix this. I'll probably have the PR up in a bit :)

tim-blackbird avatar Nov 12 '22 23:11 tim-blackbird

The behavior is that close_on_esc doesn't work (and rarely, keyboard input events aren't even received) despite the fact that the window is focused on creation.

If you figure out a way to reliably reproduce this let me know, It hasn't happened to me yet in i3 after months of use with bevy.

AxiomaticSemantics avatar Nov 14 '22 23:11 AxiomaticSemantics

Can be closed as obsolete after https://github.com/bevyengine/bevy/pull/12859.

benfrankel avatar May 23 '24 22:05 benfrankel

Ok I switched accounts lol closing this myself

Gyrobifastigium avatar May 23 '24 22:05 Gyrobifastigium