diff options
| author | Berke Güzel <wenekar1@gmail.com> | 2026-10-12 00:29:34 +0300 |
|---|---|---|
| committer | Berke Güzel <wenekar1@gmail.com> | 2026-10-12 00:29:34 +0300 |
| commit | f7fa0930cb46046f995fa1ab927aef62466e995e (patch) | |
| tree | f5ac4e1579811b5d69498a19d0bdfbf128a1d62b /src/cocoa/window.m | |
| parent | 624d1371304a5ae4b3429ad5e4267aac7cd03dfd (diff) | |
feat: add SDL3-style surface, display, and loop timer API for X11, Wayland, and Cocoa
Diffstat (limited to 'src/cocoa/window.m')
| -rw-r--r-- | src/cocoa/window.m | 26 |
1 files changed, 25 insertions, 1 deletions
diff --git a/src/cocoa/window.m b/src/cocoa/window.m index 4454be3..fc69412 100644 --- a/src/cocoa/window.m +++ b/src/cocoa/window.m @@ -110,6 +110,7 @@ struct cocoa_display { bool open; bool launched; bool pumping; + bool owns_loop; }; static struct cocoa_display darwin_ctx; @@ -867,6 +868,13 @@ int cocoa_display_dispatch_timeout(struct cocoa_display *d, int timeout_ms) d->depth++; int count = 0; @try { + if (d->loop) { + int timer_to = yasl_loop_next_timeout_ms(d->loop); + if (timer_to >= 0 && (timeout_ms < 0 || timer_to < timeout_ms)) { + timeout_ms = timer_to; + } + } + NSDate *limitDate; if (timeout_ms == 0) limitDate = [NSDate distantPast]; @@ -895,6 +903,10 @@ int cocoa_display_dispatch_timeout(struct cocoa_display *d, int timeout_ms) } } } + + if (d->loop) { + yasl_loop_step(d->loop, 0); + } } @finally { d->depth--; d->pumping = false; @@ -1003,7 +1015,14 @@ struct cocoa_display *cocoa_display_open(struct yasl_loop *loop, const struct ya @autoreleasepool { app_init(name); } darwin_ctx.base.ops = &yasl_cocoa_backend; darwin_ctx.open = true; - darwin_ctx.loop = loop; + if (!loop) { + darwin_ctx.loop = yasl_loop_create(); + darwin_ctx.owns_loop = true; + } else { + darwin_ctx.loop = loop; + darwin_ctx.owns_loop = false; + } + darwin_ctx.base.loop = darwin_ctx.loop; if (spec) { darwin_ctx.base.callbacks = spec->cbs ? *spec->cbs : (struct yasl_display_cbs){0}; darwin_ctx.cbs = &darwin_ctx.base.callbacks; @@ -1022,6 +1041,11 @@ void cocoa_display_close(struct cocoa_display *d) [NSEvent removeMonitor:d->key_up_monitor]; d->key_up_monitor = nil; } + if (d->owns_loop && d->loop) { + yasl_loop_destroy(d->loop); + d->loop = NULL; + d->base.loop = NULL; + } NSApp.delegate = nil; [d->delegate release]; d->delegate = nil; |
