uinput_sys/
lib.rs

1extern crate libc;
2
3#[macro_use]
4extern crate ioctl_sys as ioctl;
5
6use std::mem;
7
8use libc::{c_char, c_int, c_uint, c_ulong};
9use libc::{uint16_t, int32_t, uint32_t};
10use libc::timeval;
11
12macro_rules! uin {
13	(write $name:ident with $ioty:expr, $nr:expr; $ty:ty) => (
14		pub unsafe fn $name(fd: c_int, val: $ty) -> c_int {
15			ioctl::ioctl(fd, iow!($ioty, $nr, mem::size_of::<$ty>()) as c_ulong, val)
16		}
17	);
18}
19
20mod events;
21pub use events::*;
22
23pub const UINPUT_MAX_NAME_SIZE: c_int = 80;
24
25#[derive(Clone, Copy)]
26#[repr(C)]
27pub struct input_event {
28	pub time:  timeval,
29	pub kind:  uint16_t,
30	pub code:  uint16_t,
31	pub value: int32_t,
32}
33
34#[derive(Clone, Copy)]
35#[repr(C)]
36pub struct input_id {
37	pub bustype: uint16_t,
38	pub vendor:  uint16_t,
39	pub product: uint16_t,
40	pub version: uint16_t,
41}
42
43#[repr(C)]
44pub struct uinput_user_dev {
45	pub name: [c_char; UINPUT_MAX_NAME_SIZE as usize],
46	pub id:   input_id,
47
48	pub ff_effects_max: uint32_t,
49	pub absmax:  [int32_t; ABS_CNT as usize],
50	pub absmin:  [int32_t; ABS_CNT as usize],
51	pub absfuzz: [int32_t; ABS_CNT as usize],
52	pub absflat: [int32_t; ABS_CNT as usize],
53}
54
55//#[repr(C)]
56//pub struct uinput_ff_upload {
57//	pub request_id: uint32_t,
58//	pub retval:     int32_t,
59//	pub effect:     ff_effect,
60//	pub old:        ff_effect,
61//}
62//
63//#[repr(C)]
64//pub struct uinput_ff_erase {
65//	pub request_id: uint32_t,
66//	pub retval:     int32_t,
67//	pub effect_id:  uint32_t,
68//}
69
70ioctl!(none ui_dev_create with b'U', 1);
71ioctl!(none ui_dev_destroy with b'U', 2);
72
73uin!(write ui_set_evbit   with b'U', 100; c_int);
74uin!(write ui_set_keybit  with b'U', 101; c_int);
75uin!(write ui_set_relbit  with b'U', 102; c_int);
76uin!(write ui_set_absbit  with b'U', 103; c_int);
77uin!(write ui_set_mscbit  with b'U', 104; c_int);
78uin!(write ui_set_ledbit  with b'U', 105; c_int);
79uin!(write ui_set_sndbit  with b'U', 106; c_int);
80uin!(write ui_set_ffbit   with b'U', 107; c_int);
81uin!(write ui_set_phys    with b'U', 108; *const c_char);
82uin!(write ui_set_swbit   with b'U', 109; c_int);
83uin!(write ui_set_propbit with b'U', 110; c_int);
84
85//ioctl!(readwrite ui_begin_ff_upload with b'U', 200, uinput_ff_upload);
86//ioctl!(readwrite ui_end_ff_upload with b'U', 201, uinput_ff_upload);
87
88//ioctl!(readwrite ui_begin_ff_erase with b'U', 200, uinput_ff_erase);
89//ioctl!(readwrite ui_end_ff_erase with b'U', 201, uinput_ff_erase);
90
91ioctl!(read ui_get_version with b'U', 45; c_uint);