Auto merge of #209 - msanders:ms/scroll-event, r=jrmuizel
Add CGEventCreateScrollWheelEvent binding <!-- Reviewable:start --> This change is [<img src="https://reviewable.io/review_button.svg" height="34" align="absmiddle" alt="Reviewable"/>](https://reviewable.io/reviews/servo/core-foundation-rs/209) <!-- Reviewable:end -->
This commit is contained in:
@@ -10,6 +10,7 @@ use foreign_types::ForeignType;
|
||||
|
||||
pub type CGEventField = libc::uint32_t;
|
||||
pub type CGKeyCode = libc::uint16_t;
|
||||
pub type CGScrollEventUnit = libc::uint32_t;
|
||||
|
||||
/// Flags for events
|
||||
///
|
||||
@@ -94,6 +95,13 @@ impl KeyCode {
|
||||
pub const UP_ARROW: CGKeyCode = 0x7E;
|
||||
}
|
||||
|
||||
#[repr(C)]
|
||||
pub struct ScrollEventUnit {}
|
||||
impl ScrollEventUnit {
|
||||
pub const PIXEL: CGScrollEventUnit = 0;
|
||||
pub const LINE: CGScrollEventUnit = 1;
|
||||
}
|
||||
|
||||
/// Constants that specify the different types of input events.
|
||||
///
|
||||
/// [Ref](http://opensource.apple.com/source/IOHIDFamily/IOHIDFamily-700/IOHIDSystem/IOKit/hidsystem/IOLLEvent.h)
|
||||
@@ -435,6 +443,31 @@ impl CGEvent {
|
||||
}
|
||||
}
|
||||
|
||||
pub fn new_scroll_event(
|
||||
source: CGEventSource,
|
||||
units: CGScrollEventUnit,
|
||||
wheel_count: u32,
|
||||
wheel1: i32,
|
||||
wheel2: i32,
|
||||
wheel3: i32,
|
||||
) -> Result<CGEvent, ()> {
|
||||
unsafe {
|
||||
let event_ref = CGEventCreateScrollWheelEvent2(
|
||||
source.as_ptr(),
|
||||
units,
|
||||
wheel_count,
|
||||
wheel1,
|
||||
wheel2,
|
||||
wheel3,
|
||||
);
|
||||
if !event_ref.is_null() {
|
||||
Ok(Self::from_ptr(event_ref))
|
||||
} else {
|
||||
Err(())
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
pub fn post(&self, tap_location: CGEventTapLocation) {
|
||||
unsafe {
|
||||
CGEventPost(tap_location, self.as_ptr());
|
||||
@@ -545,6 +578,21 @@ extern {
|
||||
fn CGEventCreateMouseEvent(source: ::sys::CGEventSourceRef, mouseType: CGEventType,
|
||||
mouseCursorPosition: CGPoint, mouseButton: CGMouseButton) -> ::sys::CGEventRef;
|
||||
|
||||
/// A non-variadic variant version of CGEventCreateScrollWheelEvent.
|
||||
///
|
||||
/// Returns a new Quartz scrolling event.
|
||||
///
|
||||
/// This function allows you to create a scrolling event and customize the
|
||||
/// event before posting it to the event system.
|
||||
fn CGEventCreateScrollWheelEvent2(
|
||||
source: ::sys::CGEventSourceRef,
|
||||
units: CGScrollEventUnit,
|
||||
wheelCount: libc::uint32_t,
|
||||
wheel1: libc::int32_t,
|
||||
wheel2: libc::int32_t,
|
||||
wheel3: libc::int32_t,
|
||||
) -> ::sys::CGEventRef;
|
||||
|
||||
/// Post an event into the event stream at a specified location.
|
||||
///
|
||||
/// This function posts the specified event immediately before any event taps
|
||||
|
||||
Reference in New Issue
Block a user