Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add support for scrolling left and right. #788

Merged
merged 4 commits into from
Aug 5, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
4 changes: 4 additions & 0 deletions src/event.rs
Original file line number Diff line number Diff line change
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
Original file line number Diff line number Diff line change
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
Original file line number Diff line number Diff line change
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