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

close_on_esc does nothing if window was immediately focused on creation #5646

Closed
Gyrobifastigium opened this issue Aug 10, 2022 · 8 comments
Closed
Labels
A-Windowing Platform-agnostic interface layer to run your app in C-Bug An unexpected or incorrect behavior O-Linux Specific to the Linux desktop operating system

Comments

@Gyrobifastigium
Copy link

for event in focused_events.iter() {

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
Copy link
Author

Gyrobifastigium commented Aug 10, 2022

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.

@DJMcNab
Copy link
Member

DJMcNab commented Aug 10, 2022

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.

@Weibye Weibye added C-Bug An unexpected or incorrect behavior A-Windowing Platform-agnostic interface layer to run your app in O-Linux Specific to the Linux desktop operating system labels Aug 10, 2022
@ghost
Copy link

ghost commented Nov 12, 2022

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.

@benfrankel
Copy link
Contributor

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.

@tim-blackbird
Copy link
Contributor

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

bors bot pushed a commit that referenced this issue Nov 14, 2022
Add a method to get the focused window.

Use this instead of `WindowFocused` events in `close_on_esc`.
Seems that the OS/window manager might not always send focused events on application startup.

Sadly, not a fix for #5646.

Co-authored-by: devil-ira <[email protected]>
bors bot pushed a commit that referenced this issue Nov 14, 2022
Add a method to get the focused window.

Use this instead of `WindowFocused` events in `close_on_esc`.
Seems that the OS/window manager might not always send focused events on application startup.

Sadly, not a fix for #5646.

Co-authored-by: devil-ira <[email protected]>
@ghost
Copy link

ghost commented Nov 14, 2022

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.

taiyoungjang pushed a commit to taiyoungjang/bevy that referenced this issue Dec 15, 2022
Add a method to get the focused window.

Use this instead of `WindowFocused` events in `close_on_esc`.
Seems that the OS/window manager might not always send focused events on application startup.

Sadly, not a fix for bevyengine#5646.

Co-authored-by: devil-ira <[email protected]>
alradish pushed a commit to alradish/bevy that referenced this issue Jan 22, 2023
Add a method to get the focused window.

Use this instead of `WindowFocused` events in `close_on_esc`.
Seems that the OS/window manager might not always send focused events on application startup.

Sadly, not a fix for bevyengine#5646.

Co-authored-by: devil-ira <[email protected]>
ItsDoot pushed a commit to ItsDoot/bevy that referenced this issue Feb 1, 2023
Add a method to get the focused window.

Use this instead of `WindowFocused` events in `close_on_esc`.
Seems that the OS/window manager might not always send focused events on application startup.

Sadly, not a fix for bevyengine#5646.

Co-authored-by: devil-ira <[email protected]>
@benfrankel
Copy link
Contributor

Can be closed as obsolete after #12859.

@Gyrobifastigium
Copy link
Author

Gyrobifastigium commented May 23, 2024

Ok I switched accounts lol closing this myself

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-Windowing Platform-agnostic interface layer to run your app in C-Bug An unexpected or incorrect behavior O-Linux Specific to the Linux desktop operating system
Projects
None yet
Development

No branches or pull requests

5 participants