Duplicate application icons in Ubuntu dock upon launch

15,500

Solution 1

You need to add a proper StartupWMClass line to the .desktop launcher corresponding to the application (refer to this). Follow these steps:

  1. Open Files and go to your /usr/share/applications folder. Look for the "Nightly" file (i.e. the launcher for the application you want to fix) and copy it.
  2. Paste the file in ~/.local/share/applications. It should look like a file with the name <filename>.desktop.
  3. Right click on this .desktop file and open with Text Editor.
  4. Launch "Nightly" (i.e. the application you want to fix) from "Activities".
  5. Run xprop WM_CLASS in Terminal.
  6. Place the cursor over the opened "Nightly" window. The cursor should turn into a crosshair already. Click. You should get a WM_CLASS string for "Nightly" in Terminal.
  7. In the .desktop file opened in Text Editor add the following line

    StartupWMClass=OBTAINED-VALUE
    

    In place of OBTAINED-VALUE put a value you got from step 6 without any quotes.

  8. Save the .desktop file.

Solution 2

Ubuntu 20.04 on Wayland

  1. Press Alt + F2
  2. Type "lg" and hit Enter (Looking Glass)
  3. Click on the "Windows" tab.
  4. You should see the titles of all your windows. Below each one you will find a wmclass property. Write down or copy the value you see.
  5. Open up the .desktop config file corresponding to your application. It should be in the ~/.local/share/applications/ folder.
  6. On a new line add StartupWMClass=VALUE_FROM_ABOVE

In my case for Firefox it was "Firefox Developer Edition" and I had to add the line below to my .desktop file:

StartupWMClass=Firefox Developer Edition

Solution 3

related to :

Kile icon buggy in left (launcher) bar (ubuntu 18.04)

On ubuntu 18.04

  • open the file : org.kde.kile.desktop
  • at : /usr/share/applications
  • add this line at the end of file : StartupWMClass=kile
  • press ALT+F2, r

It works for me

Solution 4

In my case, I followed @Chris Hayes, method of finding the WMClass and update the file, see below for an example. I referred other *.desktop files in /usr/share/applications and found that Ubuntu 20.04 is using "StartupWMClass" as the variable and NOT "WMClass". I could not find the Icon for this application so I had to download from the internet a jpeg file icon from Google Image search, save it in the path and assign to the variable "Icon". Please note, I believe this field "StartupWMClass" is case sensitive

[Desktop Entry]
Name=PDFStudioViewer2020
Comment=View pdf documents
Keywords=pdf;ppdf;
StartupNotify=true
Terminal=false
Type=Application
Categories=Application;Office;Viewer;X-Red-Hat-Base;
MimeType=application/pdf;application/ppdf;
Icon=/opt/pdfstudioviewer2020/pdfstudio_internet_icon.jpeg
Exec=/opt/pdfstudioviewer2020/pdfstudioviewer2020 %F
StartupWMClass=PDF Studio Viewer

Solution 5

In my case with Adobe Reader 9 on Ubuntu 20.04, the function StartupWMClass=Acroread works instead of wmclass=Acroread

Share:
15,500

Related videos on Youtube

Chantz Garrett
Author by

Chantz Garrett

Updated on September 18, 2022

