winit-core: revise MouseButton type

Unify the values of `MouseButton` and thus remove `Other` variant in
limit possible buttons to 32, which was picked based on platform
capabilities, where 32 is the highest.

For the reference, SDL has identical limit.
This commit is contained in:
Diggory Hardy 2025-08-07 09:52:34 +01:00 committed by Kirill Chibisov
parent 779f52a21f
commit 9d9d21cfdb
8 changed files with 191 additions and 229 deletions

View file

@ -1007,7 +1007,6 @@ impl EventProcessor {
position,
button: MouseButton::Middle.into(),
},
xlib::Button3 => WindowEvent::PointerButton {
device_id,
primary: true,
@ -1034,28 +1033,25 @@ impl EventProcessor {
},
ElementState::Released => return,
},
8 => WindowEvent::PointerButton {
device_id,
primary: true,
state,
position,
button: MouseButton::Back.into(),
},
9 => WindowEvent::PointerButton {
x @ 8..37 => WindowEvent::PointerButton {
device_id,
primary: true,
state,
position,
button: MouseButton::Forward.into(),
// Button 8 maps to MouseButton::BACK = 3; 36 maps to MouseButton::Button32.
// 255 is the largest code yielded on X11 (tested).
button: MouseButton::try_from_u8((x - 5) as u8).unwrap().into(),
},
x => WindowEvent::PointerButton {
x @ 37..=0xff => WindowEvent::PointerButton {
device_id,
primary: true,
state,
position,
button: MouseButton::Other(x as u16).into(),
// 255 is the largest code yielded on X11 (tested).
button: ButtonSource::Unknown(x as u16),
},
_ => return,
};
app.window_event(&self.target, window_id, event);