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

Synchronize mouse button events coordinates with the cursor #267

Closed
zrzka opened this issue Oct 1, 2019 · 5 comments · Fixed by crossterm-rs/crossterm-input#7
Closed

Comments

@zrzka
Copy link
Contributor

zrzka commented Oct 1, 2019

I find it a bit weird that the cursor does use 0, 0 for the first column/row, but the mouse events do use 1, 1 for the first column/row. I'd assume that everything starts from 0, 0.

Not much investigation done on my side, I just noticed this when working on the documentation/examples.

@TimonPost
Copy link
Member

TimonPost commented Oct 1, 2019

I am going to validate this, if it is different, yes then it should be synced.

@zrzka
Copy link
Contributor Author

zrzka commented Oct 3, 2019

@TimonPost did you have a chance to validate this issue on Windows as well? Before touching it, I'd like to be sure that this isn't just some macOS/UNIX quirk or even just my computer only.

@zrzka
Copy link
Contributor Author

zrzka commented Oct 3, 2019

All three types with coordinates are producing numbers starting at 1.

Screen_Shot_2019-10-03_at_11_34_18

My test code:

use crossterm_input::{InputEvent, KeyEvent, MouseEvent, RawScreen, Result, TerminalInput};

fn main() -> Result<()> {
    let input = TerminalInput::new();
    let _raw = RawScreen::into_raw_mode()?;

    let mut reader = input.read_sync();
    input.enable_mouse_mode()?;

    loop {
        if let Some(event) = reader.next() {
            match event {
                InputEvent::Keyboard(KeyEvent::Esc) => break,
                InputEvent::Keyboard(KeyEvent::Enter) => println!("Enter"),
                InputEvent::Mouse(mouse) => {
                    match mouse {
                        MouseEvent::Press(_, x, y) => println!("Press: {}x{}", x, y),
                        MouseEvent::Hold(x, y) => println!("Move: {}x{}", x, y),
                        MouseEvent::Release(x, y) => println!("Release: {}x{}", x, y),
                        _ => {}
                    };
                }
                _ => {}
            };
        }
    }

    input.disable_mouse_mode()?;
    Ok(())
}

@TimonPost
Copy link
Member

image

In the windows terminal, they start with 1,1 as well

@zrzka
Copy link
Contributor Author

zrzka commented Oct 3, 2019

Thanks, will PR it later today ...

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants