PistonDevelopers / glfw-rs

GLFW3 bindings and idiomatic wrapper for Rust.
Apache License 2.0
646 stars 123 forks source link

Mouse Events do not trigger #491

Open tukanoidd opened 2 years ago

tukanoidd commented 2 years ago

Hello, been trying to make a simple application but mouse event don't seem to have any callback whatsoever, CursorPos and MouseButton at least.

Here's my code in the while loop in match event:

WindowEvent::Key(key, scancode, action, modifiers) => {
                    if action == Action::Press {
                        if key == Key::Escape {
                            window.native_window.set_should_close(true);
                        }

                        if key == Key::E {
                            println!("E key is being pressed");
                        }
                    }
                }
                WindowEvent::CursorPos(x_pos, y_pos) => {
                    println!("Mouse Movement Event!");
                    println!("x pos: {}", x_pos);

                    if x_pos >= 800.0 {
                        println!("Mouse is at the right part of the window.")
                    }
                }
                WindowEvent::MouseButton(button, action, modifiers) => {
                    println!("Mouse Button Event!");
                    if action == Action::Press {
                        if button == MouseButtonLeft {
                            println!("Left Mouse Click!");
                        }
                    }
                }

KeyPress works without any problems, prints out the text, but no matter what I do with the mouse, nothing is getting printed out, co cursor position, no button presses.

Details:

  1. Garuda Linux, Gnome 41, X11, linux-zen 5.15.11
  2. Rust 2021 Edition
  3. Dependencies:
    1. gl - 0.14.0
    2. glfw - 0.43.0
    3. gl_generator - 0.14.0 (generating v4.6 bindings and set this version as windowHint as well)
    4. khronos_api - 3.1.0

Thanks!

RpxdYTX commented 2 years ago

Did you call window.set_mouse_button_polling(true)? This function activates the callback that updates the mouse button events in glfw::flush_messages