9 stable releases

1.18.0 Jan 19, 2024
1.17.0 Jan 18, 2023
1.16.1 Dec 11, 2021
1.16.0 Sep 30, 2021
1.7.1 Jun 7, 2017

#255 in Operating systems

Download history 2580/week @ 2023-12-23 3417/week @ 2023-12-30 4000/week @ 2024-01-06 4726/week @ 2024-01-13 5860/week @ 2024-01-20 6555/week @ 2024-01-27 5777/week @ 2024-02-03 6246/week @ 2024-02-10 7242/week @ 2024-02-17 5731/week @ 2024-02-24 5224/week @ 2024-03-02 6116/week @ 2024-03-09 5950/week @ 2024-03-16 5894/week @ 2024-03-23 5449/week @ 2024-03-30 4308/week @ 2024-04-06

22,390 downloads per month
Used in 29 crates (via input)

MIT license

1MB
11K SLoC

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.

Note: Due to a bug within libinput, these bindings are not compatible with libinput 1.19.0. Please use the fixed 1.19.1 version.

Usage

Add to your Cargo.toml:

input = "0.8"

Install the libinput dev dependencies:

Ubuntu:

apt-get install libinput-dev

Fedora

dnf install libinput-devel

Configure and run event loop:

use input::{Libinput, LibinputInterface};
use libc::{O_RDONLY, O_RDWR, O_WRONLY};
use std::fs::{File, OpenOptions};
use std::os::unix::{fs::OpenOptionsExt, io::OwnedFd};
use std::path::Path;

struct Interface;

impl LibinputInterface for Interface {
    fn open_restricted(&mut self, path: &Path, flags: i32) -> Result<OwnedFd, 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())
            .map_err(|err| err.raw_os_error().unwrap())
    }
    fn close_restricted(&mut self, fd: OwnedFd) {
        drop(File::from(fd));
    }
}

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

No runtime deps