evdev-sys-0.2.5/.cargo_vcs_info.json0000644000000001120000000000100127570ustar { "git": { "sha1": "320c6f75ed750bdd3ad9e6c0036f5dc74a8e4c51" } } evdev-sys-0.2.5/Cargo.toml0000644000000020320000000000100107600ustar # THIS FILE IS AUTOMATICALLY GENERATED BY CARGO # # When uploading crates to the registry Cargo will automatically # "normalize" Cargo.toml files for maximal compatibility # with all versions of Cargo and also rewrite `path` dependencies # to registry (e.g., crates.io) dependencies # # If you believe there's an error in this file please file an # issue against the rust-lang/cargo repository. If you're # editing this file be aware that the upstream Cargo.toml # will likely look very different (and much more reasonable) [package] edition = "2018" name = "evdev-sys" version = "0.2.5" authors = ["Nayan Deshmukh Option<(u32, u32, u32)> { let mut major_minor_patch = ver_str .split(".") .map(|str| str.parse::().unwrap()); let major = major_minor_patch.next()?; let minor = major_minor_patch.next()?; let patch = major_minor_patch.next()?; Some((major, minor, patch)) } fn main() -> Result<(), Box> { if env::var_os("TARGET") == env::var_os("HOST") { let mut config = pkg_config::Config::new(); config.print_system_libs(false); match config.probe("libevdev") { Ok(lib) => { // panic if feature 1.10 is enabled and the installed library // is older than 1.10 #[cfg(feature = "libevdev-1-10")] { let (major, minor, patch) = parse_version(&lib.version) .expect("Could not parse version information"); assert_eq!(major, 1, "evdev-rs works only with libevdev 1"); assert!(minor >= 10, "Feature libevdev-1-10 was enabled, when compiling \ for a system with libevdev version {}.{}.{}", major, minor, patch, ); } for path in &lib.include_paths { println!("cargo:include={}", path.display()); } return Ok(()); } Err(e) => eprintln!( "Couldn't find libevdev from pkgconfig ({:?}), \ compiling it from source...", e ), }; } if !Path::new("libevdev/.git").exists() { let mut download = Command::new("git"); download.args(&["submodule", "update", "--init", "--depth", "1"]); run_ignore_error(&mut download)?; } let dst = PathBuf::from(env::var_os("OUT_DIR").unwrap()); let src = env::current_dir()?; let mut cp = Command::new("cp"); cp.arg("-r") .arg(&src.join("libevdev/")) .arg(&dst) .current_dir(&src); run(&mut cp)?; println!("cargo:rustc-link-search={}/lib", dst.display()); println!("cargo:root={}", dst.display()); println!("cargo:include={}/include", dst.display()); println!("cargo:rerun-if-changed=libevdev"); println!("cargo:rustc-link-lib=static=evdev"); let cfg = cc::Build::new(); let compiler = cfg.get_compiler(); if !&dst.join("build").exists() { fs::create_dir(&dst.join("build"))?; } let mut autogen = Command::new("sh"); let mut cflags = OsString::new(); for arg in compiler.args() { cflags.push(arg); cflags.push(" "); } autogen .env("CC", compiler.path()) .env("CFLAGS", cflags) .current_dir(&dst.join("build")) .arg( dst.join("libevdev/autogen.sh") .to_str() .unwrap() .replace("C:\\", "/c/") .replace("\\", "/"), ); if let Ok(h) = env::var("HOST") { autogen.arg(format!("--host={}", h)); } if let Ok(t) = env::var("TARGET") { autogen.arg(format!("--target={}", t)); } autogen.arg(format!("--prefix={}", sanitize_sh(&dst))); run(&mut autogen)?; let mut make = Command::new("make"); make.arg(&format!("-j{}", env::var("NUM_JOBS").unwrap())) .current_dir(&dst.join("build")); run(&mut make)?; let mut install = Command::new("make"); install.arg("install").current_dir(&dst.join("build")); run(&mut install)?; Ok(()) } fn run(cmd: &mut Command) -> std::io::Result<()> { println!("running: {:?}", cmd); assert!(cmd.status()?.success()); Ok(()) } fn run_ignore_error(cmd: &mut Command) -> std::io::Result<()> { println!("running: {:?}", cmd); let _ = cmd.status(); Ok(()) } fn sanitize_sh(path: &Path) -> String { let path = path.to_str().unwrap().replace("\\", "/"); return change_drive(&path).unwrap_or(path); fn change_drive(s: &str) -> Option { let mut ch = s.chars(); let drive = ch.next().unwrap_or('C'); if ch.next() != Some(':') { return None; } if ch.next() != Some('/') { return None; } Some(format!("/{}/{}", drive, &s[drive.len_utf8() + 2..])) } } evdev-sys-0.2.5/src/lib.rs000064400000000000000000000217570072674642500135240ustar 00000000000000#![allow(bad_style)] #![allow(dead_code)] #![allow(improper_ctypes)] use libc::{c_char, c_int, c_uint, c_void, size_t}; pub use libc::{input_absinfo, input_event, timeval}; pub type __enum_ty = libc::c_int; pub type libevdev_read_flag = __enum_ty; pub type libevdev_log_priority = __enum_ty; pub type libevdev_grab_mode = __enum_ty; pub type libevdev_read_status = __enum_ty; pub type libevdev_led_value = __enum_ty; pub type libevdev_uinput_open_mode = __enum_ty; pub const LIBEVDEV_READ_FLAG_SYNC: libevdev_read_flag = 1; pub const LIBEVDEV_READ_FLAG_NORMAL: libevdev_read_flag = 2; pub const LIBEVDEV_READ_FLAG_FORCE_SYNC: libevdev_read_flag = 4; pub const LIBEVDEV_READ_FLAG_BLOCKING: libevdev_read_flag = 8; pub const LIBEVDEV_LOG_ERROR: libevdev_log_priority = 10; pub const LIBEVDEV_LOG_INFO: libevdev_log_priority = 20; pub const LIBEVDEV_LOG_DEBUG: libevdev_log_priority = 30; pub const LIBEVDEV_GRAB: libevdev_grab_mode = 3; pub const LIBEVDEV_UNGRAB: libevdev_grab_mode = 4; pub const LIBEVDEV_READ_STATUS_SUCCESS: libevdev_read_status = 0; pub const LIBEVDEV_READ_STATUS_SYNC: libevdev_read_status = 1; pub const LIBEVDEV_LED_ON: libevdev_led_value = 3; pub const LIBEVDEV_LED_OFF: libevdev_led_value = 4; pub const LIBEVDEV_UINPUT_OPEN_MANAGED: libevdev_uinput_open_mode = -2; pub enum libevdev {} pub enum libevdev_uinput {} #[repr(C)] pub struct va_list { // TODO } type libevdev_log_func_t = extern "C" fn( *const libevdev, *mut c_void, *const c_char, c_int, *const c_char, *const c_char, va_list, ); type libevdev_device_log_func_t = extern "C" fn( *const libevdev, c_int, *mut c_void, *const c_char, c_int, *const c_char, *const c_char, va_list, ); extern "C" { pub fn libevdev_new() -> *mut libevdev; pub fn libevdev_new_from_fd(fd: c_int, ctx: *mut *mut libevdev) -> c_int; pub fn libevdev_free(ctx: *mut libevdev); pub fn libevdev_set_log_function(logfunc: libevdev_log_func_t, data: *mut c_void); pub fn libevdev_set_log_priority(priority: libevdev_log_priority); pub fn libevdev_get_log_priority() -> libevdev_log_priority; pub fn libevdev_set_device_log_function( ctx: *mut libevdev, logfunc: libevdev_device_log_func_t, priority: libevdev_log_priority, data: *mut c_void, ); pub fn libevdev_grab(ctx: *mut libevdev, grab: libevdev_grab_mode) -> c_int; pub fn libevdev_set_fd(ctx: *mut libevdev, fd: c_int) -> c_int; pub fn libevdev_change_fd(ctx: *mut libevdev, fd: c_int) -> c_int; pub fn libevdev_get_fd(ctx: *mut libevdev) -> c_int; pub fn libevdev_next_event( ctx: *mut libevdev, flags: c_uint, ev: *mut input_event, ) -> c_int; pub fn libevdev_has_event_pending(ctx: *mut libevdev) -> c_int; pub fn libevdev_get_name(ctx: *const libevdev) -> *const c_char; pub fn libevdev_set_name(ctx: *mut libevdev, name: *const c_char); pub fn libevdev_get_phys(ctx: *const libevdev) -> *const c_char; pub fn libevdev_set_phys(ctx: *mut libevdev, phys: *const c_char); pub fn libevdev_get_uniq(ctx: *const libevdev) -> *const c_char; pub fn libevdev_set_uniq(ctx: *mut libevdev, uniq: *const c_char); pub fn libevdev_get_id_product(ctx: *const libevdev) -> c_int; pub fn libevdev_set_id_product(ctx: *mut libevdev, product_id: c_int); pub fn libevdev_get_id_vendor(ctx: *const libevdev) -> c_int; pub fn libevdev_set_id_vendor(ctx: *mut libevdev, vendor_id: c_int); pub fn libevdev_get_id_bustype(ctx: *const libevdev) -> c_int; pub fn libevdev_set_id_bustype(ctx: *mut libevdev, bustype: c_int); pub fn libevdev_get_id_version(ctx: *const libevdev) -> c_int; pub fn libevdev_set_id_version(ctx: *mut libevdev, version: c_int); pub fn libevdev_get_driver_version(ctx: *const libevdev) -> c_int; pub fn libevdev_has_property(ctx: *const libevdev, prop: c_uint) -> c_int; pub fn libevdev_enable_property(ctx: *mut libevdev, prop: c_uint) -> c_int; #[cfg(feature = "libevdev-1-10")] pub fn libevdev_disable_property (ctx: *mut libevdev, prop: c_uint) -> c_int; pub fn libevdev_has_event_type(ctx: *const libevdev, type_: c_uint) -> c_int; pub fn libevdev_has_event_code( ctx: *const libevdev, type_: c_uint, code: c_uint, ) -> c_int; pub fn libevdev_get_abs_minimum(ctx: *const libevdev, code: c_uint) -> c_int; pub fn libevdev_get_abs_maximum(ctx: *const libevdev, code: c_uint) -> c_int; pub fn libevdev_get_abs_fuzz(ctx: *const libevdev, code: c_uint) -> c_int; pub fn libevdev_get_abs_flat(ctx: *const libevdev, code: c_uint) -> c_int; pub fn libevdev_get_abs_resolution(ctx: *const libevdev, code: c_uint) -> c_int; pub fn libevdev_get_abs_info( ctx: *const libevdev, code: c_uint, ) -> *const input_absinfo; pub fn libevdev_get_event_value( ctx: *const libevdev, type_: c_uint, code: c_uint, ) -> c_int; pub fn libevdev_set_event_value( ctx: *mut libevdev, type_: c_uint, code: c_uint, value: c_int, ) -> c_int; pub fn libevdev_fetch_event_value( ctx: *const libevdev, type_: c_uint, code: c_uint, value: *mut c_int, ) -> c_int; pub fn libevdev_get_slot_value( ctx: *const libevdev, slot: c_uint, code: c_uint, ) -> c_int; pub fn libevdev_set_slot_value( ctx: *mut libevdev, slot: c_uint, code: c_uint, value: c_int, ) -> c_int; pub fn libevdev_fetch_slot_value( ctx: *const libevdev, slot: c_uint, code: c_uint, value: *mut c_int, ) -> c_int; pub fn libevdev_get_num_slots(ctx: *const libevdev) -> c_int; pub fn libevdev_get_current_slot(ctx: *const libevdev) -> c_int; pub fn libevdev_set_abs_minimum(ctx: *mut libevdev, code: c_uint, min: c_int); pub fn libevdev_set_abs_maximum(ctx: *mut libevdev, code: c_uint, max: c_int); pub fn libevdev_set_abs_fuzz(ctx: *mut libevdev, code: c_uint, fuzz: c_int); pub fn libevdev_set_abs_flat(ctx: *mut libevdev, code: c_uint, flat: c_int); pub fn libevdev_set_abs_resolution( ctx: *mut libevdev, code: c_uint, resolution: c_int, ); pub fn libevdev_set_abs_info( ctx: *mut libevdev, code: c_uint, abs: *const input_absinfo, ); pub fn libevdev_enable_event_type(ctx: *mut libevdev, type_: c_uint) -> c_int; pub fn libevdev_disable_event_type(ctx: *mut libevdev, type_: c_uint) -> c_int; pub fn libevdev_enable_event_code( ctx: *mut libevdev, type_: c_uint, code: c_uint, data: *const c_void, ) -> c_int; pub fn libevdev_disable_event_code( ctx: *mut libevdev, type_: c_uint, code: c_uint, ) -> c_int; pub fn libevdev_kernel_set_abs_info( ctx: *mut libevdev, code: c_uint, abs: *const input_absinfo, ) -> c_int; pub fn libevdev_kernel_set_led_value( ctx: *mut libevdev, code: c_uint, value: libevdev_led_value, ) -> c_int; pub fn libevdev_kernel_set_led_values(ctx: *mut libevdev, ...) -> c_int; pub fn libevdev_set_clock_id(ctx: *mut libevdev, clockid: c_int) -> c_int; pub fn libevdev_event_is_type(ev: *const input_event, type_: c_uint) -> c_int; pub fn libevdev_event_is_code( ev: *const input_event, type_: c_uint, code: c_uint, ) -> c_int; pub fn libevdev_event_type_get_name(type_: c_uint) -> *const c_char; pub fn libevdev_event_code_get_name(type_: c_uint, code: c_uint) -> *const c_char; pub fn libevdev_property_get_name(prop: c_uint) -> *const c_char; pub fn libevdev_event_type_get_max(type_: c_uint) -> c_int; pub fn libevdev_event_type_from_name(name: *const c_char) -> c_int; pub fn libevdev_event_type_from_name_n(name: *const c_char, len: size_t) -> c_int; pub fn libevdev_event_code_from_name(type_: c_uint, name: *const c_char) -> c_int; pub fn libevdev_event_code_from_name_n( type_: c_uint, name: *const c_char, len: size_t, ) -> c_int; pub fn libevdev_property_from_name(name: *const c_char) -> c_int; pub fn libevdev_property_from_name_n(name: *const c_char, len: size_t) -> c_int; pub fn libevdev_get_repeat( ctx: *const libevdev, delay: *mut c_int, period: *mut c_int, ) -> c_int; pub fn libevdev_uinput_create_from_device( ctx: *const libevdev, uinput_fd: c_int, uinput_dev: *mut *mut libevdev_uinput, ) -> c_int; pub fn libevdev_uinput_destroy(uinput_dev: *mut libevdev_uinput); pub fn libevdev_uinput_get_devnode(uinput_dev: *mut libevdev_uinput) -> *const c_char; pub fn libevdev_uinput_get_fd(uinput_dev: *const libevdev_uinput) -> c_int; pub fn libevdev_uinput_get_syspath(uinput_dev: *mut libevdev_uinput) -> *const c_char; pub fn libevdev_uinput_write_event( uinput_dev: *const libevdev_uinput, type_: c_uint, code: c_uint, value: c_int, ) -> c_int; }