Edition 2018 (#25)

* Edition 2018
* cargo fmt
* Bump rev to 0.11.0-alpha-2
* Change FF_MAX and KEY_MAX to associated constants
This commit is contained in:
Jeff Hiner 2021-02-20 19:26:34 -07:00 committed by GitHub
parent fe3d0e9ab0
commit 4e700d4671
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
4 changed files with 814 additions and 663 deletions

View file

@ -1,11 +1,12 @@
[package] [package]
name = "evdev" name = "evdev"
version = "0.11.0-alpha.1" version = "0.11.0-alpha.2"
authors = ["Corey Richardson <corey@octayn.net>"] authors = ["Corey Richardson <corey@octayn.net>"]
description = "evdev interface for Linux" description = "evdev interface for Linux"
license = "Apache-2.0 OR MIT" license = "Apache-2.0 OR MIT"
repository = "https://github.com/cmr/evdev" repository = "https://github.com/cmr/evdev"
documentation = "https://docs.rs/evdev" documentation = "https://docs.rs/evdev"
edition = "2018"
[dependencies] [dependencies]
bitflags = "1.2" bitflags = "1.2"

View file

@ -34,38 +34,31 @@
#![cfg(any(unix, target_os = "android"))] #![cfg(any(unix, target_os = "android"))]
#![allow(non_camel_case_types)] #![allow(non_camel_case_types)]
#[macro_use]
extern crate bitflags;
#[macro_use]
extern crate nix;
extern crate libc;
extern crate fixedbitset;
extern crate num_traits;
pub mod raw; pub mod raw;
mod scancodes;
use std::os::unix::{io::RawFd, ffi::*}; use bitflags::bitflags;
use std::path::Path;
use std::ffi::{CString, CStr};
use std::mem::{size_of, transmute};
use fixedbitset::FixedBitSet; use fixedbitset::FixedBitSet;
use nix::Error; use nix::Error;
use std::ffi::{CStr, CString};
use std::mem::{size_of, transmute};
use std::os::unix::{ffi::*, io::RawFd};
use std::path::Path;
pub use Key::*; pub use crate::scancodes::*;
pub use FFEffect::*; pub use crate::FFEffect::*;
pub use Synchronization::*; pub use crate::Synchronization::*;
use raw::*; use crate::raw::*;
#[link(name = "rt")] #[link(name = "rt")]
extern { extern "C" {
fn clock_gettime(clkid: libc::c_int, res: *mut libc::timespec); fn clock_gettime(clkid: libc::c_int, res: *mut libc::timespec);
} }
macro_rules! do_ioctl { macro_rules! do_ioctl {
($name:ident($($arg:expr),+)) => {{ ($name:ident($($arg:expr),+)) => {{
unsafe { ::raw::$name($($arg,)+) }? unsafe { crate::raw::$name($($arg,)+) }?
}} }}
} }
@ -73,15 +66,15 @@ macro_rules! do_ioctl_buf {
($buf:ident, $name:ident, $fd:expr) => { ($buf:ident, $name:ident, $fd:expr) => {
unsafe { unsafe {
let blen = $buf.len(); let blen = $buf.len();
match ::raw::$name($fd, &mut $buf[..]) { match crate::raw::$name($fd, &mut $buf[..]) {
Ok(len) if len >= 0 => { Ok(len) if len >= 0 => {
$buf[blen - 1] = 0; $buf[blen - 1] = 0;
Some(CStr::from_ptr(&mut $buf[0] as *mut u8 as *mut _).to_owned()) Some(CStr::from_ptr(&mut $buf[0] as *mut u8 as *mut _).to_owned())
}, }
_ => None _ => None,
}
} }
} }
};
} }
bitflags! { bitflags! {
@ -144,8 +137,6 @@ bitflags! {
} }
} }
include!("scancodes.rs"); // it's a huge glob of text that I'm tired of skipping over.
bitflags! { bitflags! {
pub struct RelativeAxis: u32 { pub struct RelativeAxis: u32 {
const REL_X = 1 << 0x00; const REL_X = 1 << 0x00;
@ -331,7 +322,10 @@ pub enum FFEffect {
FF_CUSTOM = 0x5d, FF_CUSTOM = 0x5d,
FF_GAIN = 0x60, FF_GAIN = 0x60,
FF_AUTOCENTER = 0x61, FF_AUTOCENTER = 0x61,
FF_MAX = 0x7f, }
impl FFEffect {
pub const MAX: usize = 0x7f;
} }
bitflags! { bitflags! {
@ -365,7 +359,18 @@ macro_rules! impl_number {
} }
} }
impl_number!(Types, Props, RelativeAxis, AbsoluteAxis, Switch, Led, Misc, FFStatus, Repeat, Sound); impl_number!(
Types,
Props,
RelativeAxis,
AbsoluteAxis,
Switch,
Led,
Misc,
FFStatus,
Repeat,
Sound
);
#[repr(C)] #[repr(C)]
#[derive(Copy, Clone, Debug)] #[derive(Copy, Clone, Debug)]
@ -422,7 +427,9 @@ pub struct Device {
impl std::fmt::Debug for Device { impl std::fmt::Debug for Device {
fn fmt(&self, f: &mut std::fmt::Formatter) -> std::fmt::Result { fn fmt(&self, f: &mut std::fmt::Formatter) -> std::fmt::Result {
let mut ds = f.debug_struct("Device"); let mut ds = f.debug_struct("Device");
ds.field("name", &self.name).field("fd", &self.fd).field("ty", &self.ty); ds.field("name", &self.name)
.field("fd", &self.fd)
.field("ty", &self.ty);
if let Some(ref phys) = self.phys { if let Some(ref phys) = self.phys {
ds.field("phys", phys); ds.field("phys", phys);
} }
@ -433,9 +440,7 @@ impl std::fmt::Debug for Device {
.field("id", &self.id) .field("id", &self.id)
.field("props", &self.props) .field("props", &self.props)
.field("driver_version", &self.driver_version); .field("driver_version", &self.driver_version);
if self.ty.contains(Types::SYNCHRONIZATION) { if self.ty.contains(Types::SYNCHRONIZATION) {}
}
if self.ty.contains(Types::KEY) { if self.ty.contains(Types::KEY) {
ds.field("key_bits", &self.key_bits) ds.field("key_bits", &self.key_bits)
.field("key_vals", &self.state.key_vals); .field("key_vals", &self.state.key_vals);
@ -450,13 +455,14 @@ impl std::fmt::Debug for Device {
// ignore multitouch, we'll handle that later. // ignore multitouch, we'll handle that later.
if (self.abs.bits() & abs) == 1 { if (self.abs.bits() & abs) == 1 {
// eugh. // eugh.
ds.field(&format!("abs_{:x}", idx), &self.state.abs_vals[idx as usize]); ds.field(
&format!("abs_{:x}", idx),
&self.state.abs_vals[idx as usize],
);
} }
} }
} }
if self.ty.contains(Types::MISC) { if self.ty.contains(Types::MISC) {}
}
if self.ty.contains(Types::SWITCH) { if self.ty.contains(Types::SWITCH) {
ds.field("switch", &self.switch) ds.field("switch", &self.switch)
.field("switch_vals", &self.state.switch_vals); .field("switch_vals", &self.state.switch_vals);
@ -474,8 +480,7 @@ impl std::fmt::Debug for Device {
if self.ty.contains(Types::FORCEFEEDBACK) { if self.ty.contains(Types::FORCEFEEDBACK) {
ds.field("ff", &self.ff); ds.field("ff", &self.ff);
} }
if self.ty.contains(Types::POWER) { if self.ty.contains(Types::POWER) {}
}
if self.ty.contains(Types::FORCEFEEDBACKSTATUS) { if self.ty.contains(Types::FORCEFEEDBACKSTATUS) {
ds.field("ff_stat", &self.ff_stat); ds.field("ff_stat", &self.ff_stat);
} }
@ -510,94 +515,111 @@ fn bus_name(x: u16) -> &'static str {
impl std::fmt::Display for Device { impl std::fmt::Display for Device {
fn fmt(&self, f: &mut std::fmt::Formatter) -> std::fmt::Result { fn fmt(&self, f: &mut std::fmt::Formatter) -> std::fmt::Result {
try!(writeln!(f, "{:?}", self.name)); writeln!(f, "{:?}", self.name)?;
try!(writeln!(f, " Driver version: {}.{}.{}", self.driver_version.0, self.driver_version.1, self.driver_version.2)); writeln!(
f,
" Driver version: {}.{}.{}",
self.driver_version.0, self.driver_version.1, self.driver_version.2
)?;
if let Some(ref phys) = self.phys { if let Some(ref phys) = self.phys {
try!(writeln!(f, " Physical address: {:?}", phys)); writeln!(f, " Physical address: {:?}", phys)?;
} }
if let Some(ref uniq) = self.uniq { if let Some(ref uniq) = self.uniq {
try!(writeln!(f, " Unique name: {:?}", uniq)); writeln!(f, " Unique name: {:?}", uniq)?;
} }
try!(writeln!(f, " Bus: {}", bus_name(self.id.bustype))); writeln!(f, " Bus: {}", bus_name(self.id.bustype))?;
try!(writeln!(f, " Vendor: 0x{:x}", self.id.vendor)); writeln!(f, " Vendor: 0x{:x}", self.id.vendor)?;
try!(writeln!(f, " Product: 0x{:x}", self.id.product)); writeln!(f, " Product: 0x{:x}", self.id.product)?;
try!(writeln!(f, " Version: 0x{:x}", self.id.version)); writeln!(f, " Version: 0x{:x}", self.id.version)?;
try!(writeln!(f, " Properties: {:?}", self.props)); writeln!(f, " Properties: {:?}", self.props)?;
if self.ty.contains(Types::SYNCHRONIZATION) { if self.ty.contains(Types::SYNCHRONIZATION) {}
}
if self.ty.contains(Types::KEY) { if self.ty.contains(Types::KEY) {
try!(writeln!(f, " Keys supported:")); writeln!(f, " Keys supported:")?;
for key_idx in 0..self.key_bits.len() { for key_idx in 0..self.key_bits.len() {
if self.key_bits.contains(key_idx) { if self.key_bits.contains(key_idx) {
// Cross our fingers... (what did this mean?) writeln!(
try!(writeln!(f, " {:?} ({}index {})", f,
" {:?} ({}index {})",
unsafe { std::mem::transmute::<_, Key>(key_idx as libc::c_int) }, unsafe { std::mem::transmute::<_, Key>(key_idx as libc::c_int) },
if self.state.key_vals.contains(key_idx) { "pressed, " } else { "" }, if self.state.key_vals.contains(key_idx) {
key_idx)); "pressed, "
} else {
""
},
key_idx
)?;
} }
} }
} }
if self.ty.contains(Types::RELATIVE) { if self.ty.contains(Types::RELATIVE) {
try!(writeln!(f, " Relative Axes: {:?}", self.rel)); writeln!(f, " Relative Axes: {:?}", self.rel)?;
} }
if self.ty.contains(Types::ABSOLUTE) { if self.ty.contains(Types::ABSOLUTE) {
try!(writeln!(f, " Absolute Axes:")); writeln!(f, " Absolute Axes:")?;
for idx in 0..0x3f { for idx in 0..0x3f {
let abs = 1<< idx; let abs = 1 << idx;
if self.abs.bits() & abs != 0 { if self.abs.bits() & abs != 0 {
// FIXME: abs val Debug is gross // FIXME: abs val Debug is gross
try!(writeln!(f, " {:?} ({:?}, index {})", writeln!(
f,
" {:?} ({:?}, index {})",
AbsoluteAxis::from_bits(abs).unwrap(), AbsoluteAxis::from_bits(abs).unwrap(),
self.state.abs_vals[idx as usize], self.state.abs_vals[idx as usize],
idx)); idx
)?;
} }
} }
} }
if self.ty.contains(Types::MISC) { if self.ty.contains(Types::MISC) {
try!(writeln!(f, " Miscellaneous capabilities: {:?}", self.misc)); writeln!(f, " Miscellaneous capabilities: {:?}", self.misc)?;
} }
if self.ty.contains(Types::SWITCH) { if self.ty.contains(Types::SWITCH) {
try!(writeln!(f, " Switches:")); writeln!(f, " Switches:")?;
for idx in 0..0xf { for idx in 0..0xf {
let sw = 1 << idx; let sw = 1 << idx;
if sw < Switch::SW_MAX.bits() && self.switch.bits() & sw == 1 { if sw < Switch::SW_MAX.bits() && self.switch.bits() & sw == 1 {
try!(writeln!(f, " {:?} ({:?}, index {})", writeln!(
f,
" {:?} ({:?}, index {})",
Switch::from_bits(sw).unwrap(), Switch::from_bits(sw).unwrap(),
self.state.switch_vals[idx as usize], self.state.switch_vals[idx as usize],
idx)); idx
)?;
} }
} }
} }
if self.ty.contains(Types::LED) { if self.ty.contains(Types::LED) {
try!(writeln!(f, " LEDs:")); writeln!(f, " LEDs:")?;
for idx in 0..0xf { for idx in 0..0xf {
let led = 1 << idx; let led = 1 << idx;
if led < Led::LED_MAX.bits() && self.led.bits() & led == 1 { if led < Led::LED_MAX.bits() && self.led.bits() & led == 1 {
try!(writeln!(f, " {:?} ({:?}, index {})", writeln!(
f,
" {:?} ({:?}, index {})",
Led::from_bits(led).unwrap(), Led::from_bits(led).unwrap(),
self.state.led_vals[idx as usize], self.state.led_vals[idx as usize],
idx)); idx
)?;
} }
} }
} }
if self.ty.contains(Types::SOUND) { if self.ty.contains(Types::SOUND) {
try!(writeln!(f, " Sound: {:?}", self.snd)); writeln!(f, " Sound: {:?}", self.snd)?;
} }
if self.ty.contains(Types::REPEAT) { if self.ty.contains(Types::REPEAT) {
try!(writeln!(f, " Repeats: {:?}", self.rep)); writeln!(f, " Repeats: {:?}", self.rep)?;
} }
if self.ty.contains(Types::FORCEFEEDBACK) { if self.ty.contains(Types::FORCEFEEDBACK) {
try!(writeln!(f, " Force Feedback supported")); writeln!(f, " Force Feedback supported")?;
} }
if self.ty.contains(Types::POWER) { if self.ty.contains(Types::POWER) {
try!(writeln!(f, " Power supported")); writeln!(f, " Power supported")?;
} }
if self.ty.contains(Types::FORCEFEEDBACKSTATUS) { if self.ty.contains(Types::FORCEFEEDBACKSTATUS) {
try!(writeln!(f, " Force Feedback status supported")); writeln!(f, " Force Feedback status supported")?;
} }
Ok(()) Ok(())
} }
@ -606,7 +628,9 @@ impl std::fmt::Display for Device {
impl Drop for Device { impl Drop for Device {
fn drop(&mut self) { fn drop(&mut self) {
// Linux close(2) can fail, but there is nothing to do if it does. // Linux close(2) can fail, but there is nothing to do if it does.
unsafe { libc::close(self.fd); } unsafe {
libc::close(self.fd);
}
} }
} }
@ -679,14 +703,20 @@ impl Device {
&self.state &self.state
} }
pub fn open(path: &AsRef<Path>) -> Result<Device, Error> { pub fn open(path: &dyn AsRef<Path>) -> Result<Device, Error> {
let cstr = match CString::new(path.as_ref().as_os_str().as_bytes()) { let cstr = match CString::new(path.as_ref().as_os_str().as_bytes()) {
Ok(s) => s, Ok(s) => s,
Err(_) => return Err(Error::InvalidPath), Err(_) => return Err(Error::InvalidPath),
}; };
// FIXME: only need for writing is for setting LED values. re-evaluate always using RDWR // FIXME: only need for writing is for setting LED values. re-evaluate always using RDWR
// later. // later.
let fd = unsafe { libc::open(cstr.as_ptr(), libc::O_NONBLOCK | libc::O_RDWR | libc::O_CLOEXEC, 0) }; let fd = unsafe {
libc::open(
cstr.as_ptr(),
libc::O_NONBLOCK | libc::O_RDWR | libc::O_CLOEXEC,
0,
)
};
if fd == -1 { if fd == -1 {
return Err(Error::from_errno(::nix::errno::Errno::last())); return Err(Error::from_errno(::nix::errno::Errno::last()));
} }
@ -700,26 +730,29 @@ impl Device {
id: unsafe { std::mem::zeroed() }, id: unsafe { std::mem::zeroed() },
props: Props::empty(), props: Props::empty(),
driver_version: (0, 0, 0), driver_version: (0, 0, 0),
key_bits: FixedBitSet::with_capacity(KEY_MAX as usize), key_bits: FixedBitSet::with_capacity(Key::MAX),
rel: RelativeAxis::empty(), rel: RelativeAxis::empty(),
abs: AbsoluteAxis::empty(), abs: AbsoluteAxis::empty(),
switch: Switch::empty(), switch: Switch::empty(),
led: Led::empty(), led: Led::empty(),
misc: Misc::empty(), misc: Misc::empty(),
ff: FixedBitSet::with_capacity(FF_MAX as usize + 1), ff: FixedBitSet::with_capacity(FFEffect::MAX + 1),
ff_stat: FFStatus::empty(), ff_stat: FFStatus::empty(),
rep: Repeat::empty(), rep: Repeat::empty(),
snd: Sound::empty(), snd: Sound::empty(),
pending_events: Vec::with_capacity(64), pending_events: Vec::with_capacity(64),
last_seen: 0, last_seen: 0,
state: DeviceState { state: DeviceState {
timestamp: libc::timeval { tv_sec: 0, tv_usec: 0 }, timestamp: libc::timeval {
key_vals: FixedBitSet::with_capacity(KEY_MAX as usize), tv_sec: 0,
tv_usec: 0,
},
key_vals: FixedBitSet::with_capacity(Key::MAX),
abs_vals: vec![], abs_vals: vec![],
switch_vals: FixedBitSet::with_capacity(0x10), switch_vals: FixedBitSet::with_capacity(0x10),
led_vals: FixedBitSet::with_capacity(0x10), led_vals: FixedBitSet::with_capacity(0x10),
}, },
clock: libc::CLOCK_REALTIME clock: libc::CLOCK_REALTIME,
}; };
let mut bits: u32 = 0; let mut bits: u32 = 0;
@ -736,52 +769,94 @@ impl Device {
do_ioctl!(eviocgid(fd, &mut dev.id)); do_ioctl!(eviocgid(fd, &mut dev.id));
let mut driver_version: i32 = 0; let mut driver_version: i32 = 0;
do_ioctl!(eviocgversion(fd, &mut driver_version)); do_ioctl!(eviocgversion(fd, &mut driver_version));
dev.driver_version = dev.driver_version = (
(((driver_version >> 16) & 0xff) as u8, ((driver_version >> 16) & 0xff) as u8,
((driver_version >> 8) & 0xff) as u8, ((driver_version >> 8) & 0xff) as u8,
(driver_version & 0xff) as u8); (driver_version & 0xff) as u8,
);
do_ioctl!(eviocgprop(fd, std::slice::from_raw_parts_mut(&mut bits as *mut u32 as *mut u8, 0x1f))); // FIXME: handle old kernel do_ioctl!(eviocgprop(
fd,
std::slice::from_raw_parts_mut(&mut bits as *mut u32 as *mut u8, 0x1f)
)); // FIXME: handle old kernel
dev.props = Props::from_bits(bits).expect("evdev: unexpected prop bits! report a bug"); dev.props = Props::from_bits(bits).expect("evdev: unexpected prop bits! report a bug");
if dev.ty.contains(Types::KEY) { if dev.ty.contains(Types::KEY) {
do_ioctl!(eviocgbit(fd, Types::KEY.number(), dev.key_bits.len() as libc::c_int, dev.key_bits.as_mut_slice().as_mut_ptr() as *mut u8)); do_ioctl!(eviocgbit(
fd,
Types::KEY.number(),
dev.key_bits.len() as libc::c_int,
dev.key_bits.as_mut_slice().as_mut_ptr() as *mut u8
));
} }
if dev.ty.contains(Types::RELATIVE) { if dev.ty.contains(Types::RELATIVE) {
do_ioctl!(eviocgbit(fd, Types::RELATIVE.number(), 0xf, &mut bits as *mut u32 as *mut u8)); do_ioctl!(eviocgbit(
dev.rel = RelativeAxis::from_bits(bits).expect("evdev: unexpected rel bits! report a bug"); fd,
Types::RELATIVE.number(),
0xf,
&mut bits as *mut u32 as *mut u8
));
dev.rel =
RelativeAxis::from_bits(bits).expect("evdev: unexpected rel bits! report a bug");
} }
if dev.ty.contains(Types::ABSOLUTE) { if dev.ty.contains(Types::ABSOLUTE) {
do_ioctl!(eviocgbit(fd, Types::ABSOLUTE.number(), 0x3f, &mut bits64 as *mut u64 as *mut u8)); do_ioctl!(eviocgbit(
dev.abs = AbsoluteAxis::from_bits(bits64).expect("evdev: unexpected abs bits! report a bug"); fd,
Types::ABSOLUTE.number(),
0x3f,
&mut bits64 as *mut u64 as *mut u8
));
dev.abs =
AbsoluteAxis::from_bits(bits64).expect("evdev: unexpected abs bits! report a bug");
dev.state.abs_vals = vec![input_absinfo::default(); 0x3f]; dev.state.abs_vals = vec![input_absinfo::default(); 0x3f];
} }
if dev.ty.contains(Types::SWITCH) { if dev.ty.contains(Types::SWITCH) {
do_ioctl!(eviocgbit(fd, Types::SWITCH.number(), 0xf, &mut bits as *mut u32 as *mut u8)); do_ioctl!(eviocgbit(
dev.switch = Switch::from_bits(bits).expect("evdev: unexpected switch bits! report a bug"); fd,
Types::SWITCH.number(),
0xf,
&mut bits as *mut u32 as *mut u8
));
dev.switch =
Switch::from_bits(bits).expect("evdev: unexpected switch bits! report a bug");
} }
if dev.ty.contains(Types::LED) { if dev.ty.contains(Types::LED) {
do_ioctl!(eviocgbit(fd, Types::LED.number(), 0xf, &mut bits as *mut u32 as *mut u8)); do_ioctl!(eviocgbit(
fd,
Types::LED.number(),
0xf,
&mut bits as *mut u32 as *mut u8
));
dev.led = Led::from_bits(bits).expect("evdev: unexpected led bits! report a bug"); dev.led = Led::from_bits(bits).expect("evdev: unexpected led bits! report a bug");
} }
if dev.ty.contains(Types::MISC) { if dev.ty.contains(Types::MISC) {
do_ioctl!(eviocgbit(fd, Types::MISC.number(), 0x7, &mut bits as *mut u32 as *mut u8)); do_ioctl!(eviocgbit(
fd,
Types::MISC.number(),
0x7,
&mut bits as *mut u32 as *mut u8
));
dev.misc = Misc::from_bits(bits).expect("evdev: unexpected misc bits! report a bug"); dev.misc = Misc::from_bits(bits).expect("evdev: unexpected misc bits! report a bug");
} }
//do_ioctl!(eviocgbit(fd, ffs(FORCEFEEDBACK.bits()), 0x7f, &mut bits as *mut u32 as *mut u8)); //do_ioctl!(eviocgbit(fd, ffs(FORCEFEEDBACK.bits()), 0x7f, &mut bits as *mut u32 as *mut u8));
if dev.ty.contains(Types::SOUND) { if dev.ty.contains(Types::SOUND) {
do_ioctl!(eviocgbit(fd, Types::SOUND.number(), 0x7, &mut bits as *mut u32 as *mut u8)); do_ioctl!(eviocgbit(
fd,
Types::SOUND.number(),
0x7,
&mut bits as *mut u32 as *mut u8
));
dev.snd = Sound::from_bits(bits).expect("evdev: unexpected sound bits! report a bug"); dev.snd = Sound::from_bits(bits).expect("evdev: unexpected sound bits! report a bug");
} }
try!(dev.sync_state()); dev.sync_state()?;
Ok(dev) Ok(dev)
} }
@ -791,7 +866,10 @@ impl Device {
/// If there is an error at any point, the state will not be synchronized completely. /// If there is an error at any point, the state will not be synchronized completely.
pub fn sync_state(&mut self) -> Result<(), Error> { pub fn sync_state(&mut self) -> Result<(), Error> {
if self.ty.contains(Types::KEY) { if self.ty.contains(Types::KEY) {
do_ioctl!(eviocgkey(self.fd, transmute::<&mut [u32], &mut [u8]>(self.state.key_vals.as_mut_slice()))); do_ioctl!(eviocgkey(
self.fd,
transmute::<&mut [u32], &mut [u8]>(self.state.key_vals.as_mut_slice())
));
} }
if self.ty.contains(Types::ABSOLUTE) { if self.ty.contains(Types::ABSOLUTE) {
for idx in 0..0x3f { for idx in 0..0x3f {
@ -801,15 +879,25 @@ impl Device {
// handling later removed. not sure what the intention of "handling that later" was // handling later removed. not sure what the intention of "handling that later" was
// the abs data seems to be fine (tested ABS_MT_POSITION_X/Y) // the abs data seems to be fine (tested ABS_MT_POSITION_X/Y)
if self.abs.bits() & abs != 0 { if self.abs.bits() & abs != 0 {
do_ioctl!(eviocgabs(self.fd, idx as u32, &mut self.state.abs_vals[idx as usize])); do_ioctl!(eviocgabs(
self.fd,
idx as u32,
&mut self.state.abs_vals[idx as usize]
));
} }
} }
} }
if self.ty.contains(Types::SWITCH) { if self.ty.contains(Types::SWITCH) {
do_ioctl!(eviocgsw(self.fd, transmute::<&mut [u32], &mut [u8]>(self.state.switch_vals.as_mut_slice()))); do_ioctl!(eviocgsw(
self.fd,
transmute::<&mut [u32], &mut [u8]>(self.state.switch_vals.as_mut_slice())
));
} }
if self.ty.contains(Types::LED) { if self.ty.contains(Types::LED) {
do_ioctl!(eviocgled(self.fd, transmute::<&mut [u32], &mut [u8]>(self.state.led_vals.as_mut_slice()))); do_ioctl!(eviocgled(
self.fd,
transmute::<&mut [u32], &mut [u8]>(self.state.led_vals.as_mut_slice())
));
} }
Ok(()) Ok(())
@ -823,7 +911,7 @@ impl Device {
for (idx, event) in self.pending_events[self.last_seen..].iter().enumerate() { for (idx, event) in self.pending_events[self.last_seen..].iter().enumerate() {
if event._type == SYN_DROPPED as u16 { if event._type == SYN_DROPPED as u16 {
drop_from = Some(idx); drop_from = Some(idx);
break break;
} }
} }
// FIXME: see if we can *not* drop EV_REL events. EV_REL doesn't have any state, so // FIXME: see if we can *not* drop EV_REL events. EV_REL doesn't have any state, so
@ -839,16 +927,18 @@ impl Device {
} }
self.pending_events.truncate(prev_report); self.pending_events.truncate(prev_report);
} else { } else {
return Ok(()) return Ok(());
} }
// Alright, pending_events is in a sane state. Now, let's sync the local state. We will // Alright, pending_events is in a sane state. Now, let's sync the local state. We will
// create a phony packet that contains deltas from the previous device state to the current // create a phony packet that contains deltas from the previous device state to the current
// device state. // device state.
let old_state = self.state.clone(); let old_state = self.state.clone();
try!(self.sync_state()); self.sync_state()?;
let mut time = unsafe { std::mem::zeroed() }; let mut time = unsafe { std::mem::zeroed() };
unsafe { clock_gettime(self.clock, &mut time); } unsafe {
clock_gettime(self.clock, &mut time);
}
let time = libc::timeval { let time = libc::timeval {
tv_sec: time.tv_sec, tv_sec: time.tv_sec,
tv_usec: time.tv_nsec / 1000, tv_usec: time.tv_nsec / 1000,
@ -892,7 +982,11 @@ impl Device {
time: time, time: time,
_type: Types::SWITCH.number(), _type: Types::SWITCH.number(),
code: idx as u16, code: idx as u16,
value: if self.state.switch_vals[idx as usize] { 1 } else { 0 }, value: if self.state.switch_vals[idx as usize] {
1
} else {
0
},
}); });
} }
} }
@ -907,7 +1001,11 @@ impl Device {
time: time, time: time,
_type: Types::LED.number(), _type: Types::LED.number(),
code: idx as u16, code: idx as u16,
value: if self.state.led_vals[idx as usize] { 1 } else { 0 }, value: if self.state.led_vals[idx as usize] {
1
} else {
0
},
}); });
} }
} }
@ -929,10 +1027,11 @@ impl Device {
buf.reserve(20); buf.reserve(20);
let pre_len = buf.len(); let pre_len = buf.len();
let sz = unsafe { let sz = unsafe {
libc::read(self.fd, libc::read(
buf.as_mut_ptr() self.fd,
.offset(pre_len as isize) as *mut libc::c_void, buf.as_mut_ptr().offset(pre_len as isize) as *mut libc::c_void,
(size_of::<raw::input_event>() * (buf.capacity() - pre_len)) as libc::size_t) (size_of::<raw::input_event>() * (buf.capacity() - pre_len)) as libc::size_t,
)
}; };
if sz == -1 { if sz == -1 {
let errno = ::nix::errno::Errno::last(); let errno = ::nix::errno::Errno::last();
@ -952,7 +1051,7 @@ impl Device {
/// Exposes the raw evdev events without doing synchronization on SYN_DROPPED. /// Exposes the raw evdev events without doing synchronization on SYN_DROPPED.
pub fn events_no_sync(&mut self) -> Result<RawEvents, Error> { pub fn events_no_sync(&mut self) -> Result<RawEvents, Error> {
try!(self.fill_events()); self.fill_events()?;
Ok(RawEvents::new(self)) Ok(RawEvents::new(self))
} }
@ -960,8 +1059,8 @@ impl Device {
/// ///
/// Will insert "fake" events /// Will insert "fake" events
pub fn events(&mut self) -> Result<RawEvents, Error> { pub fn events(&mut self) -> Result<RawEvents, Error> {
try!(self.fill_events()); self.fill_events()?;
try!(self.compensate_dropped()); self.compensate_dropped()?;
Ok(RawEvents(self)) Ok(RawEvents(self))
} }

View file

@ -1,3 +1,8 @@
use nix::{
convert_ioctl_res, ioctl_read, ioctl_read_buf, ioctl_write_int, ioctl_write_ptr,
request_code_read,
};
ioctl_read!(eviocgeffects, b'E', 0x84, ::libc::c_int); ioctl_read!(eviocgeffects, b'E', 0x84, ::libc::c_int);
ioctl_read!(eviocgid, b'E', 0x02, /*struct*/ input_id); ioctl_read!(eviocgid, b'E', 0x02, /*struct*/ input_id);
ioctl_read!(eviocgkeycode, b'E', 0x04, [::libc::c_uint; 2]); ioctl_read!(eviocgkeycode, b'E', 0x04, [::libc::c_uint; 2]);
@ -19,12 +24,17 @@ pub struct input_event {
pub value: i32, pub value: i32,
} }
impl ::std::default::Default for input_event { impl ::std::default::Default for input_event {
fn default() -> Self { unsafe { ::std::mem::zeroed() } } fn default() -> Self {
unsafe { ::std::mem::zeroed() }
}
} }
impl ::std::fmt::Debug for input_event { impl ::std::fmt::Debug for input_event {
fn fmt(&self, f: &mut ::std::fmt::Formatter) -> ::std::fmt::Result { fn fmt(&self, f: &mut ::std::fmt::Formatter) -> ::std::fmt::Result {
write!(f, "input_event {{ time: {{ tv_sec: {}, tv_usec: {} }}, _type: {}, code: {}, value: {}", write!(
self.time.tv_sec, self.time.tv_usec, self._type, self.code, self.value) f,
"input_event {{ time: {{ tv_sec: {}, tv_usec: {} }}, _type: {}, code: {}, value: {}",
self.time.tv_sec, self.time.tv_usec, self._type, self.code, self.value
)
} }
} }
@ -66,8 +76,7 @@ impl Union_Unnamed16 {
let raw: *mut u8 = ::std::mem::transmute(&self._bindgen_data_); let raw: *mut u8 = ::std::mem::transmute(&self._bindgen_data_);
::std::mem::transmute(raw.offset(0)) ::std::mem::transmute(raw.offset(0))
} }
pub unsafe fn condition(&mut self) pub unsafe fn condition(&mut self) -> *mut [ff_condition_effect; 2usize] {
-> *mut [ff_condition_effect; 2usize] {
let raw: *mut u8 = ::std::mem::transmute(&self._bindgen_data_); let raw: *mut u8 = ::std::mem::transmute(&self._bindgen_data_);
::std::mem::transmute(raw.offset(0)) ::std::mem::transmute(raw.offset(0))
} }
@ -77,7 +86,9 @@ impl Union_Unnamed16 {
} }
} }
impl ::std::default::Default for Union_Unnamed16 { impl ::std::default::Default for Union_Unnamed16 {
fn default() -> Self { unsafe { ::std::mem::zeroed() } } fn default() -> Self {
unsafe { ::std::mem::zeroed() }
}
} }
#[repr(C)] #[repr(C)]
@ -91,7 +102,9 @@ pub struct input_absinfo {
pub resolution: i32, pub resolution: i32,
} }
impl ::std::default::Default for input_absinfo { impl ::std::default::Default for input_absinfo {
fn default() -> Self { unsafe { ::std::mem::zeroed() } } fn default() -> Self {
unsafe { ::std::mem::zeroed() }
}
} }
#[repr(C)] #[repr(C)]
#[derive(Copy, Clone, Debug)] #[derive(Copy, Clone, Debug)]
@ -103,7 +116,9 @@ pub struct input_keymap_entry {
pub scancode: [u8; 32usize], pub scancode: [u8; 32usize],
} }
impl ::std::default::Default for input_keymap_entry { impl ::std::default::Default for input_keymap_entry {
fn default() -> Self { unsafe { ::std::mem::zeroed() } } fn default() -> Self {
unsafe { ::std::mem::zeroed() }
}
} }
#[repr(C)] #[repr(C)]
#[derive(Copy, Clone, Debug)] #[derive(Copy, Clone, Debug)]
@ -112,7 +127,9 @@ pub struct ff_replay {
pub delay: u16, pub delay: u16,
} }
impl ::std::default::Default for ff_replay { impl ::std::default::Default for ff_replay {
fn default() -> Self { unsafe { ::std::mem::zeroed() } } fn default() -> Self {
unsafe { ::std::mem::zeroed() }
}
} }
#[repr(C)] #[repr(C)]
#[derive(Copy, Clone, Debug)] #[derive(Copy, Clone, Debug)]
@ -121,7 +138,9 @@ pub struct ff_trigger {
pub interval: u16, pub interval: u16,
} }
impl ::std::default::Default for ff_trigger { impl ::std::default::Default for ff_trigger {
fn default() -> Self { unsafe { ::std::mem::zeroed() } } fn default() -> Self {
unsafe { ::std::mem::zeroed() }
}
} }
#[repr(C)] #[repr(C)]
#[derive(Copy, Clone, Debug)] #[derive(Copy, Clone, Debug)]
@ -132,7 +151,9 @@ pub struct ff_envelope {
pub fade_level: u16, pub fade_level: u16,
} }
impl ::std::default::Default for ff_envelope { impl ::std::default::Default for ff_envelope {
fn default() -> Self { unsafe { ::std::mem::zeroed() } } fn default() -> Self {
unsafe { ::std::mem::zeroed() }
}
} }
#[repr(C)] #[repr(C)]
#[derive(Copy, Clone, Debug)] #[derive(Copy, Clone, Debug)]
@ -141,7 +162,9 @@ pub struct ff_constant_effect {
pub envelope: ff_envelope, pub envelope: ff_envelope,
} }
impl ::std::default::Default for ff_constant_effect { impl ::std::default::Default for ff_constant_effect {
fn default() -> Self { unsafe { ::std::mem::zeroed() } } fn default() -> Self {
unsafe { ::std::mem::zeroed() }
}
} }
#[repr(C)] #[repr(C)]
#[derive(Copy, Clone, Debug)] #[derive(Copy, Clone, Debug)]
@ -151,7 +174,9 @@ pub struct ff_ramp_effect {
pub envelope: ff_envelope, pub envelope: ff_envelope,
} }
impl ::std::default::Default for ff_ramp_effect { impl ::std::default::Default for ff_ramp_effect {
fn default() -> Self { unsafe { ::std::mem::zeroed() } } fn default() -> Self {
unsafe { ::std::mem::zeroed() }
}
} }
#[repr(C)] #[repr(C)]
#[derive(Copy, Clone, Debug)] #[derive(Copy, Clone, Debug)]
@ -164,7 +189,9 @@ pub struct ff_condition_effect {
pub center: i16, pub center: i16,
} }
impl ::std::default::Default for ff_condition_effect { impl ::std::default::Default for ff_condition_effect {
fn default() -> Self { unsafe { ::std::mem::zeroed() } } fn default() -> Self {
unsafe { ::std::mem::zeroed() }
}
} }
#[repr(C)] #[repr(C)]
#[derive(Copy, Clone, Debug)] #[derive(Copy, Clone, Debug)]
@ -179,7 +206,9 @@ pub struct ff_periodic_effect {
pub custom_data: *mut i16, pub custom_data: *mut i16,
} }
impl ::std::default::Default for ff_periodic_effect { impl ::std::default::Default for ff_periodic_effect {
fn default() -> Self { unsafe { ::std::mem::zeroed() } } fn default() -> Self {
unsafe { ::std::mem::zeroed() }
}
} }
#[repr(C)] #[repr(C)]
#[derive(Copy, Clone, Debug)] #[derive(Copy, Clone, Debug)]
@ -188,7 +217,9 @@ pub struct ff_rumble_effect {
pub weak_magnitude: u16, pub weak_magnitude: u16,
} }
impl ::std::default::Default for ff_rumble_effect { impl ::std::default::Default for ff_rumble_effect {
fn default() -> Self { unsafe { ::std::mem::zeroed() } } fn default() -> Self {
unsafe { ::std::mem::zeroed() }
}
} }
ioctl_read_buf!(eviocgname, b'E', 0x06, u8); ioctl_read_buf!(eviocgname, b'E', 0x06, u8);
@ -206,10 +237,27 @@ ioctl_write_int!(eviocgrab, b'E', 0x90);
ioctl_write_int!(eviocrevoke, b'E', 0x91); ioctl_write_int!(eviocrevoke, b'E', 0x91);
ioctl_write_int!(eviocsclockid, b'E', 0xa0); ioctl_write_int!(eviocsclockid, b'E', 0xa0);
pub unsafe fn eviocgbit(fd: ::libc::c_int, ev: u32, len: ::libc::c_int, buf: *mut u8) -> ::nix::Result<i32> { pub unsafe fn eviocgbit(
convert_ioctl_res!(::nix::libc::ioctl(fd, request_code_read!(b'E', 0x20 + ev, len), buf)) fd: ::libc::c_int,
ev: u32,
len: ::libc::c_int,
buf: *mut u8,
) -> ::nix::Result<i32> {
convert_ioctl_res!(::nix::libc::ioctl(
fd,
request_code_read!(b'E', 0x20 + ev, len),
buf
))
} }
pub unsafe fn eviocgabs(fd: ::libc::c_int, abs: u32, buf: *mut input_absinfo) -> ::nix::Result<i32> { pub unsafe fn eviocgabs(
convert_ioctl_res!(::nix::libc::ioctl(fd, request_code_read!(b'E', 0x40 + abs, ::std::mem::size_of::<input_absinfo>()), buf)) fd: ::libc::c_int,
abs: u32,
buf: *mut input_absinfo,
) -> ::nix::Result<i32> {
convert_ioctl_res!(::nix::libc::ioctl(
fd,
request_code_read!(b'E', 0x40 + abs, ::std::mem::size_of::<input_absinfo>()),
buf
))
} }

