Tk Source Code

View Ticket
Login
2026-10-06
10:00
Fix [2ef5dd8036] and [307b06cbc2]: Aqua: "pack forget" leaves window on screen check-in: e1e4cbd6 user: jan.nijtmans tags: core-9-0-branch
09:48
Fix [2ef5dd8036] and [307b06cbc2]: Aqua: "pack forget" leaves window on screen check-in: 19dc130e user: jan.nijtmans tags: trunk, main
09:46 • Closed ticket [307b06cb]: Gridded widget is not drawn in some cases (Aqua). plus 7 other changes artifact: 050d69c9 user: jan.nijtmans
2026-09-29
15:57 • Ticket [307b06cb]: 4 changes artifact: 76369357 user: serhiy.storchaka
15:57 • Ticket [2ef5dd80] Aqua: "pack forget" leaves window on screen status still Open with 4 other changes artifact: f722d65d user: serhiy.storchaka
15:28
Fix [2ef5dd8036] and [307b06cbc2]: Aqua: "pack forget" leaves window on screen. Since 9.0, unmapping a non-toplevel window no longer redrew its toplevel, so the area from which the window was removed was not redrawn and no Expose events were generated. Schedule the redraw in an idle task, as XMapWindow and XDestroyWindow do. closed check-in: 1b1c0ed6 user: serhiy.storchaka tags: aqua-unmap-redraw
2025-08-29
17:39 • Ticket [307b06cb] Gridded widget is not drawn in some cases (Aqua). status still Open with 3 other changes artifact: 47185c11 user: chrstphrchvz
2025-08-28
01:05 • Ticket [307b06cb]: 3 changes artifact: 83e50e2c user: chrstphrchvz
2025-08-13
01:56 • Ticket [307b06cb]: 3 changes artifact: f6bf1dd3 user: chrstphrchvz
2025-07-18
12:24 • New ticket [307b06cb]. artifact: 3c2fb1a7 user: SVIDevelopment

Ticket UUID: 307b06cbc2f7e7d2da6e1f4fbe270e7ab0832ad4
Title: Gridded widget is not drawn in some cases (Aqua).
Type: Bug Version: 9.0.2, 9.0.5, 9.1b1
Submitter: SVIDevelopment Created on: 2025-07-18 12:24:50
Subsystem: 49. [grid] Assigned To: jan.nijtmans
Priority: 5 Medium Severity: Minor
Status: Closed Last Modified: 2026-10-06 09:46:34
Resolution: Duplicate Closed By: jan.nijtmans
    Closed on: 2026-10-06 09:46:34
Description:
In the following script, when pressing the top button it should display the same number as the button below. However, on aqua the lower button lags behind, unless the last iteration in the loop triggers grid, not grid remove. When forcing an update by rescaling the window, the lower button shows the correct value again. The bug doees not appear without the update idletasks in updateButton.

-----------------------------------------------------------------------------

# This adjusts the counter (2 -> 1 -> 0 -> 2 -> etc), and then grids the
# button that displays that counter.
proc updateButton {} {
    global counter, buttonCnt, buttonArr

    incr ::counter $::buttonCnt
    incr ::counter -1
    set ::counter [expr {$::counter % $::buttonCnt}]
    
    for {set i 0} {$i < $::buttonCnt} {incr i} {
        if {$i == $::counter} {
            grid $::buttonArr($i)
        } else {
            grid remove $::buttonArr($i)
        }

        # This update idletasks causes the gridded button to not get shown,
        # unless the counter is $::buttonCnt - 1.
        update idletasks
    }
}

set top [toplevel .top]
tk::PlaceWindow $top
wm geometry $top 400x400

grid columnconfigure $top 0 -weight 1
grid rowconfigure $top 1 -weight 1 

set counter 0
set buttonCnt 3

set button [button $top.button \
                -textvariable ::counter \
                -command [list updateButton] \
                -fg red
           ]
grid $button -row 0 -column 0 -sticky news

for {set i 0} {$i < $buttonCnt} {incr i} {
    set buttonArr($i) [button $top.button_$i -text $i -fg blue]
    grid $buttonArr($i) -row 1 -column 0 -sticky news
}

# Update to grid the initial button, and remove the others.
updateButton

-------------------------------------------------------------------------------
User Comments: jan.nijtmans added on 2026-10-06 09:46:34:

Dup of [2ef5dd8036]

Closing


serhiy.storchaka added on 2026-09-29 15:57:06:

As found below, grid remove and other ways of unmapping a window do not redraw the container. The same issue is reported in [2ef5dd8036]. Since [fe5604ad44], XMapWindow() and XDestroyWindow() schedule the redraw in an idle task, but XUnmapWindow() does not.

Proposed fix in branch aqua-unmap-redraw: XUnmapWindow() schedules the same idle redraw. I could not test it, as I have no macOS.


chrstphrchvz added on 2025-08-29 17:39:58:

In the prototype CGImage drawing implementation, I had left a comment wondering if there was something missing from the end of XUnmapWindow() on Aqua: "Anything need to be done here instead? (Not yet aware of reasoning behind [78a3bdc4454f] i.e. why the existing approach uses addTkDirtyRect: here)".

Well, X11 documentation of XUnmapWindow() mentions that "Unmapping a window will generate Expose events on windows that were formerly obscured by it." And the lack of redrawing on Aqua indeed seems to be caused by a lack of Expose events. So something like generateExposeEvents: or maybe TkMacOSXInvalidateWindow() could be worth trying, though I am not completely certain those will not introduce other issues.


chrstphrchvz added on 2025-08-28 01:05:04:

I believe this issue is at least partly due to a simpler, more general issue: on Tk Aqua 9.0, doing pack forget/place forget/grid forget/grid remove does not cause the container widget to be redrawn, leaving behind stale drawing of the previously-contained widget. I think this issue was not apparent on Tk Aqua 8.6 due to code near the end of XUnmapWindow() (tkMacOSXSubwindows.c) which forced redrawing to occur.

In the reporter's example, when the counter is at 2, pressing the upper button causes these things to happen in order: lower button 1 is gridded, update idletasks is called, and lower button 2 is removed. So when update idletasks is called, both lower buttons 1 and 2 are gridded, and so both are redrawn; but since they are gridded in the same spot, only lower button 2 is visible since it is drawn last. When lower button 2 is then finally removed, no redrawing is done, leaving behind the stale drawing of lower button 2.


chrstphrchvz added on 2025-08-13 01:56:17:

I can reproduce this issue and its workaround on macOS with Tk Aqua 9.0, and cannot reproduce it on Windows, but I have not investigated it any further.