Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 14 additions & 3 deletions src/KDFoundation/platform/macos/macos_platform_event_loop.mm
Original file line number Diff line number Diff line change
Expand Up @@ -43,9 +43,20 @@
return [NSDate distantPast];
return [NSDate dateWithTimeIntervalSinceNow:static_cast<double>(timeout) / 1000.0];
}();
NSEvent *event = [NSApp nextEventMatchingMask:NSEventMaskAny untilDate:expiration inMode:NSDefaultRunLoopMode dequeue:YES];
if (event)
[NSApp sendEvent:event];
int round = 0;
// avoid starving the event loop by limiting the number of rounds
while (round < 5) {
NSEvent *event = [NSApp nextEventMatchingMask:NSEventMaskAny untilDate:expiration inMode:NSDefaultRunLoopMode dequeue:YES];
if (event)
[NSApp sendEvent:event];
else
break;
// once we've processed the first round of events, we set the expiration to distant past to ensure we don't block further.
if (round == 0) {
expiration = [NSDate distantPast];
}
++round;
}
}
}

Expand Down
Loading