tauri-apps / tao

The TAO of cross-platform windowing. A library in Rust built for Tauri.
Apache License 2.0
1.63k stars 191 forks source link

Pressing a mouse button has duplicit events on Linux #939

Closed DavidHusicka closed 4 months ago

DavidHusicka commented 5 months ago

When a mouse button is pressed, the event loop sends "Pressed, Pressed, Released, Released" events on the Linux platform. Sometimes it sends even more than just one duplicit event. This may cause unwanted multi-click in some applications.

To reproduce:

  1. Create a Rust project using Tao
  2. Copy the example reproduction code from bellow
  3. Click
  4. Read the terminal output
use tao::{
    event::{Event, WindowEvent},
    event_loop::{ControlFlow, EventLoop},
    window::WindowBuilder,
};

fn main() {
    let event_loop = EventLoop::new();
    let window = WindowBuilder::new().build(&event_loop).unwrap();

    event_loop.run(move |event, _, control_flow| {
        *control_flow = ControlFlow::Wait;

        match event {
            Event::WindowEvent {
                event: WindowEvent::CloseRequested,
                ..
            } => {
                println!("The close button was pressed; stopping");
                *control_flow = ControlFlow::Exit
            }
            Event::MainEventsCleared => {
                window.request_redraw();
            }
            Event::WindowEvent {
                window_id, event, ..
            } => {
                let WindowEvent::MouseInput { .. } = event else {
                    return;
                };
                dbg!(&window_id);
                dbg!(&event);
            }
            _ => (),
        }
    });
}

Expected behavior is receiving only one "Pressed" and one "Released" event to match the other platforms.

Platform and Versions: OS: Linux Rustc: cargo 1.81.0-nightly (4dcbca118 2024-06-11) Tao version: 0.28.1