Skip to content

Commit

Permalink
make Windows compile. Untested.
Browse files Browse the repository at this point in the history
  • Loading branch information
jtroo committed Oct 29, 2023
1 parent 8fa8ec2 commit 7e646fb
Show file tree
Hide file tree
Showing 3 changed files with 35 additions and 1 deletion.
32 changes: 31 additions & 1 deletion src/kanata/windows/interception.rs
Original file line number Diff line number Diff line change
Expand Up @@ -70,13 +70,14 @@ impl Kanata {
};
KeyEvent { code, value }
}
ic::Stroke::Mouse { state, .. } => {
ic::Stroke::Mouse { state, rolling, .. } => {
if let Some(hwid) = mouse_to_intercept_hwid {
log::trace!("checking mouse stroke {:?}", strokes[i]);
if let Some(event) = mouse_state_to_event(
dev,
&hwid,
state,
rolling,
&intrcptn,
&mut is_dev_interceptable,
) {
Expand Down Expand Up @@ -123,6 +124,7 @@ fn mouse_state_to_event(
input_dev: ic::Device,
allowed_hwid: &[u8; HWID_ARR_SZ],
state: ic::MouseState,
rolling: i16,
intrcptn: &ic::Interception,
is_dev_interceptable: &mut HashMap<ic::Device, bool>,
) -> Option<KeyEvent> {
Expand Down Expand Up @@ -191,6 +193,34 @@ fn mouse_state_to_event(
code: OsCode::BTN_EXTRA,
value: KeyValue::Release,
})
} else if state.contains(ic::MouseState::WHEEL) {
let osc = if rolling >= 0 {
OsCode::MouseWheelUp
} else {
OsCode::MouseWheelDown
};
if !MAPPED_KEYS.lock().contains(&osc) {
Some(KeyEvent {
code: osc,
value: KeyValue::Tap,
})
} else {
None
}
} else if state.contains(ic::MouseState::HWHEEL) {
let osc = if rolling >= 0 {
OsCode::MouseWheelRight
} else {
OsCode::MouseWheelLeft
};
if !MAPPED_KEYS.lock().contains(&osc) {
Some(KeyEvent {
code: osc,
value: KeyValue::Tap,
})
} else {
None
}
} else {
None
}
Expand Down
1 change: 1 addition & 0 deletions src/oskbd/windows/interception.rs
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ impl InputEvent {
match val {
KeyValue::Press | KeyValue::Repeat => KeyState::DOWN,
KeyValue::Release => KeyState::UP,
KeyValue::Tap => panic!("invalid value attempted to be sent"),
},
true,
);
Expand Down
3 changes: 3 additions & 0 deletions src/oskbd/windows/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,8 @@ pub use self::interception::*;
#[cfg(feature = "interception_driver")]
pub use interception_convert::*;

pub const HI_RES_SCROLL_UNITS_IN_LO_RES: u16 = 120;

fn send_uc(c: char, up: bool) {
log::debug!("sending unicode {c}");
let mut inputs: [INPUT; 2] = unsafe { mem::zeroed() };
Expand Down Expand Up @@ -54,6 +56,7 @@ fn write_code(code: u16, value: KeyValue) -> Result<(), std::io::Error> {
match value {
KeyValue::Press | KeyValue::Repeat => false,
KeyValue::Release => true,
KeyValue::Tap => panic!("invalid value attempted to be sent"),
},
);
Ok(())
Expand Down

0 comments on commit 7e646fb

Please sign in to comment.