Debian Codegraph @

third_party/rust/core-graphics/src/event_source.rs

raw
1 use core_foundation::base::{CFRelease, CFRetain, CFTypeID};
2 use foreign_types::ForeignType;
3
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,
11 }
12
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 }
20 }
21
22 impl CGEventSource {
23 pub fn type_id() -> CFTypeID {
24 unsafe {
25 CGEventSourceGetTypeID()
26 }
27 }
28
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 }
39 }
40
41 #[link(name = "CoreGraphics", kind = "framework")]
42 extern {
43 /// Return the type identifier for the opaque type `CGEventSourceRef'.
44 fn CGEventSourceGetTypeID() -> CFTypeID;
45
46 /// Return a Quartz event source created with a specified source state.
47 fn CGEventSourceCreate(stateID: CGEventSourceStateID) -> ::sys::CGEventSourceRef;
48 }