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:
parent
779f52a21f
commit
9d9d21cfdb
8 changed files with 191 additions and 229 deletions
|
|
@ -1705,9 +1705,9 @@ unsafe fn public_window_callback_inner(
|
|||
}
|
||||
},
|
||||
|
||||
WM_LBUTTONDOWN => {
|
||||
WM_LBUTTONDOWN | WM_RBUTTONDOWN | WM_MBUTTONDOWN => {
|
||||
use winit_core::event::ElementState::Pressed;
|
||||
use winit_core::event::MouseButton::Left;
|
||||
use winit_core::event::MouseButton;
|
||||
use winit_core::event::WindowEvent::PointerButton;
|
||||
|
||||
unsafe { capture_mouse(window, &mut userdata.window_state_lock()) };
|
||||
|
|
@ -1723,14 +1723,20 @@ unsafe fn public_window_callback_inner(
|
|||
primary: true,
|
||||
state: Pressed,
|
||||
position,
|
||||
button: Left.into(),
|
||||
button: match msg {
|
||||
WM_LBUTTONDOWN => MouseButton::Left,
|
||||
WM_RBUTTONDOWN => MouseButton::Right,
|
||||
WM_MBUTTONDOWN => MouseButton::Middle,
|
||||
_ => unreachable!(),
|
||||
}
|
||||
.into(),
|
||||
});
|
||||
result = ProcResult::Value(0);
|
||||
},
|
||||
|
||||
WM_LBUTTONUP => {
|
||||
WM_LBUTTONUP | WM_RBUTTONUP | WM_MBUTTONUP => {
|
||||
use winit_core::event::ElementState::Released;
|
||||
use winit_core::event::MouseButton::Left;
|
||||
use winit_core::event::MouseButton;
|
||||
use winit_core::event::WindowEvent::PointerButton;
|
||||
|
||||
unsafe { release_mouse(userdata.window_state_lock()) };
|
||||
|
|
@ -1746,106 +1752,20 @@ unsafe fn public_window_callback_inner(
|
|||
primary: true,
|
||||
state: Released,
|
||||
position,
|
||||
button: Left.into(),
|
||||
});
|
||||
result = ProcResult::Value(0);
|
||||
},
|
||||
|
||||
WM_RBUTTONDOWN => {
|
||||
use winit_core::event::ElementState::Pressed;
|
||||
use winit_core::event::MouseButton::Right;
|
||||
use winit_core::event::WindowEvent::PointerButton;
|
||||
|
||||
unsafe { capture_mouse(window, &mut userdata.window_state_lock()) };
|
||||
|
||||
update_modifiers(window, userdata);
|
||||
|
||||
let x = util::get_x_lparam(lparam as u32) as i32;
|
||||
let y = util::get_y_lparam(lparam as u32) as i32;
|
||||
let position = PhysicalPosition::new(x as f64, y as f64);
|
||||
|
||||
userdata.send_window_event(window, PointerButton {
|
||||
device_id: None,
|
||||
primary: true,
|
||||
state: Pressed,
|
||||
position,
|
||||
button: Right.into(),
|
||||
});
|
||||
result = ProcResult::Value(0);
|
||||
},
|
||||
|
||||
WM_RBUTTONUP => {
|
||||
use winit_core::event::ElementState::Released;
|
||||
use winit_core::event::MouseButton::Right;
|
||||
use winit_core::event::WindowEvent::PointerButton;
|
||||
|
||||
unsafe { release_mouse(userdata.window_state_lock()) };
|
||||
|
||||
update_modifiers(window, userdata);
|
||||
|
||||
let x = util::get_x_lparam(lparam as u32) as i32;
|
||||
let y = util::get_y_lparam(lparam as u32) as i32;
|
||||
let position = PhysicalPosition::new(x as f64, y as f64);
|
||||
|
||||
userdata.send_window_event(window, PointerButton {
|
||||
device_id: None,
|
||||
primary: true,
|
||||
state: Released,
|
||||
position,
|
||||
button: Right.into(),
|
||||
});
|
||||
result = ProcResult::Value(0);
|
||||
},
|
||||
|
||||
WM_MBUTTONDOWN => {
|
||||
use winit_core::event::ElementState::Pressed;
|
||||
use winit_core::event::MouseButton::Middle;
|
||||
use winit_core::event::WindowEvent::PointerButton;
|
||||
|
||||
unsafe { capture_mouse(window, &mut userdata.window_state_lock()) };
|
||||
|
||||
update_modifiers(window, userdata);
|
||||
|
||||
let x = util::get_x_lparam(lparam as u32) as i32;
|
||||
let y = util::get_y_lparam(lparam as u32) as i32;
|
||||
let position = PhysicalPosition::new(x as f64, y as f64);
|
||||
|
||||
userdata.send_window_event(window, PointerButton {
|
||||
device_id: None,
|
||||
primary: true,
|
||||
state: Pressed,
|
||||
position,
|
||||
button: Middle.into(),
|
||||
});
|
||||
result = ProcResult::Value(0);
|
||||
},
|
||||
|
||||
WM_MBUTTONUP => {
|
||||
use winit_core::event::ElementState::Released;
|
||||
use winit_core::event::MouseButton::Middle;
|
||||
use winit_core::event::WindowEvent::PointerButton;
|
||||
|
||||
unsafe { release_mouse(userdata.window_state_lock()) };
|
||||
|
||||
update_modifiers(window, userdata);
|
||||
|
||||
let x = util::get_x_lparam(lparam as u32) as i32;
|
||||
let y = util::get_y_lparam(lparam as u32) as i32;
|
||||
let position = PhysicalPosition::new(x as f64, y as f64);
|
||||
|
||||
userdata.send_window_event(window, PointerButton {
|
||||
device_id: None,
|
||||
primary: true,
|
||||
state: Released,
|
||||
position,
|
||||
button: Middle.into(),
|
||||
button: match msg {
|
||||
WM_LBUTTONUP => MouseButton::Left,
|
||||
WM_RBUTTONUP => MouseButton::Right,
|
||||
WM_MBUTTONUP => MouseButton::Middle,
|
||||
_ => unreachable!(),
|
||||
}
|
||||
.into(),
|
||||
});
|
||||
result = ProcResult::Value(0);
|
||||
},
|
||||
|
||||
WM_XBUTTONDOWN => {
|
||||
use winit_core::event::ElementState::Pressed;
|
||||
use winit_core::event::MouseButton::{Back, Forward, Other};
|
||||
use winit_core::event::MouseButton;
|
||||
use winit_core::event::WindowEvent::PointerButton;
|
||||
let xbutton = util::get_xbutton_wparam(wparam as u32);
|
||||
|
||||
|
|
@ -1857,25 +1777,25 @@ unsafe fn public_window_callback_inner(
|
|||
let y = util::get_y_lparam(lparam as u32) as i32;
|
||||
let position = PhysicalPosition::new(x as f64, y as f64);
|
||||
|
||||
// 1 is defined as back, 2 as forward; other codes are unexpected.
|
||||
let b = xbutton as u8 + MouseButton::Back as u8 - 1;
|
||||
|
||||
userdata.send_window_event(window, PointerButton {
|
||||
device_id: None,
|
||||
primary: true,
|
||||
state: Pressed,
|
||||
position,
|
||||
button: match xbutton {
|
||||
1 => Back,
|
||||
2 => Forward,
|
||||
_ => Other(xbutton),
|
||||
}
|
||||
.into(),
|
||||
// 1 is defined as back, 2 as forward; other codes are unexpected.
|
||||
button: MouseButton::try_from_u8(b).unwrap().into(),
|
||||
});
|
||||
result = ProcResult::Value(0);
|
||||
},
|
||||
|
||||
WM_XBUTTONUP => {
|
||||
use winit_core::event::ElementState::Released;
|
||||
use winit_core::event::MouseButton::{Back, Forward, Other};
|
||||
use winit_core::event::MouseButton;
|
||||
use winit_core::event::WindowEvent::PointerButton;
|
||||
|
||||
let xbutton = util::get_xbutton_wparam(wparam as u32);
|
||||
|
||||
unsafe { release_mouse(userdata.window_state_lock()) };
|
||||
|
|
@ -1886,17 +1806,16 @@ unsafe fn public_window_callback_inner(
|
|||
let y = util::get_y_lparam(lparam as u32) as i32;
|
||||
let position = PhysicalPosition::new(x as f64, y as f64);
|
||||
|
||||
// 1 is defined as back, 2 as forward; other codes are unexpected.
|
||||
let b = xbutton as u8 + MouseButton::Back as u8 - 1;
|
||||
|
||||
userdata.send_window_event(window, PointerButton {
|
||||
device_id: None,
|
||||
primary: true,
|
||||
state: Released,
|
||||
position,
|
||||
button: match xbutton {
|
||||
1 => Back,
|
||||
2 => Forward,
|
||||
_ => Other(xbutton),
|
||||
}
|
||||
.into(),
|
||||
// 1 is defined as back, 2 as forward; other codes are unexpected.
|
||||
button: MouseButton::try_from_u8(b).unwrap().into(),
|
||||
});
|
||||
result = ProcResult::Value(0);
|
||||
},
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue