Set Multiple values for StartupWMClass (to group under same launcher in Unity)

Same problem for me with Starcraft II launched throw playonlinux. There is first a application launcher:

  • (WM_CLASS(STRING) = "Blizzard Launcher.exe", "Wine") and then the game itself:

  • (WM_CLASS(STRING) = "SC2.exe", "Wine")

I guess that wine is setting the class with the binary executable.

I had a look in bamf code (bamf_matcher.c, insert_desktop_file_class_into_table() method):

  • There is a map that make the association between a desktop file and one and only one class,
  • The key StartupWMClass is read with g_key_file_get_string() which is not designed to return a list of strings,
  • g_key_file_get_string_list() could do that but bamf developpers did not design the framework to be able to associate multiple classes to one single desktop file.

In my case I cheat by creating 2 desktop files with same keys but StartupWMClass. This is not perfect because I still have 2 Uniy icons when in the launcher but the important thing is I know why :-).


I know this question is really old, but after going through the same problem, i think i've finally created a workaround for this, and decided to share with anyone having this issue:

As we can't set multiple WMClasses for a single .desktop file, why don't set all the windows to a single WMClass?

We can do something like this (Obviously, replace Window 1, Window 2 and potatoes with your windows names and desired WMClass):

xprop -name "Window 1" -f WM_CLASS 8s -set WM_CLASS "potatoes"

xprop -name "Window 2" -f WM_CLASS 8s -set WM_CLASS "potatoes"

And on the .desktop file we can do this: StartupWMClass=potatoes

Tadam! All windows are grouped now.
But hey, are we doing this manually every time the program opens up? Of course not.

We can just go and make a bash script that automagically does that every half second:

while true
do
    xprop -name "Window 1" -f WM_CLASS 8s -set WM_CLASS "potatoes"
    xprop -name "Window 2" -f WM_CLASS 8s -set WM_CLASS "potatoes"
    sleep 0.5
done

And finally, set the .sh we created to run every time the OS starts up: Screenshot

Hope my answer is helpful to anyone browsing this question.