Struct evdev_rs::Device [−][src]
Opaque struct representing an evdev device
Unlike libevdev, this Device
mantains an associated file as an invariant
Implementations
impl Device
[src]
pub fn new_from_file(file: File) -> Result<Device>
[src]
Initialize a new libevdev device from the given file.
This is a shortcut for
use evdev_rs::{Device, UninitDevice}; let uninit_device = UninitDevice::new().unwrap(); let device = uninit_device.set_file(file);
pub fn new_from_fd(file: File) -> Result<Device>
[src]
Prefer new_from_file
. Some function names were changed so they
more closely match their type signature. See issue 42 for discussion
https://github.com/ndesh26/evdev-rs/issues/42
pub fn file(&self) -> &File
[src]
Returns the file associated with the device
pub fn fd(&self) -> Option<File>
[src]
Prefer file
. This function can easily be misused. Calling
this method, then dropping the returned file will lead to failures
e.g. next_event will return an Err()
pub fn change_file(&mut self, file: File) -> Result<File>
[src]
Change the file for this device, without re-reading the actual device.
On success, returns the file that was previously associated with this device.
If the file changes after initializing the device, for example after a VT-switch in the X.org X server, this function updates the internal file to the newly opened. No check is made that new file points to the same device. If the device has changed, evdev’s behavior is undefined.
evdev device does not sync itself after changing the file and keeps the current device state. Use next_event with the FORCE_SYNC flag to force a re-sync.
Example
use evdev_rs::{Device, UninitDevice, ReadFlag, ReadStatus}; let mut dev = Device::new_from_file(File::open("/dev/input/input0")?)?; dev.change_file(File::open("/dev/input/input1")?)?; dev.next_event(ReadFlag::FORCE_SYNC); while dev.next_event(ReadFlag::SYNC).ok().unwrap().0 == ReadStatus::Sync {} // noop
After changing the file, the device is assumed ungrabbed and a caller must call libevdev_grab() again.
pub fn change_fd(&mut self, file: File) -> Result<()>
[src]
Prefer new_from_file. Some function names were changed so they more closely match their type signature. See issue 42 for discussion https://github.com/ndesh26/evdev-rs/issues/42
pub fn grab(&mut self, grab: GrabMode) -> Result<()>
[src]
Grab or ungrab the device through a kernel EVIOCGRAB.
This prevents other clients (including kernel-internal ones such as rfkill) from receiving events from this device. This is generally a bad idea. Don’t do this. Grabbing an already grabbed device, or ungrabbing an ungrabbed device is a noop and always succeeds.
A grab is an operation tied to a file descriptor, not a device. If a client changes the file descriptor with Device::change_file(), it must also re-issue a grab with libevdev_grab().
pub fn has_event_pending(&self) -> bool
[src]
Check if there are events waiting for us.
This function does not consume an event and may not access the device file at all. If there are events queued internally this function will return true. If the internal queue is empty, this function will poll the file descriptor for data.
This is a convenience function for simple processes, most complex programs
are expected to use select(2) or poll(2) on the file descriptor. The kernel
guarantees that if data is available, it is a multiple of sizeof(struct
input_event), and thus calling next_event
when select(2) or
poll(2) return is safe. You do not need has_event_pending
if
you’re using select(2) or poll(2).
pub fn driver_version(&self) -> i32
[src]
Return the driver version of a device already intialize with set_file
pub fn set_kernel_abs_info(&self, code: &EventCode, absinfo: &AbsInfo)
[src]
Set the device’s EV_ABS axis to the value defined in the abs parameter. This will be written to the kernel.
pub fn kernel_set_led_value(
&self,
code: &EventCode,
value: LedState
) -> Result<()>
[src]
&self,
code: &EventCode,
value: LedState
) -> Result<()>
Turn an LED on or off.
enabling an LED requires write permissions on the device’s file descriptor.
pub fn set_clock_id(&self, clockid: i32) -> Result<()>
[src]
Set the clock ID to be used for timestamps. Further events from this device will report an event time based on the given clock.
This is a modification only affecting this representation of this device.
pub fn next_event(&self, flags: ReadFlag) -> Result<(ReadStatus, InputEvent)>
[src]
Get the next event from the device. This function operates in two different modes: normal mode or sync mode.
In normal mode (when flags has evdev::NORMAL
set), this function returns
ReadStatus::Success
and returns the event. If no events are available at
this time, it returns -EAGAIN
as Err
.
If the current event is an EV_SYN::SYN_DROPPED
event, this function returns
ReadStatus::Sync
and is set to the EV_SYN
event.The caller should now call
this function with the evdev::SYNC
flag set, to get the set of events that
make up the device state delta. This function returns ReadStatus::Sync for
each event part of that delta, until it returns -EAGAIN
once all events
have been synced.
If a device needs to be synced by the caller but the caller does not call
with the evdev::SYNC
flag set, all events from the diff are dropped after
evdev updates its internal state and event processing continues as normal.
Note that the current slot and the state of touch points may have updated
during the SYN_DROPPED
event, it is strongly recommended that a caller
ignoring all sync events calls current_slot
and checks the
ABS_MT_TRACKING_ID
values for all slots.
If a device has changed state without events being enqueued in evdev,
e.g. after changing the file descriptor, use the evdev::FORCE_SYNC
flag.
This triggers an internal sync of the device and next_event
returns
ReadStatus::Sync
.
Trait Implementations
impl DeviceWrapper for Device
[src]
fn raw(&self) -> *mut libevdev
[src]
fn enable(&self, blob: &dyn Any) -> Result<()>
[src]
fn enable_property(&self, prop: &InputProp) -> Result<()>
[src]
fn enable_event_type(&self, ev_type: &EventType) -> Result<()>
[src]
fn enable_event_code(
&self,
ev_code: &EventCode,
blob: Option<&dyn Any>
) -> Result<()>
[src]
&self,
ev_code: &EventCode,
blob: Option<&dyn Any>
) -> Result<()>
fn disable(&self, blob: &dyn Any) -> Result<()>
[src]
fn disable_event_type(&self, ev_type: &EventType) -> Result<()>
[src]
fn disable_event_code(&self, code: &EventCode) -> Result<()>
[src]
fn has(&self, blob: &dyn Any) -> bool
[src]
fn has_property(&self, prop: &InputProp) -> bool
[src]
fn has_event_type(&self, ev_type: &EventType) -> bool
[src]
fn has_event_code(&self, code: &EventCode) -> bool
[src]
fn name(&self) -> Option<&str>
[src]
fn phys(&self) -> Option<&str>
[src]
fn uniq(&self) -> Option<&str>
[src]
fn set_name(&self, field: &str)
[src]
fn set_phys(&self, field: &str)
[src]
fn set_uniq(&self, field: &str)
[src]
fn product_id(&self) -> u16
[src]
fn vendor_id(&self) -> u16
[src]
fn bustype(&self) -> u16
[src]
fn version(&self) -> u16
[src]
fn set_product_id(&self, field: u16)
[src]
fn set_vendor_id(&self, field: u16)
[src]
fn set_bustype(&self, field: u16)
[src]
fn set_version(&self, field: u16)
[src]
fn abs_info(&self, code: &EventCode) -> Option<AbsInfo>
[src]
fn set_abs_info(&self, code: &EventCode, absinfo: &AbsInfo)
[src]
fn event_value(&self, code: &EventCode) -> Option<i32>
[src]
fn set_event_value(&self, code: &EventCode, val: i32) -> Result<()>
[src]
fn abs_minimum(&self, code: u32) -> Result<i32>
[src]
fn abs_maximum(&self, code: u32) -> Result<i32>
[src]
fn abs_fuzz(&self, code: u32) -> Result<i32>
[src]
fn abs_flat(&self, code: u32) -> Result<i32>
[src]
fn abs_resolution(&self, code: u32) -> Result<i32>
[src]
fn set_abs_minimum(&self, code: u32, val: i32)
[src]
fn set_abs_maximum(&self, code: u32, val: i32)
[src]
fn set_abs_fuzz(&self, code: u32, val: i32)
[src]
fn set_abs_flat(&self, code: u32, val: i32)
[src]
fn set_abs_resolution(&self, code: u32, val: i32)
[src]
fn slot_value(&self, slot: u32, code: &EventCode) -> Option<i32>
[src]
fn set_slot_value(&self, slot: u32, code: &EventCode, val: i32) -> Result<()>
[src]
fn num_slots(&self) -> Option<i32>
[src]
fn current_slot(&self) -> Option<i32>
[src]
impl Drop for Device
[src]
impl Send for Device
[src]
Auto Trait Implementations
Blanket Implementations
impl<T> Any for T where
T: 'static + ?Sized,
[src]
T: 'static + ?Sized,
impl<T> Borrow<T> for T where
T: ?Sized,
[src]
T: ?Sized,
impl<T> BorrowMut<T> for T where
T: ?Sized,
[src]
T: ?Sized,
pub fn borrow_mut(&mut self) -> &mut T
[src]
impl<T> From<T> for T
[src]
impl<T, U> Into<U> for T where
U: From<T>,
[src]
U: From<T>,
impl<T, U> TryFrom<U> for T where
U: Into<T>,
[src]
U: Into<T>,
type Error = Infallible
The type returned in the event of a conversion error.
pub fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>
[src]
impl<T, U> TryInto<U> for T where
U: TryFrom<T>,
[src]
U: TryFrom<T>,