Add pointer axis event passing
This commit is contained in:
parent
a5cfed8715
commit
01884a6aa8
|
@ -291,14 +291,14 @@ impl InputBackend for GlutinInputBackend {
|
||||||
handler.on_pointer_scroll(&self.seat,
|
handler.on_pointer_scroll(&self.seat,
|
||||||
self.time_counter,
|
self.time_counter,
|
||||||
Axis::Vertical,
|
Axis::Vertical,
|
||||||
AxisSource::Continous,
|
AxisSource::Continuous,
|
||||||
x as f64);
|
x as f64);
|
||||||
}
|
}
|
||||||
if y != 0.0 {
|
if y != 0.0 {
|
||||||
handler.on_pointer_scroll(&self.seat,
|
handler.on_pointer_scroll(&self.seat,
|
||||||
self.time_counter,
|
self.time_counter,
|
||||||
Axis::Horizontal,
|
Axis::Horizontal,
|
||||||
AxisSource::Continous,
|
AxisSource::Continuous,
|
||||||
y as f64);
|
y as f64);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -110,7 +110,7 @@ pub enum AxisSource {
|
||||||
/// The coordinate system is identical to
|
/// The coordinate system is identical to
|
||||||
/// the cursor movement, i.e. a scroll value of 1 represents the equivalent relative
|
/// the cursor movement, i.e. a scroll value of 1 represents the equivalent relative
|
||||||
/// motion of 1.
|
/// motion of 1.
|
||||||
Continous,
|
Continuous,
|
||||||
/// Scroll wheel.
|
/// Scroll wheel.
|
||||||
///
|
///
|
||||||
/// No terminating event is guaranteed (though it may happen). Scrolling is in
|
/// No terminating event is guaranteed (though it may happen). Scrolling is in
|
||||||
|
|
|
@ -9,10 +9,15 @@ use std::io::Error as IoError;
|
||||||
use std::collections::hash_map::{DefaultHasher, Entry, HashMap};
|
use std::collections::hash_map::{DefaultHasher, Entry, HashMap};
|
||||||
use std::hash::{Hash, Hasher};
|
use std::hash::{Hash, Hasher};
|
||||||
|
|
||||||
|
struct SeatDesc {
|
||||||
|
seat: Seat,
|
||||||
|
pointer: (u32, u32),
|
||||||
|
}
|
||||||
|
|
||||||
pub struct LibinputInputBackend {
|
pub struct LibinputInputBackend {
|
||||||
context: Libinput,
|
context: Libinput,
|
||||||
devices: Vec<Device>,
|
devices: Vec<Device>,
|
||||||
seats: HashMap<LibinputSeat, Seat>,
|
seats: HashMap<LibinputSeat, SeatDesc>,
|
||||||
handler: Option<Box<InputHandler<LibinputInputBackend> + 'static>>,
|
handler: Option<Box<InputHandler<LibinputInputBackend> + 'static>>,
|
||||||
logger: ::slog::Logger,
|
logger: ::slog::Logger,
|
||||||
}
|
}
|
||||||
|
@ -26,9 +31,9 @@ impl InputBackend for LibinputInputBackend {
|
||||||
self.clear_handler();
|
self.clear_handler();
|
||||||
}
|
}
|
||||||
info!(self.logger, "New input handler set.");
|
info!(self.logger, "New input handler set.");
|
||||||
for seat in self.seats.values() {
|
for desc in self.seats.values() {
|
||||||
trace!(self.logger, "Calling on_seat_created with {:?}", seat);
|
trace!(self.logger, "Calling on_seat_created with {:?}", desc.seat);
|
||||||
handler.on_seat_created(&seat);
|
handler.on_seat_created(&desc.seat);
|
||||||
}
|
}
|
||||||
self.handler = Some(Box::new(handler));
|
self.handler = Some(Box::new(handler));
|
||||||
}
|
}
|
||||||
|
@ -41,9 +46,9 @@ impl InputBackend for LibinputInputBackend {
|
||||||
|
|
||||||
fn clear_handler(&mut self) {
|
fn clear_handler(&mut self) {
|
||||||
if let Some(mut handler) = self.handler.take() {
|
if let Some(mut handler) = self.handler.take() {
|
||||||
for seat in self.seats.values() {
|
for desc in self.seats.values() {
|
||||||
trace!(self.logger, "Calling on_seat_destroyed with {:?}", seat);
|
trace!(self.logger, "Calling on_seat_destroyed with {:?}", desc.seat);
|
||||||
handler.on_seat_destroyed(&seat);
|
handler.on_seat_destroyed(&desc.seat);
|
||||||
}
|
}
|
||||||
info!(self.logger, "Removing input handler");
|
info!(self.logger, "Removing input handler");
|
||||||
}
|
}
|
||||||
|
@ -83,23 +88,26 @@ impl InputBackend for LibinputInputBackend {
|
||||||
Entry::Occupied(mut seat_entry) => {
|
Entry::Occupied(mut seat_entry) => {
|
||||||
let old_seat = seat_entry.get_mut();
|
let old_seat = seat_entry.get_mut();
|
||||||
{
|
{
|
||||||
let caps = old_seat.capabilities_mut();
|
let caps = old_seat.seat.capabilities_mut();
|
||||||
caps.pointer = new_caps.pointer || caps.pointer;
|
caps.pointer = new_caps.pointer || caps.pointer;
|
||||||
caps.keyboard = new_caps.keyboard || caps.keyboard;
|
caps.keyboard = new_caps.keyboard || caps.keyboard;
|
||||||
caps.touch = new_caps.touch || caps.touch;
|
caps.touch = new_caps.touch || caps.touch;
|
||||||
}
|
}
|
||||||
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.seat);
|
||||||
handler.on_seat_changed(old_seat);
|
handler.on_seat_changed(&old_seat.seat);
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
Entry::Vacant(seat_entry) => {
|
Entry::Vacant(seat_entry) => {
|
||||||
let mut hasher = DefaultHasher::default();
|
let mut hasher = DefaultHasher::default();
|
||||||
seat_entry.key().hash(&mut hasher);
|
seat_entry.key().hash(&mut hasher);
|
||||||
let seat = seat_entry.insert(Seat::new(hasher.finish(), new_caps));
|
let desc = seat_entry.insert(SeatDesc {
|
||||||
|
seat: Seat::new(hasher.finish(), new_caps),
|
||||||
|
pointer: (0, 0) //FIXME: What position to assume? Maybe center of the screen instead. Probably call `set_cursor_position` after this.
|
||||||
|
});
|
||||||
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 {:?}", desc.seat);
|
||||||
handler.on_seat_created(seat);
|
handler.on_seat_created(&desc.seat);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -113,8 +121,8 @@ impl InputBackend for LibinputInputBackend {
|
||||||
let device_seat = removed.seat();
|
let device_seat = removed.seat();
|
||||||
|
|
||||||
// update capabilities, so they appear correctly on `on_seat_changed` and `on_seat_destroyed`.
|
// update capabilities, so they appear correctly on `on_seat_changed` and `on_seat_destroyed`.
|
||||||
if let Some(seat) = self.seats.get_mut(&device_seat) {
|
if let Some(desc) = self.seats.get_mut(&device_seat) {
|
||||||
let caps = seat.capabilities_mut();
|
let caps = desc.seat.capabilities_mut();
|
||||||
caps.pointer = self.devices.iter().filter(|x| x.seat() == device_seat).any(|x| x.has_capability(DeviceCapability::Pointer));
|
caps.pointer = self.devices.iter().filter(|x| x.seat() == device_seat).any(|x| x.has_capability(DeviceCapability::Pointer));
|
||||||
caps.keyboard = self.devices.iter().filter(|x| x.seat() == device_seat).any(|x| x.has_capability(DeviceCapability::Keyboard));
|
caps.keyboard = self.devices.iter().filter(|x| x.seat() == device_seat).any(|x| x.has_capability(DeviceCapability::Keyboard));
|
||||||
caps.touch = self.devices.iter().filter(|x| x.seat() == device_seat).any(|x| x.has_capability(DeviceCapability::Touch));
|
caps.touch = self.devices.iter().filter(|x| x.seat() == device_seat).any(|x| x.has_capability(DeviceCapability::Touch));
|
||||||
|
@ -125,10 +133,10 @@ impl InputBackend for LibinputInputBackend {
|
||||||
// check if the seat has any other devices
|
// check if the seat has any other devices
|
||||||
if !self.devices.iter().any(|x| x.seat() == device_seat) {
|
if !self.devices.iter().any(|x| x.seat() == device_seat) {
|
||||||
// it has not, lets destroy it
|
// it has not, lets destroy it
|
||||||
if let Some(seat) = self.seats.remove(&device_seat) {
|
if let Some(desc) = 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 {:?}", desc.seat);
|
||||||
handler.on_seat_destroyed(&seat);
|
handler.on_seat_destroyed(&desc.seat);
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
panic!("Seat destroyed that was never created");
|
panic!("Seat destroyed that was never created");
|
||||||
|
@ -136,9 +144,9 @@ impl InputBackend for LibinputInputBackend {
|
||||||
} else {
|
} else {
|
||||||
// it has, notify about updates
|
// it has, notify about updates
|
||||||
if let Some(ref mut handler) = self.handler {
|
if let Some(ref mut handler) = self.handler {
|
||||||
let seat = self.seats.get(&device_seat).unwrap();
|
let desc = self.seats.get(&device_seat).unwrap();
|
||||||
trace!(self.logger, "Calling on_seat_changed with {:?}", seat);
|
trace!(self.logger, "Calling on_seat_changed with {:?}", desc.seat);
|
||||||
handler.on_seat_changed(seat);
|
handler.on_seat_changed(&desc.seat);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
@ -154,13 +162,62 @@ impl InputBackend for LibinputInputBackend {
|
||||||
KeyboardEvent::Key(event) => {
|
KeyboardEvent::Key(event) => {
|
||||||
if let Some(ref mut handler) = self.handler {
|
if let Some(ref mut handler) = self.handler {
|
||||||
let device_seat = event.device().seat();
|
let device_seat = event.device().seat();
|
||||||
handler.on_keyboard_key(self.seats.get(&device_seat).expect("Recieved key event of non existing Seat"),
|
handler.on_keyboard_key(&self.seats.get(&device_seat).expect("Recieved key event of non existing Seat").seat,
|
||||||
event.time(), event.key(), event.key_state().into(), event.seat_key_count());
|
event.time(), event.key(), event.key_state().into(), event.seat_key_count());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
Event::Pointer(pointer_event) => {},
|
Event::Pointer(pointer_event) => {
|
||||||
|
use ::input::event::pointer::*;
|
||||||
|
match pointer_event {
|
||||||
|
PointerEvent::Motion(motion_event) => {
|
||||||
|
let device_seat = motion_event.device().seat();
|
||||||
|
let desc = self.seats.get_mut(&device_seat).expect("Recieved pointer event of non existing Seat");
|
||||||
|
desc.pointer.0 += motion_event.dx() as u32;
|
||||||
|
desc.pointer.1 += motion_event.dy() as u32;
|
||||||
|
if let Some(ref mut handler) = self.handler {
|
||||||
|
handler.on_pointer_move(&desc.seat, motion_event.time(), desc.pointer);
|
||||||
|
}
|
||||||
|
},
|
||||||
|
PointerEvent::MotionAbsolute(motion_event) => {
|
||||||
|
let device_seat = motion_event.device().seat();
|
||||||
|
let desc = self.seats.get_mut(&device_seat).expect("Recieved pointer event of non existing Seat");
|
||||||
|
desc.pointer = (
|
||||||
|
motion_event.absolute_x_transformed(
|
||||||
|
/*FIXME: global.get_focused_output().width() or something like that*/ 1280) as u32,
|
||||||
|
motion_event.absolute_y_transformed(
|
||||||
|
/*FIXME: global.get_focused_output().height() or something like that*/ 800) as u32,
|
||||||
|
);
|
||||||
|
if let Some(ref mut handler) = self.handler {
|
||||||
|
handler.on_pointer_move(&desc.seat, motion_event.time(), desc.pointer);
|
||||||
|
}
|
||||||
|
},
|
||||||
|
PointerEvent::Axis(axis_event) => {
|
||||||
|
if let Some(ref mut handler) = self.handler {
|
||||||
|
let device_seat = axis_event.device().seat();
|
||||||
|
let desc = self.seats.get_mut(&device_seat).expect("Recieved pointer event of non existing Seat");
|
||||||
|
if axis_event.has_axis(Axis::Vertical) {
|
||||||
|
handler.on_pointer_scroll(&desc.seat, axis_event.time(), ::backend::input::Axis::Vertical,
|
||||||
|
axis_event.axis_source().into(), match axis_event.axis_source() {
|
||||||
|
AxisSource::Finger | AxisSource::Continuous => axis_event.axis_value(Axis::Vertical),
|
||||||
|
AxisSource::Wheel | AxisSource::WheelTilt => axis_event.axis_value_discrete(Axis::Vertical).unwrap(),
|
||||||
|
});
|
||||||
|
}
|
||||||
|
if axis_event.has_axis(Axis::Horizontal) {
|
||||||
|
handler.on_pointer_scroll(&desc.seat, axis_event.time(), ::backend::input::Axis::Horizontal,
|
||||||
|
axis_event.axis_source().into(), match axis_event.axis_source() {
|
||||||
|
AxisSource::Finger | AxisSource::Continuous => axis_event.axis_value(Axis::Horizontal),
|
||||||
|
AxisSource::Wheel | AxisSource::WheelTilt => axis_event.axis_value_discrete(Axis::Horizontal).unwrap(),
|
||||||
|
});
|
||||||
|
}
|
||||||
|
}
|
||||||
|
},
|
||||||
|
PointerEvent::Button(button_event) => {
|
||||||
|
|
||||||
|
}
|
||||||
|
}
|
||||||
|
},
|
||||||
_ => {}, //FIXME: What to do with the rest.
|
_ => {}, //FIXME: What to do with the rest.
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
@ -176,3 +233,14 @@ impl From<::input::event::keyboard::KeyState> for ::backend::input::KeyState {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
impl From<::input::event::pointer::AxisSource> for ::backend::input::AxisSource {
|
||||||
|
fn from(libinput: ::input::event::pointer::AxisSource) -> Self {
|
||||||
|
match libinput {
|
||||||
|
::input::event::pointer::AxisSource::Finger => ::backend::input::AxisSource::Finger,
|
||||||
|
::input::event::pointer::AxisSource::Continuous => ::backend::input::AxisSource::Continuous,
|
||||||
|
::input::event::pointer::AxisSource::Wheel => ::backend::input::AxisSource::Wheel,
|
||||||
|
::input::event::pointer::AxisSource::WheelTilt => ::backend::input::AxisSource::WheelTilt,
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
Loading…
Reference in New Issue