summaryrefslogtreecommitdiffstats
path: root/macosx/tkMacOSXEvent.c
diff options
context:
space:
mode:
authorculler <culler>2018-11-05 16:03:56 (GMT)
committerculler <culler>2018-11-05 16:03:56 (GMT)
commit31f82fb5b5ae52d1893a87e7a5a83c0e9eae2f58 (patch)
tree55a223472c4e168f0c0b29d3aa178a70c75b629f /macosx/tkMacOSXEvent.c
parentb236ac696bc5e78bb9aa87505d01d388b1b8cb07 (diff)
downloadtk-31f82fb5b5ae52d1893a87e7a5a83c0e9eae2f58.zip
tk-31f82fb5b5ae52d1893a87e7a5a83c0e9eae2f58.tar.gz
tk-31f82fb5b5ae52d1893a87e7a5a83c0e9eae2f58.tar.bz2
Make XSync, and hence update, be synchronous so test results are consistent. Fix duplicate
reports of calls to the test image displayProc.
Diffstat (limited to 'macosx/tkMacOSXEvent.c')
-rw-r--r--macosx/tkMacOSXEvent.c25
1 files changed, 19 insertions, 6 deletions
diff --git a/macosx/tkMacOSXEvent.c b/macosx/tkMacOSXEvent.c
index 25c0bea..36167cb 100644
--- a/macosx/tkMacOSXEvent.c
+++ b/macosx/tkMacOSXEvent.c
@@ -112,11 +112,16 @@ enum {
*
* TkMacOSXFlushWindows --
*
- * This routine is a stub called by XSync, which is called during
- * the Tk update command. It calls displayIfNeeded on all visible
- * windows. This is necessary in order to insure that update will
- * run all of the display procedures which have been registered as
- * idle tasks. The test suite assumes that this is the case.
+ * This routine is a stub called by XSync, which is called during the Tk
+ * update command. The language specification does not require that the
+ * update command be synchronous but many of the tests assume that is the
+ * case. It is not naturally the case on macOS since many idle tasks are
+ * run inside of the drawRect method of a window's contentView, and that
+ * method will not be called until after this function returns. To make
+ * the tests work, we attempt to force this to be synchronous by waiting
+ * until drawRect has been called for each window. The mechanism we use
+ * for this is to have drawRect post an ApplicationDefined NSEvent on the
+ * AppKit event queue when it finishes drawing, and wait for it here.
*
* Results:
* None.
@@ -131,11 +136,19 @@ enum {
MODULE_SCOPE void
TkMacOSXFlushWindows(void)
{
+ NSModalSession modalSession = TkMacOSXGetModalSession();
+ NSEvent *syncEvent;
NSArray *macWindows = [NSApp orderedWindows];
-
for (NSWindow *w in macWindows) {
if (TkMacOSXGetXWindow(w)) {
[w displayIfNeeded];
+ syncEvent = [NSApp
+ nextEventMatchingMask:NSApplicationDefinedEventMask
+ untilDate:[NSDate distantPast]
+ inMode:GetRunLoopMode(modalSession)
+ dequeue:YES];
+ [NSApp discardEventsMatchingMask:NSApplicationDefinedEventMask
+ beforeEvent:syncEvent];
}
}