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

Cross platfrom mouse button translation #1785

Closed
kchibisov opened this issue Dec 5, 2020 · 9 comments · Fixed by #2770
Closed

Cross platfrom mouse button translation #1785

kchibisov opened this issue Dec 5, 2020 · 9 comments · Fixed by #2770
Labels
C - needs discussion Direction must be ironed out D - easy Likely easier than most tasks here S - api Design and usability

Comments

@kchibisov
Copy link
Member

kchibisov commented Dec 5, 2020

Right now winit only provides translation for Left, Right, and Middle, mouse buttons and everything else is via Other, however each platform defines their own value for other for the same buttons, it'll be nice to agree and extend MouseButton enum to include extra mouse buttons as well.

@kchibisov kchibisov added S - api Design and usability C - needs discussion Direction must be ironed out labels Dec 5, 2020
@maroider
Copy link
Member

maroider commented Dec 5, 2020

It would probably be uncontroversial to include the Forward and Back buttons.
I'm not sure what other "common" buttons exist.

@kchibisov
Copy link
Member Author

Yeah, I also think that we can include those, I just know that there are mices with something like numpad right on them, though, I have no clue how they are identified.

@maroider
Copy link
Member

maroider commented Dec 5, 2020

I just know that there are mices with something like numpad right on them

The only mice that I know of with such features are "gaming" mice. Presumably, they don't directly expose these extra buttons as generic mouse buttons, but instead have some software component (like Razer Synapse) translate them into whatever is configured by the user. It could also be the case that the mouse presents itself to the operating system as both a mouse and a keyboard.

In particular, the "Razer Naga Trinity" and "Razer Naga Chroma" seem to match what you've described.

@dhardy
Copy link
Contributor

dhardy commented Dec 5, 2020

It could also be the case that the mouse presents itself to the operating system as both a mouse and a keyboard.

I've certainly seen this behaviour (also for keyboards).

The most "standard" buttons a mouse might have would be left/right/middle, scroll up/down/left/right, and two left and two right side buttons. However I don't think there's an OS standard beyond Back/Forward.

@maroider
Copy link
Member

maroider commented Dec 5, 2020

There are admittedly two other "buttons" which seem to be semi-standard: tilting the scroll wheel left and right, but these "buttons" seem to either emulate a horizontal scroll wheel or the "forward" and "back" buttons, depending on the exact model of mouse.

EDIT: Upon reading @dhardy's comment above, I've now realized that this comment was entirely redundant. Oops.

@chrisduerr
Copy link
Contributor

@kchibisov Which platform differences are you aware of? I know for example that the "backward" button in X11 is 8, so there seems to be quite a lot of distance between RMB and that.

I'm also not sure if this is consistent across mice? But I'd hope so at least.

@kchibisov
Copy link
Member Author

kchibisov commented Dec 5, 2020

On Wayland those are 0x113 and 0x114, since Wayland just forwards kernel buttons. On X11 they are indeed 8 and 9. Web right now uses some other stuff, and macOS, I bet, do something else as well.

@chrisduerr
Copy link
Contributor

Seems like the only option would be to have actual constants/enum values for all the buttons and painfully mapping every single one of them.

@maroider
Copy link
Member

I know for example that the "backward" button in X11 is 8, so there seems to be quite a lot of distance between RMB and that.

I wasn't actually actively looking out for this, but I stumbled onto this while dealing with XkbStateNotify.
It seems like the following values and "buttons" are used/available on X11, at least with the mouse I tried.

Button Value
Left mouse button 1
Middle mouse button 2
Right mouse button 3
Mouse wheel up 4
Mouse wheel down 5
Mouse wheel left 6
Mouse wheel right 7
Back 8
Forward 9

I was admittedly a little surprised to see these "mouse wheel" buttons, which look like they correspond to moving the mouse wheel one by one "ratchet".

I think this behaviour may also be available/implementable in some form on Windows, as I recall reading that some people would re-bind the jump key in Counter Strike to the mouse wheel in order to bhop (bunny hop) (see "mwheeldown" and "mwheelup" on the Valve Developer Community (wiki).

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
C - needs discussion Direction must be ironed out D - easy Likely easier than most tasks here S - api Design and usability
4 participants