Retrieving the _NET_WM_ICON

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 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.

6 thoughts on “Retrieving the _NET_WM_ICON

  1. bertrand Post author

    The link to the xgeticon code is alright. Only the link to the page which describes the approach I used is dead.

  2. Q

    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;

    X is so poorly documented… which is why I appreciate posts like these (not to mention the original thread).

Leave a Reply

Your email address will not be published. Required fields are marked *