[][src]Struct evdev_rs::Device

pub struct Device { /* fields omitted */ }

Opaque struct representing an evdev device

Implementations

impl Device[src]

pub fn new() -> Option<Device>[src]

Initialize a new libevdev device.

This function only initializesthe struct to sane default values. To actually hook up the device to a kernel device, use set_fd.

pub fn new_from_fd(file: File) -> Result<Device>[src]

Initialize a new libevdev device from the given fd.

This is a shortcut for

use evdev_rs::Device;

let mut device = Device::new().unwrap();
device.set_fd(fd);

pub fn name(&self) -> Option<&str>[src]

pub fn phys(&self) -> Option<&str>[src]

pub fn uniq(&self) -> Option<&str>[src]

pub fn set_name(&self, field: &str)[src]

pub fn set_phys(&self, field: &str)[src]

pub fn set_uniq(&self, field: &str)[src]

pub fn fd(&self) -> Option<File>[src]

Returns the file associated with the device

if the set_fd hasn't been called yet then it return None

pub fn set_fd(&mut self, file: File) -> Result<()>[src]

Set the file for this struct and initialize internal data.

This function may only be called once per device. If the device changed and you need to re-read a device, use new method. If you need to change the file after closing and re-opening the same device, use change_fd.

Unless otherwise specified, evdev function behavior is undefined until a successfull call to set_fd.

pub fn change_fd(&mut self, file: File) -> Result<()>[src]

Change the fd for this device, without re-reading the actual device.

If the fd changes after initializing the device, for example after a VT-switch in the X.org X server, this function updates the internal fd to the newly opened. No check is made that new fd points to the same device. If the device has changed, evdev's behavior is undefined.

evdev device does not sync itself after changing the fd and keeps the current device state. Use next_event with the FORCE_SYNC flag to force a re-sync.

Example

This example is not tested
dev.change_fd(new_fd);
dev.next_event(evdev::FORCE_SYNC);
while dev.next_event(evdev::SYNC).ok().unwrap().0 == ReadStatus::SYNC
                            {} // noop

After changing the fd, the device is assumed ungrabbed and a caller must call libevdev_grab() again.

It is an error to call this function before calling set_fd().

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 libevdev_change_fd(), it must also re-issue a grab with libevdev_grab().

pub fn abs_info(&self, code: &EventCode) -> Option<AbsInfo>[src]

Get the axis info for the given axis, as advertised by the kernel.

Returns the AbsInfo for the given the code or None if the device doesn't support this code

pub fn set_abs_info(&self, code: &EventCode, absinfo: &AbsInfo)[src]

Change the abs info for the given EV_ABS event code, if the code exists.

This function has no effect if has_event_code returns false for this code.

pub fn has(&self, blob: &dyn Any) -> bool[src]

Returns true if device support the InputProp/EventType/EventCode and false otherwise

pub fn enable(&self, blob: &dyn Any) -> Result<()>[src]

Forcibly enable an EventType/InputProp on this device, even if the underlying device does not support it. While this cannot make the device actually report such events, it will now return true for has().

This is a local modification only affecting only this representation of this device.

pub fn has_property(&self, prop: &InputProp) -> bool[src]

Returns true if device support the property and false otherwise

Note: Please use the has function instead. This function is only available for the sake of maintaining compatibility with libevdev.

pub fn enable_property(&self, prop: &InputProp) -> Result<()>[src]

Enables this property, a call to set_fd will overwrite any previously set values

Note: Please use the enable function instead. This function is only available for the sake of maintaining compatibility with libevdev.

pub fn has_event_type(&self, ev_type: &EventType) -> bool[src]

Returns true is the device support this event type and false otherwise

Note: Please use the has function instead. This function is only available for the sake of maintaining compatibility with libevdev.

pub fn has_event_code(&self, code: &EventCode) -> bool[src]

Return true is the device support this event type and code and false otherwise

Note: Please use the has function instead. This function is only available for the sake of maintaining compatibility with libevdev.

pub fn event_value(&self, code: &EventCode) -> Option<i32>[src]

Returns the current value of the event type.

If the device supports this event type and code, the return value is set to the current value of this axis. Otherwise, None is returned.

pub fn set_event_value(&self, code: &EventCode, val: i32) -> Result<()>[src]

Set the value for a given event type and code.

This only makes sense for some event types, e.g. setting the value for EV_REL is pointless.

This is a local modification only affecting only this representation of this device. A future call to event_value() will return this value, unless the value was overwritten by an event.

If the device supports ABS_MT_SLOT, the value set for any ABS_MT_* event code is the value of the currently active slot. You should use set_slot_value instead.

If the device supports ABS_MT_SLOT and the type is EV_ABS and the code is ABS_MT_SLOT, the value must be a positive number less then the number of slots on the device. Otherwise, set_event_value returns Err.

pub fn has_event_pending(&self) -> bool[src]

Check if there are events waiting for us.

This function does not read an event off the fd and may not access the fd at all. If there are events queued internally this function will return non-zero. 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 product_id(&self) -> u16[src]

pub fn vendor_id(&self) -> u16[src]

pub fn bustype(&self) -> u16[src]

pub fn version(&self) -> u16[src]

pub fn set_product_id(&self, field: u16)[src]

pub fn set_vendor_id(&self, field: u16)[src]

pub fn set_bustype(&self, field: u16)[src]

pub fn set_version(&self, field: u16)[src]

pub fn driver_version(&self) -> i32[src]

