Take the 2-minute tour ×
Unix & Linux Stack Exchange is a question and answer site for users of Linux, FreeBSD and other Un*x-like operating systems.. It's 100% free, no registration required.

Is there a way to get the icon of a running X program? When you switch between windows, you could see the icon of it, e.g through xfwm4.

share|improve this question
    
Wait, do you want it via the shell (into a file) or via C++? –  Bobby Sep 22 '12 at 15:38
    
@Bobby whatever works .. –  warl0ck Sep 22 '12 at 23:39

1 Answer 1

up vote 6 down vote accepted

This works for me. Might not work with all applications and all window managers. The pam format is at least supported by ImageMagick, so you can view it with display and convert it to other formats if need be with convert:

xprop -notype 32c _NET_WM_ICON |
  perl -0777 -pe '@_=/\d+/g;
    printf "P7\nWIDTH %d\nHEIGHT %d\nDEPTH 4\nMAXVAL 255\nTUPLTYPE RGB_ALPHA\nENDHDR\n", splice@_,0,2;
    $_=pack "N*", @_;
    s/(.)(...)/$2$1/gs' > icon.pam

(and click on the window you want to get the icon from, see also xprop's -id option)

The idea is to use xprop to get the property as a list of 32 bit decimal integers and use perl to convert that into a graphics format (pam chosen here for simplicity though I had to reorder the bytes since _NET_WM_ICON is ARGB while pam is RGBA.

(a note about the pam format. It's a netpbm format, netpbm being a venerable Unix image manipulation toolbox. However, due to various issues, mostly licensing ones, newer netpbm versions are not packages by debian and as a result its derivatives like ubuntu as well, which means that most of the pam conversion utilities are not present there. On other systems that have newer netpbm, you can pipe the output above to pamrgbatopng to generate a png image)

share|improve this answer
    
Cool, I dumped the icon and converted it to PNG format. –  warl0ck Sep 22 '12 at 23:41

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.