View file

@ -88,7 +88,7 @@ pub enum Key {
KEY_KP3 = 81, KEY_KP3 = 81,
KEY_KP0 = 82, KEY_KP0 = 82,
KEY_KPDOT = 83, KEY_KPDOT = 83,
KEY_ZENKAKUHANKAKU =85, KEY_ZENKAKUHANKAKU = 85,
KEY_102ND = 86, KEY_102ND = 86,
KEY_F11 = 87, KEY_F11 = 87,
KEY_F12 = 88, KEY_F12 = 88,
@ -96,7 +96,7 @@ pub enum Key {
KEY_KATAKANA = 90, KEY_KATAKANA = 90,
KEY_HIRAGANA = 91, KEY_HIRAGANA = 91,
KEY_HENKAN = 92, KEY_HENKAN = 92,
KEY_KATAKANAHIRAGANA =93, KEY_KATAKANAHIRAGANA = 93,
KEY_MUHENKAN = 94, KEY_MUHENKAN = 94,
KEY_KPJPCOMMA = 95, KEY_KPJPCOMMA = 95,
KEY_KPENTER = 96, KEY_KPENTER = 96,
@ -119,11 +119,11 @@ pub enum Key {
KEY_MUTE = 113, KEY_MUTE = 113,
KEY_VOLUMEDOWN = 114, KEY_VOLUMEDOWN = 114,
KEY_VOLUMEUP = 115, KEY_VOLUMEUP = 115,
KEY_POWER = 116 /* SC System Power Down */, KEY_POWER = 116, /* SC System Power Down */
KEY_KPEQUAL = 117, KEY_KPEQUAL = 117,
KEY_KPPLUSMINUS = 118, KEY_KPPLUSMINUS = 118,
KEY_PAUSE = 119, KEY_PAUSE = 119,
KEY_SCALE = 120 /* AL Compiz Scale (Expose) */, KEY_SCALE = 120, /* AL Compiz Scale (Expose) */
KEY_KPCOMMA = 121, KEY_KPCOMMA = 121,
KEY_HANGEUL = 122, KEY_HANGEUL = 122,
KEY_HANJA = 123, KEY_HANJA = 123,
@ -131,61 +131,61 @@ pub enum Key {
KEY_LEFTMETA = 125, KEY_LEFTMETA = 125,
KEY_RIGHTMETA = 126, KEY_RIGHTMETA = 126,
KEY_COMPOSE = 127, KEY_COMPOSE = 127,
KEY_STOP = 128 /* AC Stop */, KEY_STOP = 128, /* AC Stop */
KEY_AGAIN = 129, KEY_AGAIN = 129,
KEY_PROPS = 130 /* AC Properties */, KEY_PROPS = 130, /* AC Properties */
KEY_UNDO = 131 /* AC Undo */, KEY_UNDO = 131, /* AC Undo */
KEY_FRONT = 132, KEY_FRONT = 132,
KEY_COPY = 133 /* AC Copy */, KEY_COPY = 133, /* AC Copy */
KEY_OPEN = 134 /* AC Open */, KEY_OPEN = 134, /* AC Open */
KEY_PASTE = 135 /* AC Paste */, KEY_PASTE = 135, /* AC Paste */
KEY_FIND = 136 /* AC Search */, KEY_FIND = 136, /* AC Search */
KEY_CUT = 137 /* AC Cut */, KEY_CUT = 137, /* AC Cut */
KEY_HELP = 138 /* AL Integrated Help Center */, KEY_HELP = 138, /* AL Integrated Help Center */
KEY_MENU = 139 /* Menu (show menu) */, KEY_MENU = 139, /* Menu (show menu) */
KEY_CALC = 140 /* AL Calculator */, KEY_CALC = 140, /* AL Calculator */
KEY_SETUP = 141, KEY_SETUP = 141,
KEY_SLEEP = 142 /* SC System Sleep */, KEY_SLEEP = 142, /* SC System Sleep */
KEY_WAKEUP = 143 /* System Wake Up */, KEY_WAKEUP = 143, /* System Wake Up */
KEY_FILE = 144 /* AL Local Machine Browser */, KEY_FILE = 144, /* AL Local Machine Browser */
KEY_SENDFILE = 145, KEY_SENDFILE = 145,
KEY_DELETEFILE = 146, KEY_DELETEFILE = 146,
KEY_XFER = 147, KEY_XFER = 147,
KEY_PROG1 = 148, KEY_PROG1 = 148,
KEY_PROG2 = 149, KEY_PROG2 = 149,
KEY_WWW = 150 /* AL Internet Browser */, KEY_WWW = 150, /* AL Internet Browser */
KEY_MSDOS = 151, KEY_MSDOS = 151,
KEY_COFFEE = 152 /* AL Terminal Lock/Screensaver */, KEY_COFFEE = 152, /* AL Terminal Lock/Screensaver */
KEY_DIRECTION = 153, KEY_DIRECTION = 153,
KEY_CYCLEWINDOWS =154, KEY_CYCLEWINDOWS = 154,
KEY_MAIL = 155, KEY_MAIL = 155,
KEY_BOOKMARKS = 156 /* AC Bookmarks */, KEY_BOOKMARKS = 156, /* AC Bookmarks */
KEY_COMPUTER = 157, KEY_COMPUTER = 157,
KEY_BACK = 158 /* AC Back */, KEY_BACK = 158, /* AC Back */
KEY_FORWARD = 159 /* AC Forward */, KEY_FORWARD = 159, /* AC Forward */
KEY_CLOSECD = 160, KEY_CLOSECD = 160,
KEY_EJECTCD = 161, KEY_EJECTCD = 161,
KEY_EJECTCLOSECD =162, KEY_EJECTCLOSECD = 162,
KEY_NEXTSONG = 163, KEY_NEXTSONG = 163,
KEY_PLAYPAUSE = 164, KEY_PLAYPAUSE = 164,
KEY_PREVIOUSSONG =165, KEY_PREVIOUSSONG = 165,
KEY_STOPCD = 166, KEY_STOPCD = 166,
KEY_RECORD = 167, KEY_RECORD = 167,
KEY_REWIND = 168, KEY_REWIND = 168,
KEY_PHONE = 169 /* Media Select Telephone */, KEY_PHONE = 169, /* Media Select Telephone */
KEY_ISO = 170, KEY_ISO = 170,
KEY_CONFIG = 171 /* AL Consumer Control Configuration */, KEY_CONFIG = 171, /* AL Consumer Control Configuration */
KEY_HOMEPAGE = 172 /* AC Home */, KEY_HOMEPAGE = 172, /* AC Home */
KEY_REFRESH = 173 /* AC Refresh */, KEY_REFRESH = 173, /* AC Refresh */
KEY_EXIT = 174 /* AC Exit */, KEY_EXIT = 174, /* AC Exit */
KEY_MOVE = 175, KEY_MOVE = 175,
KEY_EDIT = 176, KEY_EDIT = 176,
KEY_SCROLLUP = 177, KEY_SCROLLUP = 177,
KEY_SCROLLDOWN = 178, KEY_SCROLLDOWN = 178,
KEY_KPLEFTPAREN = 179, KEY_KPLEFTPAREN = 179,
KEY_KPRIGHTPAREN =180, KEY_KPRIGHTPAREN = 180,
KEY_NEW = 181 /* AC New */, KEY_NEW = 181, /* AC New */
KEY_REDO = 182 /* AC Redo/Repeat */, KEY_REDO = 182, /* AC Redo/Repeat */
KEY_F13 = 183, KEY_F13 = 183,
KEY_F14 = 184, KEY_F14 = 184,
KEY_F15 = 185, KEY_F15 = 185,
@ -202,13 +202,13 @@ pub enum Key {
KEY_PAUSECD = 201, KEY_PAUSECD = 201,
KEY_PROG3 = 202, KEY_PROG3 = 202,
KEY_PROG4 = 203, KEY_PROG4 = 203,
KEY_DASHBOARD = 204 /* AL Dashboard */, KEY_DASHBOARD = 204, /* AL Dashboard */
KEY_SUSPEND = 205, KEY_SUSPEND = 205,
KEY_CLOSE = 206 /* AC Close */, KEY_CLOSE = 206, /* AC Close */
KEY_PLAY = 207, KEY_PLAY = 207,
KEY_FASTFORWARD = 208, KEY_FASTFORWARD = 208,
KEY_BASSBOOST = 209, KEY_BASSBOOST = 209,
KEY_PRINT = 210 /* AC Print */, KEY_PRINT = 210, /* AC Print */
KEY_HP = 211, KEY_HP = 211,
KEY_CAMERA = 212, KEY_CAMERA = 212,
KEY_SOUND = 213, KEY_SOUND = 213,
@ -222,8 +222,8 @@ pub enum Key {
KEY_SHOP = 221, KEY_SHOP = 221,
KEY_ALTERASE = 222, KEY_ALTERASE = 222,
KEY_CANCEL = 223, KEY_CANCEL = 223,
KEY_BRIGHTNESSDOWN =224, KEY_BRIGHTNESSDOWN = 224,
KEY_BRIGHTNESSUP =225, KEY_BRIGHTNESSUP = 225,
KEY_MEDIA = 226, KEY_MEDIA = 226,
KEY_SWITCHVIDEOMODE = 227, KEY_SWITCHVIDEOMODE = 227,
KEY_KBDILLUMTOGGLE = 228, KEY_KBDILLUMTOGGLE = 228,
@ -241,8 +241,8 @@ pub enum Key {
KEY_UNKNOWN = 240, KEY_UNKNOWN = 240,
KEY_VIDEO_NEXT = 241, KEY_VIDEO_NEXT = 241,
KEY_VIDEO_PREV = 242, KEY_VIDEO_PREV = 242,
KEY_BRIGHTNESS_CYCLE =243, KEY_BRIGHTNESS_CYCLE = 243,
KEY_BRIGHTNESS_AUTO =244, KEY_BRIGHTNESS_AUTO = 244,
KEY_DISPLAY_OFF = 245, KEY_DISPLAY_OFF = 245,
KEY_WWAN = 246, KEY_WWAN = 246,
KEY_RFKILL = 247, KEY_RFKILL = 247,
@ -297,17 +297,17 @@ pub enum Key {
BTN_TOOL_RUBBER = 0x141, BTN_TOOL_RUBBER = 0x141,
BTN_TOOL_BRUSH = 0x142, BTN_TOOL_BRUSH = 0x142,
BTN_TOOL_PENCIL = 0x143, BTN_TOOL_PENCIL = 0x143,
BTN_TOOL_AIRBRUSH =0x144, BTN_TOOL_AIRBRUSH = 0x144,
BTN_TOOL_FINGER = 0x145, BTN_TOOL_FINGER = 0x145,
BTN_TOOL_MOUSE = 0x146, BTN_TOOL_MOUSE = 0x146,
BTN_TOOL_LENS = 0x147, BTN_TOOL_LENS = 0x147,
BTN_TOOL_QUINTTAP =0x148 /* Five fingers on trackpad */, BTN_TOOL_QUINTTAP = 0x148, /* Five fingers on trackpad */
BTN_TOUCH = 0x14a, BTN_TOUCH = 0x14a,
BTN_STYLUS = 0x14b, BTN_STYLUS = 0x14b,
BTN_STYLUS2 = 0x14c, BTN_STYLUS2 = 0x14c,
BTN_TOOL_DOUBLETAP =0x14d, BTN_TOOL_DOUBLETAP = 0x14d,
BTN_TOOL_TRIPLETAP =0x14e, BTN_TOOL_TRIPLETAP = 0x14e,
BTN_TOOL_QUADTAP =0x14f /* Four fingers on trackpad */, BTN_TOOL_QUADTAP = 0x14f, /* Four fingers on trackpad */
BTN_GEAR_DOWN = 0x150, BTN_GEAR_DOWN = 0x150,
BTN_GEAR_UP = 0x151, BTN_GEAR_UP = 0x151,
KEY_OK = 0x160, KEY_OK = 0x160,
@ -316,15 +316,15 @@ pub enum Key {
KEY_CLEAR = 0x163, KEY_CLEAR = 0x163,
KEY_POWER2 = 0x164, KEY_POWER2 = 0x164,
KEY_OPTION = 0x165, KEY_OPTION = 0x165,
KEY_INFO = 0x166 /* AL OEM Features/Tips/Tutorial */, KEY_INFO = 0x166, /* AL OEM Features/Tips/Tutorial */
KEY_TIME = 0x167, KEY_TIME = 0x167,
KEY_VENDOR = 0x168, KEY_VENDOR = 0x168,
KEY_ARCHIVE = 0x169, KEY_ARCHIVE = 0x169,
KEY_PROGRAM = 0x16a /* Media Select Program Guide */, KEY_PROGRAM = 0x16a, /* Media Select Program Guide */
KEY_CHANNEL = 0x16b, KEY_CHANNEL = 0x16b,
KEY_FAVORITES = 0x16c, KEY_FAVORITES = 0x16c,
KEY_EPG = 0x16d, KEY_EPG = 0x16d,
KEY_PVR = 0x16e /* Media Select Home */, KEY_PVR = 0x16e, /* Media Select Home */
KEY_MHP = 0x16f, KEY_MHP = 0x16f,
KEY_LANGUAGE = 0x170, KEY_LANGUAGE = 0x170,
KEY_TITLE = 0x171, KEY_TITLE = 0x171,
@ -334,36 +334,36 @@ pub enum Key {
KEY_MODE = 0x175, KEY_MODE = 0x175,
KEY_KEYBOARD = 0x176, KEY_KEYBOARD = 0x176,
KEY_SCREEN = 0x177, KEY_SCREEN = 0x177,
KEY_PC = 0x178 /* Media Select Computer */, KEY_PC = 0x178, /* Media Select Computer */
KEY_TV = 0x179 /* Media Select TV */, KEY_TV = 0x179, /* Media Select TV */
KEY_TV2 = 0x17a /* Media Select Cable */, KEY_TV2 = 0x17a, /* Media Select Cable */
KEY_VCR = 0x17b /* Media Select VCR */, KEY_VCR = 0x17b, /* Media Select VCR */
KEY_VCR2 = 0x17c /* VCR Plus */, KEY_VCR2 = 0x17c, /* VCR Plus */
KEY_SAT = 0x17d /* Media Select Satellite */, KEY_SAT = 0x17d, /* Media Select Satellite */
KEY_SAT2 = 0x17e, KEY_SAT2 = 0x17e,
KEY_CD = 0x17f /* Media Select CD */, KEY_CD = 0x17f, /* Media Select CD */
KEY_TAPE = 0x180 /* Media Select Tape */, KEY_TAPE = 0x180, /* Media Select Tape */
KEY_RADIO = 0x181, KEY_RADIO = 0x181,
KEY_TUNER = 0x182 /* Media Select Tuner */, KEY_TUNER = 0x182, /* Media Select Tuner */
KEY_PLAYER = 0x183, KEY_PLAYER = 0x183,
KEY_TEXT = 0x184, KEY_TEXT = 0x184,
KEY_DVD = 0x185 /* Media Select DVD */, KEY_DVD = 0x185, /* Media Select DVD */
KEY_AUX = 0x186, KEY_AUX = 0x186,
KEY_MP3 = 0x187, KEY_MP3 = 0x187,
KEY_AUDIO = 0x188 /* AL Audio Browser */, KEY_AUDIO = 0x188, /* AL Audio Browser */
KEY_VIDEO = 0x189 /* AL Movie Browser */, KEY_VIDEO = 0x189, /* AL Movie Browser */
KEY_DIRECTORY = 0x18a, KEY_DIRECTORY = 0x18a,
KEY_LIST = 0x18b, KEY_LIST = 0x18b,
KEY_MEMO = 0x18c /* Media Select Messages */, KEY_MEMO = 0x18c, /* Media Select Messages */
KEY_CALENDAR = 0x18d, KEY_CALENDAR = 0x18d,
KEY_RED = 0x18e, KEY_RED = 0x18e,
KEY_GREEN = 0x18f, KEY_GREEN = 0x18f,
KEY_YELLOW = 0x190, KEY_YELLOW = 0x190,
KEY_BLUE = 0x191, KEY_BLUE = 0x191,
KEY_CHANNELUP = 0x192 /* Channel Increment */, KEY_CHANNELUP = 0x192, /* Channel Increment */
KEY_CHANNELDOWN = 0x193 /* Channel Decrement */, KEY_CHANNELDOWN = 0x193, /* Channel Decrement */
KEY_FIRST = 0x194, KEY_FIRST = 0x194,
KEY_LAST = 0x195 /* Recall Last */, KEY_LAST = 0x195, /* Recall Last */
KEY_AB = 0x196, KEY_AB = 0x196,
KEY_NEXT = 0x197, KEY_NEXT = 0x197,
KEY_RESTART = 0x198, KEY_RESTART = 0x198,
@ -374,33 +374,33 @@ pub enum Key {
KEY_DIGITS = 0x19d, KEY_DIGITS = 0x19d,
KEY_TEEN = 0x19e, KEY_TEEN = 0x19e,
KEY_TWEN = 0x19f, KEY_TWEN = 0x19f,
KEY_VIDEOPHONE = 0x1a0 /* Media Select Video Phone */, KEY_VIDEOPHONE = 0x1a0, /* Media Select Video Phone */
KEY_GAMES = 0x1a1 /* Media Select Games */, KEY_GAMES = 0x1a1, /* Media Select Games */
KEY_ZOOMIN = 0x1a2 /* AC Zoom In */, KEY_ZOOMIN = 0x1a2, /* AC Zoom In */
KEY_ZOOMOUT = 0x1a3 /* AC Zoom Out */, KEY_ZOOMOUT = 0x1a3, /* AC Zoom Out */
KEY_ZOOMRESET = 0x1a4 /* AC Zoom */, KEY_ZOOMRESET = 0x1a4, /* AC Zoom */
KEY_WORDPROCESSOR =0x1a5 /* AL Word Processor */, KEY_WORDPROCESSOR = 0x1a5, /* AL Word Processor */
KEY_EDITOR = 0x1a6 /* AL Text Editor */, KEY_EDITOR = 0x1a6, /* AL Text Editor */
KEY_SPREADSHEET = 0x1a7 /* AL Spreadsheet */, KEY_SPREADSHEET = 0x1a7, /* AL Spreadsheet */
KEY_GRAPHICSEDITOR =0x1a8 /* AL Graphics Editor */, KEY_GRAPHICSEDITOR = 0x1a8, /* AL Graphics Editor */
KEY_PRESENTATION =0x1a9 /* AL Presentation App */, KEY_PRESENTATION = 0x1a9, /* AL Presentation App */
KEY_DATABASE = 0x1aa /* AL Database App */, KEY_DATABASE = 0x1aa, /* AL Database App */
KEY_NEWS = 0x1ab /* AL Newsreader */, KEY_NEWS = 0x1ab, /* AL Newsreader */
KEY_VOICEMAIL = 0x1ac /* AL Voicemail */, KEY_VOICEMAIL = 0x1ac, /* AL Voicemail */
KEY_ADDRESSBOOK = 0x1ad /* AL Contacts/Address Book */, KEY_ADDRESSBOOK = 0x1ad, /* AL Contacts/Address Book */
KEY_MESSENGER = 0x1ae /* AL Instant Messaging */, KEY_MESSENGER = 0x1ae, /* AL Instant Messaging */
KEY_DISPLAYTOGGLE =0x1af /* Turn display (LCD) on and off */, KEY_DISPLAYTOGGLE = 0x1af, /* Turn display (LCD) on and off */
KEY_SPELLCHECK = 0x1b0 /* AL Spell Check */, KEY_SPELLCHECK = 0x1b0, /* AL Spell Check */
KEY_LOGOFF = 0x1b1 /* AL Logoff */, KEY_LOGOFF = 0x1b1, /* AL Logoff */
KEY_DOLLAR = 0x1b2, KEY_DOLLAR = 0x1b2,
KEY_EURO = 0x1b3, KEY_EURO = 0x1b3,
KEY_FRAMEBACK = 0x1b4 /* Consumer - transport controls */, KEY_FRAMEBACK = 0x1b4, /* Consumer - transport controls */
KEY_FRAMEFORWARD =0x1b5, KEY_FRAMEFORWARD = 0x1b5,
KEY_CONTEXT_MENU =0x1b6 /* GenDesc - system context menu */, KEY_CONTEXT_MENU = 0x1b6, /* GenDesc - system context menu */
KEY_MEDIA_REPEAT =0x1b7 /* Consumer - transport control */, KEY_MEDIA_REPEAT = 0x1b7, /* Consumer - transport control */
KEY_10CHANNELSUP =0x1b8 /* 10 channels up (10+) */, KEY_10CHANNELSUP = 0x1b8, /* 10 channels up (10+) */
KEY_10CHANNELSDOWN =0x1b9 /* 10 channels down (10-) */, KEY_10CHANNELSDOWN = 0x1b9, /* 10 channels down (10-) */
KEY_IMAGES = 0x1ba /* AL Image Browser */, KEY_IMAGES = 0x1ba, /* AL Image Browser */
KEY_DEL_EOL = 0x1c0, KEY_DEL_EOL = 0x1c0,
KEY_DEL_EOS = 0x1c1, KEY_DEL_EOS = 0x1c1,
KEY_INS_LINE = 0x1c2, KEY_INS_LINE = 0x1c2,
@ -436,8 +436,8 @@ pub enum Key {
KEY_BRL_DOT8 = 0x1f8, KEY_BRL_DOT8 = 0x1f8,
KEY_BRL_DOT9 = 0x1f9, KEY_BRL_DOT9 = 0x1f9,
KEY_BRL_DOT10 = 0x1fa, KEY_BRL_DOT10 = 0x1fa,
KEY_NUMERIC_0 = 0x200 /* used by phones, remote controls, */, KEY_NUMERIC_0 = 0x200, /* used by phones, remote controls, */
KEY_NUMERIC_1 = 0x201 /* and other keypads */, KEY_NUMERIC_1 = 0x201, /* and other keypads */
KEY_NUMERIC_2 = 0x202, KEY_NUMERIC_2 = 0x202,
KEY_NUMERIC_3 = 0x203, KEY_NUMERIC_3 = 0x203,
KEY_NUMERIC_4 = 0x204, KEY_NUMERIC_4 = 0x204,
@ -446,37 +446,37 @@ pub enum Key {
KEY_NUMERIC_7 = 0x207, KEY_NUMERIC_7 = 0x207,
KEY_NUMERIC_8 = 0x208, KEY_NUMERIC_8 = 0x208,
KEY_NUMERIC_9 = 0x209, KEY_NUMERIC_9 = 0x209,
KEY_NUMERIC_STAR =0x20a, KEY_NUMERIC_STAR = 0x20a,
KEY_NUMERIC_POUND =0x20b, KEY_NUMERIC_POUND = 0x20b,
KEY_CAMERA_FOCUS =0x210, KEY_CAMERA_FOCUS = 0x210,
KEY_WPS_BUTTON = 0x211 /* WiFi Protected Setup key */, KEY_WPS_BUTTON = 0x211, /* WiFi Protected Setup key */
KEY_TOUCHPAD_TOGGLE =0x212 /* Request switch touchpad on or off */, KEY_TOUCHPAD_TOGGLE = 0x212, /* Request switch touchpad on or off */
KEY_TOUCHPAD_ON = 0x213, KEY_TOUCHPAD_ON = 0x213,
KEY_TOUCHPAD_OFF =0x214, KEY_TOUCHPAD_OFF = 0x214,
KEY_CAMERA_ZOOMIN =0x215, KEY_CAMERA_ZOOMIN = 0x215,
KEY_CAMERA_ZOOMOUT =0x216, KEY_CAMERA_ZOOMOUT = 0x216,
KEY_CAMERA_UP = 0x217, KEY_CAMERA_UP = 0x217,
KEY_CAMERA_DOWN = 0x218, KEY_CAMERA_DOWN = 0x218,
KEY_CAMERA_LEFT = 0x219, KEY_CAMERA_LEFT = 0x219,
KEY_CAMERA_RIGHT =0x21a, KEY_CAMERA_RIGHT = 0x21a,
KEY_ATTENDANT_ON =0x21b, KEY_ATTENDANT_ON = 0x21b,
KEY_ATTENDANT_OFF =0x21c, KEY_ATTENDANT_OFF = 0x21c,
KEY_ATTENDANT_TOGGLE =0x21d /* Attendant call on or off */, KEY_ATTENDANT_TOGGLE = 0x21d, /* Attendant call on or off */
KEY_LIGHTS_TOGGLE =0x21e /* Reading light on or off */, KEY_LIGHTS_TOGGLE = 0x21e, /* Reading light on or off */
BTN_DPAD_UP = 0x220, BTN_DPAD_UP = 0x220,
BTN_DPAD_DOWN = 0x221, BTN_DPAD_DOWN = 0x221,
BTN_DPAD_LEFT = 0x222, BTN_DPAD_LEFT = 0x222,
BTN_DPAD_RIGHT = 0x223, BTN_DPAD_RIGHT = 0x223,
KEY_ALS_TOGGLE = 0x230 /* Ambient light sensor */, KEY_ALS_TOGGLE = 0x230, /* Ambient light sensor */
KEY_BUTTONCONFIG = 0x240 /* AL Button Configuration */, KEY_BUTTONCONFIG = 0x240, /* AL Button Configuration */
KEY_TASKMANAGER = 0x241 /* AL Task/Project Manager */, KEY_TASKMANAGER = 0x241, /* AL Task/Project Manager */
KEY_JOURNAL = 0x242 /* AL Log/Journal/Timecard */, KEY_JOURNAL = 0x242, /* AL Log/Journal/Timecard */
KEY_CONTROLPANEL = 0x243 /* AL Control Panel */, KEY_CONTROLPANEL = 0x243, /* AL Control Panel */
KEY_APPSELECT = 0x244 /* AL Select Task/Application */, KEY_APPSELECT = 0x244, /* AL Select Task/Application */
KEY_SCREENSAVER = 0x245 /* AL Screen Saver */, KEY_SCREENSAVER = 0x245, /* AL Screen Saver */
KEY_VOICECOMMAND = 0x246 /* Listening Voice Command */, KEY_VOICECOMMAND = 0x246, /* Listening Voice Command */
KEY_BRIGHTNESS_MIN = 0x250 /* Set Brightness to Minimum */, KEY_BRIGHTNESS_MIN = 0x250, /* Set Brightness to Minimum */
KEY_BRIGHTNESS_MAX = 0x251 /* Set Brightness to Maximum */, KEY_BRIGHTNESS_MAX = 0x251, /* Set Brightness to Maximum */
KEY_KBDINPUTASSIST_PREV = 0x260, KEY_KBDINPUTASSIST_PREV = 0x260,
KEY_KBDINPUTASSIST_NEXT = 0x261, KEY_KBDINPUTASSIST_NEXT = 0x261,
KEY_KBDINPUTASSIST_PREVGROUP = 0x262, KEY_KBDINPUTASSIST_PREVGROUP = 0x262,
@ -523,5 +523,8 @@ pub enum Key {
BTN_TRIGGER_HAPPY38 = 0x2e5, BTN_TRIGGER_HAPPY38 = 0x2e5,
BTN_TRIGGER_HAPPY39 = 0x2e6, BTN_TRIGGER_HAPPY39 = 0x2e6,
BTN_TRIGGER_HAPPY40 = 0x2e7, BTN_TRIGGER_HAPPY40 = 0x2e7,
KEY_MAX = 0x2ff, }
impl Key {
pub const MAX: usize = 0x2ff;
} }