Comments

  • Chantz Garrett
    Chantz Garrett over 1 year

    I'm using Ubuntu 17.10 with GNOME shell and Numix-Circle icon theme.

    When I hover over the Numix icon for Nightly Web Browser, which is pinned to the dock I get the title "Nightly Web Browser".

    enter image description here

    But when I launch the program, another icon pops up at the bottom, with the name "Nightly".

    enter image description here

  • d4nyll
    d4nyll over 6 years
    I am trying to do the same with PyCharm. Got "sun-awt-X11-XFramePeer", "jetbrains-pycharm-ce" as the output for step 6. I used StartupWMClass=jetbrains-pycharm-ce and it works.
  • Aleksey Deryagin
    Aleksey Deryagin almost 6 years
    9. Rename .desktop file to OBTAINED-VALUE.desktop (e.g. jetbrains-phpstorm.desktop instead phpstorm.desktop), works in Ubuntu 18.04
  • marts
    marts over 5 years
    Thank you for the answer. It would be really nice to have an explanation of what happens. I don't want to blindly follow some instructions. What is going on and what does the fix do? Would be great if someone could help out.
  • pomsky
    pomsky over 5 years
    @marts Please go through this for an explanations: askubuntu.com/questions/367396/…
  • Ansa211
    Ansa211 over 5 years
    @AlekseyDeryagin In step 6, I got WM_CLASS: not found. As the misbehaving application was kile and the name of the file org.kde.kile.desktop, I just added the line StartupWMClass=kile and it works. My wild guess is that the last full-stop separated part of the filename (right before .desktop) should match the StartupWMClass value.
  • Jason C
    Jason C over 4 years
    Fantastic, thank you. Worked with Qt5 Creator on Ubuntu 18.04 (StartupWMClass=QtCreator).
  • Jason C
    Jason C over 4 years
    @AlekseyDeryagin My only worry there is if the .desktop file was installed by a package manager, I wonder if it could cause conflicts/confusion in future updates/uninstalls if I forget I renamed it; otoh putting a copy in .local keeps me from touching package files. Do you think that could be an issue?
  • T_S_
    T_S_ about 4 years
    As a side note, if you run gnome-shell under Wayland, xprop won't work. You can use Alt+F2 and run 'lg' (look glass). Under the Window tab, you get the WMClass. Notice it works also under X.
  • WinEunuuchs2Unix
    WinEunuuchs2Unix over 3 years
    When an Audio CD is in the external USB DVD drive, every time machine resumes from suspend another icon appears in the launcher. The solution is in this answer with the line StartupWMClass="desktop_window", "Nautilus" inserted (Ubuntu 16.04.6 LTS)
  • Jack M
    Jack M over 3 years
    This solution doesn't work on Ubuntu 20.04 with VS Code.
  • Jacky Supit
    Jacky Supit about 3 years
    it works very well on mine. @Chantz you should mark this answer as accepted if this work for you.
  • kanehekili
    kanehekili about 3 years
    I've tried all - to no avail. But if I name the desktop file exactly like the WmClass name it seems to work in Gnome. - Strange DE that
  • Prof.Chaos
    Prof.Chaos over 2 years
    Some programs (which are listed in my left navigation) are not even listed in the folder /usr/share/applications, so this 'guide' here cannot be followed for them. I suppose that in this case I am supposed to create that file on my own? Is there an easy to follow 'manual' for each required line -- similar to this one? :)
  • pomsky
    pomsky over 2 years
    @prof It depends on how you have installed those applications. If you installed the snap version of the application, then this would help: askubuntu.com/q/1199337/480481. Check this one out if you want to create the .desktop launchers by hand anyway: askubuntu.com/q/13758/480481 and askubuntu.com/q/1191962/480481
  • ThunderBird
    ThunderBird over 2 years
    Your answer as is right now needs some clarification.
  • IStranger
    IStranger over 2 years
    Thanks, man! I've fixed my sublime installed from *.tar.bz on Ubuntu 20.04. I've just added StartupWMClass=sublime_text to sublime.desktop)
  • shvahabi
    shvahabi about 2 years
    wmclass does not work for Ubuntu 21.10, instead StartupWMClass worked for me.
  • Chris Hayes
    Chris Hayes about 2 years
    Good catch @shvahabi, would you like to make that an edit on the answer? Just so stackoverflow gives you credit for the edit.
  • shvahabi
    shvahabi about 2 years
    No, since there are already answers below with same detailed explanation.
  • Chris Hayes
    Chris Hayes about 2 years
    I think "wmclass" was more likely an error I made when writing this answer. I updated the answer to avoid further confusion.
  • Neon Warge
    Neon Warge about 2 years
    So after doing all this, would it reflect immediately? Nothing happens on me on Ubuntu 21.10
  • Chris Hayes
    Chris Hayes about 2 years
    @NeonWarge I have yet to find a good way to test the validity of an application file. Unfortunately the only way seems to be search for the application, and if it doesn't show up in search, then there's something wrong with the formatting.