Index: doc/wm.n ================================================================== --- doc/wm.n +++ doc/wm.n @@ -486,11 +486,18 @@ On X, the images are arranged into the _NET_WM_ICON X property, which most modern window managers support. A \fBwm iconbitmap\fR may exist simultaneously. It is recommended to use not more than 2 icons, placing the larger icon first. .PP -On Macintosh, this currently does nothing. +On Macintosh, the first image called is loaded into an OSX-native icon +format, and becomes the application icon in dialogs, the Dock, and +other contexts. At present images loaded from PNG format lose their +alpha channel, but GIF format preserves its alpha/transparency. At the +script level the command will accept only the first image passed in the +parameters as support for multiple sizes/resolutions on macOS is outside Tk's +scope. Developers should use the largest icon they can support +(preferably 512 pixels) to ensure smooth rendering on the Mac. .RE .TP \fBwm iconposition \fIwindow\fR ?\fIx y\fR? . If \fIx\fR and \fIy\fR are specified, they are passed to the window Index: macosx/tkMacOSXWm.c ================================================================== --- macosx/tkMacOSXWm.c +++ macosx/tkMacOSXWm.c @@ -2334,71 +2334,66 @@ *---------------------------------------------------------------------- * * WmIconphotoCmd -- * * This procedure is invoked to process the "wm iconphoto" Tcl command. - * See the user documentation for details on what it does. Not yet - * implemented for OS X. + * See the user documentation for details on what it does. * * Results: * A standard Tcl result. * * Side effects: * See the user documentation. * *---------------------------------------------------------------------- */ + static int WmIconphotoCmd( Tk_Window tkwin, /* Main window of the application. */ TkWindow *winPtr, /* Toplevel to work with */ Tcl_Interp *interp, /* Current interpreter. */ int objc, /* Number of arguments. */ Tcl_Obj *const objv[]) /* Argument objects. */ { - Tk_PhotoHandle photo; + + Tk_Image tk_icon; int i, width, height, isDefault = 0; if (objc < 4) { Tcl_WrongNumArgs(interp, 2, objv, - "window ?-default? image1 ?image2 ...?"); + "window ?-default? image1 ?image2 ...?"); return TCL_ERROR; } + if (strcmp(Tcl_GetString(objv[3]), "-default") == 0) { isDefault = 1; if (objc == 4) { Tcl_WrongNumArgs(interp, 2, objv, - "window ?-default? image1 ?image2 ...?"); + "window ?-default? image1 ?image2 ...?"); return TCL_ERROR; } } - /* - * Iterate over all images to retrieve their sizes, in order to allocate a - * buffer large enough to hold all images. - */ - - for (i = 3 + isDefault; i < objc; i++) { - photo = Tk_FindPhoto(interp, Tcl_GetString(objv[i])); - if (photo == NULL) { - Tcl_SetObjResult(interp, Tcl_ObjPrintf( - "can't use \"%s\" as iconphoto: not a photo image", - Tcl_GetString(objv[i]))); - Tcl_SetErrorCode(interp, "TK", "WM", "ICONPHOTO", "PHOTO", NULL); - return TCL_ERROR; - } - Tk_PhotoGetSize(photo, &width, &height); - } - - /* - * TODO: This requires implementation for OS X, but we silently return for - * now. - */ - + char *icon; + if (strcmp(Tcl_GetString(objv[3]), "-default") == 0) { + icon = Tcl_GetString(objv[4]); + } else { + icon = Tcl_GetString(objv[3]); + } + + tk_icon = Tk_GetImage(interp, winPtr, icon, NULL, NULL); + Tk_SizeOfImage(tk_icon, &width, &height); + + NSImage *newIcon; + newIcon = TkMacOSXGetNSImageWithTkImage(winPtr->display, tk_icon, width, height); + [NSApp setApplicationIconImage: newIcon]; + + Tk_FreeImage(tk_icon); return TCL_OK; -} - +} + /* *---------------------------------------------------------------------- * * WmIconpositionCmd -- *