Found the answer elsewhere. The .desktop file needs to be named EXACTLY the same as the binary that's launching.
Mine was something like eclipse_ide.desktop and the binary that runs is just "eclipse". Gnome shell does not seem to like that.
So, apparently my second edit wasn't correct: the way it GNOME Shell determines application grouping isn't the one I described.
After asking on the IRC gnome-shell channel, user halfline provided me the policy for grouping applications into Dash icons:
_GTK_APPLICATION_ID property of the window matched to the desktop file id or WM_CLASS matched to the desktop file id or _NET_WM_PID matched
to the desktop file started or StartupWMClass in the desktop file
matched to WM_CLASS on the window
He also suggested that it may be possible to change firefox WM_CLASS, and he's right, as there is a --class
flag for firefox that allows to change it.
Here's an example:
$ firefox &
$ xprop WM_CLASS
WM_CLASS(STRING) = "Navigator", "Firefox"
Using that flag I get
$ firefox --class "Trello" &
$ xprop WM_CLASS
WM_CLASS(STRING) = "Navigator", "Trello"
which it just have to match the desktop file ID. Now icons are correctly grouped.
Also, note that epiphany has the support to create desktop apps, handling correctly the links with the default browser, therefore for my original purpose it is even better than firefox.
Best Answer
After spending some time looking around for the answer I finally managed to make it work.
Just edit your
spotify.desktop
file under/usr/share/applications