diff --git a/Cargo.toml b/Cargo.toml index 3ec5fbd..77cfe9e 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -9,6 +9,8 @@ description = "Linux keyboard mapper" repository = "https://code.moparisthebest.com/moparisthebest/rusty-keys" keywords = ["linux", "input", "keyboard", "keymapper"] +edition = "2018" + include = [ "src/**", "Cargo.toml", diff --git a/src/device/builder.rs b/src/device/builder.rs index 92ebdd2..46907b3 100644 --- a/src/device/builder.rs +++ b/src/device/builder.rs @@ -5,7 +5,7 @@ use libc::c_int; use nix::{self, fcntl, unistd, errno::Errno}; use nix::sys::stat; use ffi::*; -use {Result as Res, Device}; +use crate::{Result as Res, Device}; use std::collections::hash_map::Values; #[cfg(feature = "udev")] @@ -22,28 +22,12 @@ impl Builder { /// Create a builder from the specified path. pub fn open>(path: P) -> Res { Ok(Builder { - fd: try!(fcntl::open(path.as_ref(), fcntl::OFlag::O_WRONLY | fcntl::OFlag::O_NONBLOCK, stat::Mode::empty())), + fd: fcntl::open(path.as_ref(), fcntl::OFlag::O_WRONLY | fcntl::OFlag::O_NONBLOCK, stat::Mode::empty())?, def: unsafe { mem::zeroed() }, abs: None, }) } - #[cfg(feature = "udev")] - /// Create a builder from the default path taken from udev. - pub fn default() -> Res { - let context = try!(udev::Context::new()); - let mut enumerator = try!(udev::Enumerator::new(&context)); - - try!(enumerator.match_subsystem("misc")); - try!(enumerator.match_sysname("uinput")); - - let device = try!(try!(enumerator.scan_devices()) - .next().ok_or(Error::NotFound)); - - Builder::open(try!(device.devnode().ok_or(Error::NotFound))) - } - - #[cfg(not(feature = "udev"))] /// Create a builder from `/dev/uinput`. pub fn default() -> Res { Builder::open("/dev/uinput") @@ -51,11 +35,11 @@ impl Builder { /// Set the name. pub fn name>(mut self, value: T) -> Res { - let string = try!(CString::new(value.as_ref())); + let string = CString::new(value.as_ref())?; let bytes = string.as_bytes_with_nul(); if bytes.len() > UINPUT_MAX_NAME_SIZE as usize { - try!(Err(nix::Error::from_errno(Errno::EINVAL))); + Err(nix::Error::from_errno(Errno::EINVAL))?; } (&mut self.def.name)[..bytes.len()] @@ -276,10 +260,10 @@ impl Builder { let ptr = &self.def as *const _ as *const u8; let size = mem::size_of_val(&self.def); - try!(unistd::write(self.fd, slice::from_raw_parts(ptr, size))); + unistd::write(self.fd, slice::from_raw_parts(ptr, size))?; //todo: try!(Errno::result(ui_dev_create(self.fd))); // try1: Errno::result(ui_dev_create(self.fd)).unwrap(); - try!(Errno::result(ui_dev_create(self.fd))); + Errno::result(ui_dev_create(self.fd))?; } Ok(Device::new(self.fd)) diff --git a/src/device/device.rs b/src/device/device.rs index fd1d0d0..52ebc62 100644 --- a/src/device/device.rs +++ b/src/device/device.rs @@ -2,7 +2,7 @@ use std::{mem, ptr, slice}; use libc::{timeval, gettimeofday, input_event, c_int}; use nix::{unistd, errno::Errno}; use ffi::*; -use {Result as Res}; +use crate::{Result as Res}; /// The virtual device. pub struct Device { @@ -37,7 +37,7 @@ impl Device { let ptr = event as *const _ as *const u8; let size = mem::size_of_val(event); - try!(unistd::write(self.fd, slice::from_raw_parts(ptr, size))); + unistd::write(self.fd, slice::from_raw_parts(ptr, size))?; } Ok(()) @@ -65,8 +65,8 @@ impl Device { /// Send a press and release event. pub fn click(&self, kind: c_int, code: c_int) -> Res<()> { - try!(self.press(kind, code)); - try!(self.release(kind, code)); + self.press(kind, code)?; + self.release(kind, code)?; Ok(()) } diff --git a/src/device/input_device.rs b/src/device/input_device.rs index 65c0fc7..d0a754e 100644 --- a/src/device/input_device.rs +++ b/src/device/input_device.rs @@ -3,7 +3,7 @@ use std::fs::File; use std::io::Read; use std::os::unix::io::AsRawFd; use libc::{input_event, c_int}; -use {Error,Result}; +use crate::{Error,Result}; ioctl_write_ptr!(eviocgrab, b'E', 0x90, c_int); diff --git a/src/keymapper.rs b/src/keymapper.rs index 8e69aca..2db64e1 100644 --- a/src/keymapper.rs +++ b/src/keymapper.rs @@ -1,5 +1,5 @@ -use device::Device; +use crate::Device; use ffi::*; use libc::{c_int, input_event}; @@ -8,7 +8,7 @@ use std::fs::File; use std::io::Read; use std::collections::HashMap; -use {Error, Result}; +use crate::{Error, Result}; // 1 is down, 0 is up const DOWN: i32 = 1;