Bug 1858509 add thread-safety annotations around MediaSourceDemuxer::mMonitor r=alwu
[gecko.git] / third_party / rust / core-graphics / src / event_source.rs
blob6db64a2dca1503907ab319b82464b91284cd8837
1 use core_foundation::base::{CFRelease, CFRetain, CFTypeID};
2 use foreign_types::ForeignType;
4 /// Possible source states of an event source.
5 #[repr(C)]
6 #[derive(Clone, Copy, Debug)]
7 pub enum CGEventSourceStateID {
8     Private = -1,
9     CombinedSessionState = 0,
10     HIDSystemState = 1,
13 foreign_type! {
14     #[doc(hidden)]
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 _;
19     }
22 impl CGEventSource {
23     pub fn type_id() -> CFTypeID {
24         unsafe {
25             CGEventSourceGetTypeID()
26         }
27     }
29     pub fn new(state_id: CGEventSourceStateID) -> Result<Self, ()> {
30         unsafe {
31             let event_source_ref = CGEventSourceCreate(state_id);
32             if !event_source_ref.is_null() {
33                 Ok(Self::from_ptr(event_source_ref))
34             } else {
35                 Err(())
36             }
37         }
38     }
41 #[link(name = "CoreGraphics", kind = "framework")]
42 extern {
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;