Skip to content

Commit

Permalink
Add support for scrolling left and right. (#788)
Browse files Browse the repository at this point in the history
  • Loading branch information
Gronis committed Aug 5, 2023
1 parent db443b0 commit 55739aa
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 1 deletion.
4 changes: 4 additions & 0 deletions src/event.rs
Expand Up @@ -575,6 +575,10 @@ pub enum MouseEventKind {
ScrollDown,
/// Scrolled mouse wheel upwards (away from the user).
ScrollUp,
/// Scrolled mouse wheel left (mostly on a laptop touchpad).
ScrollLeft,
/// Scrolled mouse wheel right (mostly on a laptop touchpad).
ScrollRight,
}

/// Represents a mouse button.
Expand Down
2 changes: 2 additions & 0 deletions src/event/sys/unix/parse.rs
Expand Up @@ -788,6 +788,8 @@ fn parse_cb(cb: u8) -> io::Result<(MouseEventKind, KeyModifiers)> {
(3, true) | (4, true) | (5, true) => MouseEventKind::Moved,
(4, false) => MouseEventKind::ScrollUp,
(5, false) => MouseEventKind::ScrollDown,
(6, false) => MouseEventKind::ScrollLeft,
(7, false) => MouseEventKind::ScrollRight,
// We do not support other buttons.
_ => return Err(could_not_parse_event_error()),
};
Expand Down
10 changes: 9 additions & 1 deletion src/event/sys/windows/parse.rs
Expand Up @@ -358,7 +358,15 @@ fn parse_mouse_event_record(
}
}
EventFlags::DoubleClick => None, // double click not supported by unix terminals
EventFlags::MouseHwheeled => None, // horizontal scroll not supported by unix terminals
EventFlags::MouseHwheeled => {
if button_state.scroll_left() {
Some(MouseEventKind::ScrollLeft)
} else if button_state.scroll_right() {
Some(MouseEventKind::ScrollRight)
} else {
None
}
}
_ => None,
};

Expand Down

0 comments on commit 55739aa

Please sign in to comment.