Knowledge Base

Preserving for the future: Shell scripts, AoC, and more

X11 change application titlebar and icon in window manager panel

If you are trying to change the listing of a running application in the window list, regardless if you're running XFCE or Cinnamon or another display manager, you might want to go down the same line of research I did. In an upcoming article, I will talk exactly about how I run a game in DOSBox with a wrapping shell script and batch file. But today, this article is about how I rename the window and change its icon. First, I run the application and I know what the titlebar looks like. I have to learn the window ID to set the icon. I set the window title to the preferred name, and then use that window name to search and then execute a series of commands, which change the class and redraws the window so the panel learns the correct name.

tid="$( xwininfo -root -children -all | grep -iE "dosbox.*STARTREK" | awk '{print $1}' )"
echo "modifying id ${tid}"
xseticon -id "${tid}" "${ICONFILE}"
xdotool set_window --name "STARTREK" "${tid}"
xdotool search --name "STARTREK" set_window --classname "STARTREK" --class "STARTREK" windowunmap windowmap

I researched on the Internet to discover how to change the application icon. I had to compile a nifty little tool written in C (xseticon), so I bundled it into an rpm. But it does exactly as the description says. Changing what appears on my Cinnamon panel was a different story, however. I eventually remembered using xdotool for something in the past, and decided to read its man page. After a lot of experimentation, I got the classname and class adjusted. But it still didn't do any good. So I finally tried the windowunmap command, which was recommended after doing some other change. And then I had to hurriedly windowmap it again, so I could see the window. It doesn't minimize the application; it removed it from the panel and display entirely, even though the process was still running. After the windowmap, it showed the custom icon, and the exact title I wanted! I learned how to chain the commands together into fewer invocations.

References

Web links

link to xseticon https://unix.stackexchange.com/questions/179174/change-icon- for-an-application-form-command-line compiling xseticon https://forum.xfce.org/viewtopic.php?id=11116 xseticon source http://www.leonerd.org.uk/code/xseticon/ rpm spec https://gitlab.com/bgstack15/stackrpms/tree/master/xseticon xseticon rpm in copr https://copr.fedorainfracloud.org/coprs/bgstack15/stackrpms/package/xseticon/

Further reading

https://stackoverflow.com/questions/36650865/set-wm-class-with-wnck-xprop-or- something-else

Internet searches

xprop change icon of running application

Man pages

xdotool(1)

Comments