In the nextEventMatchingMask method in macosx/tkMacOSXNotify.c, the tkDisplayIfNeeded method is applied to all windows each time there is an event by calling [NSApp inOrder:NO].

The tkDisplayIfNeeded method is the following:

@implementation NSWindow(TKNotify)
- (id) tkDisplayIfNeeded
{
    if (![self isAutodisplay]) {
       [self displayIfNeeded];
    }
    return nil;
}
@end

In the code creating the window (TkMacOSXMakeRealWindowExist in tkMacOSXWm.c), we call [window setAutodisplay:NO], so [self isAutodisplay] is false, and tkDisplayIfNeeded calls [self displayIfNeeded]. Thus, in each window auto-displaying is switched off, but then on each pass through the event loop we ask the window to display itself if needed anyway.

This suggests that this piece of code may not be needed, and moreover the Cocoa documentation seems to discourage the use of [NSWindow displayIfNeeded]. According to the discussion on the MacTcl mailing list starting on January 18, 2014, the [window setAutodisplay:NO] line is needed to address some issues with drawing Tk windows under Cocoa, though the details are no longer readily available.

The attached patch removed the [window setAutodisplay:NO] line from tkMacOSXWm.c (by default, windows do auto-display), and removes the tkDisplayIfNeeded code. This seems to work perfectly fine; after applying this patch, the Tk test suite actually reports one test failure less. However, if it turns out that removing [window setAutodisplay:NO] causes some issues with Cocoa to reappear, then it provides us a chance to investigate the bug in detail and find an appropriate solution for it (preferably without having to tinker with the innards of the event loop).

While this patch helps to keep the Tcl/Tk code clean, it is particularly relevant for people who are running Tcl/Tk using an external event loop (using the notifier approach, as explained at see the mailing list for details).