Skip to content

Commit 532a321

Browse files
committed
core-graphics: event: Add tests to CGEventTap
1 parent 19671d3 commit 532a321

File tree

1 file changed

+27
-0
lines changed

1 file changed

+27
-0
lines changed

core-graphics/src/event.rs

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -441,6 +441,33 @@ unsafe extern "C" fn cg_event_tap_callback_internal(
441441
}
442442

443443

444+
/// ```no_run
445+
///extern crate core_foundation;
446+
///use core_foundation::runloop::{kCFRunLoopCommonModes, CFRunLoop};
447+
///use core_graphics::event::{CGEventTap, CGEventTapLocation, CGEventTapPlacement, CGEventTapOptions, CGEventType};
448+
///let current = CFRunLoop::get_current();
449+
///match CGEventTap::new(
450+
/// CGEventTapLocation::HID,
451+
/// CGEventTapPlacement::HeadInsertEventTap,
452+
/// CGEventTapOptions::Default,
453+
/// vec![CGEventType::MouseMoved],
454+
/// |_a, _b, d| {
455+
/// println!("{:?}", d.location());
456+
/// None
457+
/// },
458+
/// ) {
459+
/// Ok(tap) => unsafe {
460+
/// let loop_source = tap
461+
/// .mach_port
462+
/// .create_runloop_source(0)
463+
/// .expect("Somethings is bad ");
464+
/// current.add_source(&loop_source, kCFRunLoopCommonModes);
465+
/// tap.enable();
466+
/// CFRunLoop::run_current();
467+
/// },
468+
/// Err(_) => (assert!(false)),
469+
/// }
470+
/// ```
444471
pub struct CGEventTap<'tap_life> {
445472
pub mach_port: CFMachPort,
446473
pub callback_ref:

0 commit comments

Comments
 (0)