1 use core_foundation::base::{CFRelease, CFRetain, CFTypeID};
2 use foreign_types::ForeignType;
4 /// Possible source states of an event source.
6 #[derive(Clone, Copy, Debug)]
7 pub enum CGEventSourceStateID {
9 CombinedSessionState = 0,
15 pub unsafe type CGEventSource {
16 type CType = ::sys::CGEventSource;
17 fn drop = |p| CFRelease(p as *mut _);
18 fn clone = |p| CFRetain(p as *const _) as *mut _;
23 pub fn type_id() -> CFTypeID {
25 CGEventSourceGetTypeID()
29 pub fn new(state_id: CGEventSourceStateID) -> Result<Self, ()> {
31 let event_source_ref = CGEventSourceCreate(state_id);
32 if !event_source_ref.is_null() {
33 Ok(Self::from_ptr(event_source_ref))
41 #[link(name = "CoreGraphics", kind = "framework")]
43 /// Return the type identifier for the opaque type `CGEventSourceRef'.
44 fn CGEventSourceGetTypeID() -> CFTypeID;
46 /// Return a Quartz event source created with a specified source state.
47 fn CGEventSourceCreate(stateID: CGEventSourceStateID) -> ::sys::CGEventSourceRef;