Skip to content

Commit

Permalink
Windows support
Browse files Browse the repository at this point in the history
  • Loading branch information
moparisthebest committed Oct 7, 2019
1 parent f47d9e4 commit f7afe19
Show file tree
Hide file tree
Showing 7 changed files with 890 additions and 5 deletions.
30 changes: 30 additions & 0 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

12 changes: 9 additions & 3 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -21,10 +21,16 @@ include = [
]

[dependencies]
libc = "0.2.62"
nix = "0.15.0"
uinput-sys = "0.1.7"
getopts = "0.2.21"
toml = "0.5.3"
serde = { version = "1.0.101", features = ["derive"] }

[target.'cfg(windows)'.dependencies]
winapi = { version = "0.3", features = ["winuser"] }
lazy_static = "1.4.0"

[target.'cfg(target_os="linux")'.dependencies]
libc = "0.2.62"
nix = "0.15.0"
uinput-sys = "0.1.7"
inotify = { version = "0.7.0", default-features = false, features = [] }
11 changes: 11 additions & 0 deletions src/error.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,22 +2,29 @@ use std::fmt;
use std::error;
use std::ffi;
use std::io;

#[cfg(target_os = "linux")]
use std::sync::mpsc;

#[cfg(target_os = "linux")]
use nix;

#[cfg(target_os = "linux")]
use libc;

/// UInput error.
#[derive(Debug)]
pub enum Error {
/// System errors.
#[cfg(target_os = "linux")]
Nix(nix::Error),

/// Errors with internal nulls in names.
Nul(ffi::NulError),

Io(io::Error),

#[cfg(target_os = "linux")]
Send(mpsc::SendError<libc::input_event>),

/// The uinput file could not be found.
Expand All @@ -33,6 +40,7 @@ impl From<ffi::NulError> for Error {
}
}

#[cfg(target_os = "linux")]
impl From<nix::Error> for Error {
fn from(value: nix::Error) -> Self {
Error::Nix(value)
Expand All @@ -45,6 +53,7 @@ impl From<io::Error> for Error {
}
}

#[cfg(target_os = "linux")]
impl From<mpsc::SendError<libc::input_event>> for Error {
fn from(value: mpsc::SendError<libc::input_event>) -> Self {
Error::Send(value)
Expand All @@ -60,6 +69,7 @@ impl fmt::Display for Error {
impl error::Error for Error {
fn description(&self) -> &str {
match self {
#[cfg(target_os = "linux")]
&Error::Nix(ref err) =>
err.description(),

Expand All @@ -69,6 +79,7 @@ impl error::Error for Error {
&Error::Io(ref err) =>
err.description(),

#[cfg(target_os = "linux")]
&Error::Send(ref err) =>
err.description(),

Expand Down
5 changes: 5 additions & 0 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,11 @@ pub type Result<T> = ::std::result::Result<T, Error>;
pub mod keymapper;
pub use keymapper::*;

#[cfg(target_os = "windows")]
mod windows;
#[cfg(target_os = "windows")]
pub use windows::*;

#[cfg(target_os = "linux")]
mod linux;
#[cfg(target_os = "linux")]
Expand Down
2 changes: 0 additions & 2 deletions src/linux/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -35,8 +35,6 @@ use inotify::{
};
use std::collections::HashMap;

const VERSION: &'static str = env!("CARGO_PKG_VERSION");

const EV_KEY_U16: u16 = EV_KEY as u16;

type LinuxKeyMaps = KeyMaps<Device, u16, input_event>;
Expand Down
Loading

0 comments on commit f7afe19

Please sign in to comment.