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
Merged
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 12 additions & 3 deletions src/input/windows.rs
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ use winapi::um::{

use crossterm_winapi::{
ButtonState, Console, ConsoleMode, EventFlags, Handle, InputEventType, KeyEventRecord,
MouseEvent,
MouseEvent, ScreenBuffer,
};
use lazy_static::lazy_static;

Expand Down Expand Up @@ -536,12 +536,21 @@ fn parse_mouse_event_record(event: &MouseEvent) -> Option<crate::MouseEvent> {
// mimicks the behavior; additionally, in xterm, mouse move is only handled when a
// mouse button is held down (ie. mouse drag)

let window_size = ScreenBuffer::current()
.unwrap()
zrzka marked this conversation as resolved.
Show resolved Hide resolved
.info()
.unwrap()
.terminal_window();

// Windows returns (0, 0) for upper/left
let xpos = event.mouse_position.x;
let ypos = event.mouse_position.y;
let mut ypos = event.mouse_position.y;

// TODO (@imdaveho): check if linux only provides coords for visible terminal window vs the total buffer
// The y position in with a mouse event is not relative to the window but absolute to screen buffer.
// This means that when the mouse cursor is at top left it will be x: 0, y: 2295 (e.g. y = number of cells counting from the absolute buffer height) instead of relative x: 0, y: 0 to the window.
ypos = ypos - window_size.top;

// TODO (@imdaveho): check if linux only provides coords for visible terminal window vs the total buffer
match event.event_flags {
EventFlags::PressOrRelease => {
// Single click
Expand Down