libnotcurses_sys/input/
reimplemented.rs

1//!
2
3use crate::{NcInput, NcInputType, NcKeyMod};
4
5/// Is this `NcInput` free of modifiers (alt, control, shift)?
6///
7/// *Method: NcInput.[nomod_p()][NcInput#method.nomod_p].*
8pub fn ncinput_nomod_p(input: &NcInput) -> bool {
9    NcKeyMod::from(input.modifiers).none_p()
10}
11
12/// Returns true if the `Shift` modifier is present.
13///
14/// *Method: NcInput.[shift_p()][NcInput#method.shift_p].*
15pub fn ncinput_shift_p(input: &NcInput) -> bool {
16    NcKeyMod::from(input.modifiers).shift_p()
17}
18
19/// Returns true if the `Alt` modifier is present.
20///
21/// *Method: NcInput.[alt_p()][NcInput#method.alt_p].*
22pub fn ncinput_alt_p(input: &NcInput) -> bool {
23    NcKeyMod::from(input.modifiers).alt_p()
24}
25
26/// Returns true if the `Ctrl` modifier is present.
27///
28/// *Method: NcInput.[ctrl_p()][NcInput#method.ctrl_p].*
29pub fn ncinput_ctrl_p(input: &NcInput) -> bool {
30    NcKeyMod::from(input.modifiers).ctrl_p()
31}
32
33/// Returns true if the `Meta` modifier is present.
34///
35/// *Method: NcInput.[meta_p()][NcInput#method.meta_p].*
36pub fn ncinput_meta_p(input: &NcInput) -> bool {
37    NcKeyMod::from(input.modifiers).meta_p()
38}
39
40/// Returns true if the `Super` modifier is present.
41///
42/// *Method: NcInput.[super_p()][NcInput#method.super_p].*
43pub fn ncinput_super_p(input: &NcInput) -> bool {
44    NcKeyMod::from(input.modifiers).super_p()
45}
46
47/// Returns true if the `Hyper` modifier is present.
48///
49/// *Method: NcInput.[hyper_p()][NcInput#method.hyper_p].*
50pub fn ncinput_hyper_p(input: &NcInput) -> bool {
51    NcKeyMod::from(input.modifiers).hyper_p()
52}
53
54/// Returns true if the `CapsLock` modifier is present.
55///
56/// *Method: NcInput.[capslock_p()][NcInput#method.capslock_p].*
57pub fn ncinput_capslock_p(input: &NcInput) -> bool {
58    NcKeyMod::from(input.modifiers).capslock_p()
59}
60
61/// Returns true if the `NumLock` modifier is present.
62///
63/// *Method: NcInput.[numlock_p()][NcInput#method.numlock_p].*
64pub fn ncinput_numlock_p(input: &NcInput) -> bool {
65    NcKeyMod::from(input.modifiers).numlock_p()
66}
67
68/// Returns true if the two `NcInput` are data-equivalent.
69///
70/// *Method: NcInput.[equal_p()][NcInput#method.equal_p].*
71pub fn ncinput_equal_p(n1: &NcInput, n2: &NcInput) -> bool {
72    if n1.id != n2.id {
73        return false;
74    }
75    if n1.y != n2.y || n1.x != n2.x {
76        return false;
77    }
78    if (n1.modifiers & !(NcKeyMod::CapsLock | NcKeyMod::NumLock))
79        != (n2.modifiers & !(NcKeyMod::CapsLock | NcKeyMod::NumLock))
80    {
81        return false;
82    }
83    if n1.evtype != n2.evtype
84        && ((n1.evtype != NcInputType::Unknown as u32 && n1.evtype != NcInputType::Press as u32)
85            || (n2.evtype != NcInputType::Unknown as u32 && n2.evtype != NcInputType::Press as u32))
86    {
87        return false;
88    }
89    if n1.ypx != n2.ypx || n1.xpx != n2.xpx {
90        return false;
91    }
92    true
93}