use std::ffi::CStr;
use crate::NcKeyMod;
pub(crate) mod reimplemented;
mod input_type;
pub use input_type::NcInputType;
mod mice_events;
pub use mice_events::NcMiceEvents;
mod received;
pub use received::NcReceived;
pub type NcInput = crate::c_api::ffi::ncinput;
impl NcInput {
pub fn new_empty() -> NcInput {
NcInput {
id: 0,
y: 0,
x: 0,
utf8: [0; 5],
alt: false,
shift: false,
ctrl: false,
evtype: NcInputType::Unknown as u32,
ypx: -1,
xpx: -1,
modifiers: 0,
}
}
pub fn new(id: char) -> NcInput {
Self::with_all_args(id, None, None, NcKeyMod::None, NcInputType::Unknown)
}
pub fn with_alt(id: char) -> NcInput {
Self::with_all_args(id, None, None, NcKeyMod::Alt, NcInputType::Unknown)
}
pub fn with_shift(id: char) -> NcInput {
Self::with_all_args(id, None, None, NcKeyMod::Shift, NcInputType::Unknown)
}
pub fn with_ctrl(id: char) -> NcInput {
Self::with_all_args(id, None, None, NcKeyMod::Ctrl, NcInputType::Unknown)
}
pub fn with_all_args(
id: char,
x: Option<u32>,
y: Option<u32>,
modifiers: NcKeyMod,
evtype: NcInputType,
) -> NcInput {
let (ix, iy);
if let Some(x) = x {
ix = x as i32
} else {
ix = -1
};
if let Some(y) = y {
iy = y as i32
} else {
iy = -1
};
NcInput {
id: id as u32,
y: ix,
x: iy,
utf8: [0; 5],
alt: false,
shift: false,
ctrl: false,
evtype: evtype as u32,
ypx: -1,
xpx: -1,
modifiers: modifiers.into(),
}
}
}
impl NcInput {
pub fn char(&self) -> Option<char> {
let cstr = unsafe { CStr::from_ptr(self.utf8.as_ptr()) };
let string = cstr.to_string_lossy();
let raw_char = string.chars().next();
if let Some(ch) = raw_char {
if ch.is_ascii_control() {
None
} else {
Some(ch)
}
} else {
None
}
}
pub fn nomod_p(&self) -> bool {
crate::c_api::ncinput_nomod_p(self)
}
pub fn shift_p(&self) -> bool {
crate::c_api::ncinput_shift_p(self)
}
pub fn alt_p(&self) -> bool {
crate::c_api::ncinput_alt_p(self)
}
pub fn ctrl_p(&self) -> bool {
crate::c_api::ncinput_ctrl_p(self)
}
pub fn meta_p(&self) -> bool {
crate::c_api::ncinput_meta_p(self)
}
pub fn super_p(&self) -> bool {
crate::c_api::ncinput_super_p(self)
}
pub fn hyper_p(&self) -> bool {
crate::c_api::ncinput_hyper_p(self)
}
pub fn capslock_p(&self) -> bool {
crate::c_api::ncinput_capslock_p(self)
}
pub fn numlock_p(&self) -> bool {
crate::c_api::ncinput_numlock_p(self)
}
pub fn equal_p(&self, other: &NcInput) -> bool {
crate::c_api::ncinput_equal_p(self, other)
}
}
pub(crate) mod c_api {
pub use super::input_type::c_api::*;
pub use super::mice_events::c_api::*;
}