Tk Source Code

View Ticket
Login
Ticket UUID: 13ac26b35dc55f7c37f70b39d59d7ef3e63017c8
Title: wm iconbitmap does not correctly set the icon pixmap hint on macOS
Type: Bug Version: 8.6, 9.0
Submitter: serhiy.storchaka Created on: 2024-12-28 18:50:54
Subsystem: 66. Aqua Window Operations Assigned To: fvogel
Priority: 5 Medium Severity: Minor
Status: Closed Last Modified: 2025-01-03 23:40:08
Resolution: Fixed Closed By: jan.nijtmans
    Closed on: 2025-01-03 23:40:08
Description:

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.

User Comments: jan.nijtmans added on 2025-01-03 23:40:08:

Now backported to 8.7 and 8.6 as well


fvogel added on 2025-01-03 20:14:34:
Merged in trunk. Thanks!

fvogel added on 2025-01-01 12:01:27:

Many thanks for the report and fir the fix, which I believe is correct. I have committed it in a bugfix branch. The constraints on the corresponding tests wm-iconbitmap-1.4 and wm-iconbitmap-2.1 that I had introduced with ticket [119bb094af] have been removed as well.