Skip to content

Phantom key presses when focusing an egui/winit window #4513

@hut

Description

@hut

Currently, when running egui in X11 on Linux with the winit backend, phantom key presses are registered when the window gains focus. Examples:

  1. If you press Alt+TAB to select the window, a key press of "TAB" is erroneously registered.
  2. My window manager has the key binding Alt+w to change workspaces. Assuming the egui window has a text box selected, if I change the workspace to the one with the egui window with the key binding Alt+w, it will erroneously type a "w" into the text box.

In either example, I would expect no key to be registered. After all, no other (non-broken) application will register/type keys simply by changing focus into the application window.

This error happens because winit sends "fake" KeyboardInput events with a field "is_synthetic" when the window focus is gained. Key presses with "is_synthetic == true" should not be interpreted as real key presses and should be filtered out, according to the maintainers of winit.

egui currently does not do special handling of KeyboardInput events with "is_synthetic == true", see

WindowEvent::KeyboardInput { event, .. } => {

The proper handling would be to discard the event if "keyboardinput.event.state == ElementState::Pressed && keyboardinput.is_synthetic" is true.

See also:

Thanks for looking into this. It probably causes a lot of confusion/frustration for X11 users that heavily customize their window manager key bindings.

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething is brokenegui-winitporblems related to winit

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions