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 2 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
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
22 changes: 17 additions & 5 deletions alacritty/src/input/mod.rs
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,9 @@ 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,
_ => (),
MouseButton::Back => self.ctx.mouse_mut().back_button_state = state,
MouseButton::Forward => self.ctx.mouse_mut().forward_button_state = state,
_ => self.ctx.mouse_mut().other_button_state = state,
Copy link
Member

Choose a reason for hiding this comment

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

How would this ever work? You're conflating all other buttons into a single state that can't possibly be accurate.

Copy link
Author

Choose a reason for hiding this comment

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

PTAL :)

Copy link
Member

Choose a reason for hiding this comment

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

The issue is still exactly the same?

Copy link
Author

Choose a reason for hiding this comment

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

hi, it was specified here to only map Back and Forward to 8 and 9 & to report other buttons according to xterm.

this was why only MouseButton::Back & MouseButton::Forward was handled in the match statement. and the default case was to handle the other buttons as is.

hence, we check for the buttons pressed on #on_mouse_release, add the respective values & report them as is.

please correct me if I am missing something here, thanks! :)

Copy link
Member

Choose a reason for hiding this comment

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

and the default case was to handle the other buttons as is.

That is not what your code does.

}

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