Rust libinput bindings

Build Status Crates.io License Docs

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.

Usage

Add to your Cargo.toml:

toml input = "0.5"

Configure and run event loop:

```rust use std::fs::{File, OpenOptions}; use std::os::unix::{fs::OpenOptionsExt, io::{RawFd, FromRawFd, IntoRawFd}}; use std::path::Path;

use input::{Libinput, LibinputInterface}; use libc::{ORDONLY, ORDWR, O_WRONLY};

struct Interface;

impl LibinputInterface for Interface { fn openrestricted(&mut self, path: &Path, flags: i32) -> Result { OpenOptions::new() .customflags(flags) .read((flags & ORDONLY != 0) | (flags & ORDWR != 0)) .write((flags & OWRONLY != 0) | (flags & ORDWR != 0)) .open(path) .map(|file| file.intorawfd()) .maperr(|err| err.rawoserror().unwrap()) } fn closerestricted(&mut self, fd: RawFd) { unsafe { File::fromrawfd(fd); } } }

fn main() { let mut input = Libinput::newwithudev(Interface); input.udevassignseat("seat0").unwrap(); loop { input.dispatch().unwrap(); for event in &mut input { println!("Got event: {:?}", event); } } } ```