mirror of
https://github.com/italicsjenga/winit-sonoma-fix.git
synced 2025-01-23 10:26:34 +11:00
Implement DeviceEvent::Button on Mac (#967)
* Add deviceevent logging to cursor_grab example * Implement DeviceEvent::Button on Mac
This commit is contained in:
parent
34db2d7d4c
commit
ac08601b40
3 changed files with 41 additions and 5 deletions
|
@ -1,5 +1,6 @@
|
||||||
# Unreleased
|
# Unreleased
|
||||||
|
|
||||||
|
- On Mac, implement `DeviceEvent::Button`.
|
||||||
- Change `Event::Suspended(true / false)` to `Event::Suspended` and `Event::Resumed`.
|
- Change `Event::Suspended(true / false)` to `Event::Suspended` and `Event::Resumed`.
|
||||||
- On X11, fix sanity check which checks that a monitor's reported width and height (in millimeters) are non-zero when calculating the DPI factor.
|
- On X11, fix sanity check which checks that a monitor's reported width and height (in millimeters) are non-zero when calculating the DPI factor.
|
||||||
- On Windows, when a window is initially invisible, it won't take focus from the existing visible windows.
|
- On Windows, when a window is initially invisible, it won't take focus from the existing visible windows.
|
||||||
|
|
|
@ -1,5 +1,5 @@
|
||||||
use winit::{
|
use winit::{
|
||||||
event::{ElementState, Event, KeyboardInput, WindowEvent},
|
event::{DeviceEvent, ElementState, Event, KeyboardInput, WindowEvent},
|
||||||
event_loop::{ControlFlow, EventLoop},
|
event_loop::{ControlFlow, EventLoop},
|
||||||
window::WindowBuilder,
|
window::WindowBuilder,
|
||||||
};
|
};
|
||||||
|
@ -14,8 +14,8 @@ fn main() {
|
||||||
|
|
||||||
event_loop.run(move |event, _, control_flow| {
|
event_loop.run(move |event, _, control_flow| {
|
||||||
*control_flow = ControlFlow::Wait;
|
*control_flow = ControlFlow::Wait;
|
||||||
if let Event::WindowEvent { event, .. } = event {
|
match event {
|
||||||
match event {
|
Event::WindowEvent { event, .. } => match event {
|
||||||
WindowEvent::CloseRequested => *control_flow = ControlFlow::Exit,
|
WindowEvent::CloseRequested => *control_flow = ControlFlow::Exit,
|
||||||
WindowEvent::KeyboardInput {
|
WindowEvent::KeyboardInput {
|
||||||
input:
|
input:
|
||||||
|
@ -36,7 +36,16 @@ fn main() {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
_ => (),
|
_ => (),
|
||||||
}
|
},
|
||||||
|
Event::DeviceEvent { event, .. } => match event {
|
||||||
|
DeviceEvent::MouseMotion { delta } => println!("mouse moved: {:?}", delta),
|
||||||
|
DeviceEvent::Button { button, state } => match state {
|
||||||
|
ElementState::Pressed => println!("mouse button {} pressed", button),
|
||||||
|
ElementState::Released => println!("mouse button {} released", button),
|
||||||
|
},
|
||||||
|
_ => (),
|
||||||
|
},
|
||||||
|
_ => (),
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
|
@ -10,7 +10,7 @@ use objc::{
|
||||||
};
|
};
|
||||||
|
|
||||||
use crate::{
|
use crate::{
|
||||||
event::{DeviceEvent, Event},
|
event::{DeviceEvent, ElementState, Event},
|
||||||
platform_impl::platform::{app_state::AppState, util, DEVICE_ID},
|
platform_impl::platform::{app_state::AppState, util, DEVICE_ID},
|
||||||
};
|
};
|
||||||
|
|
||||||
|
@ -101,6 +101,32 @@ unsafe fn maybe_dispatch_device_event(event: id) {
|
||||||
|
|
||||||
AppState::queue_events(events);
|
AppState::queue_events(events);
|
||||||
}
|
}
|
||||||
|
appkit::NSLeftMouseDown | appkit::NSRightMouseDown | appkit::NSOtherMouseDown => {
|
||||||
|
let mut events = VecDeque::with_capacity(1);
|
||||||
|
|
||||||
|
events.push_back(Event::DeviceEvent {
|
||||||
|
device_id: DEVICE_ID,
|
||||||
|
event: DeviceEvent::Button {
|
||||||
|
button: event.buttonNumber() as u32,
|
||||||
|
state: ElementState::Pressed,
|
||||||
|
},
|
||||||
|
});
|
||||||
|
|
||||||
|
AppState::queue_events(events);
|
||||||
|
}
|
||||||
|
appkit::NSLeftMouseUp | appkit::NSRightMouseUp | appkit::NSOtherMouseUp => {
|
||||||
|
let mut events = VecDeque::with_capacity(1);
|
||||||
|
|
||||||
|
events.push_back(Event::DeviceEvent {
|
||||||
|
device_id: DEVICE_ID,
|
||||||
|
event: DeviceEvent::Button {
|
||||||
|
button: event.buttonNumber() as u32,
|
||||||
|
state: ElementState::Released,
|
||||||
|
},
|
||||||
|
});
|
||||||
|
|
||||||
|
AppState::queue_events(events);
|
||||||
|
}
|
||||||
_ => (),
|
_ => (),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Reference in a new issue