Skip to content

Commit

Permalink
Fix SGR mouse reporting
Browse files Browse the repository at this point in the history
There were two bugs fixed in this commit:

1. `sgr_mouse_report` was not always called when `SGR_MOUSE` bit was set
   due to calling `normal_mouse_report` instead of `mouse_report` in the
   scrolling method.
2. SGR reporting was always going off the left mouse button state rather
   than what was appropriate. This affected SGR scroll reporting since
   it only behaves correctly for pressed events (final character 'M').

Resolves alacritty#698.
  • Loading branch information
jwilm committed Jan 6, 2018
1 parent 2920cbe commit c44f56e
Showing 1 changed file with 13 additions and 10 deletions.
23 changes: 13 additions & 10 deletions src/input.rs
Original file line number Diff line number Diff line change
Expand Up @@ -284,8 +284,9 @@ impl<'a, A: ActionContext + 'a> Processor<'a, A> {
&& (
prev_line != self.ctx.mouse_mut().line
|| prev_col != self.ctx.mouse_mut().column
) {
self.mouse_report(32);
)
{
self.mouse_report(32, ElementState::Pressed);
}
}
}
Expand All @@ -308,18 +309,20 @@ impl<'a, A: ActionContext + 'a> Processor<'a, A> {
}
}

pub fn sgr_mouse_report(&mut self, button: u8, release: bool) {
pub fn sgr_mouse_report(&mut self, button: u8, state: ElementState) {
let (line, column) = (self.ctx.mouse_mut().line, self.ctx.mouse_mut().column);
let c = if release { 'm' } else { 'M' };
let c = match state {
ElementState::Pressed => 'M',
ElementState::Released => 'm',
};

let msg = format!("\x1b[<{};{};{}{}", button, column + 1, line + 1, c);
self.ctx.write_to_pty(msg.into_bytes());
}

pub fn mouse_report(&mut self, button: u8) {
pub fn mouse_report(&mut self, button: u8, state: ElementState) {
if self.ctx.terminal_mode().contains(mode::TermMode::SGR_MOUSE) {
let release = self.ctx.mouse_mut().left_button_state != ElementState::Pressed;
self.sgr_mouse_report(button, release);
self.sgr_mouse_report(button, state);
} else {
self.normal_mouse_report(button);
}
Expand Down Expand Up @@ -355,7 +358,7 @@ impl<'a, A: ActionContext + 'a> Processor<'a, A> {
self.ctx.clear_selection();
let report_modes = mode::TermMode::MOUSE_REPORT_CLICK | mode::TermMode::MOUSE_MOTION;
if !modifiers.shift && self.ctx.terminal_mode().intersects(report_modes) {
self.mouse_report(0);
self.mouse_report(0, ElementState::Pressed);
return;
}

Expand All @@ -368,7 +371,7 @@ impl<'a, A: ActionContext + 'a> Processor<'a, A> {
let report_modes = mode::TermMode::MOUSE_REPORT_CLICK | mode::TermMode::MOUSE_MOTION;
if !modifiers.shift && self.ctx.terminal_mode().intersects(report_modes)
{
self.mouse_report(3);
self.mouse_report(3, ElementState::Released);
return;
}

Expand Down Expand Up @@ -429,7 +432,7 @@ impl<'a, A: ActionContext + 'a> Processor<'a, A> {

let faux_scrollback_lines = self.mouse_config.faux_scrollback_lines;
if self.ctx.terminal_mode().intersects(mouse_modes) {
self.normal_mouse_report(code);
self.mouse_report(code, ElementState::Pressed);
} else if faux_scrollback_lines > 0 {
// Faux scrolling
let cmd = code + 1; // 64 + 1 = A, 65 + 1 = B
Expand Down

0 comments on commit c44f56e

Please sign in to comment.