mirror of
https://gitlab.com/marcandre.lureau/qemu-display.git
synced 2024-11-09 17:40:05 +00:00
gtk: add scroll events
Signed-off-by: Marc-André Lureau <marcandre.lureau@redhat.com>
This commit is contained in:
parent
437b739c0e
commit
2a26d33561
@ -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,
|
||||
|
@ -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);
|
||||
|
Loading…
Reference in New Issue
Block a user