Tcl Source Code

Ticket Change Details
Login
Overview

Artifact ID: 658a9961acd9bcf047dafec226d8a2d52364c031
Ticket: 883155fb98a9d7a426f24cac27c71a9b353a3f7f
tkDisplayIfNeeded is unnecessary
User & Date: anonymous 2014-01-21 10:04:29
Changes

  1. assignee changed to: "nobody"
  2. closer changed to: "nobody"
  3. cmimetype changed to: "text/plain"
  4. comment changed to:
    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 makeWindowsPerform:@selector(tkDisplayIfNeeded) 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 http://www.tcl.tk/man/tcl8.5/TclLib/Notifier.htm; see the mailing list for details).
    
  5. foundin changed to: "trunk"
  6. is_private changed to: "0"
  7. login: "anonymous"
  8. priority changed to: "5 Medium"
  9. private_contact changed to: "500c9a7a4e11b3ea0441850610e04006941c0cf3"
  10. resolution changed to: "None"
  11. severity changed to: "Minor"
  12. status changed to: "Open"
  13. submitter changed to: "anonymous"
  14. subsystem changed to: "02. Event Loops"
  15. title changed to: "tkDisplayIfNeeded is unnecessary"
  16. type changed to: "Patch"