fn parse_cb(cb: u8) -> Result<(MouseEventKind, KeyModifiers)> {
    let button_number = (cb & 0b0000_0011) | ((cb & 0b1100_0000) >> 4);
    let dragging = cb & 0b0010_0000 == 0b0010_0000;

    let kind = match (button_number, dragging) {
        (0, false) => MouseEventKind::Down(MouseButton::Left),
        (1, false) => MouseEventKind::Down(MouseButton::Middle),
        (2, false) => MouseEventKind::Down(MouseButton::Right),
        (0, true) => MouseEventKind::Drag(MouseButton::Left),
        (1, true) => MouseEventKind::Drag(MouseButton::Middle),
        (2, true) => MouseEventKind::Drag(MouseButton::Right),
        (3, false) => MouseEventKind::Up(MouseButton::Left),
        (3, true) | (4, true) | (5, true) => MouseEventKind::Moved,
        (4, false) => MouseEventKind::ScrollUp,
        (5, false) => MouseEventKind::ScrollDown,
        // We do not support other buttons.
        _ => return Err(could_not_parse_event_error()),
    };

    let mut modifiers = KeyModifiers::empty();

    if cb & 0b0000_0100 == 0b0000_0100 {
        modifiers |= KeyModifiers::SHIFT;
    }
    if cb & 0b0000_1000 == 0b0000_1000 {
        modifiers |= KeyModifiers::ALT;
    }
    if cb & 0b0001_0000 == 0b0001_0000 {
        modifiers |= KeyModifiers::CONTROL;
    }

    Ok((kind, modifiers))
}
/// Cb is the byte of a mouse input that contains the button being used, the key modifiers being
/// held and whether the mouse is dragging or not.
///
/// Bit layout of cb, from low to high:
///
/// - button number
/// - button number
/// - shift
/// - meta (alt)
/// - control
/// - mouse is dragging
/// - button number
/// - button number
Cb is the byte of a mouse input that contains the button being used, the key modifiers being
held and whether the mouse is dragging or not.

Bit layout of cb, from low to high.

button number
button number
shift
meta (alt)
control
mouse is dragging
button number
button number
Cb is the byte of a mouse input that contains the button being used the key modifiers being held and whether the mouse is dragging or not . Bit layout of cb from low to high . button number button number shift meta ( alt ) control mouse is dragging button number button number
fn parse_cb(cb: u8) -> Result<(MouseEventKind, KeyModifiers)> {
    let button_number = (cb & 0b0000_0011) | ((cb & 0b1100_0000) >> 4);
    let dragging = cb & 0b0010_0000 == 0b0010_0000;
    let kind = match (button_number, dragging) {
        (0, false) => MouseEventKind::Down(MouseButton::Left),
        (1, false) => MouseEventKind::Down(MouseButton::Middle),
        (2, false) => MouseEventKind::Down(MouseButton::Right),
        (0, true) => MouseEventKind::Drag(MouseButton::Left),
        (1, true) => MouseEventKind::Drag(MouseButton::Middle),
        (2, true) => MouseEventKind::Drag(MouseButton::Right),
        (3, false) => MouseEventKind::Up(MouseButton::Left),
        (3, true) | (4, true) | (5, true) => MouseEventKind::Moved,
        (4, false) => MouseEventKind::ScrollUp,
        (5, false) => MouseEventKind::ScrollDown,
        // We do not support other buttons.
        _ => return Err(could_not_parse_event_error()),
    };
    let mut modifiers = KeyModifiers::empty();
    if cb & 0b0000_0100 == 0b0000_0100 {
        modifiers |= KeyModifiers::SHIFT;
    }
    if cb & 0b0000_1000 == 0b0000_1000 {
        modifiers |= KeyModifiers::ALT;
    }
    if cb & 0b0001_0000 == 0b0001_0000 {
        modifiers |= KeyModifiers::CONTROL;
    }
    Ok((kind, modifiers))
}
fn parse_cb ( cb : u8 ) -> Result < ( MouseEventKind , KeyModifiers ) > { let button_number = ( cb & 0b0000_0011 ) | ( ( cb & 0b1100_0000 ) >> 4 ) ; let dragging = cb & 0b0010_0000 == 0b0010_0000 ; let kind = match ( button_number , dragging ) { ( 0 , false ) => MouseEventKind :: Down ( MouseButton :: Left ) , ( 1 , false ) => MouseEventKind :: Down ( MouseButton :: Middle ) , ( 2 , false ) => MouseEventKind :: Down ( MouseButton :: Right ) , ( 0 , true ) => MouseEventKind :: Drag ( MouseButton :: Left ) , ( 1 , true ) => MouseEventKind :: Drag ( MouseButton :: Middle ) , ( 2 , true ) => MouseEventKind :: Drag ( MouseButton :: Right ) , ( 3 , false ) => MouseEventKind :: Up ( MouseButton :: Left ) , ( 3 , true ) | ( 4 , true ) | ( 5 , true ) => MouseEventKind :: Moved , ( 4 , false ) => MouseEventKind :: ScrollUp , ( 5 , false ) => MouseEventKind :: ScrollDown , // We do not support other buttons. _ => return Err ( could_not_parse_event_error ( ) ) , } ; let mut modifiers = KeyModifiers :: empty ( ) ; if cb & 0b0000_0100 == 0b0000_0100 { modifiers |= KeyModifiers :: SHIFT ; } if cb & 0b0000_1000 == 0b0000_1000 { modifiers |= KeyModifiers :: ALT ; } if cb & 0b0001_0000 == 0b0001_0000 { modifiers |= KeyModifiers :: CONTROL ; } Ok ( ( kind , modifiers ) ) }
Cb is the byte of a mouse input that contains the button being used, the key modifiers being
held and whether the mouse is dragging or not.
Cb is the byte of a mouse input that contains the button being used the key modifiers being held and whether the mouse is dragging or not .
cb
u8
cb
u8