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

Fixes #4754: report other mouse buttons #7773

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
6 changes: 6 additions & 0 deletions alacritty/src/event.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1208,6 +1208,9 @@ pub struct Mouse {
pub left_button_state: ElementState,
pub middle_button_state: ElementState,
pub right_button_state: ElementState,
pub back_button_state: ElementState,
pub forward_button_state: ElementState,
pub other_button_state: ElementState,
pub last_click_timestamp: Instant,
pub last_click_button: MouseButton,
pub click_state: ClickState,
Expand All @@ -1229,6 +1232,9 @@ impl Default for Mouse {
left_button_state: ElementState::Released,
middle_button_state: ElementState::Released,
right_button_state: ElementState::Released,
back_button_state: ElementState::Released,
forward_button_state: ElementState::Released,
other_button_state: ElementState::Released,
click_state: ClickState::None,
cell_side: Side::Left,
hint_highlight_dirty: Default::default(),
Expand Down
32 changes: 27 additions & 5 deletions alacritty/src/input/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -595,8 +595,13 @@ impl<T: EventListener, A: ActionContext<T>> Processor<T, A> {
MouseButton::Left => 0,
MouseButton::Middle => 1,
MouseButton::Right => 2,
// Can't properly report more than three buttons..
MouseButton::Back | MouseButton::Forward | MouseButton::Other(_) => return,
MouseButton::Back => 8,
MouseButton::Forward => 9,
MouseButton::Other(x) => match x {
6 | 7 => (x + 64) as u8,
10 | 11 => (x + 128) as u8,
Comment on lines +600 to +602
Copy link
Member

Choose a reason for hiding this comment

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

Why did you add this? What is it based on? X11 button IDs? How about cross-platform compatibility?

Copy link
Author

Choose a reason for hiding this comment

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

hi

Why did you add this? What is it based on? X11 button IDs?

it is based on XTerm control sequences (as mentioned here: #6957 (comment)).

How about cross-platform compatibility?

I think cross-platform compatibility is already being handled by winit (ref: rust-windowing/winit#2770)

Copy link
Member

Choose a reason for hiding this comment

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

I think cross-platform compatibility is already being handled by winit (ref: rust-windowing/winit#2770)

This is irrelevant here, because winit guarantee only for Named values, but you're mapping Other and Other is undefined. And that's what was the question about here, why you translate 6 | 7 to x + 64 where on wayland or macOS the buttons are just completely different, thus you kind of implies X11 because xterm is X11.

Copy link
Author

Choose a reason for hiding this comment

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

I think cross-platform compatibility is already being handled by winit (ref: rust-windowing/winit#2770)

This is irrelevant here, because winit guarantee only for Named values, but you're mapping Other and Other is undefined. And that's what was the question about here, why you translate 6 | 7 to x + 64 where on wayland or macOS the buttons are just completely different, thus you kind of implies X11 because xterm is X11.

alright, I will look into this & update the PR soon.

_ => return,
},
};

self.mouse_report(code, ElementState::Pressed);
Expand Down Expand Up @@ -670,8 +675,13 @@ impl<T: EventListener, A: ActionContext<T>> Processor<T, A> {
MouseButton::Left => 0,
MouseButton::Middle => 1,
MouseButton::Right => 2,
// Can't properly report more than three buttons.
MouseButton::Back | MouseButton::Forward | MouseButton::Other(_) => return,
MouseButton::Back => 8,
MouseButton::Forward => 9,
MouseButton::Other(x) => match x {
6 | 7 => (x + 64) as u8,
10 | 11 => (x + 128) as u8,
_ => return,
},
};
self.mouse_report(code, ElementState::Released);
return;
Expand Down Expand Up @@ -946,7 +956,19 @@ impl<T: EventListener, A: ActionContext<T>> Processor<T, A> {
MouseButton::Left => self.ctx.mouse_mut().left_button_state = state,
MouseButton::Middle => self.ctx.mouse_mut().middle_button_state = state,
MouseButton::Right => self.ctx.mouse_mut().right_button_state = state,
_ => (),
_ => {
let code = match button {
MouseButton::Back => 8,
MouseButton::Forward => 9,
MouseButton::Other(x) => match x {
6 | 7 => (x + 64) as u8,
10 | 11 => (x + 128) as u8,
_ => x as u8,
},
_ => return,
};
self.mouse_report(code, ElementState::Pressed)
},
}

// Skip normal mouse events if the message bar has been clicked.
Expand Down