Skip to content

FIX: macosx flush_events should process all events #23636

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Aug 20, 2022
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/_macosx.m
Original file line number Diff line number Diff line change
Expand Up @@ -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]
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I do not fully understand https://developer.apple.com/documentation/appkit/nsapplication/1428485-nexteventmatchingmask . It is not clear if "expiration" here means "do not wait longer than this" or "do not return any events newer than this". If it is the second, I think grabbing the current time outside of the while loop and passing it here will prevent the perpetual-motion machine I am worried about.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

See recent commit. The distantFuture discussion I think indicates the second of those. https://developer.apple.com/documentation/foundation/nsdate/1415385-distantfuture

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You can use the object returned by distantFuture as the date argument to wait indefinitely for the event to occur.

I read this as pointing to the first (it is a time out not a filter)?

inMode: NSDefaultRunLoopMode
dequeue: YES];
if (!event) {
break;
}
[NSApp sendEvent:event];
}
[self->view displayIfNeeded];
Py_RETURN_NONE;
}
Expand Down