Browse code
prototype: manually feed the cocoa event loop
Ed Langley authored on 21/10/2019 04:08:49
Showing 1 changed files
Showing 1 changed files
... | ... |
@@ -245,6 +245,27 @@ |
245 | 245 |
|
246 | 246 |
(defvar *application-shim* |
247 | 247 |
(make-instance 'application-shim)) |
248 |
+(defun wait-for-events () |
|
249 |
+ (let ((event [objc-runtime::ns-app @(nextEventMatchingMask:untilDate:inMode:dequeue:) |
|
250 |
+ :unsigned-long 18446744073709551615 |
|
251 |
+ :pointer [#@NSDate @(distantFuture)] |
|
252 |
+ :pointer @"kCFRunLoopDefaultMode" |
|
253 |
+ :int 1])) |
|
254 |
+ [objc-runtime::ns-app @(sendEvent:) :pointer event] |
|
255 |
+ event)) |
|
256 |
+ |
|
257 |
+(defun tick () |
|
258 |
+ (wait-for-events)) |
|
259 |
+ |
|
260 |
+(defun task-thread () |
|
261 |
+ (bt:make-thread (lambda () |
|
262 |
+ (trivial-main-thread:with-body-in-main-thread (:blocking t) |
|
263 |
+ [#@NSEvent @(startPeriodicEventsAfterDelay:withPeriod:) :double 0.0d0 :double 0.01d0]) |
|
264 |
+ (loop |
|
265 |
+ (trivial-main-thread:with-body-in-main-thread (:blocking t) |
|
266 |
+ (tick)))) |
|
267 |
+ :name "Cocoa Event Loop Feeder")) |
|
268 |
+ |
|
248 | 269 |
;;#+nil |
249 | 270 |
(defun old-main () |
250 | 271 |
(load "~/quicklisp/setup.lisp") |
... | ... |
@@ -295,4 +316,4 @@ |
295 | 316 |
[the-window @(setTitle:) :pointer application-name] |
296 | 317 |
[the-window @(makeKeyAndOrderFront:) :pointer (cffi:null-pointer)] |
297 | 318 |
[ objc-runtime::ns-app @(activateIgnoringOtherApps:) :boolean t] |
298 |
- [ objc-runtime::ns-app @(run)]))))) |
|
319 |
+ (task-thread)))))) |