gtk: add scroll events

Signed-off-by: Marc-André Lureau <marcandre.lureau@redhat.com>
This commit is contained in:
Marc-André Lureau 2021-02-20 13:28:30 +04:00
parent 437b739c0e
commit 2a26d33561
2 changed files with 20 additions and 1 deletions

View File

@ -3,7 +3,7 @@ use zbus::dbus_proxy;
use zvariant::derive::Type;
#[repr(u32)]
#[derive(Deserialize_repr, Serialize_repr, Type, Debug, PartialEq)]
#[derive(Deserialize_repr, Serialize_repr, Type, Debug, PartialEq, Clone, Copy)]
pub enum MouseButton {
Left,
Middle,

View File

@ -89,6 +89,25 @@ mod imp {
let _ = c.mouse.release(button);
}));
let ec = gtk::EventControllerScroll::new(gtk::EventControllerScrollFlags::BOTH_AXES);
self.area.add_controller(&ec);
ec.connect_scroll(clone!(@weak obj => move |_, _dx, dy| {
let c = obj.qemu_console();
let button = if dy >= 1.0 {
Some(MouseButton::WheelDown)
} else if dy <= -1.0 {
Some(MouseButton::WheelUp)
} else {
None
};
if let Some(button) = button {
let _ = c.mouse.press(button);
let _ = c.mouse.release(button);
}
glib::signal::Inhibit(true)
}));
self.area.set_sensitive(true);
self.area.set_focusable(true);
self.area.set_focus_on_click(true);