Implement DeviceEvent::Button on Mac (#967)

* Add deviceevent logging to cursor_grab example

* Implement DeviceEvent::Button on Mac
This commit is contained in:
Tristam MacDonald 2019-06-26 23:58:21 -07:00 committed by Osspial
parent 34db2d7d4c
commit ac08601b40
3 changed files with 41 additions and 5 deletions

View file

@ -10,7 +10,7 @@ use objc::{
};
use crate::{
event::{DeviceEvent, Event},
event::{DeviceEvent, ElementState, Event},
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);
}
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);
}
_ => (),
}
}