Many X applications nowadays provide nice coloured icons which are stored into the binary file directly. If the application follows the NET_WM specifications, then it is possible to retrieve the icon from the _NET_WM_ICON window property, if it is defined. Extracting the _NET_WM_ICON of an X application is therefore simply a matter of calling XGetWindowProperty with the correct arguments.
To demonstrate how this can be done in practice, I wrote a small program called xgeticon which let the user choose the window of a running X application and save the extracted icon into the file provided as argument. The program is inspired from xprop and uses the procedure explained here (dead) to retrieve and save the icon. The icon can be saved into any of the file formats supported by Imlib2; the format being automatically determined from the file extension.
The xgeticon link is broken. Where can I find it?
The link to the xgeticon code is alright. Only the link to the page which describes the approach I used is dead.
The link to the forum thread has changed as the forums have moved; it is now http://fvwmforums.org/phpBB3/viewtopic.php?f=38&t=190.
I still get a 404 error on this link:
http://mesot.swisspowered.net/site/2008/src/xgeticon/xgeticon-1.0.tar.bz2
can you please verify? I’d like to read your program.
This looks to be very useful! I’m a fan of xseticon, so this should be the perfect companion. Thank you for sharing your work.
(http://www.leonerd.org.uk/code/xseticon/)
Hello, it’s me again. I tried out both your sample program and the one mentioned by Sascha in the forum topic. They both use a memcpy that does not seem to work on 64-bit machines.
The solution is to run though the icon bitmap data, bitshifting the lower 32 bits of every “item.” Here’s an example (this would go in place of the memcpy() statement). Variable names may need changing:
for (unsigned int uY = 0; uY < uH; uY++) {
for (unsigned int uX = 0; uX > 24;
unsigned char ucR = ulData[uY * uW + uX] >> 16;
unsigned char ucG = ulData[uY * uW + uX] >> 8;
unsigned char ucB = ulData[uY * uW + uX];
dataOut[uY * uW + uX] = (ucA << 24) | (ucR << 16) | (ucG << 8) | ucB;
}
}
imlib_image_put_back_data(dataOut);
X is so poorly documented… which is why I appreciate posts like these (not to mention the original thread).
Q, I’m wondering if you could post the patched source that works on 64 bit systems. I’m trying to understand why memcpy doesn’t work and how your code fixes that.
I patched the code and updated the link.