17 unstable releases

0.9.1 Sep 27, 2024
0.9.0 Jan 19, 2024
0.8.3 Jul 7, 2023
0.8.2 Jan 31, 2023
0.2.0 Jun 7, 2017

#48 in GUI

Download history 14522/week @ 2024-08-05 13847/week @ 2024-08-12 14288/week @ 2024-08-19 14383/week @ 2024-08-26 15241/week @ 2024-09-02 13799/week @ 2024-09-09 15339/week @ 2024-09-16 16573/week @ 2024-09-23 18004/week @ 2024-09-30 16302/week @ 2024-10-07 15037/week @ 2024-10-14 16641/week @ 2024-10-21 14964/week @ 2024-10-28 17652/week @ 2024-11-04 6767/week @ 2024-11-11 6727/week @ 2024-11-18

46,945 downloads per month
Used in 35 crates (13 directly)

MIT license

1.5MB
14K 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);
        }
    }
}

Dependencies