gardesk/ers / e3cd26b

Browse files

Add CFRunLoopTimer FFI for main-thread event polling

Authored by mfwolffe <wolffemf@dukes.jmu.edu>
SHA
e3cd26ba565f9f1b96f8e0380f5f3138ecdd4b62
Parents
c562023
Tree
72ee2e6

1 changed file

StatusFile+-
M src/skylight.rs 22 0
src/skylight.rsmodified
@@ -101,7 +101,17 @@ pub type CFNumberRef = *const c_void;
101101
 pub type CFMachPortRef = *const c_void;
102102
 pub type CFRunLoopSourceRef = *const c_void;
103103
 pub type CFRunLoopRef = *const c_void;
104
+pub type CFRunLoopTimerRef = *const c_void;
104105
 pub type CFAllocatorRef = *const c_void;
106
+
107
+#[repr(C)]
108
+pub struct CFRunLoopTimerContext {
109
+    pub version: i64,
110
+    pub info: *mut c_void,
111
+    pub retain: Option<extern "C" fn(*const c_void) -> *const c_void>,
112
+    pub release: Option<extern "C" fn(*const c_void)>,
113
+    pub copy_description: Option<extern "C" fn(*const c_void) -> CFStringRef>,
114
+}
105115
 pub type CGContextRef = *mut c_void;
106116
 pub type CGPathRef = *const c_void;
107117
 pub type CGMutablePathRef = *mut c_void;
@@ -467,6 +477,18 @@ unsafe extern "C" {
467477
     pub fn CFRunLoopStop(rl: CFRunLoopRef);
468478
     pub fn CFRunLoopWakeUp(rl: CFRunLoopRef);
469479
 
480
+    pub fn CFRunLoopTimerCreate(
481
+        allocator: CFAllocatorRef,
482
+        fire_date: f64,
483
+        interval: f64,
484
+        flags: u32,
485
+        order: i64,
486
+        callout: extern "C" fn(*mut c_void, *mut c_void),
487
+        context: *mut CFRunLoopTimerContext,
488
+    ) -> CFRunLoopTimerRef;
489
+    pub fn CFRunLoopAddTimer(rl: CFRunLoopRef, timer: CFRunLoopTimerRef, mode: CFStringRef);
490
+    pub fn CFAbsoluteTimeGetCurrent() -> f64;
491
+
470492
     pub static kCFAllocatorDefault: CFAllocatorRef;
471493
     pub static kCFTypeDictionaryKeyCallBacks: c_void;
472494
     pub static kCFTypeDictionaryValueCallBacks: c_void;