Skip to content

Commit

Permalink
fix: scroll_wheel_mapped not updated after live-reload
Browse files Browse the repository at this point in the history
  • Loading branch information
rszyma committed Oct 29, 2023
1 parent 7e646fb commit 37f1612
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 7 deletions.
9 changes: 2 additions & 7 deletions src/kanata/linux.rs
Original file line number Diff line number Diff line change
Expand Up @@ -31,11 +31,6 @@ impl Kanata {
Kanata::set_repeat_rate(&k.defcfg_items)?;
drop(k);

let scroll_wheel_mapped = MAPPED_KEYS.lock().contains(&OsCode::MouseWheelUp)
|| MAPPED_KEYS.lock().contains(&OsCode::MouseWheelDown)
|| MAPPED_KEYS.lock().contains(&OsCode::MouseWheelLeft)
|| MAPPED_KEYS.lock().contains(&OsCode::MouseWheelRight);

loop {
let events = kbd_in.read().map_err(|e| anyhow!("failed read: {}", e))?;
log::trace!("{events:?}");
Expand Down Expand Up @@ -81,7 +76,7 @@ impl Kanata {
let osc: OsCode = sev
.try_into()
.expect("standard scroll should have OsCode mapping");
if scroll_wheel_mapped {
if kanata.lock().scroll_wheel_mapped {
if MAPPED_KEYS.lock().contains(&osc) {
// Send this event to processing loop.
} else {
Expand Down Expand Up @@ -119,7 +114,7 @@ impl Kanata {
..
}) => {
// Don't passthrough hi-res mouse wheel events when scroll wheel is remapped,
if scroll_wheel_mapped {
if kanata.lock().scroll_wheel_mapped {
continue;
}
// Passthrough if none of the scroll wheel events are mapped
Expand Down
11 changes: 11 additions & 0 deletions src/kanata/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -154,6 +154,7 @@ pub struct Kanata {
/// gets stored in this buffer and if the next movemouse action is opposite axis
/// than the one stored in the buffer, both events are outputted at the same time.
movemouse_buffer: Option<(Axis, CalculatedMouseMove)>,
scroll_wheel_mapped: bool,
}

#[derive(PartialEq, Clone, Copy)]
Expand Down Expand Up @@ -333,6 +334,11 @@ impl Kanata {
.map(|s| !FALSE_VALUES.contains(&s.to_lowercase().as_str()))
.unwrap_or(true);

let scroll_wheel_mapped = cfg.mapped_keys.contains(&OsCode::MouseWheelUp)
|| cfg.mapped_keys.contains(&OsCode::MouseWheelDown)
|| cfg.mapped_keys.contains(&OsCode::MouseWheelLeft)
|| cfg.mapped_keys.contains(&OsCode::MouseWheelRight);

*MAPPED_KEYS.lock() = cfg.mapped_keys;

Ok(Self {
Expand Down Expand Up @@ -392,6 +398,7 @@ impl Kanata {
waiting_for_idle: HashSet::default(),
ticks_since_idle: 0,
movemouse_buffer: None,
scroll_wheel_mapped,
})
}

Expand Down Expand Up @@ -436,6 +443,10 @@ impl Kanata {
.get("movemouse-inherit-accel-state")
.map(|s| TRUE_VALUES.contains(&s.to_lowercase().as_str()))
.unwrap_or_default();
self.scroll_wheel_mapped = cfg.mapped_keys.contains(&OsCode::MouseWheelUp)
|| cfg.mapped_keys.contains(&OsCode::MouseWheelDown)
|| cfg.mapped_keys.contains(&OsCode::MouseWheelLeft)
|| cfg.mapped_keys.contains(&OsCode::MouseWheelRight);
*MAPPED_KEYS.lock() = cfg.mapped_keys;
Kanata::set_repeat_rate(&cfg.items)?;
log::info!("Live reload successful");
Expand Down

0 comments on commit 37f1612

Please sign in to comment.