[][src]Crate input

Libinput bindings for rust

These bindings closely follow libinput's concepts and it's original API. Please refer to the libinput documentation to understand the general structure and concepts.

Differences to the C-Library:

  • Refcounting does not need to be done manually. Just call clone when you need an additional reference.
  • Libinput logging cannot (currently) not be customized.

Userdata handling

Multiple types in the libinput library allow to attach a pointer of an arbitrary type, so called userdata. Using this data is unsafe as there is no way to find out what type is stored in the libinput struct. Additionally multiple references to the same libinput object may exist and userdata may be shared mutably.

This is why using and setting userdata is an unsafe operation (except when creating an object).

If you heavily rely on userdata, you should always stored them wrapped in a Mutex and use the same type for every userdata access to further simplify usage.

You need to be especially cautious when initializing libinput types from raw pointers, you obtained from other libraries which may set their own userdata. If accessing their userdata make sure no shared mutable access may happen and don't store something else instead, if the library does not explicitly allow this.

Generally usage of this api is error-prone and discouraged if not needed.

Getting started

To get started check out the Libinput struct.

Here's a small example that prints all events:

extern crate input;
use input::{Libinput, LibinputInterface};
use std::fs::{File, OpenOptions};
use std::os::unix::fs::OpenOptionsExt;
use std::os::unix::io::{RawFd, FromRawFd, IntoRawFd};
use std::path::Path;
 
extern crate libc;
use libc::{O_RDONLY, O_RDWR, O_WRONLY};
 
struct Interface;
 
impl LibinputInterface for Interface {
	fn open_restricted(&mut self, path: &Path, flags: i32) -> Result<RawFd, i32> {
		OpenOptions::new()
		    .custom_flags(flags)
		    .read((flags & O_RDONLY != 0) | (flags & O_RDWR != 0))
		    .write((flags & O_WRONLY != 0) | (flags & O_RDWR != 0))
			.open(path)
			.map(|file| file.into_raw_fd())
			.map_err(|err| err.raw_os_error().unwrap())
	}
	fn close_restricted(&mut self, fd: RawFd) {
		unsafe {
			File::from_raw_fd(fd);
		}
	}
}
 
fn main() {
	let mut input = Libinput::new_with_udev(Interfacep());
	input.udev_assign_seat("seat0").unwrap();
	loop {
		input.dispatch().unwrap();
		for event in &mut input {
			println!("Got event: {:?}", event);
		}
	}
}

Re-exports

pub use event::Event;

Modules

event

Libinput Events

ffi

Unsafe c-api.

Structs

Device

Representation of a single input device as seen by the kernel.

DeviceGroup

Device group

Led

Mask reflecting LEDs on a device.

Libinput

Libinput context

Seat

A seat has two identifiers, the physical name and the logical name.

SendEventsMode

The send-event mode of a device defines when a device may generate events and pass those events to the caller.

Enums

AccelProfile

Pointer Acceleration Profile

ClickMethod

The click method defines when to generate software-emulated buttons, usually on a device that does not have a specific physical button available.

DeviceCapability

Capabilities on a device.

DeviceConfigError

Errors returned when applying configuration settings.

ScrollButtonLockState

Whenever scroll button lock is enabled or not

ScrollMethod

The scroll method of a device selects when to generate scroll axis events instead of pointer motion events.

TapButtonMap

Map 1/2/3 finger tips to buttons

Traits

AsRaw

Trait for types that allow to optain the underlying raw libinput pointer.

Context

Trait to receive the underlying context

FromRaw

Trait for types that allow to be initialized from a raw pointer

LibinputInterface

libinput does not open file descriptors to devices directly, instead open_restricted and close_restricted are called for each path that must be opened.

Type Definitions

DeviceConfigResult

Result returned when applying configuration settings.