diff --git a/src/event.rs b/src/event.rs
index 27954de..25dc389 100644
--- a/src/event.rs
+++ b/src/event.rs
@@ -285,7 +285,7 @@ pub enum Event {
/// ## Mouse Buttons
///
/// Some platforms/terminals do not report mouse button for the
-/// `MouseEvent::Up` and `MouseEvent::Drag` events. `MouseButton::Left`
+/// `MouseEventKind::Up` and `MouseEventKind::Drag` events. `MouseButton::Left`
/// is returned if we don't know which button was used.
///
/// ## Key Modifiers
@@ -295,27 +295,41 @@ pub enum Event {
/// `Ctrl` + left mouse button click as a right mouse button click.
#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))]
#[derive(Debug, PartialOrd, PartialEq, Eq, Clone, Copy, Hash)]
-pub enum MouseEvent {
- /// Pressed mouse button.
- ///
- /// Contains mouse button, pressed pointer location (column, row), and additional key modifiers.
- Down(MouseButton, u16, u16, KeyModifiers),
- /// Released mouse button.
- ///
- /// Contains mouse button, released pointer location (column, row), and additional key modifiers.
- Up(MouseButton, u16, u16, KeyModifiers),
- /// Moved mouse pointer while pressing a mouse button.
- ///
- /// Contains the pressed mouse button, released pointer location (column, row), and additional key modifiers.
- Drag(MouseButton, u16, u16, KeyModifiers),
+pub struct MouseEvent {
+ /// The kind of mouse event that was caused.
+ pub kind: MouseEventKind,
+ /// The column that the event occurred on.
+ pub column: u16,
+ /// The row that the event occurred on.
+ pub row: u16,
+ /// The key modifiers active when the event occurred.
+ pub modifiers: KeyModifiers,
+}
+
+/// A mouse event kind.
+///
+/// # Platform-specific Notes
+///
+/// ## Mouse Buttons
+///
+/// Some platforms/terminals do not report mouse button for the
+/// `MouseEventKind::Up` and `MouseEventKind::Drag` events. `MouseButton::Left`
+/// is returned if we don't know which button was used.
+#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))]
+#[derive(Debug, PartialOrd, PartialEq, Eq, Clone, Copy, Hash)]
+pub enum MouseEventKind {
+ /// Pressed mouse button. Contains the button that was pressed.
+ Down(MouseButton),
+ /// Released mouse button. Contains the button that was released.
+ Up(MouseButton),
+ /// Moved the mouse cursor while pressing the contained mouse button.
+ Drag(MouseButton),
+ /// Moved the mouse cursor while not pressing a mouse button.
+ Moved,
/// Scrolled mouse wheel downwards (towards the user).
- ///
- /// Contains the scroll location (column, row), and additional key modifiers.
- ScrollDown(u16, u16, KeyModifiers),
+ ScrollDown,
/// Scrolled mouse wheel upwards (away from the user).
- ///
- /// Contains the scroll location (column, row), and additional key modifiers.
- ScrollUp(u16, u16, KeyModifiers),
+ ScrollUp,
}
/// Represents a mouse button.
diff --git a/src/event/ansi.rs b/src/event/ansi.rs
index 5e5b837..b125950 100644
--- a/src/event/ansi.rs
+++ b/src/event/ansi.rs
@@ -3,15 +3,23 @@
use crate::csi;
pub(crate) const ENABLE_MOUSE_MODE_CSI_SEQUENCE: &str = concat!(
+ // Normal tracking: Send mouse X & Y on button press and release
csi!("?1000h"),
+ // Button-event tracking: Report button motion events (dragging)
csi!("?1002h"),
+ // Any-event tracking: Report all motion events
+ csi!("?1003h"),
+ // RXVT mouse mode: Allows mouse coordinates of >223
csi!("?1015h"),
- csi!("?1006h")
+ // SGR mouse mode: Allows mouse coordinates of >223, preferred over RXVT mode
+ csi!("?1006h"),
);
pub(crate) const DISABLE_MOUSE_MODE_CSI_SEQUENCE: &str = concat!(
+ // The above, in reverse order.
csi!("?1006l"),
csi!("?1015l"),
+ csi!("?1003l"),
csi!("?1002l"),
- csi!("?1000l")
+ csi!("?1000l"),
);
diff --git a/src/event/sys/unix/parse.rs b/src/event/sys/unix/parse.rs
index cd686ba..aba8ef5 100644
--- a/src/event/sys/unix/parse.rs
+++ b/src/event/sys/unix/parse.rs
@@ -1,5 +1,5 @@
use crate::{
- event::{Event, KeyCode, KeyEvent, KeyModifiers, MouseButton, MouseEvent},
+ event::{Event, KeyCode, KeyEvent, KeyModifiers, MouseButton, MouseEvent, MouseEventKind},
ErrorKind, Result,
};
@@ -141,8 +141,8 @@ pub(crate) fn parse_csi(buffer: &[u8]) -> Result