Hi Manolo,
I'm not sure I follow what you are doing with the Fl_Offscreen here, so you may be doing something too clever for me to understand!
Anyway, what I have in my code looks like this...
------------- code -------------------
// Set icon for window before we show it (MacOS uses app bundle for icon...)
#ifdef WIN32
main_window->icon((char *)LoadIcon(fl_display, MAKEINTRESOURCE(IDI_ICON)));
#elif !defined(__APPLE__)
fl_open_display(); // Make sure the display is available before we try and change it!
Pixmap pixmap, mask; // create pixmaps to hold the icon image and its mask
// load the XPM and prepare the mask
XpmCreatePixmapFromData(fl_display, DefaultRootWindow(fl_display), (char**)fn5x64_xpm_data, &pixmap, &mask, 0);
// assign to the fltk main window
// note that the fltk icon handling DOES NOT honour transparency,
// so we fix that AFTER the window is shown (see below)
main_window->icon((char*)pixmap);
#endif // WIN32
main_window->show();
#ifdef __APPLE__
fl_mac_set_about((Fl_Callback*)cb_about_box, NULL);
fl_open_callback(osx_open_callback);
#endif
#ifdef WIN32
// The fltk icon code above only loads the default icon.
// Here, once the window is shown, we can assign
// additional icons, just to make things a bit nicer.
{
HANDLE bigicon = LoadImage(GetModuleHandle(0), MAKEINTRESOURCE(IDI_ICON), IMAGE_ICON, 32, 32, 0);
SendMessage(fl_xid(main_window), WM_SETICON, ICON_BIG, (LPARAM)bigicon);
HANDLE smallicon = LoadImage(GetModuleHandle(0), MAKEINTRESOURCE(IDI_ICON), IMAGE_ICON, 16, 16, 0);
SendMessage(fl_xid(main_window), WM_SETICON, ICON_SMALL, (LPARAM)smallicon);
}
#elif !defined(__APPLE__) /* Not Apple and not win32 - assume Xlib */
// The fltk icon code doesn't handle XPM transparency well, work around that here...
{
// read in the current window hints, then modify them to allow icon transparency
XWMHints* hints = XGetWMHints(fl_display, fl_xid(main_window));
hints->flags |= IconMaskHint; // ensure transparency mask is enabled for the XPM icon
hints->icon_mask = mask; // set the transparency mask
XSetWMHints(fl_display, fl_xid(main_window), hints);
XFree(hints);
}
#endif // !WIN32
------------- end code -------------------
So the crux for me is using XpmCreatePixmapFromData() where you seem to have opted for just using
XCreatePixmap() instead.
Or am I missing something subtle here?
Anyway, once the window is shown, I then adjust the transparency hints and etc. for the X11 case (and in the Win32 case I load some extra icon sizes too.)
The Apple case of course just gets its icons from the bundle anyway.
> Is this correct?
It is not quite what I do, but I guess if it works, it must be correct!
> Is there a simpler way to achieve that?
I think my way is maybe simpler? Not sure... matter of opinion I guess!
> Shouldn't FLTK give some support for that?
Tricky... Every platform is different, and while Win32 and X11 might be wrapped up to look similar, I don't know if we can sort the Apple icon other than via the bundle? You would know about that better than anyone else here I'd guess?
Note that the ThinkLinc guys have posted a few patches in the STR's to try and improve the icon handling. There may be some scope for merging their patches and improving things from there?