Merge pull request #406 from i509VCB/input/remove-dispatch-new
input: remove `InputBackend::dispatch_new_events`
This commit is contained in:
commit
a4fab6633c
|
@ -23,6 +23,8 @@
|
||||||
- `WinitEventLoop::dispatch_new_events` is now used to receive some `WinitEvent`s.
|
- `WinitEventLoop::dispatch_new_events` is now used to receive some `WinitEvent`s.
|
||||||
- Added `TabletToolType::Unknown` as an option for tablet events
|
- Added `TabletToolType::Unknown` as an option for tablet events
|
||||||
- `render_texture` was removed from `Frame`, use `render_texture_at` or `render_texture_from_to` instead or use `Gles2Renderer::render_texture` as a direct replacement.
|
- `render_texture` was removed from `Frame`, use `render_texture_at` or `render_texture_from_to` instead or use `Gles2Renderer::render_texture` as a direct replacement.
|
||||||
|
- Remove `InputBackend::dispatch_new_events`, turning `InputBackend` into a definition of backend event types. Future input backends should be a `calloop::EventSource`.
|
||||||
|
- Remove `InputBackend::EventError` associated type as it is unneeded since `dispatch_new_events` was removed.
|
||||||
|
|
||||||
### Additions
|
### Additions
|
||||||
|
|
||||||
|
|
|
@ -1,6 +1,6 @@
|
||||||
//! Common traits for input backends to receive input from.
|
//! Common traits for input backends to receive input from.
|
||||||
|
|
||||||
use std::{error::Error, path::PathBuf};
|
use std::path::PathBuf;
|
||||||
|
|
||||||
mod tablet;
|
mod tablet;
|
||||||
|
|
||||||
|
@ -507,9 +507,6 @@ impl<B: InputBackend> TouchFrameEvent<B> for UnusedEvent {}
|
||||||
/// need to implement this and provide the same base guarantees about the precision of
|
/// need to implement this and provide the same base guarantees about the precision of
|
||||||
/// given events.
|
/// given events.
|
||||||
pub trait InputBackend: Sized {
|
pub trait InputBackend: Sized {
|
||||||
/// Type representing errors that may be returned when processing events
|
|
||||||
type EventError: Error;
|
|
||||||
|
|
||||||
/// Type representing input devices
|
/// Type representing input devices
|
||||||
type Device: Device;
|
type Device: Device;
|
||||||
/// Type representing keyboard events
|
/// Type representing keyboard events
|
||||||
|
@ -543,11 +540,6 @@ pub trait InputBackend: Sized {
|
||||||
|
|
||||||
/// Special events that are custom to this backend
|
/// Special events that are custom to this backend
|
||||||
type SpecialEvent;
|
type SpecialEvent;
|
||||||
|
|
||||||
/// Processes new events and calls the provided callback.
|
|
||||||
fn dispatch_new_events<F>(&mut self, callback: F) -> Result<(), Self::EventError>
|
|
||||||
where
|
|
||||||
F: FnMut(InputEvent<Self>);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Different events that can be generated by an input backend
|
/// Different events that can be generated by an input backend
|
||||||
|
|
|
@ -12,7 +12,6 @@ use input::event;
|
||||||
#[cfg(feature = "backend_session")]
|
#[cfg(feature = "backend_session")]
|
||||||
use std::path::Path;
|
use std::path::Path;
|
||||||
use std::{
|
use std::{
|
||||||
io::Error as IoError,
|
|
||||||
os::unix::io::{AsRawFd, RawFd},
|
os::unix::io::{AsRawFd, RawFd},
|
||||||
path::PathBuf,
|
path::PathBuf,
|
||||||
};
|
};
|
||||||
|
@ -355,8 +354,6 @@ impl backend::Event<LibinputInputBackend> for event::touch::TouchFrameEvent {
|
||||||
impl backend::TouchFrameEvent<LibinputInputBackend> for event::touch::TouchFrameEvent {}
|
impl backend::TouchFrameEvent<LibinputInputBackend> for event::touch::TouchFrameEvent {}
|
||||||
|
|
||||||
impl InputBackend for LibinputInputBackend {
|
impl InputBackend for LibinputInputBackend {
|
||||||
type EventError = IoError;
|
|
||||||
|
|
||||||
type Device = libinput::Device;
|
type Device = libinput::Device;
|
||||||
type KeyboardKeyEvent = event::keyboard::KeyboardKeyEvent;
|
type KeyboardKeyEvent = event::keyboard::KeyboardKeyEvent;
|
||||||
type PointerAxisEvent = event::pointer::PointerAxisEvent;
|
type PointerAxisEvent = event::pointer::PointerAxisEvent;
|
||||||
|
@ -374,103 +371,6 @@ impl InputBackend for LibinputInputBackend {
|
||||||
type TabletToolButtonEvent = event::tablet_tool::TabletToolButtonEvent;
|
type TabletToolButtonEvent = event::tablet_tool::TabletToolButtonEvent;
|
||||||
|
|
||||||
type SpecialEvent = backend::UnusedEvent;
|
type SpecialEvent = backend::UnusedEvent;
|
||||||
|
|
||||||
fn dispatch_new_events<F>(&mut self, mut callback: F) -> Result<(), IoError>
|
|
||||||
where
|
|
||||||
F: FnMut(InputEvent<Self>),
|
|
||||||
{
|
|
||||||
self.context.dispatch()?;
|
|
||||||
|
|
||||||
for event in &mut self.context {
|
|
||||||
match event {
|
|
||||||
libinput::Event::Device(device_event) => match device_event {
|
|
||||||
event::DeviceEvent::Added(device_added_event) => {
|
|
||||||
let added = event::EventTrait::device(&device_added_event);
|
|
||||||
|
|
||||||
info!(self.logger, "New device {:?}", added.sysname(),);
|
|
||||||
|
|
||||||
callback(InputEvent::DeviceAdded { device: added });
|
|
||||||
}
|
|
||||||
event::DeviceEvent::Removed(device_removed_event) => {
|
|
||||||
let removed = event::EventTrait::device(&device_removed_event);
|
|
||||||
|
|
||||||
info!(self.logger, "Removed device {:?}", removed.sysname(),);
|
|
||||||
|
|
||||||
callback(InputEvent::DeviceRemoved { device: removed });
|
|
||||||
}
|
|
||||||
_ => {
|
|
||||||
trace!(self.logger, "Unknown libinput device event");
|
|
||||||
}
|
|
||||||
},
|
|
||||||
libinput::Event::Touch(touch_event) => match touch_event {
|
|
||||||
event::TouchEvent::Down(down_event) => {
|
|
||||||
callback(InputEvent::TouchDown { event: down_event });
|
|
||||||
}
|
|
||||||
event::TouchEvent::Motion(motion_event) => {
|
|
||||||
callback(InputEvent::TouchMotion { event: motion_event });
|
|
||||||
}
|
|
||||||
event::TouchEvent::Up(up_event) => {
|
|
||||||
callback(InputEvent::TouchUp { event: up_event });
|
|
||||||
}
|
|
||||||
event::TouchEvent::Cancel(cancel_event) => {
|
|
||||||
callback(InputEvent::TouchCancel { event: cancel_event });
|
|
||||||
}
|
|
||||||
event::TouchEvent::Frame(frame_event) => {
|
|
||||||
callback(InputEvent::TouchFrame { event: frame_event });
|
|
||||||
}
|
|
||||||
_ => {
|
|
||||||
trace!(self.logger, "Unknown libinput touch event");
|
|
||||||
}
|
|
||||||
},
|
|
||||||
libinput::Event::Keyboard(keyboard_event) => match keyboard_event {
|
|
||||||
event::KeyboardEvent::Key(key_event) => {
|
|
||||||
callback(InputEvent::Keyboard { event: key_event });
|
|
||||||
}
|
|
||||||
_ => {
|
|
||||||
trace!(self.logger, "Unknown libinput keyboard event");
|
|
||||||
}
|
|
||||||
},
|
|
||||||
libinput::Event::Pointer(pointer_event) => match pointer_event {
|
|
||||||
event::PointerEvent::Motion(motion_event) => {
|
|
||||||
callback(InputEvent::PointerMotion { event: motion_event });
|
|
||||||
}
|
|
||||||
event::PointerEvent::MotionAbsolute(motion_abs_event) => {
|
|
||||||
callback(InputEvent::PointerMotionAbsolute {
|
|
||||||
event: motion_abs_event,
|
|
||||||
});
|
|
||||||
}
|
|
||||||
event::PointerEvent::Axis(axis_event) => {
|
|
||||||
callback(InputEvent::PointerAxis { event: axis_event });
|
|
||||||
}
|
|
||||||
event::PointerEvent::Button(button_event) => {
|
|
||||||
callback(InputEvent::PointerButton { event: button_event });
|
|
||||||
}
|
|
||||||
_ => {
|
|
||||||
trace!(self.logger, "Unknown libinput pointer event");
|
|
||||||
}
|
|
||||||
},
|
|
||||||
libinput::Event::Tablet(tablet_event) => match tablet_event {
|
|
||||||
event::TabletToolEvent::Axis(event) => {
|
|
||||||
callback(InputEvent::TabletToolAxis { event });
|
|
||||||
}
|
|
||||||
event::TabletToolEvent::Proximity(event) => {
|
|
||||||
callback(InputEvent::TabletToolProximity { event });
|
|
||||||
}
|
|
||||||
event::TabletToolEvent::Tip(event) => {
|
|
||||||
callback(InputEvent::TabletToolTip { event });
|
|
||||||
}
|
|
||||||
event::TabletToolEvent::Button(event) => {
|
|
||||||
callback(InputEvent::TabletToolButton { event });
|
|
||||||
}
|
|
||||||
_ => {
|
|
||||||
trace!(self.logger, "Unknown libinput tablet event");
|
|
||||||
}
|
|
||||||
},
|
|
||||||
_ => {} //FIXME: What to do with the rest.
|
|
||||||
}
|
|
||||||
}
|
|
||||||
Ok(())
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
impl From<event::keyboard::KeyState> for backend::KeyState {
|
impl From<event::keyboard::KeyState> for backend::KeyState {
|
||||||
|
@ -568,8 +468,101 @@ impl EventSource for LibinputInputBackend {
|
||||||
F: FnMut(Self::Event, &mut ()) -> Self::Ret,
|
F: FnMut(Self::Event, &mut ()) -> Self::Ret,
|
||||||
{
|
{
|
||||||
if token == self.token {
|
if token == self.token {
|
||||||
self.dispatch_new_events(|evt| callback(evt, &mut ()))?;
|
self.context.dispatch()?;
|
||||||
|
|
||||||
|
for event in &mut self.context {
|
||||||
|
match event {
|
||||||
|
libinput::Event::Device(device_event) => match device_event {
|
||||||
|
event::DeviceEvent::Added(device_added_event) => {
|
||||||
|
let added = event::EventTrait::device(&device_added_event);
|
||||||
|
|
||||||
|
info!(self.logger, "New device {:?}", added.sysname(),);
|
||||||
|
|
||||||
|
callback(InputEvent::DeviceAdded { device: added }, &mut ());
|
||||||
|
}
|
||||||
|
event::DeviceEvent::Removed(device_removed_event) => {
|
||||||
|
let removed = event::EventTrait::device(&device_removed_event);
|
||||||
|
|
||||||
|
info!(self.logger, "Removed device {:?}", removed.sysname(),);
|
||||||
|
|
||||||
|
callback(InputEvent::DeviceRemoved { device: removed }, &mut ());
|
||||||
|
}
|
||||||
|
_ => {
|
||||||
|
trace!(self.logger, "Unknown libinput device event");
|
||||||
|
}
|
||||||
|
},
|
||||||
|
libinput::Event::Touch(touch_event) => match touch_event {
|
||||||
|
event::TouchEvent::Down(down_event) => {
|
||||||
|
callback(InputEvent::TouchDown { event: down_event }, &mut ());
|
||||||
|
}
|
||||||
|
event::TouchEvent::Motion(motion_event) => {
|
||||||
|
callback(InputEvent::TouchMotion { event: motion_event }, &mut ());
|
||||||
|
}
|
||||||
|
event::TouchEvent::Up(up_event) => {
|
||||||
|
callback(InputEvent::TouchUp { event: up_event }, &mut ());
|
||||||
|
}
|
||||||
|
event::TouchEvent::Cancel(cancel_event) => {
|
||||||
|
callback(InputEvent::TouchCancel { event: cancel_event }, &mut ());
|
||||||
|
}
|
||||||
|
event::TouchEvent::Frame(frame_event) => {
|
||||||
|
callback(InputEvent::TouchFrame { event: frame_event }, &mut ());
|
||||||
|
}
|
||||||
|
_ => {
|
||||||
|
trace!(self.logger, "Unknown libinput touch event");
|
||||||
|
}
|
||||||
|
},
|
||||||
|
libinput::Event::Keyboard(keyboard_event) => match keyboard_event {
|
||||||
|
event::KeyboardEvent::Key(key_event) => {
|
||||||
|
callback(InputEvent::Keyboard { event: key_event }, &mut ());
|
||||||
|
}
|
||||||
|
_ => {
|
||||||
|
trace!(self.logger, "Unknown libinput keyboard event");
|
||||||
|
}
|
||||||
|
},
|
||||||
|
libinput::Event::Pointer(pointer_event) => match pointer_event {
|
||||||
|
event::PointerEvent::Motion(motion_event) => {
|
||||||
|
callback(InputEvent::PointerMotion { event: motion_event }, &mut ());
|
||||||
|
}
|
||||||
|
event::PointerEvent::MotionAbsolute(motion_abs_event) => {
|
||||||
|
callback(
|
||||||
|
InputEvent::PointerMotionAbsolute {
|
||||||
|
event: motion_abs_event,
|
||||||
|
},
|
||||||
|
&mut (),
|
||||||
|
);
|
||||||
|
}
|
||||||
|
event::PointerEvent::Axis(axis_event) => {
|
||||||
|
callback(InputEvent::PointerAxis { event: axis_event }, &mut ());
|
||||||
|
}
|
||||||
|
event::PointerEvent::Button(button_event) => {
|
||||||
|
callback(InputEvent::PointerButton { event: button_event }, &mut ());
|
||||||
|
}
|
||||||
|
_ => {
|
||||||
|
trace!(self.logger, "Unknown libinput pointer event");
|
||||||
|
}
|
||||||
|
},
|
||||||
|
libinput::Event::Tablet(tablet_event) => match tablet_event {
|
||||||
|
event::TabletToolEvent::Axis(event) => {
|
||||||
|
callback(InputEvent::TabletToolAxis { event }, &mut ());
|
||||||
|
}
|
||||||
|
event::TabletToolEvent::Proximity(event) => {
|
||||||
|
callback(InputEvent::TabletToolProximity { event }, &mut ());
|
||||||
|
}
|
||||||
|
event::TabletToolEvent::Tip(event) => {
|
||||||
|
callback(InputEvent::TabletToolTip { event }, &mut ());
|
||||||
|
}
|
||||||
|
event::TabletToolEvent::Button(event) => {
|
||||||
|
callback(InputEvent::TabletToolButton { event }, &mut ());
|
||||||
|
}
|
||||||
|
_ => {
|
||||||
|
trace!(self.logger, "Unknown libinput tablet event");
|
||||||
|
}
|
||||||
|
},
|
||||||
|
_ => {} //FIXME: What to do with the rest.
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
Ok(PostAction::Continue)
|
Ok(PostAction::Continue)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -6,12 +6,12 @@ use winit::{
|
||||||
};
|
};
|
||||||
|
|
||||||
use crate::backend::input::{
|
use crate::backend::input::{
|
||||||
self, Axis, AxisSource, ButtonState, Device, DeviceCapability, Event, InputBackend, InputEvent, KeyState,
|
self, Axis, AxisSource, ButtonState, Device, DeviceCapability, Event, InputBackend, KeyState,
|
||||||
KeyboardKeyEvent, PointerAxisEvent, PointerButtonEvent, PointerMotionAbsoluteEvent, TouchCancelEvent,
|
KeyboardKeyEvent, PointerAxisEvent, PointerButtonEvent, PointerMotionAbsoluteEvent, TouchCancelEvent,
|
||||||
TouchDownEvent, TouchMotionEvent, TouchSlot, TouchUpEvent, UnusedEvent,
|
TouchDownEvent, TouchMotionEvent, TouchSlot, TouchUpEvent, UnusedEvent,
|
||||||
};
|
};
|
||||||
|
|
||||||
use super::{WindowSize, WinitError};
|
use super::WindowSize;
|
||||||
|
|
||||||
/// Marker used to define the `InputBackend` types for the winit backend.
|
/// Marker used to define the `InputBackend` types for the winit backend.
|
||||||
#[derive(Debug)]
|
#[derive(Debug)]
|
||||||
|
@ -363,8 +363,6 @@ impl From<ElementState> for ButtonState {
|
||||||
}
|
}
|
||||||
|
|
||||||
impl InputBackend for WinitInput {
|
impl InputBackend for WinitInput {
|
||||||
type EventError = WinitError;
|
|
||||||
|
|
||||||
type Device = WinitVirtualDevice;
|
type Device = WinitVirtualDevice;
|
||||||
type KeyboardKeyEvent = WinitKeyboardInputEvent;
|
type KeyboardKeyEvent = WinitKeyboardInputEvent;
|
||||||
type PointerAxisEvent = WinitMouseWheelEvent;
|
type PointerAxisEvent = WinitMouseWheelEvent;
|
||||||
|
@ -382,11 +380,4 @@ impl InputBackend for WinitInput {
|
||||||
type TabletToolButtonEvent = UnusedEvent;
|
type TabletToolButtonEvent = UnusedEvent;
|
||||||
|
|
||||||
type SpecialEvent = UnusedEvent;
|
type SpecialEvent = UnusedEvent;
|
||||||
|
|
||||||
fn dispatch_new_events<F>(&mut self, _callback: F) -> Result<(), Self::EventError>
|
|
||||||
where
|
|
||||||
F: FnMut(InputEvent<Self>),
|
|
||||||
{
|
|
||||||
unreachable!()
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,9 +1,8 @@
|
||||||
//! Input backend implementation for the X11 backend.
|
//! Input backend implementation for the X11 backend.
|
||||||
|
|
||||||
use super::X11Error;
|
|
||||||
use crate::{
|
use crate::{
|
||||||
backend::input::{
|
backend::input::{
|
||||||
self, Axis, AxisSource, ButtonState, Device, DeviceCapability, InputBackend, InputEvent, KeyState,
|
self, Axis, AxisSource, ButtonState, Device, DeviceCapability, InputBackend, KeyState,
|
||||||
KeyboardKeyEvent, PointerAxisEvent, PointerButtonEvent, PointerMotionAbsoluteEvent, UnusedEvent,
|
KeyboardKeyEvent, PointerAxisEvent, PointerButtonEvent, PointerMotionAbsoluteEvent, UnusedEvent,
|
||||||
},
|
},
|
||||||
utils::{Logical, Size},
|
utils::{Logical, Size},
|
||||||
|
@ -182,8 +181,6 @@ impl PointerMotionAbsoluteEvent<X11Input> for X11MouseMovedEvent {
|
||||||
}
|
}
|
||||||
|
|
||||||
impl InputBackend for X11Input {
|
impl InputBackend for X11Input {
|
||||||
type EventError = X11Error;
|
|
||||||
|
|
||||||
type Device = X11VirtualDevice;
|
type Device = X11VirtualDevice;
|
||||||
type KeyboardKeyEvent = X11KeyboardInputEvent;
|
type KeyboardKeyEvent = X11KeyboardInputEvent;
|
||||||
type PointerAxisEvent = X11MouseWheelEvent;
|
type PointerAxisEvent = X11MouseWheelEvent;
|
||||||
|
@ -204,13 +201,4 @@ impl InputBackend for X11Input {
|
||||||
type TabletToolButtonEvent = UnusedEvent;
|
type TabletToolButtonEvent = UnusedEvent;
|
||||||
|
|
||||||
type SpecialEvent = UnusedEvent;
|
type SpecialEvent = UnusedEvent;
|
||||||
|
|
||||||
fn dispatch_new_events<F>(&mut self, _callback: F) -> Result<(), Self::EventError>
|
|
||||||
where
|
|
||||||
F: FnMut(InputEvent<Self>),
|
|
||||||
{
|
|
||||||
// The implementation of the trait here is exclusively for type definitions.
|
|
||||||
// See `X11Event::Input` to handle input events.
|
|
||||||
unreachable!()
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue