Skip to content
This repository has been archived by the owner on Oct 22, 2019. It is now read-only.

Calculate relative y mouse event cursor position #11

Merged
merged 6 commits into from
Oct 21, 2019

Conversation

TimonPost
Copy link
Member

@TimonPost TimonPost commented Oct 20, 2019

Fixes: crossterm-rs/crossterm#278

With patch:

TOP, LEFT click:

image

Previously:

TOP, LEFT click
image

@TimonPost TimonPost requested a review from zrzka October 20, 2019 14:13
Timon Post added 2 commits October 20, 2019 16:14
@TimonPost
Copy link
Member Author

@zrzka can you check on macos/linux if the cursor positions from input events are relative to the current window or absolute to the current screen buffer. Otherwise, this patch is not needed to sync the behavior. But I am pretty convinced it was relative to the window... We better double-check.

This PR should be merged before the release

@TimonPost TimonPost changed the title Calculate relative window size Calculate relative y mouse event cursor position Oct 20, 2019
src/input/windows.rs Outdated Show resolved Hide resolved
@zrzka
Copy link
Contributor

zrzka commented Oct 20, 2019

@TimonPost here's my test code ...

use std::io::Write;

use crossterm_input::{input, InputEvent, KeyEvent, RawScreen, Result};

fn read_asynchronously() -> Result<()> {
    let _raw = RawScreen::into_raw_mode()?;

    let input = input();

    input.enable_mouse_mode()?;

    let mut stdin = input.read_async();

    loop {
        if let Some(key_event) = stdin.next() {
            match key_event {
                InputEvent::Keyboard(KeyEvent::Esc) => break,
                InputEvent::Keyboard(KeyEvent::Up) => {
                    let mut stdout = std::io::stdout();
                    let _ = write!(stdout, "\x1B[5T");
                    let _ = stdout.flush();
                }
                InputEvent::Keyboard(KeyEvent::Down) => {
                    let mut stdout = std::io::stdout();
                    let _ = write!(stdout, "\x1B[5S");
                    let _ = stdout.flush();
                }
                ie => println!("\r{:?}", ie),
            };
        }
    }

    input.disable_mouse_mode()
}

fn main() -> Result<()> {
    read_asynchronously()
}

... no matter how many times I hit Up/Down, the top/left mouse click is reported as 0, 0.

@zrzka
Copy link
Contributor

zrzka commented Oct 20, 2019

Also there's no changelog entry, but for now, don't add it. Once you fix the unwrap() and the PR will be merged, I'll add it to the deprecated-release branch (to avoid merge conflict) and will also add it to the release-0.12 PR in the crossterm crate.

@TimonPost
Copy link
Member Author

TimonPost commented Oct 20, 2019

running your code at TOP LEFT
image

Copy link
Contributor

@zrzka zrzka left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Happy :)

@zrzka
Copy link
Contributor

zrzka commented Oct 20, 2019

Changelogs updated here & here.

@zrzka
Copy link
Contributor

zrzka commented Oct 21, 2019

@TimonPost made more tests on Linux & macOS. Both behaves in the same way, top/left is 0,0 no matter how many times I scroll up/down. If you tested this on Windows, we can merge it.

@TimonPost TimonPost merged commit b56a273 into master Oct 21, 2019
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
2 participants