Struct evdev_rs::Device
[−]
[src]
pub struct Device { /* fields omitted */ }
Opaque struct representing an evdev device
Methods
impl Device
[src]
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
.
fn new_from_fd(fd: &File) -> Result<Device, Errno>
[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);
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 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
fn set_fd(&mut self, f: &File) -> Result<(), Errno>
[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
.
fn change_fd(&mut self, f: &File) -> Result<(), Errno>
[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().
fn grab(&mut self, grab: GrabMode) -> Result<(), Errno>
[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.
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
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.
fn has(&self, blob: &Any) -> bool
[src]
Returns true
if device support the InputProp/EventType/EventCode and false otherwise
fn enable(&self, blob: &Any) -> Result<(), Errno>
[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.
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.
fn set_event_value(&self, code: &EventCode, val: i32) -> Result<(), Errno>
[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.
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).
fn product_id(&self) -> i32
[src]
fn vendor_id(&self) -> i32
[src]
fn bustype(&self) -> i32
[src]
fn version(&self) -> i32
[src]
fn set_product_id(&self, field: i32)
[src]
fn set_vendor_id(&self, field: i32)
[src]
fn set_bustype(&self, field: i32)
[src]
fn set_version(&self, field: i32)
[src]
fn driver_version(&self) -> i32
[src]
Return the driver version of a device already intialize with set_fd
fn abs_minimum(&self, code: u32) -> Result<i32, Errno>
[src]
fn abs_maximum(&self, code: u32) -> Result<i32, Errno>
[src]
fn abs_fuzz(&self, code: u32) -> Result<i32, Errno>
[src]
fn abs_flat(&self, code: u32) -> Result<i32, Errno>
[src]
fn abs_resolution(&self, code: u32) -> Result<i32, Errno>
[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]
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
fn set_slot_value(
&self,
slot: u32,
code: &EventCode,
val: i32
) -> Result<(), Errno>
[src]
&self,
slot: u32,
code: &EventCode,
val: i32
) -> Result<(), Errno>
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.
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"
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.
fn disable(&self, blob: &Any) -> Result<(), Errno>
[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.
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.
fn kernel_set_led_value(
&self,
code: &EventCode,
value: LedState
) -> Result<(), Errno>
[src]
&self,
code: &EventCode,
value: LedState
) -> Result<(), Errno>
Turn an LED on or off.
enabling an LED requires write permissions on the device's file descriptor.
fn set_clock_id(&self, clockid: i32) -> Result<(), Errno>
[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.
fn next_event(&self, flags: ReadFlag) -> Result<(ReadStatus, InputEvent), Errno>
[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
.