From 9921e398aa58951793b069bfa27118196d968527 Mon Sep 17 00:00:00 2001 From: Greg Lucas Date: Tue, 16 Aug 2022 08:14:51 -0600 Subject: [PATCH] FIX: macosx flush_events should process all events --- src/_macosx.m | 17 ++++++++++++++--- 1 file changed, 14 insertions(+), 3 deletions(-) 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; }