Clean up unused warnings for all features
moparisthebest/rusty-keys/pipeline/head This commit looks good Details

This commit is contained in:
Travis Burtrum 2021-09-25 01:00:09 -04:00
parent bcea441630
commit 8ffe640c4b
3 changed files with 16 additions and 12 deletions

View File

@ -1,11 +1,12 @@
use std::fs::File;
use std::io::Read;
use std::collections::HashMap;
use std::hash::Hash;
use std::convert::TryFrom;
use crate::{Error, Result};
#[cfg(feature = "toml_serde")]
use std::path::Path;
use crate::Result;
const INVERT_KEY_FLAG: char = '^';
const CAPS_MODIFY_KEY_FLAG: char = '*';
@ -454,8 +455,6 @@ impl<K, T, E, R> KeyMapper<K, T, E, R> for Key<T>
}
}
use std::path::Path;
#[cfg(feature = "toml_serde")]
#[derive(serde::Deserialize, Debug)]
pub struct KeymapConfig {
@ -469,10 +468,11 @@ pub struct KeymapConfig {
#[cfg(feature = "toml_serde")]
fn parse_cfg<P: AsRef<Path>>(path: P) -> Result<KeymapConfig> {
let mut f = File::open(path)?;
use std::io::Read;
let mut f = std::fs::File::open(path)?;
let mut input = String::new();
f.read_to_string(&mut input)?;
toml::from_str(&input).map_err(|e| Error::Toml(e))
toml::from_str(&input).map_err(|e| crate::Error::Toml(e))
}
#[cfg(not(feature = "toml_serde"))]

View File

@ -2,13 +2,11 @@ use std::mem;
use std::fs::File;
use std::io::Read;
use std::os::unix::io::AsRawFd;
use std::os::unix::prelude::RawFd;
use libc::{input_event, c_int};
use nix::{ioctl_write_ptr, ioctl_read_buf};
use nix::fcntl::{OFlag, fcntl, FcntlArg};
#[cfg(feature = "epoll_inotify")]
use epoll::ControlOptions::{EPOLL_CTL_ADD, EPOLL_CTL_DEL};
use std::os::unix::prelude::RawFd;
use crate::{Error,Result};
use crate::linux::{EV_KEY, KEY_MAX, NAME, KEY_W, KEY_A, KEY_S, KEY_D};
@ -23,6 +21,7 @@ const SIZE_OF_INPUT_EVENT: usize = mem::size_of::<input_event>();
pub struct InputDevice {
device_file: File,
grabbed: bool,
#[cfg(feature = "epoll_inotify")]
epoll_fd: Option<RawFd>,
}
@ -31,6 +30,7 @@ impl InputDevice {
Ok(InputDevice {
device_file: File::open(path)?,
grabbed: false,
#[cfg(feature = "epoll_inotify")]
epoll_fd: None,
})
}
@ -109,6 +109,8 @@ impl InputDevice {
#[cfg(feature = "epoll_inotify")]
pub fn epoll_add(mut self, epoll_fd: RawFd, data: u64) -> Result<Self> {
use nix::fcntl::{OFlag, fcntl, FcntlArg};
if None != self.epoll_fd {
return Err(Error::EpollAlreadyAdded);
}
@ -120,7 +122,7 @@ impl InputDevice {
fcntl(raw_fd, FcntlArg::F_SETFL(flags | OFlag::O_NONBLOCK))?;
let epoll_event = epoll::Event::new(epoll::Events::EPOLLIN | epoll::Events::EPOLLET, data);
epoll::ctl(epoll_fd, EPOLL_CTL_ADD, raw_fd, epoll_event)?;
epoll::ctl(epoll_fd, epoll::ControlOptions::EPOLL_CTL_ADD, raw_fd, epoll_event)?;
self.epoll_fd = Some(epoll_fd);
Ok(self)
}
@ -131,7 +133,7 @@ impl InputDevice {
// set this to None first, if we end up returning an Err early, we can't do anything else anyway...
self.epoll_fd = None;
let empty_event = epoll::Event::new(epoll::Events::empty(), 0);
epoll::ctl(epoll_fd, EPOLL_CTL_DEL, self.device_file.as_raw_fd(), empty_event)?;
epoll::ctl(epoll_fd, epoll::ControlOptions::EPOLL_CTL_DEL, self.device_file.as_raw_fd(), empty_event)?;
}
Ok(self)
}

View File

@ -11,6 +11,7 @@ use std::process::exit;
use std::env;
use std::collections::HashMap;
#[cfg(feature = "epoll_inotify")]
const INPUT_FOLDER: &str = "/dev/input/";
// 1 is down, 0 is up
@ -268,6 +269,7 @@ fn parse_args() -> Config {
Config::new(matches.free, config_file)
}
#[cfg(feature = "epoll_inotify")]
fn get_keyboard_devices() -> Vec<InputDevice> {
let mut res = Vec::new();
if let Ok(entries) = std::fs::read_dir(INPUT_FOLDER) {