I'm trying to capture up a right click event on a TreeView I have in my application using Rust and gtk4-rs. I don't see a specific EventController for mouse buttons events. I do see EventControllers for things like keyboard presses and motion events. I ended up using the EventControllerLegacy and just detecting the event type inside the closure, but I feel like I'm missing something here. Is there some other way I should be getting button press events from the mouse? Here's my code:
pub fn build_tree_view() -> TreeView {
let tree_view: TreeView = TreeView::new();
tree_view.set_headers_visible(false);
let event_controller = EventControllerLegacy::new();
event_controller.connect_event(|controller, event| {
if event.event_type() == ButtonPress {
let button_event = event.clone().downcast::<ButtonEvent>().unwrap();
if button_event.button() == GDK_BUTTON_SECONDARY as u32 {
println!("got mouse button: {}", button_event.button());
}
}
return Inhibit(false);
});
tree_view.add_controller(&event_controller);
return tree_view;
}
The reason I believe I am missing something is that the documentation for EventControllerLegacy states the following:
EventControllerLegacy is an event controller that provides raw access to the event stream. It should only be used as a last resort if none of the other event controllers or gestures do the job.
I am using Rust 1.56.0 and gtk4-rs 0.4.2
Thanks