### HotplugMonitor::new Source: https://docs.rs/evdevil/0.4.0/evdevil/hotplug/struct.HotplugMonitor.html Creates a new HotplugMonitor and starts listening for hotplug events. This operation is always blocking. ```APIDOC ## `HotplugMonitor::new()` ### Description Creates a new `HotplugMonitor` and starts listening for hotplug events. This operation is always blocking. ### Method `pub fn new() -> Result` ### Errors - `io::ErrorKind::Unsupported`: On unsupported platforms. - Other `io::Error` types: If connecting to the system’s hotplug mechanism fails. ### Usage Callers should degrade gracefully, by using only the currently plugged-in devices and not supporting hotplug functionality. ### Example ```rust use evdevil::hotplug::HotplugMonitor; use std::io::Result; fn main() -> Result<()> { let monitor = HotplugMonitor::new()?; // Use the monitor... Ok(()) } ``` ``` -------------------------------- ### Define AbsSetup struct Source: https://docs.rs/evdevil/0.4.0/evdevil/uinput/struct.AbsSetup.html The internal structure definition for absolute axis setup. ```rust pub struct AbsSetup(/* private fields */); ``` -------------------------------- ### Implement AsRawFd for UinputDevice Source: https://docs.rs/evdevil/0.4.0/src/evdevil/uinput.rs.html Provides a way to get the raw file descriptor of the UinputDevice. ```rust impl AsRawFd for UinputDevice { #[inline] fn as_raw_fd(&self) -> RawFd { self.file.as_raw_fd() } } ``` -------------------------------- ### Ioctl for Repeat Settings Source: https://docs.rs/evdevil/0.4.0/src/evdevil/raw/input.rs.html Use EVIOCGREP to get the current key repeat settings. EVIOCSREP is used to set them. ```rust /// Get repeat settings. pub const EVIOCGREP: Ioctl<*mut [c_uint; 2]> = _IOR(b'E', 0x03); /// Set repeat settings. pub const EVIOCSREP: Ioctl<*const [c_uint; 2]> = _IOW(b'E', 0x03); ``` -------------------------------- ### Ioctl for Keycode (V2) Source: https://docs.rs/evdevil/0.4.0/src/evdevil/raw/input.rs.html Use EVIOCGKEYCODE_V2 to get keycode information and EVIOCSKEYCODE_V2 to set it. Older versions are deprecated. ```rust /// Get keycode. #[expect(dead_code)] // replaced by _V2 in 2010 pub const EVIOCGKEYCODE: Ioctl<*mut [c_uint; 2]> = _IOR(b'E', 0x04); pub const EVIOCGKEYCODE_V2: Ioctl<*mut input_keymap_entry> = _IOR(b'E', 0x04); /// Set keycode. #[expect(dead_code)] // replaced by _V2 in 2010 pub const EVIOCSKEYCODE: Ioctl<*const [c_uint; 2]> = _IOW(b'E', 0x04); pub const EVIOCSKEYCODE_V2: Ioctl<*const input_keymap_entry> = _IOW(b'E', 0x04); ``` -------------------------------- ### AbsInfo::new Source: https://docs.rs/evdevil/0.4.0/evdevil/struct.AbsInfo.html Creates a new `AbsInfo` with a minimum and maximum value. All other fields start out as zero. ```APIDOC ## `AbsInfo::new` ### Description Creates a new `AbsInfo` with a minimum and maximum value. All other fields start out as zero. ### Method `const fn new(minimum: i32, maximum: i32) -> Self` ### Parameters * **minimum** (i32) - Required - The minimum value for the axis. * **maximum** (i32) - Required - The maximum value for the axis. ### Returns A new `AbsInfo` instance. ``` -------------------------------- ### Ioctl for MT Slots Source: https://docs.rs/evdevil/0.4.0/src/evdevil/raw/input.rs.html Use EVIOCGMTSLOTS to get multi-touch slots. Behavior differs slightly between Linux and FreeBSD. ```rust pub const fn EVIOCGMTSLOTS(len: usize) -> Ioctl<*mut c_void> { if cfg!(target_os = "freebsd") { _IOC(IOC_INOUT, b'E', 0x0a, len) } else { // NB: declared as `_IOC_READ`, but writes the `code` _IOC(_IOC_READ, b'E', 0x0a, len) } } ``` -------------------------------- ### Ioctl for Sounds State Source: https://docs.rs/evdevil/0.4.0/src/evdevil/raw/input.rs.html Use EVIOCGSND with a specified length to get the state of all sounds. ```rust /// Get all sounds state. pub const fn EVIOCGSND(len: usize) -> Ioctl<*mut c_void> { _IOC(_IOC_READ, b'E', 0x1a, len) } ``` -------------------------------- ### POST /uinput/build Source: https://docs.rs/evdevil/0.4.0/evdevil/uinput/struct.Builder.html Finalizes the configuration and creates the uinput device. ```APIDOC ## build(name: &str) ### Description Creates the uinput device. After this method returns, the device appears in /dev/input. ### Parameters - **name** (str) - Required - The name of the device (max 79 bytes, ASCII). ### Response - **Success** (Result) - Returns the initialized UinputDevice instance. ``` -------------------------------- ### Get Ramp Effect Start Level Source: https://docs.rs/evdevil/0.4.0/src/evdevil/ff.rs.html Retrieves the starting level for the ramp effect. ```rust pub fn start_level(&self) -> i16 { self.0.start_level } ``` -------------------------------- ### Get Attack Level Source: https://docs.rs/evdevil/0.4.0/evdevil/ff/struct.Envelope.html Retrieves the configured starting intensity level for the effect's fade-in. ```rust pub fn attack_level(&self) -> u16 ``` -------------------------------- ### Initialize Hotplug Monitor and Enumerate Devices Source: https://docs.rs/evdevil/0.4.0/src/evdevil/enumerate.rs.html Sets up the hotplug monitor and performs an initial scan of devices, reconciling readdir results with hotplug events to avoid duplicates. ```rust let monitor = match HotplugMonitor::new() { Ok(m) => Some(m), Err(e) => { log::warn!("couldn't open hotplug monitor: {e}; device hotplug will not work"); None } }; let mut results = Vec::new(); let mut path_map = HashMap::new(); for res in enumerate()? { match res { Ok((path, evdev)) => { let index = results.len(); results.push(Ok((path.clone(), evdev))); path_map.insert(path, index); } Err(e) => results.push(Err(e)), } } if cfg!(test) { thread::sleep(Duration::from_millis(500)); } if let Some(mon) = &monitor { mon.set_nonblocking(true)?; for res in mon { let Ok(event) = res else { break; }; match path_map.get(event.path()) { Some(&i) => { match &results[i] { Ok((path, evdev)) if evdev.driver_version().is_ok() => { log::debug!("device at `{}` still present", path.display()); continue; } _ => { log::debug!( "device at `{}` unplugged or errored; reopening", event.path().display() ); results[i] = event.open().map(|evdev| (event.into_path(), evdev)); } } } None => { log::debug!( "found new device during enumeration: {}", event.path().display() ); let index = results.len(); let res = event .open() .map(|evdev| (event.path().to_path_buf(), evdev)); results.push(res); path_map.insert(event.into_path(), index); } } } mon.set_nonblocking(false)?; } Ok(Self { to_yield: results.into_iter(), monitor, delay_ms: INITIAL_DELAY, }) ``` -------------------------------- ### Get Waveform Phase Source: https://docs.rs/evdevil/0.4.0/evdevil/ff/struct.Periodic.html Returns the horizontal phase offset, indicating the starting point of waveform playback. ```rust pub fn phase(&self) -> u16 ``` -------------------------------- ### UinputDevice Creation and Configuration Source: https://docs.rs/evdevil/0.4.0/src/evdevil/uinput.rs.html Provides methods for creating and configuring UinputDevice instances, including obtaining a builder, creating from a file descriptor, and managing non-blocking mode. ```APIDOC ## UinputDevice Builder API ### Description Returns a [`Builder`] for configuring a new input device. This is the primary way to start creating a new uinput device. ### Method GET ### Endpoint `/uinput/builder` ### Parameters None ### Request Example None ### Response #### Success Response (200) - **Builder** (object) - An object representing the builder for a new uinput device. #### Response Example ```json { "builder_id": "unique_builder_identifier" } ``` ## UinputDevice from Owned File Descriptor ### Description Creates a [`UinputDevice`] instance from a bare file descriptor. This method is unsafe and requires the provided file descriptor to refer specifically to a uinput character device. ### Method POST ### Endpoint `/uinput/from_owned_fd` ### Parameters #### Request Body - **owned_fd** (OwnedFd) - Required - The owned file descriptor referring to a uinput character device. ### Request Example ```json { "owned_fd": "file_descriptor_value" } ``` ### Response #### Success Response (200) - **UinputDevice** (object) - An instance of the UinputDevice. #### Response Example ```json { "device_handle": "device_handle_value" } ``` ## UinputDevice Non-blocking Mode ### Description Moves this handle into or out of non-blocking mode. This affects how I/O operations on the device behave. ### Method PUT ### Endpoint `/uinput/{device_id}/nonblocking` ### Parameters #### Path Parameters - **device_id** (string) - Required - The identifier of the UinputDevice. #### Request Body - **nonblocking** (boolean) - Required - `true` to enable non-blocking mode, `false` to disable. ### Request Example ```json { "nonblocking": true } ``` ### Response #### Success Response (200) - **previous_state** (boolean) - `true` if the device was previously in non-blocking mode, `false` otherwise. #### Response Example ```json { "previous_state": false } ``` ``` -------------------------------- ### Get TypeId for Generic Type T Source: https://docs.rs/evdevil/0.4.0/evdevil/event/struct.AbsEvent.html Gets the TypeId of a generic type T. This is part of the Any trait implementation. ```rust fn type_id(&self) -> TypeId ``` -------------------------------- ### Define uinput_setup structure Source: https://docs.rs/evdevil/0.4.0/src/evdevil/raw/uinput.rs.html Defines the structure for setting up a uinput device. This includes device identification, name, and the maximum number of force feedback effects. ```rust pub struct uinput_setup { pub id: input_id, pub name: [c_char; UINPUT_MAX_NAME_SIZE], pub ff_effects_max: u32, } ``` -------------------------------- ### Consume HotplugEvent to Get Device Path Source: https://docs.rs/evdevil/0.4.0/evdevil/hotplug/struct.HotplugEvent.html Consumes the HotplugEvent and returns the device path as a PathBuf. This is useful for getting the path without cloning. ```rust pub fn into_path(self) -> PathBuf ``` -------------------------------- ### Device State and Configuration Source: https://docs.rs/evdevil/0.4.0/src/evdevil/evdev.rs.html Methods for setting device LEDs, global force-feedback parameters, and clock settings. ```APIDOC ## set_led ### Description Sets the state of a device LED. ### Parameters #### Request Body - **led** (Led) - Required - The LED to control. - **on** (bool) - Required - The state to set (true for on, false for off). ## set_ff_gain ### Description Sets the global gain for force-feedback effects as a fraction of 65535. ### Parameters #### Request Body - **gain** (u16) - Required - The gain value. ## set_ff_autocenter ### Description Controls the autocenter feature for force-feedback effects. ### Parameters #### Request Body - **autocenter** (u16) - Required - The autocenter power as a fraction of 65535. ## set_clockid ### Description Sets the clockid_t to be used for event timestamps. ### Parameters #### Request Body - **clockid** (clockid_t) - Required - The clock ID to use. ``` -------------------------------- ### GET /key_repeat Source: https://docs.rs/evdevil/0.4.0/src/evdevil/evdev.rs.html Queries the current autorepeat settings. ```APIDOC ## GET /key_repeat ### Description Returns the current key repeat delay and period if supported by the device. ``` -------------------------------- ### Tokio Runtime Setup for Tests Source: https://docs.rs/evdevil/0.4.0/src/evdevil/util/async.rs.html Provides a simple Tokio runtime for testing asynchronous operations. It enables IO and builds a current-thread runtime. ```rust pub fn new() -> io::Result { let rt = tokio::runtime::Builder::new_current_thread() .enable_io() .build()?; Ok(Self { rt }) } ``` ```rust pub fn enter(&self) -> impl Sized + '_ { self.rt.enter() } ``` ```rust pub fn block_on(&self, fut: F) -> F::Output { self.rt.block_on(fut) } ``` -------------------------------- ### Get Waveform Magnitude Source: https://docs.rs/evdevil/0.4.0/evdevil/ff/struct.Periodic.html Retrieves the magnitude of the waveform. ```rust pub fn magnitude(&self) -> i16 ``` -------------------------------- ### Build and Create Uinput Device Source: https://docs.rs/evdevil/0.4.0/src/evdevil/uinput.rs.html Creates the uinput device with the specified name. The device will appear in `/dev/input` after successful creation. Note that device permissions might be temporarily incorrect due to `udev`. ```rust pub fn build(mut self, name: &str) -> io::Result { if name.len() >= UINPUT_MAX_NAME_SIZE { return Err(io::Error::new( io::ErrorKind::InvalidInput, "uinput device name is too long", )); } unsafe { ptr::copy_nonoverlapping( name.as_ptr(), self.setup.name.as_mut_ptr().cast(), name.len(), ); } unsafe { self.device .ioctl("UI_DEV_SETUP", UI_DEV_SETUP, &self.setup)?; UI_DEV_CREATE.ioctl(&self.device)?; } Ok(self.device) } ``` -------------------------------- ### Configure sudo runner for tests Source: https://docs.rs/evdevil/0.4.0/evdevil/index.html To run the test suite, including all examples, with sudo privileges, configure the .cargo/config.toml file with the provided runner setting. ```toml [target.'cfg(true)'] runner = "sudo -E --preserve-env=PATH" ``` -------------------------------- ### Get EventType from InputEvent Source: https://docs.rs/evdevil/0.4.0/evdevil/event/struct.AbsEvent.html Returns the EventType of this event. ```rust pub fn event_type(&self) -> EventType ``` -------------------------------- ### GET /writer Source: https://docs.rs/evdevil/0.4.0/evdevil/uinput/struct.UinputDevice.html Returns an EventWriter for streaming events to the device. ```APIDOC ## GET /writer ### Description Returns an EventWriter instance used for writing events to the device. Call EventWriter::finish to finalize the batch with a SYN_REPORT event. ### Method GET ### Endpoint /writer ``` -------------------------------- ### Create a UinputDevice Builder Source: https://docs.rs/evdevil/0.4.0/src/evdevil/uinput.rs.html Returns a builder for configuring a new input device. This operation requires read and write permissions for /dev/uinput and may fail with a permission denied error. ```rust pub fn builder() -> io::Result { Builder::new() } ``` -------------------------------- ### GET /switch_state Source: https://docs.rs/evdevil/0.4.0/src/evdevil/evdev.rs.html Retrieves the current state of switches on the device. ```APIDOC ## GET /switch_state ### Description Fetches the current bitset state of switches (EVIOCGSW) from the device. ### Method GET ### Response #### Success Response (200) - **state** (BitSet) - The current state of the device switches. ``` -------------------------------- ### Replay Struct and Methods Source: https://docs.rs/evdevil/0.4.0/evdevil/ff/struct.Replay.html Details on the Replay struct, how to create a new Replay instance, and how to access its length and delay. ```APIDOC ## Struct Replay ### Description Configures how an `Effect` should be scheduled. Appears to be ignored by most devices. ### Methods #### `new(length: u16, delay: u16) -> Self` Creates a new `Replay` instance with the specified length and delay. #### `length(&self) -> u16` Returns the configured length of the replay. #### `delay(&self) -> u16` Returns the configured delay of the replay. ``` -------------------------------- ### Get Waveform Period Source: https://docs.rs/evdevil/0.4.0/evdevil/ff/struct.Periodic.html Returns the period of the waveform in milliseconds. ```rust pub fn period(&self) -> u16 ``` -------------------------------- ### Create UinputDevice Builder Source: https://docs.rs/evdevil/0.4.0/evdevil/uinput/struct.UinputDevice.html Returns a Builder for configuring a new input device. This may fail with a permission denied error if the user lacks write access to /dev/uinput. ```rust pub fn builder() -> Result ``` -------------------------------- ### Get the Switch Type Source: https://docs.rs/evdevil/0.4.0/evdevil/event/struct.SwitchEvent.html Retrieves the Switch associated with this event. ```rust pub fn switch(&self) -> Switch ``` -------------------------------- ### AbsSetup Configuration Source: https://docs.rs/evdevil/0.4.0/src/evdevil/uinput.rs.html AbsSetup is used to configure absolute axis information for virtual input devices. ```APIDOC ## AbsSetup ### Description `AbsSetup` wraps `uinput_abs_setup` to configure specific absolute axes for a virtual device. ### Parameters - **abs** (Abs) - The axis to configure. - **abs_info** (AbsInfo) - The configuration details for the axis. ``` -------------------------------- ### EventReader Initialization and Basic Operations Source: https://docs.rs/evdevil/0.4.0/src/evdevil/reader.rs.html Details on creating an EventReader, retrieving the underlying Evdev device, and checking device states. ```APIDOC ## EventReader::new ### Description Creates a new `EventReader` instance from an `Evdev` device. ### Method `EventReader::new(evdev: Evdev) -> io::Result` ### Parameters - `evdev` (Evdev) - The Evdev device to create the reader from. ### Response - `Ok(EventReader)` on success. - `Err(io::Error)` on failure. ## EventReader::into_evdev ### Description Destroys the `EventReader` and returns the original `Evdev` device. All buffered input events are dropped. ### Method `EventReader::into_evdev(self) -> Evdev` ### Response - `Evdev` - The original Evdev device. ## EventReader::evdev ### Description Returns a reference to the underlying `Evdev` device. ### Method `EventReader::evdev(&self) -> &Evdev` ### Response - `&Evdev` - A reference to the Evdev device. ``` -------------------------------- ### Get ForceFeedbackEvent Code Source: https://docs.rs/evdevil/0.4.0/evdevil/event/struct.ForceFeedbackEvent.html Retrieves the code associated with the ForceFeedbackEvent. ```rust pub fn code(&self) -> Option ``` -------------------------------- ### Build a UinputDevice Source: https://docs.rs/evdevil/0.4.0/src/evdevil/uinput.rs.html Initializes a new UinputDevice builder and configures device properties. The builder manages the lifecycle of the /dev/uinput file descriptor. ```rust /// A builder for creating a [`UinputDevice`]. /// /// Returned by [`UinputDevice::builder`]. pub struct Builder { device: UinputDevice, // handle to `/dev/uinput` setup: uinput_setup, } impl fmt::Debug for Builder { fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { f.debug_struct("Builder") .field("file", &self.device.file) .field("input_id", &InputId(self.setup.id)) .field("ff_effects_max", &self.setup.ff_effects_max) .finish() } } impl Builder { fn new() -> io::Result { let file = File::options() .read(true) .write(true) .open("/dev/uinput") .map_err(|e| io::Error::new(e.kind(), format!("failed to open '/dev/uinput': {e}")))?; let device = UinputDevice { file }; unsafe { let mut version = 0; device.ioctl("UI_GET_VERSION", UI_GET_VERSION, &mut version)?; log::debug!("opened /dev/uinput; version={version:#x}"); } Ok(Self { device, setup: unsafe { mem::zeroed() }, }) } /// Configures the device's hardware IDs. /// /// They can be fetched from an input device by calling [`Evdev::input_id`]. /// /// [`Evdev::input_id`]: crate::Evdev::input_id #[inline pub fn with_input_id(mut self, id: InputId) -> io::Result { // Returns an `io::Result` so that all the builder methods have the same signature. self.setup.id = id.0; Ok(self) } /// Sets the physical path of the device. /// /// By default, the physical path of a `uinput` device is unset, and the corresponding /// [`Evdev::phys`] method will return [`None`]. /// /// This method can be used to change that behavior and expose the proper hardware location to /// consumers. /// ``` -------------------------------- ### Get UinputDevice Events Source: https://docs.rs/evdevil/0.4.0/evdevil/uinput/struct.UinputDevice.html Returns an iterator over events received by the UinputDevice. ```APIDOC ## GET /uinput/device/{sysname}/events ### Description Returns an iterator over events _received_ by this `UinputDevice`. ### Method GET ### Endpoint `/uinput/device/{sysname}/events` ### Parameters #### Path Parameters - **sysname** (string) - Required - The sysname of the uinput device. ### Response #### Success Response (200) - **Events** (iterator) - An iterator yielding `UinputEvent`s. #### Response Example (Iterator yielding UinputEvent objects) ### Usage Notes If the device exposes functionality like LEDs, Sounds, or Force Feedback, this iterator should be used to read events that trigger these features and act accordingly. For force feedback, specific `ff_upload` and `ff_erase` methods should be called based on received `UinputEvent`s. ``` -------------------------------- ### Initialize DeviceState Source: https://docs.rs/evdevil/0.4.0/src/evdevil/reader.rs.html Creates a new, empty device state. Initializes all states to default values and sets the last event time to the current system time. ```rust fn new(abs_axes: BitSet) -> Self { Self { keys: BitSet::new(), leds: BitSet::new(), sounds: BitSet::new(), switches: BitSet::new(), abs: [0; Abs::MT_SLOT.raw() as usize], abs_axes, mt_storage: MtStorage::empty(), // We emit events to update to the current device state, but without having any device // events available to get a timestamp from. // Default to `now()` so that there's a reasonable default time. // This should be the correct default time source, too. last_event: SystemTime::now(), } } ``` -------------------------------- ### GET /abs_info Source: https://docs.rs/evdevil/0.4.0/src/evdevil/evdev.rs.html Retrieves the absolute axis information for a specific axis. ```APIDOC ## GET /abs_info ### Description Queries the current absolute axis information for the specified axis. ### Parameters #### Request Body - **abs** (Abs) - Required - The absolute axis to query. ### Response #### Success Response (200) - **AbsInfo** (Object) - The absolute axis information structure. ``` -------------------------------- ### Ioctl for Properties Source: https://docs.rs/evdevil/0.4.0/src/evdevil/raw/input.rs.html Use EVIOCGPROP with a specified length to retrieve device properties. ```rust pub const fn EVIOCGPROP(len: usize) -> Ioctl<*mut c_void> { _IOC(_IOC_READ, b'E', 0x09, len) } ``` -------------------------------- ### Get Evdev Driver Version Source: https://docs.rs/evdevil/0.4.0/evdevil/struct.Evdev.html Retrieves the version of the evdev subsystem. ```rust pub fn driver_version(&self) -> Result ``` -------------------------------- ### Get Value from AbsEvent Source: https://docs.rs/evdevil/0.4.0/evdevil/event/struct.AbsEvent.html Retrieves the i32 value associated with the AbsEvent. ```rust pub fn value(&self) -> i32 ``` -------------------------------- ### Device Creation Source: https://docs.rs/evdevil/0.4.0/src/evdevil/uinput.rs.html Method for finalizing the uinput device creation. ```APIDOC ## `build(name: &str)` Creates the `uinput` device. After this method returns successfully, the device will show up in `/dev/input` and emit hotplug events accordingly. **NOTE**: Because of how `udev` works, devices can show up with incorrect permission bits for a short time, before those permissions are set correctly by the system. This means that calling `enumerate` immediately after creating a `uinput` device might fail to access the device. However, *hotplug* events should arrive only after the device has been given the correct permissions. ### Parameters - **name** (string) - Required - The name of the device. Should be ASCII, and must not be longer than 79 bytes, or this method will return an error. ``` -------------------------------- ### Get UinputDevice Sysname Source: https://docs.rs/evdevil/0.4.0/evdevil/uinput/struct.UinputDevice.html Retrieves the sysfs directory name for the uinput device. ```APIDOC ## GET /uinput/device/{sysname} ### Description Retrieves the uinput device’s directory name in the sysfs hierarchy. ### Method GET ### Endpoint `/uinput/device/{sysname}` ### Parameters #### Path Parameters - **sysname** (string) - Required - The sysname of the uinput device. ### Response #### Success Response (200) - **sysname** (OsString) - The directory name in sysfs. #### Response Example ```json { "sysname": "eventX" } ``` ### Platform Notes This functionality is generally non-portable and only works on Linux. The full path is typically `/sys/devices/virtual/input/` followed by the returned name. ``` -------------------------------- ### Builder Configuration Methods Source: https://docs.rs/evdevil/0.4.0/evdevil/uinput/struct.Builder.html Methods used to configure the characteristics and capabilities of a uinput device before instantiation. ```APIDOC ## Configuration Methods ### Description These methods allow setting various device attributes such as hardware IDs, physical paths, and supported input event types. ### Methods - **with_input_id(id: InputId)**: Configures the device's hardware IDs. - **with_phys(path: &str)**: Sets the physical path of the device. - **with_props(props: impl IntoIterator)**: Sets device properties. - **with_keys(keys: impl IntoIterator)**: Enables specific keys. - **with_rel_axes(rel: impl IntoIterator)**: Enables relative axes. - **with_abs_axes(axes: impl IntoIterator)**: Enables absolute axes. - **with_ff_effects_max(ff_max: u32)**: Sets max force-feedback effects. - **with_ff_features(feat: impl IntoIterator)**: Sets force-feedback capabilities. ``` -------------------------------- ### Initialize async-io Async Source: https://docs.rs/evdevil/0.4.0/src/evdevil/util/async.rs.html Creates a new async_io::Async for a given file descriptor, enabling non-blocking operations. This is necessary for integrating with the async-io event loop. ```rust pub fn new(fd: RawFd) -> io::Result { let fd = unsafe { BorrowedFd::borrow_raw(fd) }; Async::new_nonblocking(fd).map(Self) } ``` -------------------------------- ### Get Deadband from Condition Source: https://docs.rs/evdevil/0.4.0/src/evdevil/ff.rs.html Retrieves the current deadband value from the Condition struct. ```rust pub fn deadband(&self) -> u16 { self.0.deadband } ``` -------------------------------- ### Evdev::open Source: https://docs.rs/evdevil/0.4.0/evdevil/struct.Evdev.html Opens a filesystem path referring to an evdev node. ```APIDOC ## POST /api/users ### Description Opens a filesystem path referring to an `evdev` node. The path must belong to an `evdev` device like `/dev/input/event*`, not to a legacy _“joydev”_ device (`/dev/input/js`) and not to a legacy _“mousedev”_ (`/dev/input/mouse` or `/dev/input/mice`). #### Permissions This method will attempt to open `path` with read-write permissions, fall back to read-only permissions if the current user does not have read and write permissions, and finally fall back to write-only permissions. If all of these attempts fail with a `io::ErrorKind::PermissionDenied` error, this method will return that error to the caller. #### Errors This method will return an error if `path` doesn’t refer to a path matching `/dev/input/event*` (after resolving symlinks). ### Method GET ### Endpoint /api/users ### Parameters #### Path Parameters - **id** (integer) - Required - The unique identifier of the user. ``` -------------------------------- ### Get Periodic Effect Envelope Source: https://docs.rs/evdevil/0.4.0/src/evdevil/ff.rs.html Retrieves the envelope settings for a periodic effect. ```rust pub fn envelope(&self) -> Envelope { Envelope(self.raw.envelope) } ``` -------------------------------- ### Key Trait Implementations Source: https://docs.rs/evdevil/0.4.0/evdevil/event/struct.Key.html Demonstrates various trait implementations for the Key struct. ```APIDOC ## GET /websites/rs_evdevil_0_4_0/key/traits ### Description Provides information about the implemented traits for the Key struct. ### Method GET ### Endpoint /websites/rs_evdevil_0_4_0/key/traits ### Response #### Success Response (200) - **traits** (array) - A list of implemented traits. - **name** (string) - The name of the trait. - **methods** (array) - A list of methods provided by the trait. - **name** (string) - The name of the method. - **description** (string) - A brief description of the method. - **parameters** (array) - List of parameters for the method. - **return_type** (string) - The return type of the method. #### Response Example ```json { "traits": [ { "name": "Copy", "methods": [] }, { "name": "Eq", "methods": [] }, { "name": "StructuralPartialEq", "methods": [] }, { "name": "Freeze", "methods": [] }, { "name": "RefUnwindSafe", "methods": [] }, { "name": "Send", "methods": [] }, { "name": "Sync", "methods": [] }, { "name": "Unpin", "methods": [] }, { "name": "UnwindSafe", "methods": [] }, { "name": "Any", "methods": [ { "name": "type_id", "description": "Gets the `TypeId` of `self`.", "parameters": [], "return_type": "TypeId" } ] }, { "name": "Borrow", "methods": [ { "name": "borrow", "description": "Immutably borrows from an owned value.", "parameters": [], "return_type": "&T" } ] }, { "name": "BorrowMut", "methods": [ { "name": "borrow_mut", "description": "Mutably borrows from an owned value.", "parameters": [], "return_type": "&mut T" } ] }, { "name": "CloneToUninit", "methods": [ { "name": "clone_to_uninit", "description": "Performs copy-assignment from `self` to `dest`.", "parameters": [ { "name": "dest", "type": "*mut u8", "description": "Pointer to the destination memory." } ], "return_type": "()" } ] }, { "name": "From", "methods": [ { "name": "from", "description": "Returns the argument unchanged.", "parameters": [ { "name": "t", "type": "T", "description": "The value to convert." } ], "return_type": "T" } ] }, { "name": "Instrument", "methods": [ { "name": "instrument", "description": "Instruments this type with the provided `Span`, returning an `Instrumented` wrapper.", "parameters": [ { "name": "span", "type": "Span", "description": "The span to instrument with." } ], "return_type": "Instrumented" }, { "name": "in_current_span", "description": "Instruments this type with the current `Span`, returning an `Instrumented` wrapper.", "parameters": [], "return_type": "Instrumented" } ] }, { "name": "Into", "methods": [ { "name": "into", "description": "Calls `U::from(self)`.", "parameters": [], "return_type": "U" } ] }, { "name": "ToOwned", "methods": [ { "name": "to_owned", "description": "Creates owned data from borrowed data, usually by cloning.", "parameters": [], "return_type": "T" }, { "name": "clone_into", "description": "Uses borrowed data to replace owned data, usually by cloning.", "parameters": [ { "name": "target", "type": "&mut T", "description": "The mutable reference to the owned data to be replaced." } ], "return_type": "()" } ] }, { "name": "TryFrom", "methods": [ { "name": "try_from", "description": "Performs the conversion.", "parameters": [ { "name": "value", "type": "U", "description": "The value to convert." } ], "return_type": "Result>::Error>" } ] }, { "name": "TryInto", "methods": [ { "name": "try_into", "description": "Performs the conversion.", "parameters": [], "return_type": "Result>::Error>" } ] }, { "name": "WithSubscriber", "methods": [ { "name": "with_subscriber", "description": "Attaches the provided `Subscriber` to this type, returning a `WithDispatch` wrapper.", "parameters": [ { "name": "subscriber", "type": "S", "description": "The subscriber to attach." } ], "return_type": "WithDispatch" }, { "name": "with_current_subscriber", "description": "Attaches the current default `Subscriber` to this type, returning a `WithDispatch` wrapper.", "parameters": [], "return_type": "WithDispatch" } ] }, { "name": "DeserializeOwned", "methods": [] } ] } ``` ``` -------------------------------- ### GET /is_readable Source: https://docs.rs/evdevil/0.4.0/src/evdevil/evdev.rs.html Checks if the device has pending events that can be read without blocking. ```APIDOC ## GET /is_readable ### Description Returns whether this device has any pending raw events that can be read without blocking. ### Method GET ### Response #### Success Response (200) - **readable** (bool) - True if events are available, false otherwise. ``` -------------------------------- ### Get Flat Value Source: https://docs.rs/evdevil/0.4.0/src/evdevil/abs_info.rs.html Returns the flat value of the axis, which configures the deadzone. ```rust pub const fn flat(&self) -> i32 { self.0.flat } ``` -------------------------------- ### Create UinputDevice from OwnedFd Source: https://docs.rs/evdevil/0.4.0/evdevil/uinput/struct.UinputDevice.html Creates a UinputDevice instance from an existing owned file descriptor. ```APIDOC ## POST /uinput/device/from_owned_fd ### Description Creates a `UinputDevice` instance from a bare file descriptor. ### Method POST ### Endpoint `/uinput/device/from_owned_fd` ### Parameters #### Request Body - **owned_fd** (OwnedFd) - Required - The owned file descriptor referring to a uinput character device. ### Response #### Success Response (200) - **UinputDevice** (object) - The created UinputDevice instance. #### Response Example (UinputDevice object representation) ### Safety `owned_fd` must refer to a uinput character device. Using a file descriptor for an `evdev` device can lead to undefined behavior. ``` -------------------------------- ### Get Evdev Device Name Source: https://docs.rs/evdevil/0.4.0/evdevil/struct.Evdev.html Retrieves the human-readable name of the evdev device. ```rust pub fn name(&self) -> Result ``` -------------------------------- ### Initialize HotplugMonitor Source: https://docs.rs/evdevil/0.4.0/src/evdevil/hotplug.rs.html Creates a new HotplugMonitor to start listening for hotplug events. This operation is blocking and may fail on unsupported platforms or if connection to the system's hotplug mechanism fails. Callers should degrade gracefully if this fails. ```rust pub fn new() -> io::Result { Ok(Self { imp: Impl::open()? }) } ``` -------------------------------- ### Get Waveform Type Source: https://docs.rs/evdevil/0.4.0/evdevil/ff/struct.Periodic.html Retrieves the type of Waveform used by this Periodic effect. ```rust pub fn waveform(&self) -> Waveform ``` -------------------------------- ### AbsSetup Struct API Source: https://docs.rs/evdevil/0.4.0/evdevil/uinput/struct.AbsSetup.html Methods for creating and inspecting absolute axis configuration. ```APIDOC ## Struct AbsSetup ### Description Represents absolute axis setup information used by `Builder::with_abs_axes`. ### Methods #### new(abs: Abs, abs_info: AbsInfo) -> Self Creates a new `AbsSetup` value that configures the given `Abs` axis. #### abs(&self) -> Abs Returns the `Abs` axis this `AbsSetup` is configuring. #### abs_info(&self) -> &AbsInfo Returns the `AbsInfo` configuration that is applied to the `Abs` axis. ``` -------------------------------- ### Get Attack Length Source: https://docs.rs/evdevil/0.4.0/evdevil/ff/struct.Envelope.html Retrieves the configured attack length in milliseconds for the envelope. ```rust pub fn attack_length(&self) -> u16 ``` -------------------------------- ### Enumerate devices with hot-plug support Source: https://docs.rs/evdevil/0.4.0/src/evdevil/enumerate.rs.html Yields currently connected devices and then blocks to wait for new devices to be plugged in. If the hotplug monitor fails to initialize, it degrades to only yielding currently connected devices. ```rust use evdevil::enumerate_hotplug; for res in enumerate_hotplug()? { let (path, evdev) = res?; println!("{}: {}", path.display(), evdev.name()?); } # Ok::<_, std::io::Error>(()) ``` -------------------------------- ### Effect::effect_type - Get Effect Type Source: https://docs.rs/evdevil/0.4.0/evdevil/ff/struct.Effect.html Retrieves the type of the force-feedback effect. ```rust pub fn effect_type(&self) -> EffectType ``` -------------------------------- ### Get Abs Value from AbsEvent Source: https://docs.rs/evdevil/0.4.0/evdevil/event/struct.AbsEvent.html Retrieves the Abs value associated with the AbsEvent. ```rust pub fn abs(&self) -> Abs ``` -------------------------------- ### Initialize MtStorage Source: https://docs.rs/evdevil/0.4.0/src/evdevil/reader.rs.html Logic to initialize MtStorage from an Evdev device, validating MT slot support and fetching current axis values. ```rust impl MtStorage { fn empty() -> Self { Self { data: Vec::new(), slots: 0, codes: 0, active_slot: 0, } } fn current(evdev: &Evdev, abs_axes: &BitSet) -> io::Result { let mut this = Self { data: Vec::new(), slots: 0, codes: 0, active_slot: 0, }; if !abs_axes.contains(Abs::MT_SLOT) { return Ok(this); } if !abs_axes.contains(Abs::MT_TRACKING_ID) { log::warn!( "device {} advertises support for `ABS_MT_SLOT` but not `ABS_MT_TRACKING_ID`; multitouch support will not work", evdev .name() .unwrap_or_else(|e| format!("(failed to fetch name: {e})")), ); return Ok(this); } let mt_slot_info = evdev.abs_info(Abs::MT_SLOT)?; if mt_slot_info.minimum() != 0 { log::warn!("`ABS_MT_SLOT` has a non-0 minimum: {:?}", mt_slot_info); } let slot_count = mt_slot_info.maximum().saturating_add(1); if mt_slot_info.maximum() > MAX_MT_SLOTS { log::warn!( "`ABS_MT_SLOT` declares too many slots: {:?} (only the first {} will be used)", mt_slot_info, MAX_MT_SLOTS, ); } this.slots = slot_count.clamp(0, MAX_MT_SLOTS) as u32; this.active_slot = mt_slot_info.value().max(0) as u32; this.data.clear(); this.codes = 0; for mt_code in Abs::MT_SLOT.raw() + 1..Abs::MAX.raw() { if !abs_axes.contains(Abs::from_raw(mt_code)) { continue; } // `mt_code` is supported; fetch its current value for all slots, appending it to `data` this.codes += 1; let start_idx = this.data.len(); this.data .resize(this.data.len() + 1 + this.slots as usize, 0); this.data[start_idx] = mt_code.into(); unsafe { evdev.ioctl( "EVIOCGMTSLOTS", EVIOCGMTSLOTS((this.slots as usize + 1) * 4), ``` -------------------------------- ### enumerate() Source: https://docs.rs/evdevil/0.4.0/src/evdevil/enumerate.rs.html Enumerates all currently plugged-in Evdev devices by scanning /dev/input. ```APIDOC ## enumerate() ### Description Enumerates all currently plugged-in Evdev devices. This function is blocking and should be performed in a background thread for interactive applications. ### Response - **Iterator** (Result) - An iterator yielding Result<(PathBuf, Evdev)> for each discovered device. ``` -------------------------------- ### Implement IntoRawFd for UinputDevice Source: https://docs.rs/evdevil/0.4.0/src/evdevil/uinput.rs.html Allows consuming the UinputDevice to get its raw file descriptor. ```rust impl IntoRawFd for UinputDevice { #[inline] fn into_raw_fd(self) -> RawFd { self.file.into_raw_fd() } } ``` -------------------------------- ### Initialize Tokio AsyncFd Source: https://docs.rs/evdevil/0.4.0/src/evdevil/util/async.rs.html Creates a new Tokio AsyncFd for a given file descriptor, registering it with READABLE interest. This is crucial for integrating with the Tokio event loop. ```rust pub fn new(fd: RawFd) -> io::Result { // Note: only register with READABLE interest; otherwise this fails with EINVAL on FreeBSD. let fd = AsyncFd::with_interest(fd, Interest::READABLE)?; Ok(Self(fd)) } ``` -------------------------------- ### Get Center Value from Condition Source: https://docs.rs/evdevil/0.4.0/src/evdevil/ff.rs.html Retrieves the current center value from the Condition struct. ```rust pub fn center(&self) -> i16 { self.0.center } ``` -------------------------------- ### CloneToUninit for T Source: https://docs.rs/evdevil/0.4.0/evdevil/event/enum.EventKind.html Nightly-only experimental API for cloning to uninitialized memory. ```APIDOC ## impl CloneToUninit for T where T: Clone ### unsafe fn clone_to_uninit(&self, dest: *mut u8) Performs copy-assignment from `self` to `dest`. ``` -------------------------------- ### Get Ramp Effect End Level Source: https://docs.rs/evdevil/0.4.0/src/evdevil/ff.rs.html Retrieves the ending level for the ramp effect. ```rust pub fn end_level(&self) -> i16 { self.0.end_level } ``` -------------------------------- ### Get Envelope for Constant Effect Source: https://docs.rs/evdevil/0.4.0/src/evdevil/ff.rs.html Retrieves the envelope settings applied to this Constant effect. ```rust pub fn envelope(&self) -> Envelope { Envelope(self.0.envelope) } ``` -------------------------------- ### Ioctl for LEDs Source: https://docs.rs/evdevil/0.4.0/src/evdevil/raw/input.rs.html Use EVIOCGLED with a specified length to retrieve the state of all LEDs. ```rust /// Get all LEDs. pub const fn EVIOCGLED(len: usize) -> Ioctl<*mut c_void> { _IOC(_IOC_READ, b'E', 0x19, len) } ``` -------------------------------- ### Define raw module structure Source: https://docs.rs/evdevil/0.4.0/src/evdevil/raw.rs.html Initializes the input and uinput modules within the raw namespace. ```rust 1#![allow(bad_style)] 3pub mod input; 4pub mod uinput; ``` -------------------------------- ### Get Constant Effect Level Source: https://docs.rs/evdevil/0.4.0/src/evdevil/ff.rs.html Retrieves the constant force level applied by this effect. ```rust pub fn level(&self) -> i16 { self.0.level } ``` -------------------------------- ### Configure Device Properties Source: https://docs.rs/evdevil/0.4.0/src/evdevil/uinput.rs.html Sets input properties for the device, such as identifying it as a drawing tablet. ```rust pub fn with_props(self, props: impl IntoIterator) -> io::Result { for prop in props { unsafe { self.device .ioctl("UI_SET_PROPBIT", UI_SET_PROPBIT, prop.0.into())?; } } Ok(self) } ``` -------------------------------- ### Get driver version Source: https://docs.rs/evdevil/0.4.0/src/evdevil/evdev.rs.html Retrieves the evdev subsystem version using the EVIOCGVERSION ioctl. ```rust pub fn driver_version(&self) -> io::Result { unsafe { let mut version = 0; self.ioctl("EVIOCGVERSION", EVIOCGVERSION, &mut version)?; Ok(Version(version)) } } ``` -------------------------------- ### EVIOCGMASK - Get Event Mask Source: https://docs.rs/evdevil/0.4.0/src/evdevil/raw/input.rs.html Retrieves the current event mask for the input device. ```APIDOC ## EVIOCGMASK ### Description Get the event mask. ### Method IOCTL ### Endpoint N/A (Kernel IOCTL) ### Parameters #### Path Parameters None #### Query Parameters None #### Request Body None ### Response #### Success Response (200) - **mask** (*mut input_mask) - Pointer to a structure to be filled with the event mask. ``` -------------------------------- ### Builder Configuration Source: https://docs.rs/evdevil/0.4.0/src/evdevil/uinput.rs.html Methods for configuring the uinput device builder, including force-feedback and autorepeat settings. ```APIDOC ## Builder Configuration Methods ### `with_ff_effects_max(ff_max: u32)` Advertises support for a maximum number of force-feedback events. - **ff_max** (u32) - Required - The maximum number of force-feedback effects the device can accept. ### `with_ff_features(feat: impl IntoIterator)` Advertises specific force-feedback capabilities. - **feat** (Iterator of `ff::Feature`) - Required - The force-feedback features to enable. ### `with_key_repeat()` Enables support for autorepeat functionality. This allows for `RepeatEvent`s to be written and for clients to query/modify key repeat settings. ``` -------------------------------- ### Clone UinputDevice Source: https://docs.rs/evdevil/0.4.0/evdevil/uinput/struct.UinputDevice.html Creates a new UinputDevice instance that shares the same underlying file handle. ```APIDOC ## POST /uinput/device/clone ### Description Creates a new `UinputDevice` instance that refers to the same underlying file handle. ### Method POST ### Endpoint `/uinput/device/clone` ### Parameters None ### Request Body None ### Response #### Success Response (200) - **UinputDevice** (object) - A new `UinputDevice` instance sharing the same handle. #### Response Example (UinputDevice object representation) ### Notes All properties, such as whether the handle is in non-blocking mode, will be shared between the instances. ``` -------------------------------- ### Ioctl for Getting Driver Version Source: https://docs.rs/evdevil/0.4.0/src/evdevil/raw/input.rs.html Use EVIOCGVERSION to retrieve the version of the input driver. ```rust /// Get driver version. pub const EVIOCGVERSION: Ioctl<*mut c_int> = _IOR(b'E', 0x01); ```