backend.libinput: migrate to wayland-rs 0.20
This commit is contained in:
parent
31a3d40589
commit
53242bd974
|
@ -233,7 +233,7 @@ use std::sync::{Arc, Once, ONCE_INIT};
|
||||||
use std::sync::atomic::{AtomicBool, Ordering};
|
use std::sync::atomic::{AtomicBool, Ordering};
|
||||||
use std::time::Duration;
|
use std::time::Duration;
|
||||||
use wayland_server::{Display, LoopToken};
|
use wayland_server::{Display, LoopToken};
|
||||||
use wayland_server::commons::{downcast_impl, Implementation};
|
use wayland_server::commons::Implementation;
|
||||||
use wayland_server::sources::{FdEvent, FdInterest, Source};
|
use wayland_server::sources::{FdEvent, FdInterest, Source};
|
||||||
|
|
||||||
mod backend;
|
mod backend;
|
||||||
|
|
|
@ -11,8 +11,9 @@ use std::hash::{Hash, Hasher};
|
||||||
use std::io::Error as IoError;
|
use std::io::Error as IoError;
|
||||||
use std::os::unix::io::RawFd;
|
use std::os::unix::io::RawFd;
|
||||||
use std::path::Path;
|
use std::path::Path;
|
||||||
use wayland_server::EventLoopHandle;
|
use wayland_server::LoopToken;
|
||||||
use wayland_server::sources::{FdEventSource, FdEventSourceImpl, FdInterest};
|
use wayland_server::commons::Implementation;
|
||||||
|
use wayland_server::sources::{FdEvent, FdInterest, Source};
|
||||||
|
|
||||||
// No idea if this is the same across unix platforms
|
// No idea if this is the same across unix platforms
|
||||||
// Lets make this linux exclusive for now, once someone tries to build it for
|
// Lets make this linux exclusive for now, once someone tries to build it for
|
||||||
|
@ -256,16 +257,14 @@ 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>(
|
fn set_handler<H: backend::InputHandler<Self> + 'static>(&mut self, mut handler: H) {
|
||||||
&mut self, evlh: &mut EventLoopHandle, mut handler: H
|
|
||||||
) {
|
|
||||||
if self.handler.is_some() {
|
if self.handler.is_some() {
|
||||||
self.clear_handler(evlh);
|
self.clear_handler();
|
||||||
}
|
}
|
||||||
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(evlh, seat);
|
handler.on_seat_created(seat);
|
||||||
}
|
}
|
||||||
self.handler = Some(Box::new(handler));
|
self.handler = Some(Box::new(handler));
|
||||||
}
|
}
|
||||||
|
@ -276,11 +275,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, evlh: &mut EventLoopHandle) {
|
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 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(evlh, seat);
|
handler.on_seat_destroyed(seat);
|
||||||
}
|
}
|
||||||
info!(self.logger, "Removing input handler");
|
info!(self.logger, "Removing input handler");
|
||||||
}
|
}
|
||||||
|
@ -290,7 +289,7 @@ impl backend::InputBackend for LibinputInputBackend {
|
||||||
&mut self.devices
|
&mut self.devices
|
||||||
}
|
}
|
||||||
|
|
||||||
fn dispatch_new_events(&mut self, evlh: &mut EventLoopHandle) -> Result<(), IoError> {
|
fn dispatch_new_events(&mut self) -> Result<(), IoError> {
|
||||||
use input::event::EventTrait;
|
use input::event::EventTrait;
|
||||||
|
|
||||||
self.context.dispatch()?;
|
self.context.dispatch()?;
|
||||||
|
@ -323,7 +322,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(evlh, old_seat);
|
handler.on_seat_changed(old_seat);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
Entry::Vacant(seat_entry) => {
|
Entry::Vacant(seat_entry) => {
|
||||||
|
@ -340,7 +339,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_created with {:?}", seat);
|
trace!(self.logger, "Calling on_seat_created with {:?}", seat);
|
||||||
handler.on_seat_created(evlh, seat);
|
handler.on_seat_created(seat);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -379,7 +378,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(evlh, &seat);
|
handler.on_seat_destroyed(&seat);
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
warn!(self.logger, "Seat destroyed that was never created");
|
warn!(self.logger, "Seat destroyed that was never created");
|
||||||
|
@ -389,7 +388,7 @@ impl backend::InputBackend for LibinputInputBackend {
|
||||||
} else if let Some(ref mut handler) = self.handler {
|
} else if let Some(ref mut handler) = self.handler {
|
||||||
if let Some(seat) = self.seats.get(&device_seat) {
|
if let Some(seat) = self.seats.get(&device_seat) {
|
||||||
trace!(self.logger, "Calling on_seat_changed with {:?}", seat);
|
trace!(self.logger, "Calling on_seat_changed with {:?}", seat);
|
||||||
handler.on_seat_changed(evlh, &seat);
|
handler.on_seat_changed(&seat);
|
||||||
} else {
|
} else {
|
||||||
warn!(self.logger, "Seat changed that was never created");
|
warn!(self.logger, "Seat changed that was never created");
|
||||||
continue;
|
continue;
|
||||||
|
@ -398,7 +397,7 @@ impl backend::InputBackend for LibinputInputBackend {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if let Some(ref mut handler) = self.handler {
|
if let Some(ref mut handler) = self.handler {
|
||||||
handler.on_input_config_changed(evlh, &mut self.devices);
|
handler.on_input_config_changed(&mut self.devices);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
libinput::Event::Touch(touch_event) => {
|
libinput::Event::Touch(touch_event) => {
|
||||||
|
@ -409,7 +408,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(evlh, seat, down_event)
|
handler.on_touch_down(seat, down_event)
|
||||||
}
|
}
|
||||||
TouchEvent::Motion(motion_event) => {
|
TouchEvent::Motion(motion_event) => {
|
||||||
trace!(
|
trace!(
|
||||||
|
@ -417,11 +416,11 @@ impl backend::InputBackend for LibinputInputBackend {
|
||||||
"Calling on_touch_motion with {:?}",
|
"Calling on_touch_motion with {:?}",
|
||||||
motion_event
|
motion_event
|
||||||
);
|
);
|
||||||
handler.on_touch_motion(evlh, seat, motion_event)
|
handler.on_touch_motion(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(evlh, seat, up_event)
|
handler.on_touch_up(seat, up_event)
|
||||||
}
|
}
|
||||||
TouchEvent::Cancel(cancel_event) => {
|
TouchEvent::Cancel(cancel_event) => {
|
||||||
trace!(
|
trace!(
|
||||||
|
@ -429,11 +428,11 @@ impl backend::InputBackend for LibinputInputBackend {
|
||||||
"Calling on_touch_cancel with {:?}",
|
"Calling on_touch_cancel with {:?}",
|
||||||
cancel_event
|
cancel_event
|
||||||
);
|
);
|
||||||
handler.on_touch_cancel(evlh, seat, cancel_event)
|
handler.on_touch_cancel(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(evlh, seat, frame_event)
|
handler.on_touch_frame(seat, frame_event)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
|
@ -449,7 +448,7 @@ impl backend::InputBackend for LibinputInputBackend {
|
||||||
let device_seat = key_event.device().seat();
|
let device_seat = key_event.device().seat();
|
||||||
if let &Some(ref seat) = &self.seats.get(&device_seat) {
|
if let &Some(ref seat) = &self.seats.get(&device_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(evlh, seat, key_event);
|
handler.on_keyboard_key(seat, key_event);
|
||||||
} else {
|
} else {
|
||||||
warn!(self.logger, "Recieved key event of non existing Seat");
|
warn!(self.logger, "Recieved key event of non existing Seat");
|
||||||
continue;
|
continue;
|
||||||
|
@ -469,7 +468,7 @@ impl backend::InputBackend for LibinputInputBackend {
|
||||||
"Calling on_pointer_move with {:?}",
|
"Calling on_pointer_move with {:?}",
|
||||||
motion_event
|
motion_event
|
||||||
);
|
);
|
||||||
handler.on_pointer_move(evlh, seat, motion_event);
|
handler.on_pointer_move(seat, motion_event);
|
||||||
}
|
}
|
||||||
PointerEvent::MotionAbsolute(motion_abs_event) => {
|
PointerEvent::MotionAbsolute(motion_abs_event) => {
|
||||||
trace!(
|
trace!(
|
||||||
|
@ -477,11 +476,11 @@ 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(evlh, seat, motion_abs_event);
|
handler.on_pointer_move_absolute(seat, motion_abs_event);
|
||||||
}
|
}
|
||||||
PointerEvent::Axis(axis_event) => {
|
PointerEvent::Axis(axis_event) => {
|
||||||
trace!(self.logger, "Calling on_pointer_axis with {:?}", axis_event);
|
trace!(self.logger, "Calling on_pointer_axis with {:?}", axis_event);
|
||||||
handler.on_pointer_axis(evlh, seat, axis_event);
|
handler.on_pointer_axis(seat, axis_event);
|
||||||
}
|
}
|
||||||
PointerEvent::Button(button_event) => {
|
PointerEvent::Button(button_event) => {
|
||||||
trace!(
|
trace!(
|
||||||
|
@ -489,7 +488,7 @@ impl backend::InputBackend for LibinputInputBackend {
|
||||||
"Calling on_pointer_button with {:?}",
|
"Calling on_pointer_button with {:?}",
|
||||||
button_event
|
button_event
|
||||||
);
|
);
|
||||||
handler.on_pointer_button(evlh, seat, button_event);
|
handler.on_pointer_button(seat, button_event);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
|
@ -554,7 +553,7 @@ impl From<event::pointer::ButtonState> for backend::MouseButtonState {
|
||||||
|
|
||||||
#[cfg(feature = "backend_session")]
|
#[cfg(feature = "backend_session")]
|
||||||
impl SessionObserver for libinput::Libinput {
|
impl SessionObserver for libinput::Libinput {
|
||||||
fn pause(&mut self, _state: &mut EventLoopHandle, device: Option<(u32, u32)>) {
|
fn pause(&mut self, device: Option<(u32, u32)>) {
|
||||||
if let Some((major, _)) = device {
|
if let Some((major, _)) = device {
|
||||||
if major != INPUT_MAJOR {
|
if major != INPUT_MAJOR {
|
||||||
return;
|
return;
|
||||||
|
@ -564,7 +563,7 @@ impl SessionObserver for libinput::Libinput {
|
||||||
self.suspend()
|
self.suspend()
|
||||||
}
|
}
|
||||||
|
|
||||||
fn activate(&mut self, _state: &mut EventLoopHandle, _device: Option<(u32, u32, Option<RawFd>)>) {
|
fn activate(&mut self, _device: Option<(u32, u32, Option<RawFd>)>) {
|
||||||
// libinput closes the devices on suspend, so we should not get any INPUT_MAJOR calls
|
// libinput closes the devices on suspend, so we should not get any INPUT_MAJOR calls
|
||||||
// also lets hope multiple resumes are okay in case of logind
|
// also lets hope multiple resumes are okay in case of logind
|
||||||
self.resume().expect("Unable to resume libinput context");
|
self.resume().expect("Unable to resume libinput context");
|
||||||
|
@ -602,27 +601,25 @@ impl<S: Session> libinput::LibinputInterface for LibinputSessionInterface<S> {
|
||||||
/// Automatically feeds the backend with incoming events without any manual calls to
|
/// Automatically feeds the backend with incoming events without any manual calls to
|
||||||
/// `dispatch_new_events`. Should be used to achieve the smallest possible latency.
|
/// `dispatch_new_events`. Should be used to achieve the smallest possible latency.
|
||||||
pub fn libinput_bind(
|
pub fn libinput_bind(
|
||||||
backend: LibinputInputBackend, evlh: &mut EventLoopHandle
|
backend: LibinputInputBackend,
|
||||||
) -> ::std::result::Result<FdEventSource<LibinputInputBackend>, (IoError, LibinputInputBackend)> {
|
token: LoopToken,
|
||||||
|
) -> ::std::result::Result<Source<FdEvent>, (IoError, LibinputInputBackend)> {
|
||||||
let fd = unsafe { backend.context.fd() };
|
let fd = unsafe { backend.context.fd() };
|
||||||
evlh.add_fd_event_source(
|
token.add_fd_event_source(fd, FdInterest::READ, backend)
|
||||||
fd,
|
|
||||||
fd_event_source_implementation(),
|
|
||||||
backend,
|
|
||||||
FdInterest::READ,
|
|
||||||
)
|
|
||||||
}
|
}
|
||||||
|
|
||||||
fn fd_event_source_implementation() -> FdEventSourceImpl<LibinputInputBackend> {
|
impl Implementation<(), FdEvent> for LibinputInputBackend {
|
||||||
FdEventSourceImpl {
|
fn receive(&mut self, event: FdEvent, (): ()) {
|
||||||
ready: |evlh, ref mut backend, _, _| {
|
match event {
|
||||||
|
FdEvent::Ready { .. } => {
|
||||||
use backend::input::InputBackend;
|
use backend::input::InputBackend;
|
||||||
if let Err(error) = backend.dispatch_new_events(evlh) {
|
if let Err(error) = self.dispatch_new_events() {
|
||||||
warn!(backend.logger, "Libinput errored: {}", error);
|
warn!(self.logger, "Libinput errored: {}", error);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
FdEvent::Error { error, .. } => {
|
||||||
|
warn!(self.logger, "Libinput fd errored: {}", error);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
},
|
|
||||||
error: |_evlh, ref backend, _, error| {
|
|
||||||
warn!(backend.logger, "Libinput fd errored: {}", error);
|
|
||||||
},
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -21,8 +21,8 @@ pub mod graphics;
|
||||||
//pub mod winit;
|
//pub mod winit;
|
||||||
#[cfg(feature = "backend_drm")]
|
#[cfg(feature = "backend_drm")]
|
||||||
pub mod drm;
|
pub mod drm;
|
||||||
//#[cfg(feature = "backend_libinput")]
|
#[cfg(feature = "backend_libinput")]
|
||||||
//pub mod libinput;
|
pub mod libinput;
|
||||||
#[cfg(feature = "backend_session")]
|
#[cfg(feature = "backend_session")]
|
||||||
pub mod session;
|
pub mod session;
|
||||||
#[cfg(feature = "backend_udev")]
|
#[cfg(feature = "backend_udev")]
|
||||||
|
|
|
@ -351,7 +351,6 @@ where
|
||||||
info!(self.logger, "Devnum: {:b}", devnum);
|
info!(self.logger, "Devnum: {:b}", devnum);
|
||||||
if let Some(&(_, ref device)) = self.devices.borrow_mut().get(&devnum) {
|
if let Some(&(_, ref device)) = self.devices.borrow_mut().get(&devnum) {
|
||||||
let handler = &mut self.handler;
|
let handler = &mut self.handler;
|
||||||
let logger = &self.logger;
|
|
||||||
handler.device_changed(&mut device.borrow_mut());
|
handler.device_changed(&mut device.borrow_mut());
|
||||||
} else {
|
} else {
|
||||||
info!(self.logger, "changed, but device not tracked by backend");
|
info!(self.logger, "changed, but device not tracked by backend");
|
||||||
|
|
Loading…
Reference in New Issue