StartupWMClass problem

I am running KVM on Ubuntu 24.04 and inside KVM, two virtual machines (Windows and Whoonix). Of course I would like to start them by clicking an icon in the left menu (sidebar).

So I did a desktop entry - one for Windows, another for Whoonix:

[Desktop Entry]
Type=Application
Name=Windows
Exec=/home/matej/.local/bin/startwindows.sh
Icon=/home/matej/.local/share/applications/windows.png
Terminal=false
Comment=Start Windows

startwindows.sh is using remote-viewer:

/usr/bin/virsh start windows
/usr/bin/remote-viewer spice://localhost:5901

I added the icon to sidebar, so when I click it, Windows VM (or Whoonix VM for the other icon) is started.

Now, the problem is, that then in the sidebar menu Remote Viewer’s icon appears (below, as running app).

I would like, that the “windows” icon in sidebar would be indicated as running. So I added StartupWMClass to .desktop file:

StartupWMClass=remote-viewer

I tried to use xprop to get the StartupWMClass name, but it did not detect Remote Viewer’s window, so I just guessed.

While this works kinda fine, the problem is when I close the Windows VM and start Whoonix. Then the small dot indicating which app is active (running) appears at “windows” icon, not “whoonix’”.

So, how to solve this?

P. S. I hope I explained the problem well enough. If not understandable, I can add a picture.

If you want those to appear as distinct apps, the windows would need to have distinct WM_CLASS properties (for X11 windows) or set a distinct app id (for Wayland windows). Those are something that is set by the application creating those windows, so if the application itself does not support changing this from commandline options (which remote-viewer seemingly doesn’t), this will be difficult.

Since you mention xprop not working for those windows, are those maybe Wayland windows? You can check the window type (and the used WM_CLASS/app id) using gnome-shell looking glass in the window section. Clicking on the window title should tell you whether a window is a MetaWindowWayland (Wayland) or a MetaWindowXWayland/MetaWindowX11 (X11).

For Wayland windows you can’t externally modify what app id the application sets on its windows without modifying its source code (or some LD_PRELOAD hacks).

For X11 windows, you can use xdotool to find a window based on for example its title or some other property and change its WM_CLASS. You could add this to your script after some delay with sleep to ensure that the window has been created.

And if the application is using Wayland, you can try forcing it to fall back to X11 by unsetting the WAYLAND_DISPLAY environment variable before starting it or by setting GDK_BACKEND=x11 if it is a gtk3/gtk4 application or QT_QPA_PLATFORM=xcb if it is a Qt application.