Tk Source Code

Ticket Change Details
Login
Overview

Artifact ID: 9cf6116e0319bb63b1c30012440babee67c8691ef8176c0e04f0d544720e34ea
Ticket: 13ac26b35dc55f7c37f70b39d59d7ef3e63017c8
wm iconbitmap does not correctly set the icon pixmap hint on macOS
User & Date: fvogel 2025-01-01 10:51:04
Changes

  1. comment changed to:
    `wm iconbitmap` does not correctly set `hints.icon_pixmap` and `hints.flags` on macOS unless the argument is an empty string. After `wm iconbitmap . hourglass`, 
    `wm iconbitmap .` returns "hourglass" on Linux and Windows, but an empty string on macOS.
    
    It looks that the `else` block is placed after wrong `if`. Other bug is that the function always returns `TCL_OK` even if `WmSetAttribute()` fails. Comparing with the code on Linux and Windows, I believe that the following patch should fix the issue:
    
    ```
    Index: macosx/tkMacOSXWm.c
    ==================================================================
    --- macosx/tkMacOSXWm.c
    +++ macosx/tkMacOSXWm.c
    @@ -2975,18 +2975,19 @@
         }
         if (!TkMacOSXHostToplevelExists(winPtr)) {
            TkMacOSXMakeRealWindowExist(winPtr);
         }
         if (WmSetAttribute(winPtr, TkMacOSXGetNSWindowForDrawable(winPtr->window), interp,
    -           WMATT_TITLEPATH, objv[3]) == TCL_OK) {
    -       if (!len) {
    -           if (wmPtr->hints.icon_pixmap != None) {
    -               Tk_FreeBitmap(winPtr->display, wmPtr->hints.icon_pixmap);
    -               wmPtr->hints.icon_pixmap = None;
    -           }
    -           wmPtr->hints.flags &= ~IconPixmapHint;
    -       }
    +           WMATT_TITLEPATH, objv[3]) != TCL_OK) {
    +       return TCL_ERROR;
    +    }
    +    if (!len) {
    +       if (wmPtr->hints.icon_pixmap != None) {
    +           Tk_FreeBitmap(winPtr->display, wmPtr->hints.icon_pixmap);
    +           wmPtr->hints.icon_pixmap = None;
    +       }
    +       wmPtr->hints.flags &= ~IconPixmapHint;
         } else {
            pixmap = Tk_GetBitmap(interp, (Tk_Window)winPtr, str);
            if (pixmap == None) {
                return TCL_ERROR;
            }
    ```
    
    I encountered this bug after adding tests for Tkinter (<https://github.com/python/cpython/pull/128015>).
    
    This bug was already known (ticket [](119bb094afd86d959039)), but it was closed without proper fix. So you need also to restore the skipped tests on macOS.
    
  2. login: "fvogel"
  3. mimetype: "text/plain"