#wayland #input #bindings

sys input-sys

Bindgen generated unsafe libinput wrapper

5 stable releases

1.15.1 Jul 5, 2021
1.15.0 Apr 11, 2020
1.9.0 Dec 6, 2017
1.7.1 Jun 7, 2017
1.7.0 Apr 14, 2017

#64 in Operating systems

Download history 48/week @ 2021-04-02 80/week @ 2021-04-09 63/week @ 2021-04-16 56/week @ 2021-04-23 140/week @ 2021-04-30 120/week @ 2021-05-07 123/week @ 2021-05-14 163/week @ 2021-05-21 137/week @ 2021-05-28 131/week @ 2021-06-04 98/week @ 2021-06-11 98/week @ 2021-06-18 159/week @ 2021-06-25 232/week @ 2021-07-02 482/week @ 2021-07-09 317/week @ 2021-07-16

495 downloads per month
Used in 5 crates (via input)

MIT license

4MB
83K 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.

Usage

Add to your Cargo.toml:

input = "0.5"

Configure and run event loop:

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::{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(Interface);
    input.udev_assign_seat("seat0").unwrap();
    loop {
        input.dispatch().unwrap();
        for event in &mut input {
            println!("Got event: {:?}", event);
        }
    }
}

Dependencies