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

Drop events on focus #50

Open
wants to merge 24 commits into
base: main
Choose a base branch
from
Open

Conversation

rezural
Copy link

@rezural rezural commented Jan 6, 2022

This is a POC of dropping/suppressing of keyboard & mouse events, when the pointer is over any egui windows. Im not really that happy with it, but there is nothing wrong with it per-se, with the current state of bevy.

This is based off of jakobhellerman/bevy_egui#bevy-main, as it also depends on a slightly patched version of bevy:https://github.com/rezural/bevy/tree/input-derive-clone

I have gated it behind the drop_events_on_focus feature (feel free to rename this to something better), as while it is probably handy for bevy_egui consumers to opt into, it makes decisions about when to drop events, which are fairly arbitrary.

In reality, the application itself will probably want to decide which input state it is in (i.e. if there is a mouse pointer, or not), and a host of other concerns that will have to be fleshed out properly in bevy & the larger UI effort. I imagine this will come as a result of the bevy ui effort.

@rezural
Copy link
Author

rezural commented Jan 6, 2022

The actual only relevant commit is
53c1773

@rezural
Copy link
Author

rezural commented Jan 6, 2022

This shows an small example app that shows suppression of events, copy this into example/simple.rs, run with:

cargo run --example simple --features=drop_events_on_focus

use bevy::prelude::*;
use bevy_egui::{egui, EguiContext, EguiPlugin};

fn main() {
    App::new()
        .add_plugins(DefaultPlugins)
        .add_plugin(EguiPlugin)
        .add_system(ui_example.system())
        .add_system(input_events.system())
        .run();
}

fn ui_example(egui_context: Res<EguiContext>) {
    egui::Window::new("Hello").show(egui_context.ctx(), |ui| {
        ui.label("world");
    });
    egui::Window::new("Hello2").show(egui_context.ctx(), |ui| {
        ui.label("world");
    });
}

fn input_events(mut ev_cursor: EventReader<CursorMoved>) {
    for event in ev_cursor.iter() {
        println!("Mouse move: {:?}", event);
    }
}

@rezural
Copy link
Author

rezural commented Jan 6, 2022

Fixes #47

@rezural
Copy link
Author

rezural commented Jan 6, 2022

One thing I only just thought of, is to leave most of the event consumption code the same in process_input system. And clear the input events in a system just after process_inputs.

If you think this PR has merit, I can rework this, so that most of process_input remains unchanged (except for the Input::clone())

@vladbat00 vladbat00 force-pushed the main branch 3 times, most recently from f454510 to 022ebd1 Compare May 1, 2022 09:49
@ndavd
Copy link

ndavd commented Dec 1, 2023

Any updates on this?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

6 participants