diff --git a/src/_macosx.m b/src/_macosx.m index 0d30a64ad06d..9e097ff0dc31 100755 --- a/src/_macosx.m +++ b/src/_macosx.m @@ -391,9 +391,20 @@ static CGFloat _get_device_scale(CGContextRef cr) static PyObject* FigureCanvas_flush_events(FigureCanvas* self) { - // We need to allow the runloop to run very briefly - // to allow the view to be displayed when used in a fast updating animation - [[NSRunLoop currentRunLoop] runUntilDate:[NSDate dateWithTimeIntervalSinceNow:0.0]]; + // We run the app, matching any events that are waiting in the queue + // to process, breaking out of the loop when no events remain and + // displaying the canvas if needed. + NSEvent *event; + while (true) { + event = [NSApp nextEventMatchingMask: NSEventMaskAny + untilDate: [NSDate distantPast] + inMode: NSDefaultRunLoopMode + dequeue: YES]; + if (!event) { + break; + } + [NSApp sendEvent:event]; + } [self->view displayIfNeeded]; Py_RETURN_NONE; }