objc2_core_graphics/generated/
CGEvent.rs

1//! This file has been automatically generated by `objc2`'s `header-translator`.
2//! DO NOT EDIT
3use core::ffi::*;
4use core::ptr::NonNull;
5use objc2_core_foundation::*;
6
7use crate::*;
8
9#[cfg(feature = "CGEventTypes")]
10unsafe impl ConcreteType for CGEvent {
11    #[doc(alias = "CGEventGetTypeID")]
12    #[inline]
13    fn type_id() -> CFTypeID {
14        extern "C-unwind" {
15            fn CGEventGetTypeID() -> CFTypeID;
16        }
17        unsafe { CGEventGetTypeID() }
18    }
19}
20
21#[cfg(feature = "CGEventTypes")]
22impl CGEvent {
23    #[doc(alias = "CGEventCreate")]
24    #[cfg(feature = "CGEventTypes")]
25    #[inline]
26    pub fn new(source: Option<&CGEventSource>) -> Option<CFRetained<CGEvent>> {
27        extern "C-unwind" {
28            fn CGEventCreate(source: Option<&CGEventSource>) -> Option<NonNull<CGEvent>>;
29        }
30        let ret = unsafe { CGEventCreate(source) };
31        ret.map(|ret| unsafe { CFRetained::from_raw(ret) })
32    }
33
34    #[doc(alias = "CGEventCreateData")]
35    #[cfg(feature = "CGEventTypes")]
36    #[inline]
37    pub fn new_data(
38        allocator: Option<&CFAllocator>,
39        event: Option<&CGEvent>,
40    ) -> Option<CFRetained<CFData>> {
41        extern "C-unwind" {
42            fn CGEventCreateData(
43                allocator: Option<&CFAllocator>,
44                event: Option<&CGEvent>,
45            ) -> Option<NonNull<CFData>>;
46        }
47        let ret = unsafe { CGEventCreateData(allocator, event) };
48        ret.map(|ret| unsafe { CFRetained::from_raw(ret) })
49    }
50
51    #[doc(alias = "CGEventCreateFromData")]
52    #[cfg(feature = "CGEventTypes")]
53    #[inline]
54    pub fn from_data(
55        allocator: Option<&CFAllocator>,
56        data: Option<&CFData>,
57    ) -> Option<CFRetained<CGEvent>> {
58        extern "C-unwind" {
59            fn CGEventCreateFromData(
60                allocator: Option<&CFAllocator>,
61                data: Option<&CFData>,
62            ) -> Option<NonNull<CGEvent>>;
63        }
64        let ret = unsafe { CGEventCreateFromData(allocator, data) };
65        ret.map(|ret| unsafe { CFRetained::from_raw(ret) })
66    }
67
68    #[doc(alias = "CGEventCreateMouseEvent")]
69    #[cfg(feature = "CGEventTypes")]
70    #[inline]
71    pub fn new_mouse_event(
72        source: Option<&CGEventSource>,
73        mouse_type: CGEventType,
74        mouse_cursor_position: CGPoint,
75        mouse_button: CGMouseButton,
76    ) -> Option<CFRetained<CGEvent>> {
77        extern "C-unwind" {
78            fn CGEventCreateMouseEvent(
79                source: Option<&CGEventSource>,
80                mouse_type: CGEventType,
81                mouse_cursor_position: CGPoint,
82                mouse_button: CGMouseButton,
83            ) -> Option<NonNull<CGEvent>>;
84        }
85        let ret = unsafe {
86            CGEventCreateMouseEvent(source, mouse_type, mouse_cursor_position, mouse_button)
87        };
88        ret.map(|ret| unsafe { CFRetained::from_raw(ret) })
89    }
90
91    #[doc(alias = "CGEventCreateKeyboardEvent")]
92    #[cfg(all(feature = "CGEventTypes", feature = "CGRemoteOperation"))]
93    #[inline]
94    pub fn new_keyboard_event(
95        source: Option<&CGEventSource>,
96        virtual_key: CGKeyCode,
97        key_down: bool,
98    ) -> Option<CFRetained<CGEvent>> {
99        extern "C-unwind" {
100            fn CGEventCreateKeyboardEvent(
101                source: Option<&CGEventSource>,
102                virtual_key: CGKeyCode,
103                key_down: bool,
104            ) -> Option<NonNull<CGEvent>>;
105        }
106        let ret = unsafe { CGEventCreateKeyboardEvent(source, virtual_key, key_down) };
107        ret.map(|ret| unsafe { CFRetained::from_raw(ret) })
108    }
109
110    #[doc(alias = "CGEventCreateScrollWheelEvent2")]
111    #[cfg(feature = "CGEventTypes")]
112    #[inline]
113    pub fn new_scroll_wheel_event2(
114        source: Option<&CGEventSource>,
115        units: CGScrollEventUnit,
116        wheel_count: u32,
117        wheel1: i32,
118        wheel2: i32,
119        wheel3: i32,
120    ) -> Option<CFRetained<CGEvent>> {
121        extern "C-unwind" {
122            fn CGEventCreateScrollWheelEvent2(
123                source: Option<&CGEventSource>,
124                units: CGScrollEventUnit,
125                wheel_count: u32,
126                wheel1: i32,
127                wheel2: i32,
128                wheel3: i32,
129            ) -> Option<NonNull<CGEvent>>;
130        }
131        let ret = unsafe {
132            CGEventCreateScrollWheelEvent2(source, units, wheel_count, wheel1, wheel2, wheel3)
133        };
134        ret.map(|ret| unsafe { CFRetained::from_raw(ret) })
135    }
136
137    #[doc(alias = "CGEventCreateCopy")]
138    #[cfg(feature = "CGEventTypes")]
139    #[inline]
140    pub fn new_copy(event: Option<&CGEvent>) -> Option<CFRetained<CGEvent>> {
141        extern "C-unwind" {
142            fn CGEventCreateCopy(event: Option<&CGEvent>) -> Option<NonNull<CGEvent>>;
143        }
144        let ret = unsafe { CGEventCreateCopy(event) };
145        ret.map(|ret| unsafe { CFRetained::from_raw(ret) })
146    }
147
148    #[doc(alias = "CGEventCreateSourceFromEvent")]
149    #[cfg(feature = "CGEventTypes")]
150    #[inline]
151    pub fn new_source_from_event(event: Option<&CGEvent>) -> Option<CFRetained<CGEventSource>> {
152        extern "C-unwind" {
153            fn CGEventCreateSourceFromEvent(
154                event: Option<&CGEvent>,
155            ) -> Option<NonNull<CGEventSource>>;
156        }
157        let ret = unsafe { CGEventCreateSourceFromEvent(event) };
158        ret.map(|ret| unsafe { CFRetained::from_raw(ret) })
159    }
160
161    #[doc(alias = "CGEventSetSource")]
162    #[cfg(feature = "CGEventTypes")]
163    #[inline]
164    pub fn set_source(event: Option<&CGEvent>, source: Option<&CGEventSource>) {
165        extern "C-unwind" {
166            fn CGEventSetSource(event: Option<&CGEvent>, source: Option<&CGEventSource>);
167        }
168        unsafe { CGEventSetSource(event, source) }
169    }
170
171    #[doc(alias = "CGEventGetType")]
172    #[cfg(feature = "CGEventTypes")]
173    #[inline]
174    pub fn r#type(event: Option<&CGEvent>) -> CGEventType {
175        extern "C-unwind" {
176            fn CGEventGetType(event: Option<&CGEvent>) -> CGEventType;
177        }
178        unsafe { CGEventGetType(event) }
179    }
180
181    #[doc(alias = "CGEventSetType")]
182    #[cfg(feature = "CGEventTypes")]
183    #[inline]
184    pub fn set_type(event: Option<&CGEvent>, r#type: CGEventType) {
185        extern "C-unwind" {
186            fn CGEventSetType(event: Option<&CGEvent>, r#type: CGEventType);
187        }
188        unsafe { CGEventSetType(event, r#type) }
189    }
190
191    #[doc(alias = "CGEventGetTimestamp")]
192    #[cfg(feature = "CGEventTypes")]
193    #[inline]
194    pub fn timestamp(event: Option<&CGEvent>) -> CGEventTimestamp {
195        extern "C-unwind" {
196            fn CGEventGetTimestamp(event: Option<&CGEvent>) -> CGEventTimestamp;
197        }
198        unsafe { CGEventGetTimestamp(event) }
199    }
200
201    #[doc(alias = "CGEventSetTimestamp")]
202    #[cfg(feature = "CGEventTypes")]
203    #[inline]
204    pub fn set_timestamp(event: Option<&CGEvent>, timestamp: CGEventTimestamp) {
205        extern "C-unwind" {
206            fn CGEventSetTimestamp(event: Option<&CGEvent>, timestamp: CGEventTimestamp);
207        }
208        unsafe { CGEventSetTimestamp(event, timestamp) }
209    }
210
211    #[doc(alias = "CGEventGetLocation")]
212    #[cfg(feature = "CGEventTypes")]
213    #[inline]
214    pub fn location(event: Option<&CGEvent>) -> CGPoint {
215        extern "C-unwind" {
216            fn CGEventGetLocation(event: Option<&CGEvent>) -> CGPoint;
217        }
218        unsafe { CGEventGetLocation(event) }
219    }
220
221    #[doc(alias = "CGEventGetUnflippedLocation")]
222    #[cfg(feature = "CGEventTypes")]
223    #[inline]
224    pub fn unflipped_location(event: Option<&CGEvent>) -> CGPoint {
225        extern "C-unwind" {
226            fn CGEventGetUnflippedLocation(event: Option<&CGEvent>) -> CGPoint;
227        }
228        unsafe { CGEventGetUnflippedLocation(event) }
229    }
230
231    #[doc(alias = "CGEventSetLocation")]
232    #[cfg(feature = "CGEventTypes")]
233    #[inline]
234    pub fn set_location(event: Option<&CGEvent>, location: CGPoint) {
235        extern "C-unwind" {
236            fn CGEventSetLocation(event: Option<&CGEvent>, location: CGPoint);
237        }
238        unsafe { CGEventSetLocation(event, location) }
239    }
240
241    #[doc(alias = "CGEventGetFlags")]
242    #[cfg(feature = "CGEventTypes")]
243    #[inline]
244    pub fn flags(event: Option<&CGEvent>) -> CGEventFlags {
245        extern "C-unwind" {
246            fn CGEventGetFlags(event: Option<&CGEvent>) -> CGEventFlags;
247        }
248        unsafe { CGEventGetFlags(event) }
249    }
250
251    #[doc(alias = "CGEventSetFlags")]
252    #[cfg(feature = "CGEventTypes")]
253    #[inline]
254    pub fn set_flags(event: Option<&CGEvent>, flags: CGEventFlags) {
255        extern "C-unwind" {
256            fn CGEventSetFlags(event: Option<&CGEvent>, flags: CGEventFlags);
257        }
258        unsafe { CGEventSetFlags(event, flags) }
259    }
260
261    /// # Safety
262    ///
263    /// - `actual_string_length` must be a valid pointer or null.
264    /// - `unicode_string` must be a valid pointer or null.
265    #[doc(alias = "CGEventKeyboardGetUnicodeString")]
266    #[cfg(feature = "CGEventTypes")]
267    #[inline]
268    pub unsafe fn keyboard_get_unicode_string(
269        event: Option<&CGEvent>,
270        max_string_length: UniCharCount,
271        actual_string_length: *mut UniCharCount,
272        unicode_string: *mut UniChar,
273    ) {
274        extern "C-unwind" {
275            fn CGEventKeyboardGetUnicodeString(
276                event: Option<&CGEvent>,
277                max_string_length: UniCharCount,
278                actual_string_length: *mut UniCharCount,
279                unicode_string: *mut UniChar,
280            );
281        }
282        unsafe {
283            CGEventKeyboardGetUnicodeString(
284                event,
285                max_string_length,
286                actual_string_length,
287                unicode_string,
288            )
289        }
290    }
291
292    /// # Safety
293    ///
294    /// `unicode_string` must be a valid pointer or null.
295    #[doc(alias = "CGEventKeyboardSetUnicodeString")]
296    #[cfg(feature = "CGEventTypes")]
297    #[inline]
298    pub unsafe fn keyboard_set_unicode_string(
299        event: Option<&CGEvent>,
300        string_length: UniCharCount,
301        unicode_string: *const UniChar,
302    ) {
303        extern "C-unwind" {
304            fn CGEventKeyboardSetUnicodeString(
305                event: Option<&CGEvent>,
306                string_length: UniCharCount,
307                unicode_string: *const UniChar,
308            );
309        }
310        unsafe { CGEventKeyboardSetUnicodeString(event, string_length, unicode_string) }
311    }
312
313    #[doc(alias = "CGEventGetIntegerValueField")]
314    #[cfg(feature = "CGEventTypes")]
315    #[inline]
316    pub fn integer_value_field(event: Option<&CGEvent>, field: CGEventField) -> i64 {
317        extern "C-unwind" {
318            fn CGEventGetIntegerValueField(event: Option<&CGEvent>, field: CGEventField) -> i64;
319        }
320        unsafe { CGEventGetIntegerValueField(event, field) }
321    }
322
323    #[doc(alias = "CGEventSetIntegerValueField")]
324    #[cfg(feature = "CGEventTypes")]
325    #[inline]
326    pub fn set_integer_value_field(event: Option<&CGEvent>, field: CGEventField, value: i64) {
327        extern "C-unwind" {
328            fn CGEventSetIntegerValueField(
329                event: Option<&CGEvent>,
330                field: CGEventField,
331                value: i64,
332            );
333        }
334        unsafe { CGEventSetIntegerValueField(event, field, value) }
335    }
336
337    #[doc(alias = "CGEventGetDoubleValueField")]
338    #[cfg(feature = "CGEventTypes")]
339    #[inline]
340    pub fn double_value_field(event: Option<&CGEvent>, field: CGEventField) -> c_double {
341        extern "C-unwind" {
342            fn CGEventGetDoubleValueField(event: Option<&CGEvent>, field: CGEventField)
343                -> c_double;
344        }
345        unsafe { CGEventGetDoubleValueField(event, field) }
346    }
347
348    #[doc(alias = "CGEventSetDoubleValueField")]
349    #[cfg(feature = "CGEventTypes")]
350    #[inline]
351    pub fn set_double_value_field(event: Option<&CGEvent>, field: CGEventField, value: c_double) {
352        extern "C-unwind" {
353            fn CGEventSetDoubleValueField(
354                event: Option<&CGEvent>,
355                field: CGEventField,
356                value: c_double,
357            );
358        }
359        unsafe { CGEventSetDoubleValueField(event, field, value) }
360    }
361
362    /// # Safety
363    ///
364    /// - `callback` must be implemented correctly.
365    /// - `user_info` must be a valid pointer or null.
366    #[doc(alias = "CGEventTapCreate")]
367    #[cfg(feature = "CGEventTypes")]
368    #[inline]
369    pub unsafe fn tap_create(
370        tap: CGEventTapLocation,
371        place: CGEventTapPlacement,
372        options: CGEventTapOptions,
373        events_of_interest: CGEventMask,
374        callback: CGEventTapCallBack,
375        user_info: *mut c_void,
376    ) -> Option<CFRetained<CFMachPort>> {
377        extern "C-unwind" {
378            fn CGEventTapCreate(
379                tap: CGEventTapLocation,
380                place: CGEventTapPlacement,
381                options: CGEventTapOptions,
382                events_of_interest: CGEventMask,
383                callback: CGEventTapCallBack,
384                user_info: *mut c_void,
385            ) -> Option<NonNull<CFMachPort>>;
386        }
387        let ret = unsafe {
388            CGEventTapCreate(tap, place, options, events_of_interest, callback, user_info)
389        };
390        ret.map(|ret| unsafe { CFRetained::from_raw(ret) })
391    }
392
393    /// # Safety
394    ///
395    /// - `process_serial_number` must be a valid pointer.
396    /// - `callback` must be implemented correctly.
397    /// - `user_info` must be a valid pointer or null.
398    #[doc(alias = "CGEventTapCreateForPSN")]
399    #[cfg(feature = "CGEventTypes")]
400    #[inline]
401    pub unsafe fn tap_create_for_psn(
402        process_serial_number: NonNull<c_void>,
403        place: CGEventTapPlacement,
404        options: CGEventTapOptions,
405        events_of_interest: CGEventMask,
406        callback: CGEventTapCallBack,
407        user_info: *mut c_void,
408    ) -> Option<CFRetained<CFMachPort>> {
409        extern "C-unwind" {
410            fn CGEventTapCreateForPSN(
411                process_serial_number: NonNull<c_void>,
412                place: CGEventTapPlacement,
413                options: CGEventTapOptions,
414                events_of_interest: CGEventMask,
415                callback: CGEventTapCallBack,
416                user_info: *mut c_void,
417            ) -> Option<NonNull<CFMachPort>>;
418        }
419        let ret = unsafe {
420            CGEventTapCreateForPSN(
421                process_serial_number,
422                place,
423                options,
424                events_of_interest,
425                callback,
426                user_info,
427            )
428        };
429        ret.map(|ret| unsafe { CFRetained::from_raw(ret) })
430    }
431
432    /// # Safety
433    ///
434    /// - `callback` must be implemented correctly.
435    /// - `user_info` must be a valid pointer or null.
436    #[doc(alias = "CGEventTapCreateForPid")]
437    #[cfg(all(feature = "CGEventTypes", feature = "libc"))]
438    #[inline]
439    pub unsafe fn tap_create_for_pid(
440        pid: libc::pid_t,
441        place: CGEventTapPlacement,
442        options: CGEventTapOptions,
443        events_of_interest: CGEventMask,
444        callback: CGEventTapCallBack,
445        user_info: *mut c_void,
446    ) -> Option<CFRetained<CFMachPort>> {
447        extern "C-unwind" {
448            fn CGEventTapCreateForPid(
449                pid: libc::pid_t,
450                place: CGEventTapPlacement,
451                options: CGEventTapOptions,
452                events_of_interest: CGEventMask,
453                callback: CGEventTapCallBack,
454                user_info: *mut c_void,
455            ) -> Option<NonNull<CFMachPort>>;
456        }
457        let ret = unsafe {
458            CGEventTapCreateForPid(pid, place, options, events_of_interest, callback, user_info)
459        };
460        ret.map(|ret| unsafe { CFRetained::from_raw(ret) })
461    }
462
463    #[doc(alias = "CGEventTapEnable")]
464    #[inline]
465    pub fn tap_enable(tap: &CFMachPort, enable: bool) {
466        extern "C-unwind" {
467            fn CGEventTapEnable(tap: &CFMachPort, enable: bool);
468        }
469        unsafe { CGEventTapEnable(tap, enable) }
470    }
471
472    #[doc(alias = "CGEventTapIsEnabled")]
473    #[inline]
474    pub fn tap_is_enabled(tap: &CFMachPort) -> bool {
475        extern "C-unwind" {
476            fn CGEventTapIsEnabled(tap: &CFMachPort) -> bool;
477        }
478        unsafe { CGEventTapIsEnabled(tap) }
479    }
480
481    /// # Safety
482    ///
483    /// `proxy` must be a valid pointer or null.
484    #[doc(alias = "CGEventTapPostEvent")]
485    #[cfg(feature = "CGEventTypes")]
486    #[inline]
487    pub unsafe fn tap_post_event(proxy: CGEventTapProxy, event: Option<&CGEvent>) {
488        extern "C-unwind" {
489            fn CGEventTapPostEvent(proxy: CGEventTapProxy, event: Option<&CGEvent>);
490        }
491        unsafe { CGEventTapPostEvent(proxy, event) }
492    }
493
494    #[doc(alias = "CGEventPost")]
495    #[cfg(feature = "CGEventTypes")]
496    #[inline]
497    pub fn post(tap: CGEventTapLocation, event: Option<&CGEvent>) {
498        extern "C-unwind" {
499            fn CGEventPost(tap: CGEventTapLocation, event: Option<&CGEvent>);
500        }
501        unsafe { CGEventPost(tap, event) }
502    }
503
504    /// # Safety
505    ///
506    /// `process_serial_number` must be a valid pointer or null.
507    #[doc(alias = "CGEventPostToPSN")]
508    #[cfg(feature = "CGEventTypes")]
509    #[inline]
510    pub unsafe fn post_to_psn(process_serial_number: *mut c_void, event: Option<&CGEvent>) {
511        extern "C-unwind" {
512            fn CGEventPostToPSN(process_serial_number: *mut c_void, event: Option<&CGEvent>);
513        }
514        unsafe { CGEventPostToPSN(process_serial_number, event) }
515    }
516
517    #[doc(alias = "CGEventPostToPid")]
518    #[cfg(all(feature = "CGEventTypes", feature = "libc"))]
519    #[inline]
520    pub fn post_to_pid(pid: libc::pid_t, event: Option<&CGEvent>) {
521        extern "C-unwind" {
522            fn CGEventPostToPid(pid: libc::pid_t, event: Option<&CGEvent>);
523        }
524        unsafe { CGEventPostToPid(pid, event) }
525    }
526}
527
528extern "C-unwind" {
529    /// # Safety
530    ///
531    /// - `tap_list` must be a valid pointer or null.
532    /// - `event_tap_count` must be a valid pointer or null.
533    #[cfg(all(feature = "CGError", feature = "CGEventTypes", feature = "libc"))]
534    pub fn CGGetEventTapList(
535        max_number_of_taps: u32,
536        tap_list: *mut CGEventTapInformation,
537        event_tap_count: *mut u32,
538    ) -> CGError;
539}
540
541#[inline]
542pub extern "C-unwind" fn CGPreflightListenEventAccess() -> bool {
543    extern "C-unwind" {
544        fn CGPreflightListenEventAccess() -> bool;
545    }
546    unsafe { CGPreflightListenEventAccess() }
547}
548
549#[inline]
550pub extern "C-unwind" fn CGRequestListenEventAccess() -> bool {
551    extern "C-unwind" {
552        fn CGRequestListenEventAccess() -> bool;
553    }
554    unsafe { CGRequestListenEventAccess() }
555}
556
557#[inline]
558pub extern "C-unwind" fn CGPreflightPostEventAccess() -> bool {
559    extern "C-unwind" {
560        fn CGPreflightPostEventAccess() -> bool;
561    }
562    unsafe { CGPreflightPostEventAccess() }
563}
564
565#[inline]
566pub extern "C-unwind" fn CGRequestPostEventAccess() -> bool {
567    extern "C-unwind" {
568        fn CGRequestPostEventAccess() -> bool;
569    }
570    unsafe { CGRequestPostEventAccess() }
571}
572
573#[cfg(feature = "CGEventTypes")]
574#[deprecated = "renamed to `CGEvent::new`"]
575#[inline]
576pub extern "C-unwind" fn CGEventCreate(
577    source: Option<&CGEventSource>,
578) -> Option<CFRetained<CGEvent>> {
579    extern "C-unwind" {
580        fn CGEventCreate(source: Option<&CGEventSource>) -> Option<NonNull<CGEvent>>;
581    }
582    let ret = unsafe { CGEventCreate(source) };
583    ret.map(|ret| unsafe { CFRetained::from_raw(ret) })
584}
585
586#[cfg(feature = "CGEventTypes")]
587#[deprecated = "renamed to `CGEvent::new_data`"]
588#[inline]
589pub extern "C-unwind" fn CGEventCreateData(
590    allocator: Option<&CFAllocator>,
591    event: Option<&CGEvent>,
592) -> Option<CFRetained<CFData>> {
593    extern "C-unwind" {
594        fn CGEventCreateData(
595            allocator: Option<&CFAllocator>,
596            event: Option<&CGEvent>,
597        ) -> Option<NonNull<CFData>>;
598    }
599    let ret = unsafe { CGEventCreateData(allocator, event) };
600    ret.map(|ret| unsafe { CFRetained::from_raw(ret) })
601}
602
603#[cfg(feature = "CGEventTypes")]
604#[deprecated = "renamed to `CGEvent::from_data`"]
605#[inline]
606pub extern "C-unwind" fn CGEventCreateFromData(
607    allocator: Option<&CFAllocator>,
608    data: Option<&CFData>,
609) -> Option<CFRetained<CGEvent>> {
610    extern "C-unwind" {
611        fn CGEventCreateFromData(
612            allocator: Option<&CFAllocator>,
613            data: Option<&CFData>,
614        ) -> Option<NonNull<CGEvent>>;
615    }
616    let ret = unsafe { CGEventCreateFromData(allocator, data) };
617    ret.map(|ret| unsafe { CFRetained::from_raw(ret) })
618}
619
620#[cfg(feature = "CGEventTypes")]
621#[deprecated = "renamed to `CGEvent::new_mouse_event`"]
622#[inline]
623pub extern "C-unwind" fn CGEventCreateMouseEvent(
624    source: Option<&CGEventSource>,
625    mouse_type: CGEventType,
626    mouse_cursor_position: CGPoint,
627    mouse_button: CGMouseButton,
628) -> Option<CFRetained<CGEvent>> {
629    extern "C-unwind" {
630        fn CGEventCreateMouseEvent(
631            source: Option<&CGEventSource>,
632            mouse_type: CGEventType,
633            mouse_cursor_position: CGPoint,
634            mouse_button: CGMouseButton,
635        ) -> Option<NonNull<CGEvent>>;
636    }
637    let ret =
638        unsafe { CGEventCreateMouseEvent(source, mouse_type, mouse_cursor_position, mouse_button) };
639    ret.map(|ret| unsafe { CFRetained::from_raw(ret) })
640}
641
642#[cfg(all(feature = "CGEventTypes", feature = "CGRemoteOperation"))]
643#[deprecated = "renamed to `CGEvent::new_keyboard_event`"]
644#[inline]
645pub extern "C-unwind" fn CGEventCreateKeyboardEvent(
646    source: Option<&CGEventSource>,
647    virtual_key: CGKeyCode,
648    key_down: bool,
649) -> Option<CFRetained<CGEvent>> {
650    extern "C-unwind" {
651        fn CGEventCreateKeyboardEvent(
652            source: Option<&CGEventSource>,
653            virtual_key: CGKeyCode,
654            key_down: bool,
655        ) -> Option<NonNull<CGEvent>>;
656    }
657    let ret = unsafe { CGEventCreateKeyboardEvent(source, virtual_key, key_down) };
658    ret.map(|ret| unsafe { CFRetained::from_raw(ret) })
659}
660
661#[cfg(feature = "CGEventTypes")]
662#[deprecated = "renamed to `CGEvent::new_scroll_wheel_event2`"]
663#[inline]
664pub extern "C-unwind" fn CGEventCreateScrollWheelEvent2(
665    source: Option<&CGEventSource>,
666    units: CGScrollEventUnit,
667    wheel_count: u32,
668    wheel1: i32,
669    wheel2: i32,
670    wheel3: i32,
671) -> Option<CFRetained<CGEvent>> {
672    extern "C-unwind" {
673        fn CGEventCreateScrollWheelEvent2(
674            source: Option<&CGEventSource>,
675            units: CGScrollEventUnit,
676            wheel_count: u32,
677            wheel1: i32,
678            wheel2: i32,
679            wheel3: i32,
680        ) -> Option<NonNull<CGEvent>>;
681    }
682    let ret = unsafe {
683        CGEventCreateScrollWheelEvent2(source, units, wheel_count, wheel1, wheel2, wheel3)
684    };
685    ret.map(|ret| unsafe { CFRetained::from_raw(ret) })
686}
687
688#[cfg(feature = "CGEventTypes")]
689#[deprecated = "renamed to `CGEvent::new_copy`"]
690#[inline]
691pub extern "C-unwind" fn CGEventCreateCopy(event: Option<&CGEvent>) -> Option<CFRetained<CGEvent>> {
692    extern "C-unwind" {
693        fn CGEventCreateCopy(event: Option<&CGEvent>) -> Option<NonNull<CGEvent>>;
694    }
695    let ret = unsafe { CGEventCreateCopy(event) };
696    ret.map(|ret| unsafe { CFRetained::from_raw(ret) })
697}
698
699#[cfg(feature = "CGEventTypes")]
700#[deprecated = "renamed to `CGEvent::new_source_from_event`"]
701#[inline]
702pub extern "C-unwind" fn CGEventCreateSourceFromEvent(
703    event: Option<&CGEvent>,
704) -> Option<CFRetained<CGEventSource>> {
705    extern "C-unwind" {
706        fn CGEventCreateSourceFromEvent(event: Option<&CGEvent>) -> Option<NonNull<CGEventSource>>;
707    }
708    let ret = unsafe { CGEventCreateSourceFromEvent(event) };
709    ret.map(|ret| unsafe { CFRetained::from_raw(ret) })
710}
711
712#[cfg(feature = "CGEventTypes")]
713#[deprecated = "renamed to `CGEvent::set_source`"]
714#[inline]
715pub extern "C-unwind" fn CGEventSetSource(event: Option<&CGEvent>, source: Option<&CGEventSource>) {
716    extern "C-unwind" {
717        fn CGEventSetSource(event: Option<&CGEvent>, source: Option<&CGEventSource>);
718    }
719    unsafe { CGEventSetSource(event, source) }
720}
721
722#[cfg(feature = "CGEventTypes")]
723#[deprecated = "renamed to `CGEvent::type`"]
724#[inline]
725pub extern "C-unwind" fn CGEventGetType(event: Option<&CGEvent>) -> CGEventType {
726    extern "C-unwind" {
727        fn CGEventGetType(event: Option<&CGEvent>) -> CGEventType;
728    }
729    unsafe { CGEventGetType(event) }
730}
731
732#[cfg(feature = "CGEventTypes")]
733#[deprecated = "renamed to `CGEvent::set_type`"]
734#[inline]
735pub extern "C-unwind" fn CGEventSetType(event: Option<&CGEvent>, r#type: CGEventType) {
736    extern "C-unwind" {
737        fn CGEventSetType(event: Option<&CGEvent>, r#type: CGEventType);
738    }
739    unsafe { CGEventSetType(event, r#type) }
740}
741
742#[cfg(feature = "CGEventTypes")]
743#[deprecated = "renamed to `CGEvent::timestamp`"]
744#[inline]
745pub extern "C-unwind" fn CGEventGetTimestamp(event: Option<&CGEvent>) -> CGEventTimestamp {
746    extern "C-unwind" {
747        fn CGEventGetTimestamp(event: Option<&CGEvent>) -> CGEventTimestamp;
748    }
749    unsafe { CGEventGetTimestamp(event) }
750}
751
752#[cfg(feature = "CGEventTypes")]
753#[deprecated = "renamed to `CGEvent::set_timestamp`"]
754#[inline]
755pub extern "C-unwind" fn CGEventSetTimestamp(event: Option<&CGEvent>, timestamp: CGEventTimestamp) {
756    extern "C-unwind" {
757        fn CGEventSetTimestamp(event: Option<&CGEvent>, timestamp: CGEventTimestamp);
758    }
759    unsafe { CGEventSetTimestamp(event, timestamp) }
760}
761
762#[cfg(feature = "CGEventTypes")]
763#[deprecated = "renamed to `CGEvent::location`"]
764#[inline]
765pub extern "C-unwind" fn CGEventGetLocation(event: Option<&CGEvent>) -> CGPoint {
766    extern "C-unwind" {
767        fn CGEventGetLocation(event: Option<&CGEvent>) -> CGPoint;
768    }
769    unsafe { CGEventGetLocation(event) }
770}
771
772#[cfg(feature = "CGEventTypes")]
773#[deprecated = "renamed to `CGEvent::unflipped_location`"]
774#[inline]
775pub extern "C-unwind" fn CGEventGetUnflippedLocation(event: Option<&CGEvent>) -> CGPoint {
776    extern "C-unwind" {
777        fn CGEventGetUnflippedLocation(event: Option<&CGEvent>) -> CGPoint;
778    }
779    unsafe { CGEventGetUnflippedLocation(event) }
780}
781
782#[cfg(feature = "CGEventTypes")]
783#[deprecated = "renamed to `CGEvent::set_location`"]
784#[inline]
785pub extern "C-unwind" fn CGEventSetLocation(event: Option<&CGEvent>, location: CGPoint) {
786    extern "C-unwind" {
787        fn CGEventSetLocation(event: Option<&CGEvent>, location: CGPoint);
788    }
789    unsafe { CGEventSetLocation(event, location) }
790}
791
792#[cfg(feature = "CGEventTypes")]
793#[deprecated = "renamed to `CGEvent::flags`"]
794#[inline]
795pub extern "C-unwind" fn CGEventGetFlags(event: Option<&CGEvent>) -> CGEventFlags {
796    extern "C-unwind" {
797        fn CGEventGetFlags(event: Option<&CGEvent>) -> CGEventFlags;
798    }
799    unsafe { CGEventGetFlags(event) }
800}
801
802#[cfg(feature = "CGEventTypes")]
803#[deprecated = "renamed to `CGEvent::set_flags`"]
804#[inline]
805pub extern "C-unwind" fn CGEventSetFlags(event: Option<&CGEvent>, flags: CGEventFlags) {
806    extern "C-unwind" {
807        fn CGEventSetFlags(event: Option<&CGEvent>, flags: CGEventFlags);
808    }
809    unsafe { CGEventSetFlags(event, flags) }
810}
811
812extern "C-unwind" {
813    #[cfg(feature = "CGEventTypes")]
814    #[deprecated = "renamed to `CGEvent::keyboard_get_unicode_string`"]
815    pub fn CGEventKeyboardGetUnicodeString(
816        event: Option<&CGEvent>,
817        max_string_length: UniCharCount,
818        actual_string_length: *mut UniCharCount,
819        unicode_string: *mut UniChar,
820    );
821}
822
823extern "C-unwind" {
824    #[cfg(feature = "CGEventTypes")]
825    #[deprecated = "renamed to `CGEvent::keyboard_set_unicode_string`"]
826    pub fn CGEventKeyboardSetUnicodeString(
827        event: Option<&CGEvent>,
828        string_length: UniCharCount,
829        unicode_string: *const UniChar,
830    );
831}
832
833#[cfg(feature = "CGEventTypes")]
834#[deprecated = "renamed to `CGEvent::integer_value_field`"]
835#[inline]
836pub extern "C-unwind" fn CGEventGetIntegerValueField(
837    event: Option<&CGEvent>,
838    field: CGEventField,
839) -> i64 {
840    extern "C-unwind" {
841        fn CGEventGetIntegerValueField(event: Option<&CGEvent>, field: CGEventField) -> i64;
842    }
843    unsafe { CGEventGetIntegerValueField(event, field) }
844}
845
846#[cfg(feature = "CGEventTypes")]
847#[deprecated = "renamed to `CGEvent::set_integer_value_field`"]
848#[inline]
849pub extern "C-unwind" fn CGEventSetIntegerValueField(
850    event: Option<&CGEvent>,
851    field: CGEventField,
852    value: i64,
853) {
854    extern "C-unwind" {
855        fn CGEventSetIntegerValueField(event: Option<&CGEvent>, field: CGEventField, value: i64);
856    }
857    unsafe { CGEventSetIntegerValueField(event, field, value) }
858}
859
860#[cfg(feature = "CGEventTypes")]
861#[deprecated = "renamed to `CGEvent::double_value_field`"]
862#[inline]
863pub extern "C-unwind" fn CGEventGetDoubleValueField(
864    event: Option<&CGEvent>,
865    field: CGEventField,
866) -> c_double {
867    extern "C-unwind" {
868        fn CGEventGetDoubleValueField(event: Option<&CGEvent>, field: CGEventField) -> c_double;
869    }
870    unsafe { CGEventGetDoubleValueField(event, field) }
871}
872
873#[cfg(feature = "CGEventTypes")]
874#[deprecated = "renamed to `CGEvent::set_double_value_field`"]
875#[inline]
876pub extern "C-unwind" fn CGEventSetDoubleValueField(
877    event: Option<&CGEvent>,
878    field: CGEventField,
879    value: c_double,
880) {
881    extern "C-unwind" {
882        fn CGEventSetDoubleValueField(
883            event: Option<&CGEvent>,
884            field: CGEventField,
885            value: c_double,
886        );
887    }
888    unsafe { CGEventSetDoubleValueField(event, field, value) }
889}
890
891#[cfg(feature = "CGEventTypes")]
892#[deprecated = "renamed to `CGEvent::tap_create`"]
893#[inline]
894pub unsafe extern "C-unwind" fn CGEventTapCreate(
895    tap: CGEventTapLocation,
896    place: CGEventTapPlacement,
897    options: CGEventTapOptions,
898    events_of_interest: CGEventMask,
899    callback: CGEventTapCallBack,
900    user_info: *mut c_void,
901) -> Option<CFRetained<CFMachPort>> {
902    extern "C-unwind" {
903        fn CGEventTapCreate(
904            tap: CGEventTapLocation,
905            place: CGEventTapPlacement,
906            options: CGEventTapOptions,
907            events_of_interest: CGEventMask,
908            callback: CGEventTapCallBack,
909            user_info: *mut c_void,
910        ) -> Option<NonNull<CFMachPort>>;
911    }
912    let ret =
913        unsafe { CGEventTapCreate(tap, place, options, events_of_interest, callback, user_info) };
914    ret.map(|ret| unsafe { CFRetained::from_raw(ret) })
915}
916
917#[cfg(feature = "CGEventTypes")]
918#[deprecated = "renamed to `CGEvent::tap_create_for_psn`"]
919#[inline]
920pub unsafe extern "C-unwind" fn CGEventTapCreateForPSN(
921    process_serial_number: NonNull<c_void>,
922    place: CGEventTapPlacement,
923    options: CGEventTapOptions,
924    events_of_interest: CGEventMask,
925    callback: CGEventTapCallBack,
926    user_info: *mut c_void,
927) -> Option<CFRetained<CFMachPort>> {
928    extern "C-unwind" {
929        fn CGEventTapCreateForPSN(
930            process_serial_number: NonNull<c_void>,
931            place: CGEventTapPlacement,
932            options: CGEventTapOptions,
933            events_of_interest: CGEventMask,
934            callback: CGEventTapCallBack,
935            user_info: *mut c_void,
936        ) -> Option<NonNull<CFMachPort>>;
937    }
938    let ret = unsafe {
939        CGEventTapCreateForPSN(
940            process_serial_number,
941            place,
942            options,
943            events_of_interest,
944            callback,
945            user_info,
946        )
947    };
948    ret.map(|ret| unsafe { CFRetained::from_raw(ret) })
949}
950
951#[cfg(all(feature = "CGEventTypes", feature = "libc"))]
952#[deprecated = "renamed to `CGEvent::tap_create_for_pid`"]
953#[inline]
954pub unsafe extern "C-unwind" fn CGEventTapCreateForPid(
955    pid: libc::pid_t,
956    place: CGEventTapPlacement,
957    options: CGEventTapOptions,
958    events_of_interest: CGEventMask,
959    callback: CGEventTapCallBack,
960    user_info: *mut c_void,
961) -> Option<CFRetained<CFMachPort>> {
962    extern "C-unwind" {
963        fn CGEventTapCreateForPid(
964            pid: libc::pid_t,
965            place: CGEventTapPlacement,
966            options: CGEventTapOptions,
967            events_of_interest: CGEventMask,
968            callback: CGEventTapCallBack,
969            user_info: *mut c_void,
970        ) -> Option<NonNull<CFMachPort>>;
971    }
972    let ret = unsafe {
973        CGEventTapCreateForPid(pid, place, options, events_of_interest, callback, user_info)
974    };
975    ret.map(|ret| unsafe { CFRetained::from_raw(ret) })
976}
977
978#[deprecated = "renamed to `CGEvent::tap_enable`"]
979#[inline]
980pub extern "C-unwind" fn CGEventTapEnable(tap: &CFMachPort, enable: bool) {
981    extern "C-unwind" {
982        fn CGEventTapEnable(tap: &CFMachPort, enable: bool);
983    }
984    unsafe { CGEventTapEnable(tap, enable) }
985}
986
987#[deprecated = "renamed to `CGEvent::tap_is_enabled`"]
988#[inline]
989pub extern "C-unwind" fn CGEventTapIsEnabled(tap: &CFMachPort) -> bool {
990    extern "C-unwind" {
991        fn CGEventTapIsEnabled(tap: &CFMachPort) -> bool;
992    }
993    unsafe { CGEventTapIsEnabled(tap) }
994}
995
996extern "C-unwind" {
997    #[cfg(feature = "CGEventTypes")]
998    #[deprecated = "renamed to `CGEvent::tap_post_event`"]
999    pub fn CGEventTapPostEvent(proxy: CGEventTapProxy, event: Option<&CGEvent>);
1000}
1001
1002#[cfg(feature = "CGEventTypes")]
1003#[deprecated = "renamed to `CGEvent::post`"]
1004#[inline]
1005pub extern "C-unwind" fn CGEventPost(tap: CGEventTapLocation, event: Option<&CGEvent>) {
1006    extern "C-unwind" {
1007        fn CGEventPost(tap: CGEventTapLocation, event: Option<&CGEvent>);
1008    }
1009    unsafe { CGEventPost(tap, event) }
1010}
1011
1012extern "C-unwind" {
1013    #[cfg(feature = "CGEventTypes")]
1014    #[deprecated = "renamed to `CGEvent::post_to_psn`"]
1015    pub fn CGEventPostToPSN(process_serial_number: *mut c_void, event: Option<&CGEvent>);
1016}
1017
1018#[cfg(all(feature = "CGEventTypes", feature = "libc"))]
1019#[deprecated = "renamed to `CGEvent::post_to_pid`"]
1020#[inline]
1021pub extern "C-unwind" fn CGEventPostToPid(pid: libc::pid_t, event: Option<&CGEvent>) {
1022    extern "C-unwind" {
1023        fn CGEventPostToPid(pid: libc::pid_t, event: Option<&CGEvent>);
1024    }
1025    unsafe { CGEventPostToPid(pid, event) }
1026}