Return the driver version of a device already intialize with set_fd

pub fn abs_minimum(&self, code: u32) -> Result<i32>[src]

pub fn abs_maximum(&self, code: u32) -> Result<i32>[src]

pub fn abs_fuzz(&self, code: u32) -> Result<i32>[src]

pub fn abs_flat(&self, code: u32) -> Result<i32>[src]

pub fn abs_resolution(&self, code: u32) -> Result<i32>[src]

pub fn set_abs_minimum(&self, code: u32, val: i32)[src]

pub fn set_abs_maximum(&self, code: u32, val: i32)[src]

pub fn set_abs_fuzz(&self, code: u32, val: i32)[src]

pub fn set_abs_flat(&self, code: u32, val: i32)[src]

pub fn set_abs_resolution(&self, code: u32, val: i32)[src]

pub fn slot_value(&self, slot: u32, code: &EventCode) -> Option<i32>[src]

Return the current value of the code for the given slot.

If the device supports this event code, the return value is is set to the current value of this axis. Otherwise, or if the event code is not an ABS_MT_* event code, None is returned

pub fn set_slot_value(
    &self,
    slot: u32,
    code: &EventCode,
    val: i32
) -> Result<()>
[src]

Set the value for a given code for the given slot.

This is a local modification only affecting only this representation of this device. A future call to slot_value will return this value, unless the value was overwritten by an event.

This function does not set event values for axes outside the ABS_MT range, use set_event_value instead.

pub fn num_slots(&self) -> Option<i32>[src]

Get the number of slots supported by this device.

The number of slots supported, or None if the device does not provide any slots

A device may provide ABS_MT_SLOT but a total number of 0 slots. Hence the return value of None for "device does not provide slots at all"

pub fn current_slot(&self) -> Option<i32>[src]

Get the currently active slot.

This may differ from the value an ioctl may return at this time as events may have been read off the fd since changing the slot value but those events are still in the buffer waiting to be processed. The returned value is the value a caller would see if it were to process events manually one-by-one.

pub fn enable_event_type(&self, ev_type: &EventType) -> Result<()>[src]

Forcibly enable an event type on this device, even if the underlying device does not support it. While this cannot make the device actually report such events, it will now return true for libevdev_has_event_type().

This is a local modification only affecting only this representation of this device.

Note: Please use the enable function instead. This function is only available for the sake of maintaining compatibility with libevdev.

pub fn enable_event_code(
    &self,
    ev_code: &EventCode,
    blob: Option<&dyn Any>
) -> Result<()>
[src]

Forcibly enable an event type on this device, even if the underlying device does not support it. While this cannot make the device actually report such events, it will now return true for libevdev_has_event_code().

The last argument depends on the type and code: If type is EV_ABS, data must be a pointer to a struct input_absinfo containing the data for this axis. If type is EV_REP, data must be a pointer to a int containing the data for this axis. For all other types, the argument must be NULL.

Note: Please use the enable function instead. This function is only available for the sake of maintaining compatibility with libevdev.

pub fn disable(&self, blob: &dyn Any) -> Result<()>[src]

Forcibly disable an EventType/EventCode on this device, even if the underlying device provides it. This effectively mutes the respective set of events. has() will return false for this EventType/EventCode

In most cases, a caller likely only wants to disable a single code, not the whole type.

Disabling EV_SYN will not work. In Peter's Words "Don't shoot yourself in the foot. It hurts".

This is a local modification only affecting only this representation of this device.

pub fn disable_event_type(&self, ev_type: &EventType) -> Result<()>[src]

Forcibly disable an event type on this device, even if the underlying device provides it. This effectively mutes the respective set of events. libevdev will filter any events matching this type and none will reach the caller. libevdev_has_event_type() will return false for this type.

In most cases, a caller likely only wants to disable a single code, not the whole type. Use disable_event_code for that.

Disabling EV_SYN will not work. In Peter's Words "Don't shoot yourself in the foot. It hurts".

This is a local modification only affecting only this representation of this device.

Note: Please use the disable function instead. This function is only available for the sake of maintaining compatibility with libevdev.

pub fn disable_event_code(&self, code: &EventCode) -> Result<()>[src]

Forcibly disable an event code on this device, even if the underlying device provides it. This effectively mutes the respective set of events. libevdev will filter any events matching this type and code and none will reach the caller. has_event_code will return false for this code.

Disabling all event codes for a given type will not disable the event type. Use disable_event_type for that.

This is a local modification only affecting only this representation of this device.

Disabling codes of type EV_SYN will not work. Don't shoot yourself in the foot. It hurts.

Note: Please use the disable function instead. This function is only available for the sake of maintaining compatibility with libevdev.

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]

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 Drop for Device[src]

Auto Trait Implementations

impl RefUnwindSafe for Device

impl !Send for Device

impl !Sync for Device

impl Unpin for Device

impl UnwindSafe for Device

Blanket Implementations

impl<T> Any for T where
    T: 'static + ?Sized
[src]

impl<T> Borrow<T> for T where
    T: ?Sized
[src]

impl<T> BorrowMut<T> for T where
    T: ?Sized
[src]

impl<T> From<T> for T[src]

impl<T, U> Into<U> for T where
    U: From<T>, 
[src]

impl<T, U> TryFrom<U> for T where
    U: Into<T>, 
[src]

type Error = Infallible

The type returned in the event of a conversion error.

impl<T, U> TryInto<U> for T where
    U: TryFrom<T>, 
[src]

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.