summaryrefslogtreecommitdiff
path: root/src/cocoa/window.m
diff options
context:
space:
mode:
Diffstat (limited to 'src/cocoa/window.m')
-rw-r--r--src/cocoa/window.m51
1 files changed, 42 insertions, 9 deletions
diff --git a/src/cocoa/window.m b/src/cocoa/window.m
index 0edf694..6c28f3f 100644
--- a/src/cocoa/window.m
+++ b/src/cocoa/window.m
@@ -843,29 +843,62 @@ static void pump_window(struct yasl_surface *w)
@autoreleasepool { render_and_commit(w); }
}
-void yasl_display_dispatch(struct yasl_display *d)
+int yasl_display_dispatch_timeout(struct yasl_display *d, int timeout_ms)
{
assert([NSThread isMainThread]);
if (!d || d->pumping)
- return;
+ return -1;
d->pumping = true;
d->depth++;
+ int count = 0;
@try {
- for (;;) {
- @autoreleasepool {
- NSEvent *ev = [NSApp nextEventMatchingMask:NSEventMaskAny
- untilDate:[NSDate distantPast]
- inMode:NSDefaultRunLoopMode
- dequeue:YES];
- if (!ev) break;
+ NSDate *limitDate;
+ if (timeout_ms == 0)
+ limitDate = [NSDate distantPast];
+ else if (timeout_ms < 0)
+ limitDate = [NSDate distantFuture];
+ else
+ limitDate = [NSDate dateWithTimeIntervalSinceNow:(double)timeout_ms / 1000.0];
+
+ @autoreleasepool {
+ NSEvent *ev = [NSApp nextEventMatchingMask:NSEventMaskAny
+ untilDate:limitDate
+ inMode:NSDefaultRunLoopMode
+ dequeue:YES];
+ if (ev) {
+ count++;
[NSApp sendEvent:ev];
[NSApp updateWindows];
+
+ while ((ev = [NSApp nextEventMatchingMask:NSEventMaskAny
+ untilDate:[NSDate distantPast]
+ inMode:NSDefaultRunLoopMode
+ dequeue:YES])) {
+ count++;
+ [NSApp sendEvent:ev];
+ [NSApp updateWindows];
+ }
}
}
} @finally {
d->depth--;
d->pumping = false;
}
+ return count;
+}
+
+void yasl_display_dispatch(struct yasl_display *d)
+{
+ if (!d) return;
+ bool immediate = false;
+ for (int i = 0; i < d->count; i++) {
+ struct yasl_surface *w = d->windows[i];
+ if (w->input.count > 0 || (w->want_draw && (!w->link || w->frame_due || w->unpaced))) {
+ immediate = true;
+ break;
+ }
+ }
+ yasl_display_dispatch_timeout(d, immediate ? 0 : -1);
}
void yasl_display_flush(struct yasl_display *d)