Add event_loop to `InputBackend` and `InputHandler` traits
This commit is contained in:
parent
b483add6a5
commit
a9c75656a2
|
@ -55,7 +55,7 @@ use std::rc::Rc;
|
||||||
use std::sync::Arc;
|
use std::sync::Arc;
|
||||||
use std::sync::atomic::{AtomicBool, Ordering};
|
use std::sync::atomic::{AtomicBool, Ordering};
|
||||||
use std::time::Duration;
|
use std::time::Duration;
|
||||||
use wayland_server::{Display, StateProxy, StateToken};
|
use wayland_server::{Display, EventLoopHandle, StateProxy, StateToken};
|
||||||
use wayland_server::protocol::{wl_output, wl_pointer};
|
use wayland_server::protocol::{wl_output, wl_pointer};
|
||||||
use xkbcommon::xkb::keysyms as xkb;
|
use xkbcommon::xkb::keysyms as xkb;
|
||||||
|
|
||||||
|
@ -78,16 +78,18 @@ impl LibinputInputHandler {
|
||||||
}
|
}
|
||||||
|
|
||||||
impl InputHandler<LibinputInputBackend> for LibinputInputHandler {
|
impl InputHandler<LibinputInputBackend> for LibinputInputHandler {
|
||||||
fn on_seat_created(&mut self, _: &input::Seat) {
|
fn on_seat_created(&mut self, _evlh: &mut EventLoopHandle, _: &input::Seat) {
|
||||||
/* we just create a single static one */
|
/* we just create a single static one */
|
||||||
}
|
}
|
||||||
fn on_seat_destroyed(&mut self, _: &input::Seat) {
|
fn on_seat_destroyed(&mut self, _evlh: &mut EventLoopHandle, _: &input::Seat) {
|
||||||
/* we just create a single static one */
|
/* we just create a single static one */
|
||||||
}
|
}
|
||||||
fn on_seat_changed(&mut self, _: &input::Seat) {
|
fn on_seat_changed(&mut self, _evlh: &mut EventLoopHandle, _: &input::Seat) {
|
||||||
/* we just create a single static one */
|
/* we just create a single static one */
|
||||||
}
|
}
|
||||||
fn on_keyboard_key(&mut self, _: &input::Seat, evt: event::keyboard::KeyboardKeyEvent) {
|
fn on_keyboard_key(
|
||||||
|
&mut self, _evlh: &mut EventLoopHandle, _: &input::Seat, evt: event::keyboard::KeyboardKeyEvent
|
||||||
|
) {
|
||||||
let keycode = evt.key();
|
let keycode = evt.key();
|
||||||
let state = evt.state();
|
let state = evt.state();
|
||||||
debug!(self.log, "key"; "keycode" => keycode, "state" => format!("{:?}", state));
|
debug!(self.log, "key"; "keycode" => keycode, "state" => format!("{:?}", state));
|
||||||
|
@ -106,7 +108,9 @@ impl InputHandler<LibinputInputBackend> for LibinputInputHandler {
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
fn on_pointer_move(&mut self, _: &input::Seat, evt: event::pointer::PointerMotionEvent) {
|
fn on_pointer_move(
|
||||||
|
&mut self, _evlh: &mut EventLoopHandle, _: &input::Seat, evt: event::pointer::PointerMotionEvent
|
||||||
|
) {
|
||||||
let (x, y) = (evt.dx(), evt.dy());
|
let (x, y) = (evt.dx(), evt.dy());
|
||||||
let serial = self.next_serial();
|
let serial = self.next_serial();
|
||||||
let mut location = self.pointer_location.borrow_mut();
|
let mut location = self.pointer_location.borrow_mut();
|
||||||
|
@ -121,7 +125,10 @@ impl InputHandler<LibinputInputBackend> for LibinputInputHandler {
|
||||||
evt.time(),
|
evt.time(),
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
fn on_pointer_move_absolute(&mut self, _: &input::Seat, evt: event::pointer::PointerMotionAbsoluteEvent) {
|
fn on_pointer_move_absolute(
|
||||||
|
&mut self, _evlh: &mut EventLoopHandle, _: &input::Seat,
|
||||||
|
evt: event::pointer::PointerMotionAbsoluteEvent,
|
||||||
|
) {
|
||||||
let (x, y) = (
|
let (x, y) = (
|
||||||
evt.absolute_x_transformed(self.screen_size.0),
|
evt.absolute_x_transformed(self.screen_size.0),
|
||||||
evt.absolute_y_transformed(self.screen_size.1),
|
evt.absolute_y_transformed(self.screen_size.1),
|
||||||
|
@ -135,7 +142,9 @@ impl InputHandler<LibinputInputBackend> for LibinputInputHandler {
|
||||||
evt.time(),
|
evt.time(),
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
fn on_pointer_button(&mut self, _: &input::Seat, evt: event::pointer::PointerButtonEvent) {
|
fn on_pointer_button(
|
||||||
|
&mut self, _evlh: &mut EventLoopHandle, _: &input::Seat, evt: event::pointer::PointerButtonEvent
|
||||||
|
) {
|
||||||
let serial = self.next_serial();
|
let serial = self.next_serial();
|
||||||
let button = evt.button();
|
let button = evt.button();
|
||||||
let state = match evt.state() {
|
let state = match evt.state() {
|
||||||
|
@ -152,29 +161,39 @@ impl InputHandler<LibinputInputBackend> for LibinputInputHandler {
|
||||||
};
|
};
|
||||||
self.pointer.button(button, state, serial, evt.time());
|
self.pointer.button(button, state, serial, evt.time());
|
||||||
}
|
}
|
||||||
fn on_pointer_axis(&mut self, _: &input::Seat, evt: LibinputPointerAxisEvent) {
|
fn on_pointer_axis(
|
||||||
|
&mut self, _evlh: &mut EventLoopHandle, _: &input::Seat, evt: LibinputPointerAxisEvent
|
||||||
|
) {
|
||||||
let axis = match evt.axis() {
|
let axis = match evt.axis() {
|
||||||
input::Axis::Vertical => wayland_server::protocol::wl_pointer::Axis::VerticalScroll,
|
input::Axis::Vertical => wayland_server::protocol::wl_pointer::Axis::VerticalScroll,
|
||||||
input::Axis::Horizontal => wayland_server::protocol::wl_pointer::Axis::HorizontalScroll,
|
input::Axis::Horizontal => wayland_server::protocol::wl_pointer::Axis::HorizontalScroll,
|
||||||
};
|
};
|
||||||
self.pointer.axis(axis, evt.amount(), evt.time());
|
self.pointer.axis(axis, evt.amount(), evt.time());
|
||||||
}
|
}
|
||||||
fn on_touch_down(&mut self, _: &input::Seat, _: event::touch::TouchDownEvent) {
|
fn on_touch_down(
|
||||||
|
&mut self, _evlh: &mut EventLoopHandle, _: &input::Seat, _: event::touch::TouchDownEvent
|
||||||
|
) {
|
||||||
/* not done in this example */
|
/* not done in this example */
|
||||||
}
|
}
|
||||||
fn on_touch_motion(&mut self, _: &input::Seat, _: event::touch::TouchMotionEvent) {
|
fn on_touch_motion(
|
||||||
|
&mut self, _evlh: &mut EventLoopHandle, _: &input::Seat, _: event::touch::TouchMotionEvent
|
||||||
|
) {
|
||||||
/* not done in this example */
|
/* not done in this example */
|
||||||
}
|
}
|
||||||
fn on_touch_up(&mut self, _: &input::Seat, _: event::touch::TouchUpEvent) {
|
fn on_touch_up(&mut self, _evlh: &mut EventLoopHandle, _: &input::Seat, _: event::touch::TouchUpEvent) {
|
||||||
/* not done in this example */
|
/* not done in this example */
|
||||||
}
|
}
|
||||||
fn on_touch_cancel(&mut self, _: &input::Seat, _: event::touch::TouchCancelEvent) {
|
fn on_touch_cancel(
|
||||||
|
&mut self, _evlh: &mut EventLoopHandle, _: &input::Seat, _: event::touch::TouchCancelEvent
|
||||||
|
) {
|
||||||
/* not done in this example */
|
/* not done in this example */
|
||||||
}
|
}
|
||||||
fn on_touch_frame(&mut self, _: &input::Seat, _: event::touch::TouchFrameEvent) {
|
fn on_touch_frame(
|
||||||
|
&mut self, _evlh: &mut EventLoopHandle, _: &input::Seat, _: event::touch::TouchFrameEvent
|
||||||
|
) {
|
||||||
/* not done in this example */
|
/* not done in this example */
|
||||||
}
|
}
|
||||||
fn on_input_config_changed(&mut self, _: &mut [LibinputDevice]) {
|
fn on_input_config_changed(&mut self, _evlh: &mut EventLoopHandle, _: &mut [LibinputDevice]) {
|
||||||
/* not done in this example */
|
/* not done in this example */
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -304,16 +323,19 @@ fn main() {
|
||||||
let libinput_session_id = notifier.register(libinput_context.clone());
|
let libinput_session_id = notifier.register(libinput_context.clone());
|
||||||
libinput_context.udev_assign_seat(&seat).unwrap();
|
libinput_context.udev_assign_seat(&seat).unwrap();
|
||||||
let mut libinput_backend = LibinputInputBackend::new(libinput_context, log.clone());
|
let mut libinput_backend = LibinputInputBackend::new(libinput_context, log.clone());
|
||||||
libinput_backend.set_handler(LibinputInputHandler {
|
libinput_backend.set_handler(
|
||||||
log: log.clone(),
|
&mut event_loop,
|
||||||
pointer,
|
LibinputInputHandler {
|
||||||
keyboard,
|
log: log.clone(),
|
||||||
window_map: window_map.clone(),
|
pointer,
|
||||||
pointer_location,
|
keyboard,
|
||||||
screen_size: (w, h),
|
window_map: window_map.clone(),
|
||||||
serial: 0,
|
pointer_location,
|
||||||
running: running.clone(),
|
screen_size: (w, h),
|
||||||
});
|
serial: 0,
|
||||||
|
running: running.clone(),
|
||||||
|
},
|
||||||
|
);
|
||||||
let libinput_event_source = libinput_bind(libinput_backend, &mut event_loop).unwrap();
|
let libinput_event_source = libinput_bind(libinput_backend, &mut event_loop).unwrap();
|
||||||
|
|
||||||
let session_event_source = direct_session_bind(notifier, &mut event_loop, log.clone()).unwrap();
|
let session_event_source = direct_session_bind(notifier, &mut event_loop, log.clone()).unwrap();
|
||||||
|
|
|
@ -26,6 +26,7 @@ use smithay::wayland::seat::{KeyboardHandle, PointerHandle, Seat};
|
||||||
use smithay::wayland::shm::init_shm_global;
|
use smithay::wayland::shm::init_shm_global;
|
||||||
use std::cell::RefCell;
|
use std::cell::RefCell;
|
||||||
use std::rc::Rc;
|
use std::rc::Rc;
|
||||||
|
use wayland_server::EventLoopHandle;
|
||||||
use wayland_server::protocol::{wl_output, wl_pointer};
|
use wayland_server::protocol::{wl_output, wl_pointer};
|
||||||
|
|
||||||
struct WinitInputHandler {
|
struct WinitInputHandler {
|
||||||
|
@ -45,26 +46,30 @@ impl WinitInputHandler {
|
||||||
}
|
}
|
||||||
|
|
||||||
impl InputHandler<winit::WinitInputBackend> for WinitInputHandler {
|
impl InputHandler<winit::WinitInputBackend> for WinitInputHandler {
|
||||||
fn on_seat_created(&mut self, _: &input::Seat) {
|
fn on_seat_created(&mut self, _evlh: &mut EventLoopHandle, _: &input::Seat) {
|
||||||
/* never happens with winit */
|
/* never happens with winit */
|
||||||
}
|
}
|
||||||
fn on_seat_destroyed(&mut self, _: &input::Seat) {
|
fn on_seat_destroyed(&mut self, _evlh: &mut EventLoopHandle, _: &input::Seat) {
|
||||||
/* never happens with winit */
|
/* never happens with winit */
|
||||||
}
|
}
|
||||||
fn on_seat_changed(&mut self, _: &input::Seat) {
|
fn on_seat_changed(&mut self, _evlh: &mut EventLoopHandle, _: &input::Seat) {
|
||||||
/* never happens with winit */
|
/* never happens with winit */
|
||||||
}
|
}
|
||||||
fn on_keyboard_key(&mut self, _: &input::Seat, evt: winit::WinitKeyboardInputEvent) {
|
fn on_keyboard_key(
|
||||||
|
&mut self, _evlh: &mut EventLoopHandle, _: &input::Seat, evt: winit::WinitKeyboardInputEvent
|
||||||
|
) {
|
||||||
let keycode = evt.key_code();
|
let keycode = evt.key_code();
|
||||||
let state = evt.state();
|
let state = evt.state();
|
||||||
debug!(self.log, "key"; "keycode" => keycode, "state" => format!("{:?}", state));
|
debug!(self.log, "key"; "keycode" => keycode, "state" => format!("{:?}", state));
|
||||||
let serial = self.next_serial();
|
let serial = self.next_serial();
|
||||||
self.keyboard.input(keycode, state, serial, |_, _| true);
|
self.keyboard.input(keycode, state, serial, |_, _| true);
|
||||||
}
|
}
|
||||||
fn on_pointer_move(&mut self, _: &input::Seat, _: input::UnusedEvent) {
|
fn on_pointer_move(&mut self, _evlh: &mut EventLoopHandle, _: &input::Seat, _: input::UnusedEvent) {
|
||||||
/* never happens with winit */
|
/* never happens with winit */
|
||||||
}
|
}
|
||||||
fn on_pointer_move_absolute(&mut self, _: &input::Seat, evt: winit::WinitMouseMovedEvent) {
|
fn on_pointer_move_absolute(
|
||||||
|
&mut self, _evlh: &mut EventLoopHandle, _: &input::Seat, evt: winit::WinitMouseMovedEvent
|
||||||
|
) {
|
||||||
// on winit, mouse events are already in pixel coordinates
|
// on winit, mouse events are already in pixel coordinates
|
||||||
let (x, y) = evt.position();
|
let (x, y) = evt.position();
|
||||||
self.pointer_location = (x, y);
|
self.pointer_location = (x, y);
|
||||||
|
@ -76,7 +81,9 @@ impl InputHandler<winit::WinitInputBackend> for WinitInputHandler {
|
||||||
evt.time(),
|
evt.time(),
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
fn on_pointer_button(&mut self, _: &input::Seat, evt: winit::WinitMouseInputEvent) {
|
fn on_pointer_button(
|
||||||
|
&mut self, _evlh: &mut EventLoopHandle, _: &input::Seat, evt: winit::WinitMouseInputEvent
|
||||||
|
) {
|
||||||
let serial = self.next_serial();
|
let serial = self.next_serial();
|
||||||
let button = match evt.button() {
|
let button = match evt.button() {
|
||||||
input::MouseButton::Left => 0x110,
|
input::MouseButton::Left => 0x110,
|
||||||
|
@ -98,29 +105,37 @@ impl InputHandler<winit::WinitInputBackend> for WinitInputHandler {
|
||||||
};
|
};
|
||||||
self.pointer.button(button, state, serial, evt.time());
|
self.pointer.button(button, state, serial, evt.time());
|
||||||
}
|
}
|
||||||
fn on_pointer_axis(&mut self, _: &input::Seat, evt: winit::WinitMouseWheelEvent) {
|
fn on_pointer_axis(
|
||||||
|
&mut self, _evlh: &mut EventLoopHandle, _: &input::Seat, evt: winit::WinitMouseWheelEvent
|
||||||
|
) {
|
||||||
let axis = match evt.axis() {
|
let axis = match evt.axis() {
|
||||||
input::Axis::Vertical => wayland_server::protocol::wl_pointer::Axis::VerticalScroll,
|
input::Axis::Vertical => wayland_server::protocol::wl_pointer::Axis::VerticalScroll,
|
||||||
input::Axis::Horizontal => wayland_server::protocol::wl_pointer::Axis::HorizontalScroll,
|
input::Axis::Horizontal => wayland_server::protocol::wl_pointer::Axis::HorizontalScroll,
|
||||||
};
|
};
|
||||||
self.pointer.axis(axis, evt.amount(), evt.time());
|
self.pointer.axis(axis, evt.amount(), evt.time());
|
||||||
}
|
}
|
||||||
fn on_touch_down(&mut self, _: &input::Seat, _: winit::WinitTouchStartedEvent) {
|
fn on_touch_down(
|
||||||
|
&mut self, _evlh: &mut EventLoopHandle, _: &input::Seat, _: winit::WinitTouchStartedEvent
|
||||||
|
) {
|
||||||
/* not done in this example */
|
/* not done in this example */
|
||||||
}
|
}
|
||||||
fn on_touch_motion(&mut self, _: &input::Seat, _: winit::WinitTouchMovedEvent) {
|
fn on_touch_motion(
|
||||||
|
&mut self, _evlh: &mut EventLoopHandle, _: &input::Seat, _: winit::WinitTouchMovedEvent
|
||||||
|
) {
|
||||||
/* not done in this example */
|
/* not done in this example */
|
||||||
}
|
}
|
||||||
fn on_touch_up(&mut self, _: &input::Seat, _: winit::WinitTouchEndedEvent) {
|
fn on_touch_up(&mut self, _evlh: &mut EventLoopHandle, _: &input::Seat, _: winit::WinitTouchEndedEvent) {
|
||||||
/* not done in this example */
|
/* not done in this example */
|
||||||
}
|
}
|
||||||
fn on_touch_cancel(&mut self, _: &input::Seat, _: winit::WinitTouchCancelledEvent) {
|
fn on_touch_cancel(
|
||||||
|
&mut self, _evlh: &mut EventLoopHandle, _: &input::Seat, _: winit::WinitTouchCancelledEvent
|
||||||
|
) {
|
||||||
/* not done in this example */
|
/* not done in this example */
|
||||||
}
|
}
|
||||||
fn on_touch_frame(&mut self, _: &input::Seat, _: input::UnusedEvent) {
|
fn on_touch_frame(&mut self, _evlh: &mut EventLoopHandle, _: &input::Seat, _: input::UnusedEvent) {
|
||||||
/* never happens with winit */
|
/* never happens with winit */
|
||||||
}
|
}
|
||||||
fn on_input_config_changed(&mut self, _: &mut ()) {
|
fn on_input_config_changed(&mut self, _evlh: &mut EventLoopHandle, _: &mut ()) {
|
||||||
/* never happens with winit */
|
/* never happens with winit */
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -201,14 +216,17 @@ fn main() {
|
||||||
refresh: 60_000,
|
refresh: 60_000,
|
||||||
});
|
});
|
||||||
|
|
||||||
input.set_handler(WinitInputHandler {
|
input.set_handler(
|
||||||
log: log.clone(),
|
&mut event_loop,
|
||||||
pointer,
|
WinitInputHandler {
|
||||||
keyboard,
|
log: log.clone(),
|
||||||
window_map: window_map.clone(),
|
pointer,
|
||||||
pointer_location: (0.0, 0.0),
|
keyboard,
|
||||||
serial: 0,
|
window_map: window_map.clone(),
|
||||||
});
|
pointer_location: (0.0, 0.0),
|
||||||
|
serial: 0,
|
||||||
|
},
|
||||||
|
);
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Add a listening socket:
|
* Add a listening socket:
|
||||||
|
@ -217,7 +235,7 @@ fn main() {
|
||||||
println!("Listening on socket: {}", name);
|
println!("Listening on socket: {}", name);
|
||||||
|
|
||||||
loop {
|
loop {
|
||||||
input.dispatch_new_events().unwrap();
|
input.dispatch_new_events(&mut event_loop).unwrap();
|
||||||
|
|
||||||
let mut frame = drawer.draw();
|
let mut frame = drawer.draw();
|
||||||
frame.clear(None, Some((0.8, 0.8, 0.9, 1.0)), false, Some(1.0), None);
|
frame.clear(None, Some((0.8, 0.8, 0.9, 1.0)), false, Some(1.0), None);
|
||||||
|
|
|
@ -1,6 +1,7 @@
|
||||||
//! Common traits for input backends to receive input from.
|
//! Common traits for input backends to receive input from.
|
||||||
|
|
||||||
use std::error::Error;
|
use std::error::Error;
|
||||||
|
use wayland_server::EventLoopHandle;
|
||||||
|
|
||||||
/// A seat describes a group of input devices and at least one
|
/// A seat describes a group of input devices and at least one
|
||||||
/// graphics device belonging together.
|
/// graphics device belonging together.
|
||||||
|
@ -506,31 +507,31 @@ pub trait InputBackend: Sized {
|
||||||
type TouchFrameEvent: TouchFrameEvent;
|
type TouchFrameEvent: TouchFrameEvent;
|
||||||
|
|
||||||
/// Sets a new handler for this `InputBackend`
|
/// Sets a new handler for this `InputBackend`
|
||||||
fn set_handler<H: InputHandler<Self> + 'static>(&mut self, handler: H);
|
fn set_handler<H: InputHandler<Self> + 'static>(&mut self, evlh: &mut EventLoopHandle, handler: H);
|
||||||
/// Get a reference to the currently set handler, if any
|
/// Get a reference to the currently set handler, if any
|
||||||
fn get_handler(&mut self) -> Option<&mut InputHandler<Self>>;
|
fn get_handler(&mut self) -> Option<&mut InputHandler<Self>>;
|
||||||
/// Clears the currently handler, if one is set
|
/// Clears the currently handler, if one is set
|
||||||
fn clear_handler(&mut self);
|
fn clear_handler(&mut self, evlh: &mut EventLoopHandle);
|
||||||
|
|
||||||
/// Get current `InputConfig`
|
/// Get current `InputConfig`
|
||||||
fn input_config(&mut self) -> &mut Self::InputConfig;
|
fn input_config(&mut self) -> &mut Self::InputConfig;
|
||||||
|
|
||||||
/// Processes new events of the underlying backend and drives the `InputHandler`.
|
/// Processes new events of the underlying backend and drives the `InputHandler`.
|
||||||
fn dispatch_new_events(&mut self) -> Result<(), Self::EventError>;
|
fn dispatch_new_events(&mut self, evlh: &mut EventLoopHandle) -> Result<(), Self::EventError>;
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Implement to receive input events from any `InputBackend`.
|
/// Implement to receive input events from any `InputBackend`.
|
||||||
pub trait InputHandler<B: InputBackend> {
|
pub trait InputHandler<B: InputBackend> {
|
||||||
/// Called when a new `Seat` has been created
|
/// Called when a new `Seat` has been created
|
||||||
fn on_seat_created(&mut self, seat: &Seat);
|
fn on_seat_created(&mut self, evlh: &mut EventLoopHandle, seat: &Seat);
|
||||||
/// Called when an existing `Seat` has been destroyed.
|
/// Called when an existing `Seat` has been destroyed.
|
||||||
fn on_seat_destroyed(&mut self, seat: &Seat);
|
fn on_seat_destroyed(&mut self, evlh: &mut EventLoopHandle, seat: &Seat);
|
||||||
/// Called when a `Seat`'s properties have changed.
|
/// Called when a `Seat`'s properties have changed.
|
||||||
///
|
///
|
||||||
/// ## Note:
|
/// ## Note:
|
||||||
///
|
///
|
||||||
/// It is not guaranteed that any change has actually happened.
|
/// It is not guaranteed that any change has actually happened.
|
||||||
fn on_seat_changed(&mut self, seat: &Seat);
|
fn on_seat_changed(&mut self, evlh: &mut EventLoopHandle, seat: &Seat);
|
||||||
|
|
||||||
/// Called when a new keyboard event was received.
|
/// Called when a new keyboard event was received.
|
||||||
///
|
///
|
||||||
|
@ -539,7 +540,7 @@ pub trait InputHandler<B: InputBackend> {
|
||||||
/// - `seat` - The `Seat` the event belongs to
|
/// - `seat` - The `Seat` the event belongs to
|
||||||
/// - `event` - The keyboard event
|
/// - `event` - The keyboard event
|
||||||
///
|
///
|
||||||
fn on_keyboard_key(&mut self, seat: &Seat, event: B::KeyboardKeyEvent);
|
fn on_keyboard_key(&mut self, evlh: &mut EventLoopHandle, seat: &Seat, event: B::KeyboardKeyEvent);
|
||||||
|
|
||||||
/// Called when a new pointer movement event was received.
|
/// Called when a new pointer movement event was received.
|
||||||
///
|
///
|
||||||
|
@ -547,28 +548,30 @@ pub trait InputHandler<B: InputBackend> {
|
||||||
///
|
///
|
||||||
/// - `seat` - The `Seat` the event belongs to
|
/// - `seat` - The `Seat` the event belongs to
|
||||||
/// - `event` - The pointer movement event
|
/// - `event` - The pointer movement event
|
||||||
fn on_pointer_move(&mut self, seat: &Seat, event: B::PointerMotionEvent);
|
fn on_pointer_move(&mut self, evlh: &mut EventLoopHandle, seat: &Seat, event: B::PointerMotionEvent);
|
||||||
/// Called when a new pointer absolute movement event was received.
|
/// Called when a new pointer absolute movement event was received.
|
||||||
///
|
///
|
||||||
/// # Arguments
|
/// # Arguments
|
||||||
///
|
///
|
||||||
/// - `seat` - The `Seat` the event belongs to
|
/// - `seat` - The `Seat` the event belongs to
|
||||||
/// - `event` - The pointer absolute movement event
|
/// - `event` - The pointer absolute movement event
|
||||||
fn on_pointer_move_absolute(&mut self, seat: &Seat, event: B::PointerMotionAbsoluteEvent);
|
fn on_pointer_move_absolute(
|
||||||
|
&mut self, evlh: &mut EventLoopHandle, seat: &Seat, event: B::PointerMotionAbsoluteEvent
|
||||||
|
);
|
||||||
/// Called when a new pointer button event was received.
|
/// Called when a new pointer button event was received.
|
||||||
///
|
///
|
||||||
/// # Arguments
|
/// # Arguments
|
||||||
///
|
///
|
||||||
/// - `seat` - The `Seat` the event belongs to
|
/// - `seat` - The `Seat` the event belongs to
|
||||||
/// - `event` - The pointer button event
|
/// - `event` - The pointer button event
|
||||||
fn on_pointer_button(&mut self, seat: &Seat, event: B::PointerButtonEvent);
|
fn on_pointer_button(&mut self, evlh: &mut EventLoopHandle, seat: &Seat, event: B::PointerButtonEvent);
|
||||||
/// Called when a new pointer scroll event was received.
|
/// Called when a new pointer scroll event was received.
|
||||||
///
|
///
|
||||||
/// # Arguments
|
/// # Arguments
|
||||||
///
|
///
|
||||||
/// - `seat` - The `Seat` the event belongs to
|
/// - `seat` - The `Seat` the event belongs to
|
||||||
/// - `event` - A upward counting variable useful for event ordering. Makes no gurantees about actual time passed between events.
|
/// - `event` - A upward counting variable useful for event ordering. Makes no gurantees about actual time passed between events.
|
||||||
fn on_pointer_axis(&mut self, seat: &Seat, event: B::PointerAxisEvent);
|
fn on_pointer_axis(&mut self, evlh: &mut EventLoopHandle, seat: &Seat, event: B::PointerAxisEvent);
|
||||||
|
|
||||||
/// Called when a new touch down event was received.
|
/// Called when a new touch down event was received.
|
||||||
///
|
///
|
||||||
|
@ -576,97 +579,99 @@ pub trait InputHandler<B: InputBackend> {
|
||||||
///
|
///
|
||||||
/// - `seat` - The `Seat` the event belongs to
|
/// - `seat` - The `Seat` the event belongs to
|
||||||
/// - `event` - The touch down event
|
/// - `event` - The touch down event
|
||||||
fn on_touch_down(&mut self, seat: &Seat, event: B::TouchDownEvent);
|
fn on_touch_down(&mut self, evlh: &mut EventLoopHandle, seat: &Seat, event: B::TouchDownEvent);
|
||||||
/// Called when a new touch motion event was received.
|
/// Called when a new touch motion event was received.
|
||||||
///
|
///
|
||||||
/// # Arguments
|
/// # Arguments
|
||||||
///
|
///
|
||||||
/// - `seat` - The `Seat` the event belongs to
|
/// - `seat` - The `Seat` the event belongs to
|
||||||
/// - `event` - The touch motion event.
|
/// - `event` - The touch motion event.
|
||||||
fn on_touch_motion(&mut self, seat: &Seat, event: B::TouchMotionEvent);
|
fn on_touch_motion(&mut self, evlh: &mut EventLoopHandle, seat: &Seat, event: B::TouchMotionEvent);
|
||||||
/// Called when a new touch up event was received.
|
/// Called when a new touch up event was received.
|
||||||
///
|
///
|
||||||
/// # Arguments
|
/// # Arguments
|
||||||
///
|
///
|
||||||
/// - `seat` - The `Seat` the event belongs to
|
/// - `seat` - The `Seat` the event belongs to
|
||||||
/// - `event` - The touch up event.
|
/// - `event` - The touch up event.
|
||||||
fn on_touch_up(&mut self, seat: &Seat, event: B::TouchUpEvent);
|
fn on_touch_up(&mut self, evlh: &mut EventLoopHandle, seat: &Seat, event: B::TouchUpEvent);
|
||||||
/// Called when a new touch cancel event was received.
|
/// Called when a new touch cancel event was received.
|
||||||
///
|
///
|
||||||
/// # Arguments
|
/// # Arguments
|
||||||
///
|
///
|
||||||
/// - `seat` - The `Seat` the event belongs to
|
/// - `seat` - The `Seat` the event belongs to
|
||||||
/// - `event` - The touch cancel event.
|
/// - `event` - The touch cancel event.
|
||||||
fn on_touch_cancel(&mut self, seat: &Seat, event: B::TouchCancelEvent);
|
fn on_touch_cancel(&mut self, evlh: &mut EventLoopHandle, seat: &Seat, event: B::TouchCancelEvent);
|
||||||
/// Called when a new touch frame event was received.
|
/// Called when a new touch frame event was received.
|
||||||
///
|
///
|
||||||
/// # Arguments
|
/// # Arguments
|
||||||
///
|
///
|
||||||
/// - `seat` - The `Seat` the event belongs to
|
/// - `seat` - The `Seat` the event belongs to
|
||||||
/// - `event` - The touch frame event.
|
/// - `event` - The touch frame event.
|
||||||
fn on_touch_frame(&mut self, seat: &Seat, event: B::TouchFrameEvent);
|
fn on_touch_frame(&mut self, evlh: &mut EventLoopHandle, seat: &Seat, event: B::TouchFrameEvent);
|
||||||
|
|
||||||
/// Called when the `InputConfig` was changed through an external event.
|
/// Called when the `InputConfig` was changed through an external event.
|
||||||
///
|
///
|
||||||
/// What kind of events can trigger this call is completely backend dependent.
|
/// What kind of events can trigger this call is completely backend dependent.
|
||||||
/// E.g. an input devices was attached/detached or changed it's own configuration.
|
/// E.g. an input devices was attached/detached or changed it's own configuration.
|
||||||
fn on_input_config_changed(&mut self, config: &mut B::InputConfig);
|
fn on_input_config_changed(&mut self, evlh: &mut EventLoopHandle, config: &mut B::InputConfig);
|
||||||
}
|
}
|
||||||
|
|
||||||
impl<B: InputBackend> InputHandler<B> for Box<InputHandler<B>> {
|
impl<B: InputBackend> InputHandler<B> for Box<InputHandler<B>> {
|
||||||
fn on_seat_created(&mut self, seat: &Seat) {
|
fn on_seat_created(&mut self, evlh: &mut EventLoopHandle, seat: &Seat) {
|
||||||
(**self).on_seat_created(seat)
|
(**self).on_seat_created(evlh, seat)
|
||||||
}
|
}
|
||||||
|
|
||||||
fn on_seat_destroyed(&mut self, seat: &Seat) {
|
fn on_seat_destroyed(&mut self, evlh: &mut EventLoopHandle, seat: &Seat) {
|
||||||
(**self).on_seat_destroyed(seat)
|
(**self).on_seat_destroyed(evlh, seat)
|
||||||
}
|
}
|
||||||
|
|
||||||
fn on_seat_changed(&mut self, seat: &Seat) {
|
fn on_seat_changed(&mut self, evlh: &mut EventLoopHandle, seat: &Seat) {
|
||||||
(**self).on_seat_changed(seat)
|
(**self).on_seat_changed(evlh, seat)
|
||||||
}
|
}
|
||||||
|
|
||||||
fn on_keyboard_key(&mut self, seat: &Seat, event: B::KeyboardKeyEvent) {
|
fn on_keyboard_key(&mut self, evlh: &mut EventLoopHandle, seat: &Seat, event: B::KeyboardKeyEvent) {
|
||||||
(**self).on_keyboard_key(seat, event)
|
(**self).on_keyboard_key(evlh, seat, event)
|
||||||
}
|
}
|
||||||
|
|
||||||
fn on_pointer_move(&mut self, seat: &Seat, event: B::PointerMotionEvent) {
|
fn on_pointer_move(&mut self, evlh: &mut EventLoopHandle, seat: &Seat, event: B::PointerMotionEvent) {
|
||||||
(**self).on_pointer_move(seat, event)
|
(**self).on_pointer_move(evlh, seat, event)
|
||||||
}
|
}
|
||||||
|
|
||||||
fn on_pointer_move_absolute(&mut self, seat: &Seat, event: B::PointerMotionAbsoluteEvent) {
|
fn on_pointer_move_absolute(
|
||||||
(**self).on_pointer_move_absolute(seat, event)
|
&mut self, evlh: &mut EventLoopHandle, seat: &Seat, event: B::PointerMotionAbsoluteEvent
|
||||||
|
) {
|
||||||
|
(**self).on_pointer_move_absolute(evlh, seat, event)
|
||||||
}
|
}
|
||||||
|
|
||||||
fn on_pointer_button(&mut self, seat: &Seat, event: B::PointerButtonEvent) {
|
fn on_pointer_button(&mut self, evlh: &mut EventLoopHandle, seat: &Seat, event: B::PointerButtonEvent) {
|
||||||
(**self).on_pointer_button(seat, event)
|
(**self).on_pointer_button(evlh, seat, event)
|
||||||
}
|
}
|
||||||
|
|
||||||
fn on_pointer_axis(&mut self, seat: &Seat, event: B::PointerAxisEvent) {
|
fn on_pointer_axis(&mut self, evlh: &mut EventLoopHandle, seat: &Seat, event: B::PointerAxisEvent) {
|
||||||
(**self).on_pointer_axis(seat, event)
|
(**self).on_pointer_axis(evlh, seat, event)
|
||||||
}
|
}
|
||||||
|
|
||||||
fn on_touch_down(&mut self, seat: &Seat, event: B::TouchDownEvent) {
|
fn on_touch_down(&mut self, evlh: &mut EventLoopHandle, seat: &Seat, event: B::TouchDownEvent) {
|
||||||
(**self).on_touch_down(seat, event)
|
(**self).on_touch_down(evlh, seat, event)
|
||||||
}
|
}
|
||||||
|
|
||||||
fn on_touch_motion(&mut self, seat: &Seat, event: B::TouchMotionEvent) {
|
fn on_touch_motion(&mut self, evlh: &mut EventLoopHandle, seat: &Seat, event: B::TouchMotionEvent) {
|
||||||
(**self).on_touch_motion(seat, event)
|
(**self).on_touch_motion(evlh, seat, event)
|
||||||
}
|
}
|
||||||
|
|
||||||
fn on_touch_up(&mut self, seat: &Seat, event: B::TouchUpEvent) {
|
fn on_touch_up(&mut self, evlh: &mut EventLoopHandle, seat: &Seat, event: B::TouchUpEvent) {
|
||||||
(**self).on_touch_up(seat, event)
|
(**self).on_touch_up(evlh, seat, event)
|
||||||
}
|
}
|
||||||
|
|
||||||
fn on_touch_cancel(&mut self, seat: &Seat, event: B::TouchCancelEvent) {
|
fn on_touch_cancel(&mut self, evlh: &mut EventLoopHandle, seat: &Seat, event: B::TouchCancelEvent) {
|
||||||
(**self).on_touch_cancel(seat, event)
|
(**self).on_touch_cancel(evlh, seat, event)
|
||||||
}
|
}
|
||||||
|
|
||||||
fn on_touch_frame(&mut self, seat: &Seat, event: B::TouchFrameEvent) {
|
fn on_touch_frame(&mut self, evlh: &mut EventLoopHandle, seat: &Seat, event: B::TouchFrameEvent) {
|
||||||
(**self).on_touch_frame(seat, event)
|
(**self).on_touch_frame(evlh, seat, event)
|
||||||
}
|
}
|
||||||
|
|
||||||
fn on_input_config_changed(&mut self, config: &mut B::InputConfig) {
|
fn on_input_config_changed(&mut self, evlh: &mut EventLoopHandle, config: &mut B::InputConfig) {
|
||||||
(**self).on_input_config_changed(config)
|
(**self).on_input_config_changed(evlh, config)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -262,14 +262,16 @@ impl backend::InputBackend for LibinputInputBackend {
|
||||||
type TouchCancelEvent = event::touch::TouchCancelEvent;
|
type TouchCancelEvent = event::touch::TouchCancelEvent;
|
||||||
type TouchFrameEvent = event::touch::TouchFrameEvent;
|
type TouchFrameEvent = event::touch::TouchFrameEvent;
|
||||||
|
|
||||||
fn set_handler<H: backend::InputHandler<Self> + 'static>(&mut self, mut handler: H) {
|
fn set_handler<H: backend::InputHandler<Self> + 'static>(
|
||||||
|
&mut self, evlh: &mut EventLoopHandle, mut handler: H
|
||||||
|
) {
|
||||||
if self.handler.is_some() {
|
if self.handler.is_some() {
|
||||||
self.clear_handler();
|
self.clear_handler(evlh);
|
||||||
}
|
}
|
||||||
info!(self.logger, "New input handler set");
|
info!(self.logger, "New input handler set");
|
||||||
for seat in self.seats.values() {
|
for seat in self.seats.values() {
|
||||||
trace!(self.logger, "Calling on_seat_created with {:?}", seat);
|
trace!(self.logger, "Calling on_seat_created with {:?}", seat);
|
||||||
handler.on_seat_created(seat);
|
handler.on_seat_created(evlh, seat);
|
||||||
}
|
}
|
||||||
self.handler = Some(Box::new(handler));
|
self.handler = Some(Box::new(handler));
|
||||||
}
|
}
|
||||||
|
@ -280,11 +282,11 @@ impl backend::InputBackend for LibinputInputBackend {
|
||||||
.map(|handler| handler as &mut backend::InputHandler<Self>)
|
.map(|handler| handler as &mut backend::InputHandler<Self>)
|
||||||
}
|
}
|
||||||
|
|
||||||
fn clear_handler(&mut self) {
|
fn clear_handler(&mut self, evlh: &mut EventLoopHandle) {
|
||||||
if let Some(mut handler) = self.handler.take() {
|
if let Some(mut handler) = self.handler.take() {
|
||||||
for seat in self.seats.values() {
|
for seat in self.seats.values() {
|
||||||
trace!(self.logger, "Calling on_seat_destroyed with {:?}", seat);
|
trace!(self.logger, "Calling on_seat_destroyed with {:?}", seat);
|
||||||
handler.on_seat_destroyed(seat);
|
handler.on_seat_destroyed(evlh, seat);
|
||||||
}
|
}
|
||||||
info!(self.logger, "Removing input handler");
|
info!(self.logger, "Removing input handler");
|
||||||
}
|
}
|
||||||
|
@ -294,7 +296,7 @@ impl backend::InputBackend for LibinputInputBackend {
|
||||||
&mut self.devices
|
&mut self.devices
|
||||||
}
|
}
|
||||||
|
|
||||||
fn dispatch_new_events(&mut self) -> Result<(), IoError> {
|
fn dispatch_new_events(&mut self, evlh: &mut EventLoopHandle) -> Result<(), IoError> {
|
||||||
use input::event::EventTrait;
|
use input::event::EventTrait;
|
||||||
|
|
||||||
self.context.dispatch()?;
|
self.context.dispatch()?;
|
||||||
|
@ -327,7 +329,7 @@ impl backend::InputBackend for LibinputInputBackend {
|
||||||
}
|
}
|
||||||
if let Some(ref mut handler) = self.handler {
|
if let Some(ref mut handler) = self.handler {
|
||||||
trace!(self.logger, "Calling on_seat_changed with {:?}", old_seat);
|
trace!(self.logger, "Calling on_seat_changed with {:?}", old_seat);
|
||||||
handler.on_seat_changed(old_seat);
|
handler.on_seat_changed(evlh, old_seat);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
Entry::Vacant(seat_entry) => {
|
Entry::Vacant(seat_entry) => {
|
||||||
|
@ -337,7 +339,7 @@ impl backend::InputBackend for LibinputInputBackend {
|
||||||
seat_entry.insert(backend::Seat::new(hasher.finish(), new_caps));
|
seat_entry.insert(backend::Seat::new(hasher.finish(), new_caps));
|
||||||
if let Some(ref mut handler) = self.handler {
|
if let Some(ref mut handler) = self.handler {
|
||||||
trace!(self.logger, "Calling on_seat_created with {:?}", seat);
|
trace!(self.logger, "Calling on_seat_created with {:?}", seat);
|
||||||
handler.on_seat_created(seat);
|
handler.on_seat_created(evlh, seat);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -375,7 +377,7 @@ impl backend::InputBackend for LibinputInputBackend {
|
||||||
if let Some(seat) = self.seats.remove(&device_seat) {
|
if let Some(seat) = self.seats.remove(&device_seat) {
|
||||||
if let Some(ref mut handler) = self.handler {
|
if let Some(ref mut handler) = self.handler {
|
||||||
trace!(self.logger, "Calling on_seat_destroyed with {:?}", seat);
|
trace!(self.logger, "Calling on_seat_destroyed with {:?}", seat);
|
||||||
handler.on_seat_destroyed(&seat);
|
handler.on_seat_destroyed(evlh, &seat);
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
panic!("Seat destroyed that was never created");
|
panic!("Seat destroyed that was never created");
|
||||||
|
@ -384,12 +386,12 @@ impl backend::InputBackend for LibinputInputBackend {
|
||||||
} else if let Some(ref mut handler) = self.handler {
|
} else if let Some(ref mut handler) = self.handler {
|
||||||
let seat = self.seats[&device_seat];
|
let seat = self.seats[&device_seat];
|
||||||
trace!(self.logger, "Calling on_seat_changed with {:?}", seat);
|
trace!(self.logger, "Calling on_seat_changed with {:?}", seat);
|
||||||
handler.on_seat_changed(&seat);
|
handler.on_seat_changed(evlh, &seat);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if let Some(ref mut handler) = self.handler {
|
if let Some(ref mut handler) = self.handler {
|
||||||
handler.on_input_config_changed(&mut self.devices);
|
handler.on_input_config_changed(evlh, &mut self.devices);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
libinput::Event::Touch(touch_event) => {
|
libinput::Event::Touch(touch_event) => {
|
||||||
|
@ -402,7 +404,7 @@ impl backend::InputBackend for LibinputInputBackend {
|
||||||
match touch_event {
|
match touch_event {
|
||||||
TouchEvent::Down(down_event) => {
|
TouchEvent::Down(down_event) => {
|
||||||
trace!(self.logger, "Calling on_touch_down with {:?}", down_event);
|
trace!(self.logger, "Calling on_touch_down with {:?}", down_event);
|
||||||
handler.on_touch_down(seat, down_event)
|
handler.on_touch_down(evlh, seat, down_event)
|
||||||
}
|
}
|
||||||
TouchEvent::Motion(motion_event) => {
|
TouchEvent::Motion(motion_event) => {
|
||||||
trace!(
|
trace!(
|
||||||
|
@ -410,11 +412,11 @@ impl backend::InputBackend for LibinputInputBackend {
|
||||||
"Calling on_touch_motion with {:?}",
|
"Calling on_touch_motion with {:?}",
|
||||||
motion_event
|
motion_event
|
||||||
);
|
);
|
||||||
handler.on_touch_motion(seat, motion_event)
|
handler.on_touch_motion(evlh, seat, motion_event)
|
||||||
}
|
}
|
||||||
TouchEvent::Up(up_event) => {
|
TouchEvent::Up(up_event) => {
|
||||||
trace!(self.logger, "Calling on_touch_up with {:?}", up_event);
|
trace!(self.logger, "Calling on_touch_up with {:?}", up_event);
|
||||||
handler.on_touch_up(seat, up_event)
|
handler.on_touch_up(evlh, seat, up_event)
|
||||||
}
|
}
|
||||||
TouchEvent::Cancel(cancel_event) => {
|
TouchEvent::Cancel(cancel_event) => {
|
||||||
trace!(
|
trace!(
|
||||||
|
@ -422,11 +424,11 @@ impl backend::InputBackend for LibinputInputBackend {
|
||||||
"Calling on_touch_cancel with {:?}",
|
"Calling on_touch_cancel with {:?}",
|
||||||
cancel_event
|
cancel_event
|
||||||
);
|
);
|
||||||
handler.on_touch_cancel(seat, cancel_event)
|
handler.on_touch_cancel(evlh, seat, cancel_event)
|
||||||
}
|
}
|
||||||
TouchEvent::Frame(frame_event) => {
|
TouchEvent::Frame(frame_event) => {
|
||||||
trace!(self.logger, "Calling on_touch_frame with {:?}", frame_event);
|
trace!(self.logger, "Calling on_touch_frame with {:?}", frame_event);
|
||||||
handler.on_touch_frame(seat, frame_event)
|
handler.on_touch_frame(evlh, seat, frame_event)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -440,7 +442,7 @@ impl backend::InputBackend for LibinputInputBackend {
|
||||||
.get(&device_seat)
|
.get(&device_seat)
|
||||||
.expect("Recieved key event of non existing Seat");
|
.expect("Recieved key event of non existing Seat");
|
||||||
trace!(self.logger, "Calling on_keyboard_key with {:?}", key_event);
|
trace!(self.logger, "Calling on_keyboard_key with {:?}", key_event);
|
||||||
handler.on_keyboard_key(seat, key_event);
|
handler.on_keyboard_key(evlh, seat, key_event);
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -458,7 +460,7 @@ impl backend::InputBackend for LibinputInputBackend {
|
||||||
"Calling on_pointer_move with {:?}",
|
"Calling on_pointer_move with {:?}",
|
||||||
motion_event
|
motion_event
|
||||||
);
|
);
|
||||||
handler.on_pointer_move(seat, motion_event);
|
handler.on_pointer_move(evlh, seat, motion_event);
|
||||||
}
|
}
|
||||||
PointerEvent::MotionAbsolute(motion_abs_event) => {
|
PointerEvent::MotionAbsolute(motion_abs_event) => {
|
||||||
trace!(
|
trace!(
|
||||||
|
@ -466,7 +468,7 @@ impl backend::InputBackend for LibinputInputBackend {
|
||||||
"Calling on_pointer_move_absolute with {:?}",
|
"Calling on_pointer_move_absolute with {:?}",
|
||||||
motion_abs_event
|
motion_abs_event
|
||||||
);
|
);
|
||||||
handler.on_pointer_move_absolute(seat, motion_abs_event);
|
handler.on_pointer_move_absolute(evlh, seat, motion_abs_event);
|
||||||
}
|
}
|
||||||
PointerEvent::Axis(axis_event) => {
|
PointerEvent::Axis(axis_event) => {
|
||||||
let rc_axis_event = Rc::new(axis_event);
|
let rc_axis_event = Rc::new(axis_event);
|
||||||
|
@ -477,6 +479,7 @@ impl backend::InputBackend for LibinputInputBackend {
|
||||||
*rc_axis_event
|
*rc_axis_event
|
||||||
);
|
);
|
||||||
handler.on_pointer_axis(
|
handler.on_pointer_axis(
|
||||||
|
evlh,
|
||||||
seat,
|
seat,
|
||||||
self::PointerAxisEvent {
|
self::PointerAxisEvent {
|
||||||
axis: Axis::Vertical,
|
axis: Axis::Vertical,
|
||||||
|
@ -491,6 +494,7 @@ impl backend::InputBackend for LibinputInputBackend {
|
||||||
*rc_axis_event
|
*rc_axis_event
|
||||||
);
|
);
|
||||||
handler.on_pointer_axis(
|
handler.on_pointer_axis(
|
||||||
|
evlh,
|
||||||
seat,
|
seat,
|
||||||
self::PointerAxisEvent {
|
self::PointerAxisEvent {
|
||||||
axis: Axis::Horizontal,
|
axis: Axis::Horizontal,
|
||||||
|
@ -505,7 +509,7 @@ impl backend::InputBackend for LibinputInputBackend {
|
||||||
"Calling on_pointer_button with {:?}",
|
"Calling on_pointer_button with {:?}",
|
||||||
button_event
|
button_event
|
||||||
);
|
);
|
||||||
handler.on_pointer_button(seat, button_event);
|
handler.on_pointer_button(evlh, seat, button_event);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -611,9 +615,9 @@ pub fn libinput_bind(
|
||||||
|
|
||||||
fn fd_event_source_implementation() -> FdEventSourceImpl<LibinputInputBackend> {
|
fn fd_event_source_implementation() -> FdEventSourceImpl<LibinputInputBackend> {
|
||||||
FdEventSourceImpl {
|
FdEventSourceImpl {
|
||||||
ready: |_evlh, ref mut backend, _, _| {
|
ready: |evlh, ref mut backend, _, _| {
|
||||||
use backend::input::InputBackend;
|
use backend::input::InputBackend;
|
||||||
if let Err(error) = backend.dispatch_new_events() {
|
if let Err(error) = backend.dispatch_new_events(evlh) {
|
||||||
warn!(backend.logger, "Libinput errored: {}", error);
|
warn!(backend.logger, "Libinput errored: {}", error);
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
|
|
@ -17,7 +17,7 @@ use std::error;
|
||||||
use std::fmt;
|
use std::fmt;
|
||||||
use std::rc::Rc;
|
use std::rc::Rc;
|
||||||
use wayland_client::egl as wegl;
|
use wayland_client::egl as wegl;
|
||||||
use wayland_server::Display;
|
use wayland_server::{Display, EventLoopHandle};
|
||||||
use winit::{ElementState, Event, EventsLoop, KeyboardInput, MouseButton as WinitMouseButton, MouseCursor,
|
use winit::{ElementState, Event, EventsLoop, KeyboardInput, MouseButton as WinitMouseButton, MouseCursor,
|
||||||
MouseScrollDelta, Touch, TouchPhase, Window as WinitWindow, WindowBuilder, WindowEvent};
|
MouseScrollDelta, Touch, TouchPhase, Window as WinitWindow, WindowBuilder, WindowEvent};
|
||||||
|
|
||||||
|
@ -573,13 +573,13 @@ impl InputBackend for WinitInputBackend {
|
||||||
type TouchCancelEvent = WinitTouchCancelledEvent;
|
type TouchCancelEvent = WinitTouchCancelledEvent;
|
||||||
type TouchFrameEvent = UnusedEvent;
|
type TouchFrameEvent = UnusedEvent;
|
||||||
|
|
||||||
fn set_handler<H: InputHandler<Self> + 'static>(&mut self, mut handler: H) {
|
fn set_handler<H: InputHandler<Self> + 'static>(&mut self, evlh: &mut EventLoopHandle, mut handler: H) {
|
||||||
if self.handler.is_some() {
|
if self.handler.is_some() {
|
||||||
self.clear_handler();
|
self.clear_handler(evlh);
|
||||||
}
|
}
|
||||||
info!(self.logger, "New input handler set.");
|
info!(self.logger, "New input handler set.");
|
||||||
trace!(self.logger, "Calling on_seat_created with {:?}", self.seat);
|
trace!(self.logger, "Calling on_seat_created with {:?}", self.seat);
|
||||||
handler.on_seat_created(&self.seat);
|
handler.on_seat_created(evlh, &self.seat);
|
||||||
self.handler = Some(Box::new(handler));
|
self.handler = Some(Box::new(handler));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -589,14 +589,14 @@ impl InputBackend for WinitInputBackend {
|
||||||
.map(|handler| handler as &mut InputHandler<Self>)
|
.map(|handler| handler as &mut InputHandler<Self>)
|
||||||
}
|
}
|
||||||
|
|
||||||
fn clear_handler(&mut self) {
|
fn clear_handler(&mut self, evlh: &mut EventLoopHandle) {
|
||||||
if let Some(mut handler) = self.handler.take() {
|
if let Some(mut handler) = self.handler.take() {
|
||||||
trace!(
|
trace!(
|
||||||
self.logger,
|
self.logger,
|
||||||
"Calling on_seat_destroyed with {:?}",
|
"Calling on_seat_destroyed with {:?}",
|
||||||
self.seat
|
self.seat
|
||||||
);
|
);
|
||||||
handler.on_seat_destroyed(&self.seat);
|
handler.on_seat_destroyed(evlh, &self.seat);
|
||||||
}
|
}
|
||||||
info!(self.logger, "Removing input handler");
|
info!(self.logger, "Removing input handler");
|
||||||
}
|
}
|
||||||
|
@ -617,11 +617,13 @@ impl InputBackend for WinitInputBackend {
|
||||||
///
|
///
|
||||||
/// The linked `WinitGraphicsBackend` will error with a lost Context and should
|
/// The linked `WinitGraphicsBackend` will error with a lost Context and should
|
||||||
/// not be used anymore as well.
|
/// not be used anymore as well.
|
||||||
fn dispatch_new_events(&mut self) -> ::std::result::Result<(), WinitInputError> {
|
fn dispatch_new_events(
|
||||||
|
&mut self, evlh: &mut EventLoopHandle
|
||||||
|
) -> ::std::result::Result<(), WinitInputError> {
|
||||||
let mut closed = false;
|
let mut closed = false;
|
||||||
|
|
||||||
{
|
{
|
||||||
// NOTE: This ugly pile of references is here, because rustc could
|
// NOTE: This ugly pile of references is here, because rustc could not
|
||||||
// figure out how to reference all these objects correctly into the
|
// figure out how to reference all these objects correctly into the
|
||||||
// upcoming closure, which is why all are borrowed manually and the
|
// upcoming closure, which is why all are borrowed manually and the
|
||||||
// assignments are then moved into the closure to avoid rustc's
|
// assignments are then moved into the closure to avoid rustc's
|
||||||
|
@ -669,6 +671,7 @@ impl InputBackend for WinitInputBackend {
|
||||||
(scancode, state)
|
(scancode, state)
|
||||||
);
|
);
|
||||||
handler.on_keyboard_key(
|
handler.on_keyboard_key(
|
||||||
|
evlh,
|
||||||
seat,
|
seat,
|
||||||
WinitKeyboardInputEvent {
|
WinitKeyboardInputEvent {
|
||||||
time: *time_counter,
|
time: *time_counter,
|
||||||
|
@ -686,6 +689,7 @@ impl InputBackend for WinitInputBackend {
|
||||||
) => {
|
) => {
|
||||||
trace!(logger, "Calling on_pointer_move_absolute with {:?}", (x, y));
|
trace!(logger, "Calling on_pointer_move_absolute with {:?}", (x, y));
|
||||||
handler.on_pointer_move_absolute(
|
handler.on_pointer_move_absolute(
|
||||||
|
evlh,
|
||||||
seat,
|
seat,
|
||||||
WinitMouseMovedEvent {
|
WinitMouseMovedEvent {
|
||||||
window: window.clone(),
|
window: window.clone(),
|
||||||
|
@ -708,7 +712,7 @@ impl InputBackend for WinitInputBackend {
|
||||||
"Calling on_pointer_axis for Axis::Horizontal with {:?}",
|
"Calling on_pointer_axis for Axis::Horizontal with {:?}",
|
||||||
x
|
x
|
||||||
);
|
);
|
||||||
handler.on_pointer_axis(seat, event);
|
handler.on_pointer_axis(evlh, seat, event);
|
||||||
}
|
}
|
||||||
if y != 0.0 {
|
if y != 0.0 {
|
||||||
let event = WinitMouseWheelEvent {
|
let event = WinitMouseWheelEvent {
|
||||||
|
@ -721,7 +725,7 @@ impl InputBackend for WinitInputBackend {
|
||||||
"Calling on_pointer_axis for Axis::Vertical with {:?}",
|
"Calling on_pointer_axis for Axis::Vertical with {:?}",
|
||||||
y
|
y
|
||||||
);
|
);
|
||||||
handler.on_pointer_axis(seat, event);
|
handler.on_pointer_axis(evlh, seat, event);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
@ -732,6 +736,7 @@ impl InputBackend for WinitInputBackend {
|
||||||
(button, state)
|
(button, state)
|
||||||
);
|
);
|
||||||
handler.on_pointer_button(
|
handler.on_pointer_button(
|
||||||
|
evlh,
|
||||||
seat,
|
seat,
|
||||||
WinitMouseInputEvent {
|
WinitMouseInputEvent {
|
||||||
time: *time_counter,
|
time: *time_counter,
|
||||||
|
@ -751,6 +756,7 @@ impl InputBackend for WinitInputBackend {
|
||||||
) => {
|
) => {
|
||||||
trace!(logger, "Calling on_touch_down at {:?}", (x, y));
|
trace!(logger, "Calling on_touch_down at {:?}", (x, y));
|
||||||
handler.on_touch_down(
|
handler.on_touch_down(
|
||||||
|
evlh,
|
||||||
seat,
|
seat,
|
||||||
WinitTouchStartedEvent {
|
WinitTouchStartedEvent {
|
||||||
window: window.clone(),
|
window: window.clone(),
|
||||||
|
@ -771,6 +777,7 @@ impl InputBackend for WinitInputBackend {
|
||||||
) => {
|
) => {
|
||||||
trace!(logger, "Calling on_touch_motion at {:?}", (x, y));
|
trace!(logger, "Calling on_touch_motion at {:?}", (x, y));
|
||||||
handler.on_touch_motion(
|
handler.on_touch_motion(
|
||||||
|
evlh,
|
||||||
seat,
|
seat,
|
||||||
WinitTouchMovedEvent {
|
WinitTouchMovedEvent {
|
||||||
window: window.clone(),
|
window: window.clone(),
|
||||||
|
@ -791,6 +798,7 @@ impl InputBackend for WinitInputBackend {
|
||||||
) => {
|
) => {
|
||||||
trace!(logger, "Calling on_touch_motion at {:?}", (x, y));
|
trace!(logger, "Calling on_touch_motion at {:?}", (x, y));
|
||||||
handler.on_touch_motion(
|
handler.on_touch_motion(
|
||||||
|
evlh,
|
||||||
seat,
|
seat,
|
||||||
WinitTouchMovedEvent {
|
WinitTouchMovedEvent {
|
||||||
window: window.clone(),
|
window: window.clone(),
|
||||||
|
@ -801,6 +809,7 @@ impl InputBackend for WinitInputBackend {
|
||||||
);
|
);
|
||||||
trace!(logger, "Calling on_touch_up");
|
trace!(logger, "Calling on_touch_up");
|
||||||
handler.on_touch_up(
|
handler.on_touch_up(
|
||||||
|
evlh,
|
||||||
seat,
|
seat,
|
||||||
WinitTouchEndedEvent {
|
WinitTouchEndedEvent {
|
||||||
time: *time_counter,
|
time: *time_counter,
|
||||||
|
@ -818,6 +827,7 @@ impl InputBackend for WinitInputBackend {
|
||||||
) => {
|
) => {
|
||||||
trace!(logger, "Calling on_touch_cancel");
|
trace!(logger, "Calling on_touch_cancel");
|
||||||
handler.on_touch_cancel(
|
handler.on_touch_cancel(
|
||||||
|
evlh,
|
||||||
seat,
|
seat,
|
||||||
WinitTouchCancelledEvent {
|
WinitTouchCancelledEvent {
|
||||||
time: *time_counter,
|
time: *time_counter,
|
||||||
|
|
Loading…
Reference in New Issue