This is a follow-up to thread219-1225348. I did some more digging and have finally gotten somewhere.
The task was in trying to figure out how to make the window icon of a Tk app have transparency in it. Using a GIF, PNG, or XPM file with transparent pixels doesn't work--the transparent parts just get filled in with black (inconsistently; oftentimes there will be small speckles of transparent pixels among the black ones).
On Win32, Tk windows have a default icon of the letters "Tk" with red text, and the rest of the icon is transparent. On Linux, the default icon is that of a generic application icon (i.e. an icon of a white box with a title bar of sorts).
I used to think that maybe XPM files were the key to having transparent window icons, but XPM files with explicit transparency pixels set gave the same effect that GIF and PNG did (black pixels). At any rate, on Linux I copied the Tk.xpm file from Tk's folder (the one I thought Tk was using as its default icon on Windows) and had my test script explicitly use that icon.
The XPM file itself has a teal background and red text, and the same was the result of my window's icon. So, the possibility of teal being a special reserved color was out of the question.
I did some more Googling and discovered that through the use of bitmaps you can specify an "icon mask". I tested it with a built-in bitmap: questhead.
This would set the icon to be the built-in bitmap questhead. The bitmap itself was white but the background remained black. However, add the "iconmask" method, and:
Voila: a really transparent icon! Here's it again using the Clearlooks theme to see the transparency better:
I then kinda crossed the two, and combined the XPM of the Tk icon with the built-in bitmap called 'Tk':
The result: on Linux, I got the window icon to look just like the default icon on Windows: red Tk letters on a transparent background.
So, I've finally unlocked the secret to having transparent window icons for Tk scripts. The task now is to try to figure out how to create my own custom bitmap images. I looked into that once before (well, specifically I was looking for custom cursors, but the idea is the same) and iirc it wasn't very easy to do. Specifically, while Tk has a handful of built-in bitmaps, the files containing these bitmaps is quite elusive to find. However, the existence of Tk::Bitmap leaves me hopeful.
The idea of combining a GIF, PNG, or XPM image with a bitmap to define its transparency mask is pretty fun to think about.
-------------
Cuvou.com | My personal homepage
Project Fearless | My web blog
The task was in trying to figure out how to make the window icon of a Tk app have transparency in it. Using a GIF, PNG, or XPM file with transparent pixels doesn't work--the transparent parts just get filled in with black (inconsistently; oftentimes there will be small speckles of transparent pixels among the black ones).
On Win32, Tk windows have a default icon of the letters "Tk" with red text, and the rest of the icon is transparent. On Linux, the default icon is that of a generic application icon (i.e. an icon of a white box with a title bar of sorts).
I used to think that maybe XPM files were the key to having transparent window icons, but XPM files with explicit transparency pixels set gave the same effect that GIF and PNG did (black pixels). At any rate, on Linux I copied the Tk.xpm file from Tk's folder (the one I thought Tk was using as its default icon on Windows) and had my test script explicitly use that icon.
Code:
use Tk;
my $mw = MainWindow->new (
-title => 'Test',
);
my $icon = $mw->Photo (
-file => 'Tk.xpm',
-format => 'xpm',
);
$mw->Icon (-image => $icon);
MainLoop;

The XPM file itself has a teal background and red text, and the same was the result of my window's icon. So, the possibility of teal being a special reserved color was out of the question.
I did some more Googling and discovered that through the use of bitmaps you can specify an "icon mask". I tested it with a built-in bitmap: questhead.
Code:
use Tk;
my $mw = MainWindow->new (
-title => 'Test',
);
$mw->iconbitmap ('questhead');
MainLoop;

This would set the icon to be the built-in bitmap questhead. The bitmap itself was white but the background remained black. However, add the "iconmask" method, and:
Code:
use Tk;
my $mw = MainWindow->new (
-title => 'Test',
);
$mw->iconbitmap ('questhead');
$mw->iconmask ('questhead');
MainLoop;

Voila: a really transparent icon! Here's it again using the Clearlooks theme to see the transparency better:

I then kinda crossed the two, and combined the XPM of the Tk icon with the built-in bitmap called 'Tk':
Code:
use Tk;
my $mw = MainWindow->new (
-title => 'Test',
);
my $icon = $mw->Photo (
-file => 'Tk.xpm',
-format => 'xpm',
);
$mw->Icon (-image => $icon);
$mw->iconmask ('Tk');
MainLoop;
The result: on Linux, I got the window icon to look just like the default icon on Windows: red Tk letters on a transparent background.

So, I've finally unlocked the secret to having transparent window icons for Tk scripts. The task now is to try to figure out how to create my own custom bitmap images. I looked into that once before (well, specifically I was looking for custom cursors, but the idea is the same) and iirc it wasn't very easy to do. Specifically, while Tk has a handful of built-in bitmaps, the files containing these bitmaps is quite elusive to find. However, the existence of Tk::Bitmap leaves me hopeful.
The idea of combining a GIF, PNG, or XPM image with a bitmap to define its transparency mask is pretty fun to think about.
-------------
Cuvou.com | My personal homepage
Project Fearless | My web blog