pub struct EventReader { /* private fields */ }Expand description
Stores a userspace view of a device, and reads events emitted by it.
Created by Evdev::into_reader.
This is the recommended way of ingesting input events from an evdev.
In addition to reading the raw events emitted by the device, EventReader will:
- Keep a view of the current device state that the user can query.
- Fetch the current device state on creation and when a
SYN_DROPPEDevent is received (indicating that one or more events have been lost due to the buffer filling up). - Synthesize events so that the consumer will see an up-to-date state.
The current device state from the EventReader’s PoV can be queried via
EventReader::key_state, EventReader::abs_state, EventReader::slot_state, and similar
methods.
These methods are faster than the equivalent methods on Evdev, since they do not have to
perform a system call to fetch the data (they just return data already stored in the
EventReader).
The reader’s view of the device state is automatically updated as events are pulled from it, but
can also be manually updated by calling EventReader::update, which will pull and discard all
available events.
Implementations§
Source§impl EventReader
impl EventReader
Sourcepub fn into_evdev(self) -> Evdev
pub fn into_evdev(self) -> Evdev
Destroys this EventReader and returns the original Evdev.
This will drop all input events buffered in the EventReader.
Sourcepub fn evdev(&self) -> &Evdev
pub fn evdev(&self) -> &Evdev
Returns a reference to the Evdev this EventReader was created from.
Sourcepub fn update(&mut self) -> Result<()>
pub fn update(&mut self) -> Result<()>
Update the local device state by reading all available events from the kernel, and discarding them.
This does not block.
This method can be used when the application isn’t interested in processing events or
reports itself, and only wants to know what the current state of the input device is.
EventReader::update is potentially faster than calling Evdev::key_state and other
Evdev getters, since each of the Evdev getters perform a syscall.
After a call to EventReader::update, the up-to-date device state can be retrieved with
the EventReader::key_state, EventReader::led_state, and other EventReader
methods without incurring any additional syscalls.
Sourcepub fn sound_state(&self) -> &BitSet<Sound>
pub fn sound_state(&self) -> &BitSet<Sound>
Sourcepub fn switch_state(&self) -> &BitSet<Switch>
pub fn switch_state(&self) -> &BitSet<Switch>
Sourcepub fn abs_state(&self, abs: Abs) -> i32
pub fn abs_state(&self, abs: Abs) -> i32
Returns the current value of an absolute axis.
abs must be less than Abs::MT_SLOT, or this method will panic. To access
multitouch slots, use EventReader::slot_state instead.
Call EventReader::update, or drain incoming events using the iterator interface in order
to update the multitouch slot state.
Sourcepub fn valid_slots(&self) -> impl Iterator<Item = Slot> + '_
pub fn valid_slots(&self) -> impl Iterator<Item = Slot> + '_
Returns an iterator that yields all Slots that have valid data in them.
A Slot is considered valid if its value of Abs::MT_TRACKING_ID is non-negative.
Call EventReader::update, or drain incoming events using the iterator interface in order
to update the multitouch slot state.
Sourcepub fn slot_state(&self, slot: impl TryInto<Slot>, code: Abs) -> Option<i32>
pub fn slot_state(&self, slot: impl TryInto<Slot>, code: Abs) -> Option<i32>
Returns an Abs axis value for a multitouch slot.
code must be one of the Abs::MT_* codes (but not Abs::MT_SLOT), as only those are
associated with a multitouch slot.
Non-MT Abs codes can be queried via EventReader::abs_state.
Returns None if code isn’t advertised by the device (ie. the property does not exist)
or if slot is out of range (ie. the device does not have the requested slot).
If slot isn’t valid (yielded by EventReader::valid_slots), invalid stale data may be
returned.
Sourcepub fn current_slot(&self) -> Slot
pub fn current_slot(&self) -> Slot
Returns the currently selected multitouch slot.
Events with ABS_MT_* code affect this slot, but not other slots.
Sourcepub fn events(&mut self) -> Events<'_> ⓘ
pub fn events(&mut self) -> Events<'_> ⓘ
Returns an iterator over incoming events.
Events read from the iterator will automatically update the state of the EventReader.
If the underlying device is in non-blocking mode, the iterator will return None when no
more events are available.
If the device is not in non-blocking mode, the iterator will block until more events
arrive.
Note: Retrieving an event with this iterator will remove that event from the Report
it belongs to if that report is later fetched with EventReader::reports.
It is best to stick to either per-event or per-report processing in your program to avoid
this.
Sourcepub fn reports(&mut self) -> Reports<'_> ⓘ
pub fn reports(&mut self) -> Reports<'_> ⓘ
Returns an iterator over incoming device reports.
Reports are groups of InputEvents that belong together.
If the underlying device is in non-blocking mode, the iterator will return None when no
more events are available.
If the device is not in non-blocking mode, the iterator will block until more events
arrive.
Note: Retrieving an event individually (for example, via EventReader::events) will
remove that event from the Report it belongs to if that report is later fetched with
EventReader::reports.
It is best to stick to either per-event or per-report processing in your program to avoid
this.
Sourcepub fn async_events(&mut self) -> Result<AsyncEvents<'_>>
Available on crate features tokio or async-io only.
pub fn async_events(&mut self) -> Result<AsyncEvents<'_>>
tokio or async-io only.Returns an async iterator over incoming events.
Events read from the iterator will automatically update the state of the EventReader.
The underlying device will be put in non-blocking mode while the returned AsyncEvents
is alive (if it isn’t already).
When using the "tokio" Cargo feature, this must be called while inside a tokio context.
Sourcepub fn async_reports(&mut self) -> Result<AsyncReports<'_>>
Available on crate features tokio or async-io only.
pub fn async_reports(&mut self) -> Result<AsyncReports<'_>>
tokio or async-io only.Returns an async iterator over incoming device reports.
The underlying device will be put in non-blocking mode while the returned AsyncReports
is alive (if it isn’t already).
When using the "tokio" Cargo feature, this must be called while inside a tokio context.