Struct evdev_rs::Device [] [src]

pub struct Device { /* fields omitted */ }

Opaque struct representing an evdev device

Methods

impl Device
[src]

[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.

[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);

[src]

[src]

[src]

[src]

[src]

[src]

[src]

Returns the file associated with the device

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

[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.

[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

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

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

[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.

[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

[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.

[src]

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

[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.

[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.

[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 get_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.

[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).

[src]

[src]

[src]

[src]

[src]

[src]

[src]

[src]

[src]

Return the driver version of a device already intialize with set_fd

[src]

[src]

[src]

[src]

[src]

[src]

[src]

[src]

[src]

[src]

[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

[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.

[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"

[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.

[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.

[src]

Set the device's EV_ABS axis to the value defined in the abs parameter. This will be written to the kernel.

[src]

Turn an LED on or off.

enabling an LED requires write permissions on the device's file descriptor.

[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.

[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 get_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]

[src]

Executes the destructor for this type. Read more